Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
FGFormdata.php
1 <?php
2 
3 /**
4  * This is the model class for table "formdata".
5  *
6  * The followings are the available columns in table 'formdata':
7  * @property string $id
8  * @property string $form_id
9  * @property string $created_at
10  * @property string $referer
11  * @property string $ip
12  * @property string $json
13  */
14 class FGFormdata extends CActiveRecord
15 {
16  /**
17  * Returns the static model of the specified AR class.
18  * @param string $className active record class name.
19  * @return FGFormdata the static model class
20  */
21  public static function model($className=__CLASS__)
22  {
23  return parent::model($className);
24  }
25 
26  /**
27  * @return string the associated database table name
28  */
29  public function tableName()
30  {
31  return 'formdata';
32  }
33 
34  /**
35  * @return array validation rules for model attributes.
36  */
37  public function rules()
38  {
39  // NOTE: you should only define rules for those attributes that
40  // will receive user inputs.
41  return array(
42  array('form_id, json', 'required'),
43  array('referer', 'length', 'max'=>2083),
44  array('ip', 'length', 'max'=>15),
45  array('created_at', 'safe'),
46  // The following rule is used by search().
47  // Please remove those attributes that should not be searched.
48  array('id, form_id, created_at, referer, ip, json', 'safe', 'on'=>'search'),
49  );
50  }
51 
52  /**
53  * @return array relational rules.
54  */
55  public function relations()
56  {
57  // NOTE: you may need to adjust the relation name and the related
58  // class name for the relations automatically generated below.
59  return array(
60  'form' => array(self::BELONGS_TO, 'FGForms', 'form_id')
61  );
62  }
63 
64  public function scopes()
65  {
66  return array(
67  );
68  }
69 
70  public function defaultScope()
71  {
72  return array('order'=>'id DESC');
73  }
74 
75  /**
76  * @return array customized attribute labels (name=>label)
77  */
78  public function attributeLabels()
79  {
80  return array(
81  'id' => 'ID',
82  'form_id' => 'Form',
83  'created_at' => 'Created At',
84  'referer' => 'Referer',
85  'ip' => 'Ip',
86  'json' => 'Json',
87  );
88  }
89 
90  public function JSONToArray()
91  {
92  return CJSON::decode($this->json);
93  }
94 
95  public function getDisplayData()
96  {
97  $data = $this->JSONToArray();
98  $display = array();
99  foreach($data as $name => $value) {
100  /* Temporary cap */
101  $display[$name] = is_array($value)? implode("<br />", $value) : CHtml::encode($value);
102  }
103  return $display;
104  }
105 
106  /**
107  * Retrieves a list of models based on the current search/filter conditions.
108  * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
109  */
110  public function search()
111  {
112  // Warning: Please modify the following code to remove attributes that
113  // should not be searched.
114 
115  $criteria=new CDbCriteria;
116 
117  $criteria->compare('id',$this->id,true);
118  $criteria->compare('form_id',$this->form_id,true);
119  $criteria->compare('created_at',$this->created_at,true);
120  $criteria->compare('referer',$this->referer,true);
121  $criteria->compare('ip',$this->ip,true);
122  $criteria->compare('json',$this->json,true);
123 
124  return new CActiveDataProvider($this, array(
125  'criteria'=>$criteria,
126  ));
127  }
128 }