From aa1aa84b5214a190a1c0fbf479e1f33757ec5fe4 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 30 Jul 2007 19:15:33 +0000 Subject: [PATCH] --- .../user-management-system.txt | 101 ------------------ 1 file changed, 101 deletions(-) diff --git a/manual/new/docs/en/real-world-examples/user-management-system.txt b/manual/new/docs/en/real-world-examples/user-management-system.txt index eb039cd86..8b1378917 100644 --- a/manual/new/docs/en/real-world-examples/user-management-system.txt +++ b/manual/new/docs/en/real-world-examples/user-management-system.txt @@ -1,102 +1 @@ -In the following example we make a user management system where -# Each user and group are entities -# User is an entity of type 0 -# Group is an entity of type 1 -# Each entity (user/group) has 0-1 email -# Each entity has 0-* phonenumbers -# If an entity is saved all its emails and phonenumbers are also saved -# If an entity is deleted all its emails and phonenumbers are also deleted -# When an entity is created and saved a current timestamp will be assigned to 'created' field -# When an entity is updated a current timestamp will be assigned to 'updated' field -# Entities will always be fetched in batches - - -class Entity extends Doctrine_Record -{ - public function setUp() - { - $this->ownsOne('Email', 'Entity.email_id'); - $this->ownsMany('Phonenumber', 'Phonenumber.entity_id'); - $this->setAttribute(Doctrine::ATTR_LISTENER, new EntityListener()); - } - public function setTableDefinition() - { - $this->hasColumn('name', 'string', 50); - $this->hasColumn('loginname', 'string', 20); - $this->hasColumn('password', 'string', 16); - - } -} -class Group extends Entity -{ - public function setUp() - { - parent::setUp(); - $this->hasMany('User', 'Groupuser.user_id'); - $this->setInheritanceMap(array('type'=>1)); - } -} -class User extends Entity -{ - public function setUp() - { - parent::setUp(); - $this->hasMany('Group', 'Groupuser.group_id'); - $this->setInheritanceMap(array('type'=>0)); - } -} -class Groupuser extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('group_id', 'integer'); - $this->hasColumn('user_id', 'integer'); - } -} - -class Phonenumber extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('phonenumber', 'string', 20); - $this->hasColumn('entity_id', 'integer'); - } -} -class Email extends Doctrine_Record -{ - public function setTableDefinition() - { - $this->hasColumn('address', 'string', 150, 'email|unique'); - } -} -class EntityListener extends Doctrine_EventListener -{ - public function onPreUpdate(Doctrine_Record $record) - { - $record->updated = time(); - } - public function onPreInsert(Doctrine_Record $record) - { - $record->created = time(); - } -} - -// USER MANAGEMENT SYSTEM IN ACTION: - -$manager = Doctrine_Manager::getInstance(); - -$conn = $manager->openConnection(new PDO('DSN','username','password')); - -$user = new User(); - -$user->name = 'Jack Daniels'; -$user->Email->address = 'jackdaniels@drinkmore.info'; -$user->Phonenumber[0]->phonenumber = '123 123'; -$user->Phonenumber[1]->phonenumber = '133 133'; -$user->save(); - -$user->Group[0]->name = 'beer lovers'; -$user->Group[0]->Email->address = 'beerlovers@drinkmore.info'; -$user->Group[0]->save(); -