1 | <?php |
||
13 | class Events extends CiiModel |
||
|
|||
14 | { |
||
15 | /** |
||
16 | * Adds the CTimestampBehavior to this class |
||
17 | * @return array |
||
18 | */ |
||
19 | public function behaviors() |
||
31 | |||
32 | /** |
||
33 | * Query Scoping |
||
34 | */ |
||
35 | public function scopes() |
||
36 | { |
||
37 | return array( |
||
38 | 'groupByUrl' => array( |
||
39 | 'group' => 't.uri', |
||
40 | 'select' => 't.uri, COUNT(*) as id', |
||
41 | 'order' => 't.id ASC', |
||
42 | 'condition' => 't.event = "_trackPageView" AND t.created >= ' . strtotime("24 hours ago") |
||
43 | ), |
||
44 | ); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @return string the associated database table name |
||
49 | */ |
||
50 | public function tableName() |
||
54 | |||
55 | /** |
||
56 | * @return array validation rules for model attributes. |
||
57 | */ |
||
58 | public function rules() |
||
59 | { |
||
60 | // NOTE: you should only define rules for those attributes that |
||
61 | // will receive user inputs. |
||
62 | return array( |
||
63 | array('event, uri', 'required'), |
||
64 | array('id', 'numerical', 'integerOnly'=>true), |
||
65 | array('event, uri, ', 'length', 'max'=>255), |
||
66 | array('event_data, created', 'safe'), |
||
67 | array('id, content_id, page_title, event, event_data, uri, created', 'safe', 'on'=>'search'), |
||
68 | ); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @return array customized attribute labels (name=>label) |
||
73 | */ |
||
74 | public function attributeLabels() |
||
85 | |||
86 | public function beforeValidate() |
||
87 | { |
||
88 | $this->event_data = CJSON::encode($this->event_data); |
||
89 | return parent::beforeValidate(); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Retrieves a list of models based on the current search/filter conditions. |
||
94 | * |
||
95 | * Typical usecase: |
||
96 | * - Initialize the model fields with values from filter form. |
||
97 | * - Execute this method to get CActiveDataProvider instance which will filter |
||
98 | * models according to data in model fields. |
||
99 | * - Pass data provider to CGridView, CListView or any similar widget. |
||
100 | * |
||
101 | * @return CActiveDataProvider the data provider that can return the models |
||
102 | * based on the search/filter conditions. |
||
103 | */ |
||
104 | public function search() |
||
121 | |||
122 | /** |
||
123 | * Returns the static model of the specified AR class. |
||
124 | * Please note that you should have this exact method in all your CActiveRecord descendants! |
||
125 | * @param string $className active record class name. |
||
126 | * @return Events the static model class |
||
127 | */ |
||
128 | public static function model($className=__CLASS__) |
||
132 | } |
||
133 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.