1: <?php
2: /**
3: * CActiveRecordBehavior class file.
4: *
5: * @author Qiang Xue <qiang.xue@gmail.com>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11: /**
12: * CActiveRecordBehavior is the base class for behaviors that can be attached to {@link CActiveRecord}.
13: * Compared with {@link CModelBehavior}, CActiveRecordBehavior attaches to more events
14: * that are only defined by {@link CActiveRecord}.
15: *
16: * @property CActiveRecord $owner The owner AR that this behavior is attached to.
17: *
18: * @author Qiang Xue <qiang.xue@gmail.com>
19: * @package system.db.ar
20: */
21: class CActiveRecordBehavior extends CModelBehavior
22: {
23: /**
24: * Declares events and the corresponding event handler methods.
25: * If you override this method, make sure you merge the parent result to the return value.
26: * @return array events (array keys) and the corresponding event handler methods (array values).
27: * @see CBehavior::events
28: */
29: public function events()
30: {
31: return array_merge(parent::events(), array(
32: 'onBeforeSave'=>'beforeSave',
33: 'onAfterSave'=>'afterSave',
34: 'onBeforeDelete'=>'beforeDelete',
35: 'onAfterDelete'=>'afterDelete',
36: 'onBeforeFind'=>'beforeFind',
37: 'onAfterFind'=>'afterFind',
38: 'onBeforeCount'=>'beforeCount',
39: ));
40: }
41:
42: /**
43: * Responds to {@link CActiveRecord::onBeforeSave} event.
44: * Override this method and make it public if you want to handle the corresponding
45: * event of the {@link CBehavior::owner owner}.
46: * You may set {@link CModelEvent::isValid} to be false to quit the saving process.
47: * @param CModelEvent $event event parameter
48: */
49: protected function beforeSave($event)
50: {
51: }
52:
53: /**
54: * Responds to {@link CActiveRecord::onAfterSave} event.
55: * Override this method and make it public if you want to handle the corresponding event
56: * of the {@link CBehavior::owner owner}.
57: * @param CEvent $event event parameter
58: */
59: protected function afterSave($event)
60: {
61: }
62:
63: /**
64: * Responds to {@link CActiveRecord::onBeforeDelete} event.
65: * Override this method and make it public if you want to handle the corresponding event
66: * of the {@link CBehavior::owner owner}.
67: * You may set {@link CModelEvent::isValid} to be false to quit the deletion process.
68: * @param CEvent $event event parameter
69: */
70: protected function beforeDelete($event)
71: {
72: }
73:
74: /**
75: * Responds to {@link CActiveRecord::onAfterDelete} event.
76: * Override this method and make it public if you want to handle the corresponding event
77: * of the {@link CBehavior::owner owner}.
78: * @param CEvent $event event parameter
79: */
80: protected function afterDelete($event)
81: {
82: }
83:
84: /**
85: * Responds to {@link CActiveRecord::onBeforeFind} event.
86: * Override this method and make it public if you want to handle the corresponding event
87: * of the {@link CBehavior::owner owner}.
88: * @param CEvent $event event parameter
89: */
90: protected function beforeFind($event)
91: {
92: }
93:
94: /**
95: * Responds to {@link CActiveRecord::onAfterFind} event.
96: * Override this method and make it public if you want to handle the corresponding event
97: * of the {@link CBehavior::owner owner}.
98: * @param CEvent $event event parameter
99: */
100: protected function afterFind($event)
101: {
102: }
103:
104: /**
105: * Responds to {@link CActiveRecord::onBeforeCount} event.
106: * Override this method and make it public if you want to handle the corresponding event
107: * of the {@link CBehavior::owner owner}.
108: * @param CEvent $event event parameter
109: * @since 1.1.14
110: */
111: protected function beforeCount($event)
112: {
113: }
114: }
115: