Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Account.php
1 <?php
2 /**
3  *
4  */
5 class Account extends CActiveRecord
6 {
7  /**
8  * Returns the static model of the specified AR class.
9  * @return CActiveRecord the static model class
10  */
11  public static function model($className = __CLASS__)
12  {
13  return parent::model($className);
14  }
15 
16  /**
17  * @return string the associated database table name
18  */
19  public function tableName()
20  {
21  return Yii::app()->getModule('user')->tableAccounts;
22  }
23 
24  public function rules()
25  {
26  return array(
27  array('service, service_id', 'required'),
28  array('user_id', 'numerical', 'integerOnly' => true),
29  array('service, service_id', 'length', 'max' => 255),
30  array('data', 'safe')
31  );
32  }
33 
34  public function relations()
35  {
36  return array(
37  'user' => array(self::HAS_ONE, 'User', array('id' => 'user_id'))
38  );
39  }
40 
41  public function afterFind()
42  {
43  $this->data = (array)unserialize($this->data);
44  return parent::afterFind();
45  }
46 
47  public function beforeSave()
48  {
49  $this->data = serialize((array)$this->data);
50  return parent::beforeSave();
51  }
52 
53  public static function create($service)
54  {
55  $account = new Account();
56  $account->attributes = array(
57  'service' => $service->serviceName,
58  'service_id' => $service->id,
59  );
60  $account->save();
61 
62  return $account;
63  }
64 }