1 : <?php
2 :
3 :
4 :
5 :
6 :
7 :
8 :
9 :
10 :
11 : class BasicRelationsMain extends BasicRelationsModel {
12 :
13 :
14 :
15 :
16 : public static function model($className=__CLASS__) {
17 5 : return parent::model($className);
18 : }
19 :
20 :
21 :
22 :
23 : public function tableName() {
24 10 : return 'tbl_basic_relations_main';
25 : }
26 :
27 :
28 :
29 :
30 : public function rules() {
31 : return array(
32 6 : array ('column_belongs_to_id, column_main_content', 'required'),
33 6 : array ('column_belongs_to_id', 'numerical', 'integerOnly' => true),
34 6 : array ('column_belongs_to_id', 'validBelongsToID'),
35 6 : array ('column_main_content', 'length', 'max' => 255),
36 :
37 6 : array ('magic_attribute_has_one', 'validMagic_Attribute_Has_One'),
38 6 : array ('id, column_belongs_to_id, column_main_content', 'safe', 'on' => 'search'),
39 6 : );
40 : }
41 :
42 :
43 :
44 :
45 : public function relations() {
46 : return array(
47 6 : 'relation_belongs_to' => array (self::BELONGS_TO, 'BasicRelationsBelongsTo', 'column_belongs_to_id'),
48 6 : 'relation_has_one' => array (self::HAS_ONE, 'BasicRelationsHasOne', 'column_main_id'),
49 6 : 'relation_has_many' => array (self::HAS_MANY, 'BasicRelationsHasMany', 'column_main_id'),
50 6 : 'relation_many_manys' => array (self::MANY_MANY, 'BasicRelationsManyMany', 'tbl_basic_relations_pivot(column_main_id, column_many_many_id)'),
51 6 : );
52 : }
53 :
54 :
55 :
56 :
57 : public function pivots() {
58 : return array (
59 1 : 'relation_many_many' => 'BasicRelationsPivot',
60 1 : );
61 3 : }
62 3 :
63 :
64 :
65 :
66 : public function attributeLabels() {
67 : return array(
68 5 : 'id' => 'ID',
69 5 : 'column_belongs_to_id' => 'Column Belongs To ID',
70 5 : 'column_main_content' => 'Column Main Content',
71 5 : );
72 : }
73 :
74 :
75 :
76 :
77 :
78 : public function search() {
79 1 : $criteria=new CDbCriteria;
80 :
81 1 : $criteria->compare('id',$this->id);
82 1 : $criteria->compare('column_belongs_to_id',$this->column_belongs_to_id);
83 1 : $criteria->compare('column_main_content',$this->column_main_content,true);
84 :
85 1 : return new CActiveDataProvider('BasicRelationsMain', array(
86 1 : 'criteria'=>$criteria,
87 1 : ));
88 : }
89 :
90 :
91 :
92 :
93 :
94 :
95 :
96 :
97 :
98 : public function validBelongsToID ($attribute, $params) {
99 :
100 5 : if (isset ($this->errors) && isset ($this->errors[$attribute]))
101 5 : return;
102 : $t_params=array (
103 3 : '{attribute}' => $this->getAttributeLabel($attribute),
104 3 : '{attribute_value}' => $this->$attribute,
105 3 : '{basic_relations_belongs_to_table}' => BasicRelationsBelongsTo::tableName(),
106 3 : );
107 3 : if (!BasicRelationsBelongsTo::model()->idPresent ($this->$attribute))
108 3 : $this->addError ($attribute, Yii::t ('basic_relations', 'The {attribute} of \'{attribute_value}\' does not exist in the {basic_relations_belongs_to_table} table.', $t_params));
109 3 : }
110 :
111 :
112 :
113 :
114 :
115 : public function getMagic_Attribute_Belongs_To_List () {
116 1 : if (isset ($this->_magic_attributes['belongs_to_list']))
117 1 : return $this->_magic_attributes['belongs_to_list'];
118 1 : $belongs_to_entries=BasicRelationsBelongsTo::model()->findAll ();
119 1 : if (empty ($belongs_to_entries))
120 1 : return array();
121 1 : $belongs_to_list=array();
122 1 : foreach ($belongs_to_entries as $belongs_to) {
123 1 : $belongs_to_list[$belongs_to->id]=$belongs_to->column_belongs_to_content;
124 1 : }
125 1 : return $this->_magic_attributes['belongs_to_list']=$belongs_to_list;
126 : }
127 :
128 : public function getMagic_Attribute_Belongs_To_Content () {
129 1 : if (empty ($this->relation_belongs_to))
130 1 : return null;
131 1 : return $this->relation_belongs_to->column_belongs_to_content;
132 : }
133 :
134 : public function getMagic_Attribute_Has_One () {
135 1 : return $this->magicRelationHasOneRead ('relation_has_one','column_has_one_content');
136 : }
137 :
138 : public function setMagic_Attribute_Has_One ($value) {
139 3 : $this->magicRelationHasOneWrite ('relation_has_one', 'column_has_one_content', $value);
140 3 : }
141 :
142 : public function validMagic_Attribute_Has_One ($attribute, $params) {
143 5 : $this->magicRelationHasOneValidate ('relation_has_one', 'column_has_one_content', 'magic_attribute_has_one', $params);
144 5 : }
145 :
146 : public function getMagic_Attribute_Has_Many () {
147 0 : return $this->magicRelationHasManyRead ('relation_has_many');
148 : }
149 :
150 : public function setMagic_Attribute_Has_Many (array $value_array) {
151 0 : $this->magicRelationHasManyWrite ('relation_has_many', $value_array);
152 0 : }
153 :
154 : public function getMagic_Attribute_Many_Many () {
155 0 : }
156 :
157 : public function setMagic_Attribute_Many_Many () {
158 0 : }
159 :
160 : }
|