1 <?php
2 /**
3 * Class File
4 *
5 * @author Tobias Munk <schmunk@usrbin.de>
6 * @link http://www.phundament.com/
7 * @copyright Copyright © 2005-2010 diemeisterei GmbH
8 * @license http://www.phundament.com/license/
9 */
10
11 /**
12 * ActiveRecord, basic settings for p2 core models
13 *
14 * @author Tobias Munk <schmunk@usrbin.de>
15 * @package p3extensions.components
16 */
17 class P3ActiveRecord extends CActiveRecord {
18
19 /**
20 * @return array relational rules.
21 */
22 public function relations() {
23 return array(
24 #'P2Info' => array(self::HAS_ONE, 'P2Info', 'modelId',
25 # 'condition'=>'P2Info.model = "'.get_class($this).'"'
26 #),
27 );
28 }
29
30 /**
31 * @return array model behaviours
32 */
33 public function behaviors() {
34 return array(
35 #'Logable' =>'application.modules.p2.behaviors.P2ActiveRecordLogableBehavior',
36 #'Info' =>'application.modules.p2.behaviors.P2ActiveRecordInfoBehavior',
37 );
38 }
39
40 /**
41 * @return array scopes.
42 */
43 public function scopes() {
44 $checkAccess = (Yii::app()->user->isGuest)?'':' OR P2Info.checkAccess IN ("'.implode('","',array_keys(Yii::app()->authManager->getRoles(Yii::app()->user->id))).'")';
45
46 $scopes = array(
47 'localized'=>array(
48 #'with' => array('P2Info'),
49 #'condition' => 'P2Info.language = "'.Yii::app()->language.'" or P2Info.language IS NULL',
50 ),
51 'localizedStrict'=>array(
52 #'with' => array('P2Info'),
53 #'condition' => 'P2Info.language = "'.Yii::app()->language.'" ',
54 ),
55 'active'=>array(
56 #'with' => array('P2Info'),
57 #'condition' => '(P2Info.status = '.P2Info::STATUS_ACTIVE.' OR P2Info.status = '.P2Info::STATUS_LOCKED.' OR P2Info.status = '.P2Info::STATUS_HIDDEN.')',
58 ),
59 'ongoing'=>array(
60 #'with' => array('P2Info'),
61 'condition' => '(P2Info.begin <= NOW() AND (P2Info.end > NOW() OR P2Info.end IS NULL OR P2Info.end = 0))',
62 ),
63 'checkAccess'=>array(
64 #'with' => array('P2Info'),
65 #'condition' => 'P2Info.checkAccess IS NULL '.$checkAccess,
66 ),
67 );
68 $scopes['default'] = array(
69 #'with' => array('P2Info'),
70 /*'condition' => '('.
71 $scopes['localized']['condition'].') AND ('.
72 $scopes['active']['condition'].') AND ('.
73 $scopes['checkAccess']['condition'].
74 ')',*/
75 );
76
77 return $scopes;
78 }
79
80
81 }
82 ?>
83