Advertisement
Guest User

Untitled

a guest
Jan 20th, 2011
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.40 KB | None | 0 0
  1. //MODEL USER
  2. <?php
  3. // system/application/models/user.php
  4. class User extends Doctrine_Record {
  5.  
  6.     public function setTableDefinition() {
  7.         $this->hasColumn('username', 'string', 255, array('unique' => 'true'));
  8.         $this->hasColumn('password', 'string', 255);
  9.         $this->hasColumn('email', 'string', 255, array('unique' => 'true'));
  10.         $this->hasColumn('privilege', 'enum', null,
  11.             array('values' => array('admin', 'ceo', 'director', 'member'),
  12.                   'default' => 'member')
  13.         );
  14.     }
  15.     public function setUp() {
  16.         $this->setTableName('user');
  17.         $this->actAs('Timestampable');
  18.         $this->hasMutator('password', '_encrypt_password');
  19.         $this->hasMany('Api as api_keys', array(
  20.                 'local' => 'id',
  21.                 'foreign' => 'api_user_id'
  22.             )
  23.         );
  24.     }
  25.     protected function _encrypt_password($value) {
  26.         $salt = '#*seCrEt!@-*%';
  27.         $this->_set('password', md5($salt . $value));
  28.     }
  29.     public function getInfo($username) {
  30.         $q = Doctrine_Query::create()
  31.             ->from('User u')
  32.             ->leftJoin('u.Api a')
  33.             ->leftJoin('u.Characters c')
  34.             ->where('u.username = ?', $username);
  35.  
  36.         return $q->fetchOne();
  37.     }
  38. }
  39.  
  40. //MODEL API
  41. <?php
  42. class Api extends Doctrine_Record {
  43.  
  44.     public function setTableDefinition() {
  45.         $this->hasColumn('api_id', 'integer', 4, array('unique' => 'true'));
  46.         $this->hasColumn('api_key', 'string', 255, array('unique' => 'true'));
  47.         $this->hasColumn('api_user_id', 'integer', 4);
  48.     }
  49.     public function setUp() {
  50.         $this->setTableName('api');
  51.         $this->actAs('Timestampable');
  52.         $this->hasOne('User as user', array(
  53.                 'local' => 'api_user_id',
  54.                 'foreign' => 'id'
  55.             )
  56.         );
  57.         $this->hasMany('Characters as characters', array(
  58.                 'local' => 'api_id',
  59.                 'foreign' => 'api_characters_id'
  60.             )
  61.         );
  62.     }
  63. }
  64.  
  65. //MODEL CHARACTERS
  66. <?php
  67. class Characters extends Doctrine_Record {
  68.  
  69.     public function setTableDefinition() {
  70.         $this->hasColumn('characters_id', 'integer', 4, array('unique' => 'true'));
  71.         $this->hasColumn('activate', 'integer', 1);
  72.         $this->hasColumn('api_characters_id', 'integer', 4);
  73.     }
  74.     public function setUp() {
  75.         $this->setTableName('characters');
  76.         $this->actAs('Timestampable');
  77.         $this->hasOne('Api as api_keys', array(
  78.                 'local' => 'api_characters_id',
  79.                 'foreign' => 'api_id'
  80.             )
  81.         );
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement