2007-09-02 14:24:49 +00:00
|
|
|
<?php
|
2007-09-03 16:09:04 +00:00
|
|
|
|
|
|
|
require_once('Entity.php');
|
|
|
|
|
|
|
|
|
|
|
|
class User extends Entity
|
2007-09-02 14:24:49 +00:00
|
|
|
{
|
2008-02-03 21:29:57 +00:00
|
|
|
public static function initMetadata($class)
|
2007-09-02 14:24:49 +00:00
|
|
|
{
|
2008-02-03 21:29:57 +00:00
|
|
|
$class->hasMany('Address', array(
|
2007-09-05 04:42:02 +00:00
|
|
|
'local' => 'user_id',
|
2007-09-25 21:39:38 +00:00
|
|
|
'foreign' => 'address_id',
|
|
|
|
'refClass' => 'EntityAddress',
|
|
|
|
));
|
2008-02-03 21:29:57 +00:00
|
|
|
$class->hasMany('Address as Addresses', array(
|
2007-09-25 21:39:38 +00:00
|
|
|
'local' => 'user_id',
|
2007-09-05 04:42:02 +00:00
|
|
|
'foreign' => 'address_id',
|
|
|
|
'refClass' => 'EntityAddress',
|
|
|
|
));
|
2008-02-03 21:29:57 +00:00
|
|
|
$class->hasMany('Album', array('local' => 'id', 'foreign' => 'user_id'));
|
|
|
|
$class->hasMany('Book', array('local' => 'id', 'foreign' => 'user_id'));
|
|
|
|
$class->hasMany('Group', array(
|
2007-09-05 04:42:02 +00:00
|
|
|
'local' => 'user_id',
|
|
|
|
'foreign' => 'group_id',
|
2008-02-03 21:29:57 +00:00
|
|
|
'refClass' => 'Groupuser'
|
2008-03-26 11:10:45 +00:00
|
|
|
));
|
2007-09-02 14:24:49 +00:00
|
|
|
}
|
2007-10-21 06:23:59 +00:00
|
|
|
|
2007-09-02 14:24:49 +00:00
|
|
|
/** Custom validation */
|
|
|
|
public function validate()
|
|
|
|
{
|
|
|
|
// Allow only one name!
|
|
|
|
if ($this->name !== 'The Saint') {
|
|
|
|
$this->errorStack()->add('name', 'notTheSaint');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function validateOnInsert()
|
|
|
|
{
|
|
|
|
if ($this->password !== 'Top Secret') {
|
|
|
|
$this->errorStack()->add('password', 'pwNotTopSecret');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function validateOnUpdate()
|
|
|
|
{
|
|
|
|
if ($this->loginname !== 'Nobody') {
|
|
|
|
$this->errorStack()->add('loginname', 'notNobody');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|