1 <?php
2 /**
3 * Class file.
4 *
5 * @author Tobias Munk <schmunk@usrbin.de>
6 * @link http://www.phundament.com/
7 * @copyright Copyright © 2005-2011 diemeisterei GmbH
8 * @license http://www.phundament.com/license/
9 */
10
11 /**
12 * This is the model class for table "p3_widgets".
13 *
14 * The followings are the available columns in table 'p3_widgets':
15 * @property integer $id
16 * @property string $alias
17 * @property string $properties
18 * @property integer $rank
19 * @property string $containerId
20 * @property string $moduleId
21 * @property string $controllerId
22 * @property string $actionName
23 * @property string $requestParam
24 * @property string $sessionParam
25
26 * @author Tobias Munk <schmunk@usrbin.de>
27 * @package p3widgets.models
28 * @since 3.0.1
29 */
30 class Widget extends CActiveRecord
31 {
32 /**
33 * Returns the static model of the specified AR class.
34 * @return Widgets the static model class
35 */
36 public static function model($className=__CLASS__)
37 {
38 return parent::model($className);
39 }
40
41 /**
42 * @return string the associated database table name
43 */
44 public function tableName()
45 {
46 return 'p3_widget';
47 }
48
49 /**
50 * @return array validation rules for model attributes.
51 */
52 public function rules()
53 {
54 // NOTE: you should only define rules for those attributes that
55 // will receive user inputs.
56 return array(
57 array('alias, containerId, rank', 'required'),
58 array('rank', 'numerical', 'integerOnly'=>true),
59 array('alias', 'length', 'max'=>255),
60 array('containerId', 'length', 'max'=>64),
61 array('moduleId, controllerId, actionName, requestParam, sessionParam', 'length', 'max'=>128),
62 #array('containerId, moduleId, controllerId, actionName, requestParam, sessionParam', 'default', 'setOnEmpty' => true, 'value' => null),
63 array('properties, content', 'safe'),
64 // The following rule is used by search().
65 // Please remove those attributes that should not be searched.
66 array('id, alias, properties, content, rank, containerId, moduleId, controllerId, actionName, requestParam, sessionParam', 'safe', 'on'=>'search'),
67 );
68 }
69
70 /**
71 * @return array relational rules.
72 */
73 public function relations() {
74 return array(
75 'metaData' => array(self::HAS_ONE, 'P3WidgetMeta', 'id'),
76 );
77 }
78
79 public function behaviors() {
80 return array_merge(
81 array(
82 'MetaData' => array(
83 'class' => 'P3MetaDataBehavior',
84 'metaDataRelation' => 'metaData',
85 )
86 ), parent::behaviors()
87 );
88 }
89 /**
90 * @return array customized attribute labels (name=>label)
91 */
92 public function attributeLabels()
93 {
94 return array(
95 'id' => 'ID',
96 'alias' => 'Alias',
97 'properties' => 'Properties',
98 'rank' => 'Rank',
99 'containerId' => 'Container',
100 'moduleId' => 'Module',
101 'controllerId' => 'Controller',
102 'actionName' => 'Action Name',
103 'requestParam' => 'Request Param',
104 'sessionParam' => 'Session Param',
105 );
106 }
107
108 /**
109 * Retrieves a list of models based on the current search/filter conditions.
110 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
111 */
112 public function search()
113 {
114 // Warning: Please modify the following code to remove attributes that
115 // should not be searched.
116
117 $criteria=new CDbCriteria;
118
119 $criteria->compare('id',$this->id);
120 $criteria->compare('alias',$this->alias,true);
121 $criteria->compare('properties',$this->properties,true);
122 $criteria->compare('rank',$this->rank);
123 $criteria->compare('containerId',$this->containerId,true);
124 $criteria->compare('moduleId',$this->moduleId,true);
125 $criteria->compare('controllerId',$this->controllerId,true);
126 $criteria->compare('actionName',$this->actionName,true);
127 $criteria->compare('requestParam',$this->requestParam,true);
128 $criteria->compare('sessionParam',$this->sessionParam,true);
129
130 return new CActiveDataProvider(get_class($this), array(
131 'criteria'=>$criteria,
132 ));
133 }
134 }