Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
UserAnswer.php
1 <?php
2 
3 /**
4  * Gentics Portal.Node PHP
5  * Author & Copyright (c) by Gentics Software GmbH
6  * sales@gentics.com
7  * http://www.gentics.com
8  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
9  * You must not use this software without a valid license agreement.
10  *
11  * Represents single user answer to the question
12  *
13  **/
14 class UserAnswer extends CActiveRecord
15 {
16 
17  /**
18  * Returns the static model of the specified AR class.
19  *
20  * @param string $className active record class name
21  *
22  * @return array|CActiveRecord
23  */
24  public static function model($className = __CLASS__)
25  {
26  return parent::model($className);
27  }
28 
29  /**
30  * Returns the name of the associated database table.
31  * By default this method returns the class name as the table name.
32  * You may override this method if the table is not named after this convention.
33  *
34  * @return string the table name
35  */
36  public function tableName()
37  {
38  return '{{user_answer}}';
39  }
40 
41  /**
42  * Returns the validation rules for attributes.
43  *
44  * @return array
45  */
46  public function rules()
47  {
48  return array(
49  array('created', 'default', 'value' => AppHelper::mysqlDate()),
50  array('answer_id, user_id','required'),
51  array('answer_id', 'numerical', 'integerOnly' => true),
52  array('user_id', 'length', 'max'=>255),
53  array('additional', 'safe'),
54  array('created', 'type', 'type'=>'datetime', 'datetimeFormat' => 'yyyy-MM-dd HH:mm:ss'),
55  array('id, question_id, text, order, created','safe', 'on'=>'search'),
56  );
57  }
58 
59 
60  public function getAttributeLabel($name)
61  {
62  return VoteModule::t(parent::getAttributeLabel($name));
63  }
64 
65  protected function beforeSave()
66  {
67  if($this->additional !== null) {
68  $this->additional = serialize($this->additional);
69  }
70  return parent::beforeSave();
71  }
72 
73  protected function afterSave()
74  {
75  if($this->additional !== null) {
76  $this->additional = unserialize($this->additional);
77  }
78  }
79 
80  protected function afterFind()
81  {
82  if($this->additional !== null) {
83  $this->additional = unserialize($this->additional);
84  }
85  }
86 }
87