1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This is the model class for table "club". |
5
|
|
|
* |
6
|
|
|
* The followings are the available columns in table 'club': |
7
|
|
|
* @property string $id |
8
|
|
|
* @property integer $owner |
9
|
|
|
* @property string $name |
10
|
|
|
* @property string $created |
11
|
|
|
*/ |
12
|
|
|
class ClubAR extends CActiveRecord |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Returns the static model of the specified AR class. |
16
|
|
|
* @param string $className active record class name. |
17
|
|
|
* @return Club the static model class |
18
|
|
|
*/ |
19
|
|
|
public static function model($className = __CLASS__) |
20
|
|
|
{ |
21
|
|
|
return parent::model($className); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return string the associated database table name |
26
|
|
|
*/ |
27
|
|
|
public function tableName() |
28
|
|
|
{ |
29
|
|
|
return 'club'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return array validation rules for model attributes. |
34
|
|
|
*/ |
35
|
|
|
public function rules() |
36
|
|
|
{ |
37
|
|
|
// NOTE: you should only define rules for those attributes that |
38
|
|
|
// will receive user inputs. |
39
|
|
|
return array( |
40
|
|
|
['name', 'clean'], |
41
|
|
|
['name', 'required'], |
42
|
|
|
['name', 'length', 'min'=>6, 'max'=>14], |
43
|
|
|
['name', 'levelRequirement'], |
44
|
|
|
['name', 'hasOtherClub'], |
45
|
|
|
['name', 'nameIsFree'], |
46
|
|
|
['id, owner', 'safe', 'on'=>'search'], |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function clean($attribute) |
51
|
|
|
{ |
52
|
|
|
$this->$attribute = trim($this->$attribute); |
53
|
|
|
$this->$attribute = strip_tags($this->$attribute); |
54
|
|
|
$this->$attribute = htmlspecialchars($this->$attribute); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function levelRequirement($attribute, $params) |
58
|
|
|
{ |
59
|
|
View Code Duplication |
if (Yii::app()->player->model->level < Yii::app()->params['clubCreateLevelRequirement']) { |
60
|
|
|
$this->addError($attribute, 'Saját klub indĂtásához minimum ' . Yii::app()->params['clubCreateLevelRequirement'] . '. szintre kell fejlĹ‘dnöd.'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function hasOtherClub($attribute, $params) |
65
|
|
|
{ |
66
|
|
|
if (Yii::app()->player->model->in_club) { |
67
|
|
|
$this->addError($attribute, 'Egy másik klub tagja vagy. Először lépj ki abból.'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function nameIsFree($attribute, $params) |
72
|
|
|
{ |
73
|
|
|
$clubWithSameName = Yii::app()->db->createCommand() |
74
|
|
|
->select('id') |
75
|
|
|
->from('club') |
76
|
|
|
->where('name=:name', [':name'=>$this->$attribute]) |
77
|
|
|
->queryScalar(); |
78
|
|
|
if ($clubWithSameName) { |
79
|
|
|
$this->addError($attribute, 'Ez a név már foglalt.'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return array customized attribute labels (name=>label) |
85
|
|
|
*/ |
86
|
|
|
public function attributeLabels() |
87
|
|
|
{ |
88
|
|
|
return array( |
89
|
|
|
'id' => 'ID', |
90
|
|
|
'owner' => 'Tulajdonos', |
91
|
|
|
'name' => 'Klub neve', |
92
|
|
|
'created' => 'Létrehozva', |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Retrieves a list of models based on the current search/filter conditions. |
98
|
|
|
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
99
|
|
|
*/ |
100
|
|
|
public function search() |
101
|
|
|
{ |
102
|
|
|
// Warning: Please modify the following code to remove attributes that |
103
|
|
|
// should not be searched. |
104
|
|
|
|
105
|
|
|
$criteria=new CDbCriteria; |
106
|
|
|
|
107
|
|
|
$criteria->compare('id', $this->id, true); |
108
|
|
|
$criteria->compare('owner', $this->owner); |
109
|
|
|
$criteria->compare('name', $this->name, true); |
110
|
|
|
$criteria->compare('created', $this->created, true); |
111
|
|
|
|
112
|
|
|
return new CActiveDataProvider($this, array( |
113
|
|
|
'criteria'=>$criteria, |
114
|
|
|
)); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
protected function beforeSave() |
|
|
|
|
118
|
|
|
{ |
119
|
|
|
$this->owner = Yii::app()->player->uid; |
120
|
|
|
return parent::beforeSave(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
protected function afterSave() |
124
|
|
|
{ |
125
|
|
|
$forum = new Forum; |
126
|
|
|
$forum->id = $this->id; |
127
|
|
|
$forum->save(Yii::app()->player->model->user . ' megalapĂtotta a klubot.', true); |
128
|
|
|
|
129
|
|
|
Yii::app()->badge->model->triggerSimple('club_create'); |
130
|
|
|
|
131
|
|
|
//delete inactive join request |
132
|
|
|
Yii::app()->db->createCommand()->delete('club_members', 'uid=:uid AND approved=0', [':uid'=>Yii::app()->player->model->uid]); |
133
|
|
|
parent::afterSave(); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.