Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MODEL USER
- <?php
- // system/application/models/user.php
- class User extends Doctrine_Record {
- public function setTableDefinition() {
- $this->hasColumn('username', 'string', 255, array('unique' => 'true'));
- $this->hasColumn('password', 'string', 255);
- $this->hasColumn('email', 'string', 255, array('unique' => 'true'));
- $this->hasColumn('privilege', 'enum', null,
- array('values' => array('admin', 'ceo', 'director', 'member'),
- 'default' => 'member')
- );
- }
- public function setUp() {
- $this->setTableName('user');
- $this->actAs('Timestampable');
- $this->hasMutator('password', '_encrypt_password');
- $this->hasMany('Api as api_keys', array(
- 'local' => 'id',
- 'foreign' => 'api_user_id'
- )
- );
- }
- protected function _encrypt_password($value) {
- $salt = '#*seCrEt!@-*%';
- $this->_set('password', md5($salt . $value));
- }
- public function getInfo($username) {
- $q = Doctrine_Query::create()
- ->from('User u')
- ->leftJoin('u.Api a')
- ->leftJoin('u.Characters c')
- ->where('u.username = ?', $username);
- return $q->fetchOne();
- }
- }
- //MODEL API
- <?php
- class Api extends Doctrine_Record {
- public function setTableDefinition() {
- $this->hasColumn('api_id', 'integer', 4, array('unique' => 'true'));
- $this->hasColumn('api_key', 'string', 255, array('unique' => 'true'));
- $this->hasColumn('api_user_id', 'integer', 4);
- }
- public function setUp() {
- $this->setTableName('api');
- $this->actAs('Timestampable');
- $this->hasOne('User as user', array(
- 'local' => 'api_user_id',
- 'foreign' => 'id'
- )
- );
- $this->hasMany('Characters as characters', array(
- 'local' => 'api_id',
- 'foreign' => 'api_characters_id'
- )
- );
- }
- }
- //MODEL CHARACTERS
- <?php
- class Characters extends Doctrine_Record {
- public function setTableDefinition() {
- $this->hasColumn('characters_id', 'integer', 4, array('unique' => 'true'));
- $this->hasColumn('activate', 'integer', 1);
- $this->hasColumn('api_characters_id', 'integer', 4);
- }
- public function setUp() {
- $this->setTableName('characters');
- $this->actAs('Timestampable');
- $this->hasOne('Api as api_keys', array(
- 'local' => 'api_characters_id',
- 'foreign' => 'api_id'
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement