User.php 1.54 KB
Newer Older
1
<?php
jackbravo's avatar
jackbravo committed
2 3 4

require_once('Entity.php');

5 6
// UserTable doesn't extend Doctrine_Table -> Doctrine_Connection
// won't initialize grouptable when Doctrine_Connection->getTable('User') is called
7
class UserTable extends Doctrine_Table { }
jackbravo's avatar
jackbravo committed
8 9

class User extends Entity
10 11 12 13
{
    public function setUp() 
    {
        parent::setUp();
14 15
        $this->hasMany('Address', array(
            'local' => 'user_id', 
16 17 18 19 20
            'foreign' => 'address_id',
            'refClass' => 'EntityAddress',
        ));
        $this->hasMany('Address as Addresses', array(
            'local' => 'user_id', 
21 22 23 24 25 26 27 28 29 30
            'foreign' => 'address_id',
            'refClass' => 'EntityAddress',
        ));
        $this->hasMany('Album', array('local' => 'id', 'foreign' => 'user_id'));
        $this->hasMany('Book', array('local' => 'id', 'foreign' => 'user_id'));
        $this->hasMany('Group', array(
            'local' => 'user_id', 
            'foreign' => 'group_id',
            'refClass' => 'Groupuser',
        ));
31
    }
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    /** 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');
        }
    }
}