1 | <?php |
||
55 | class Profile extends BaseBlameableModel |
||
56 | { |
||
57 | public $createdByAttribute = 'guid'; |
||
58 | |||
59 | // The host of Profile is only permitted to modify it. |
||
60 | public $updatedByAttribute = false; |
||
61 | |||
62 | // Profile do not have its identifier. |
||
63 | public $idAttribute = false; |
||
64 | |||
65 | // Profile do not need to record IP address. |
||
66 | public $enableIP = 0; |
||
67 | |||
68 | /** |
||
69 | * @var string Specify the nickname as the content attribute. |
||
70 | */ |
||
71 | public $contentAttribute = 'nickname'; |
||
72 | |||
73 | const SCENARIO_UPDATE = 'update'; |
||
74 | |||
75 | public function attributeLabels() |
||
76 | { |
||
77 | return [ |
||
78 | 'nickname' => Yii::t('user', 'Nickname'), |
||
79 | 'first_name' => Yii::t('user', 'First Name'), |
||
80 | 'last_name' => Yii::t('user', 'Last Name'), |
||
81 | 'gender' => Yii::t('user', 'Gender'), |
||
82 | 'gravatar_type' => Yii::t('user', 'Gravatar Type'), |
||
83 | 'gravatar' => Yii::t('user', 'Gravatar'), |
||
84 | 'timezone' => Yii::t('user', 'Timezone'), |
||
85 | 'individual_sign' => Yii::t('user', 'Individual Signature'), |
||
86 | 'created_at' => Yii::t('user', 'Creation Time'), |
||
87 | 'updated_at' => Yii::t('user', 'Last Updated Time'), |
||
88 | ]; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Get rules associated with individual sign attribute. |
||
93 | * You can override this method if current rules do not satisfy your needs. |
||
94 | * If you do not use individual sign attribute, please override this method and return empty array. |
||
95 | * @return array Rules associated with individual sign. |
||
96 | */ |
||
97 | 16 | public function getIndividualSignRules() |
|
98 | { |
||
99 | return [ |
||
100 | 16 | ['individual_sign', 'string', 'skipOnEmpty' => true], |
|
101 | 16 | ['individual_sign', 'default', 'value' => ''], |
|
102 | 16 | ]; |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * Get rules associated with name attribute. |
||
107 | * You can override this method if current rules do not satisfy your needs. |
||
108 | * If you do not use name attribute, please override this method and return empty array. |
||
109 | * @return array Rules associated with name. |
||
110 | */ |
||
111 | 16 | public function getNameRules() |
|
112 | { |
||
113 | return [ |
||
114 | 16 | [['first_name', 'last_name'], 'string', 'max' => 255, 'skipOnEmpty' => true], |
|
115 | 16 | [['first_name', 'last_name'], 'default', 'value' => ''], |
|
116 | 16 | ]; |
|
117 | } |
||
118 | |||
119 | const GENDER_UNSPECIFIED = 0; |
||
120 | const GENDER_MALE = 1; |
||
121 | const GENDER_FEMALE = 2; |
||
122 | |||
123 | public static $genders = [ |
||
124 | self::GENDER_UNSPECIFIED => 'Unspecified', |
||
125 | self::GENDER_MALE => 'Male', |
||
126 | self::GENDER_FEMALE => 'Female', |
||
127 | ]; |
||
128 | |||
129 | /** |
||
130 | * Get rules associated with gender attribute. |
||
131 | * You can override this method if current rules do not satisfy your needs. |
||
132 | * If you do not use gender attribute, please override this method and return empty array. |
||
133 | * @return array Rules associated with gender. |
||
134 | */ |
||
135 | 16 | public function getGenderRules() |
|
136 | { |
||
137 | return [ |
||
138 | 16 | ['gender', 'default', 'value' => 0], |
|
139 | 16 | ['gender', 'in', 'range' => array_keys(static::$genders)], |
|
140 | 16 | ]; |
|
141 | } |
||
142 | |||
143 | public static function getGenderDesc($gender = null) |
||
144 | { |
||
145 | if (array_key_exists($gender, self::$genders)) { |
||
146 | return Yii::t('user', self::$genders[$gender]); |
||
147 | } |
||
148 | return null; |
||
149 | } |
||
150 | |||
151 | public static function getGenderDescs() |
||
152 | { |
||
153 | $genders = []; |
||
154 | foreach (self::$genders as $key => $gender) { |
||
155 | $genders[$key] = static::getGenderDesc($key); |
||
156 | } |
||
157 | return $genders; |
||
158 | } |
||
159 | |||
160 | 16 | public function getGravatarRules() |
|
161 | { |
||
162 | return [ |
||
163 | 16 | ['gravatar_type', 'default', 'value' => 0], |
|
164 | 16 | ['gravatar_type', 'integer'], |
|
165 | 16 | ['gravatar', 'default', 'value' => ''], |
|
166 | 16 | ['gravatar', 'string', 'max' => 255], |
|
167 | 16 | ]; |
|
168 | } |
||
169 | |||
170 | 16 | public function getTimezoneRules() |
|
171 | { |
||
172 | return [ |
||
173 | 16 | ['timezone', 'default', 'value' => 'UTC'], |
|
174 | 16 | ['timezone', 'string'], |
|
175 | 16 | ]; |
|
176 | } |
||
177 | |||
178 | /** |
||
179 | * @inheritdoc |
||
180 | */ |
||
181 | 16 | public function rules() |
|
190 | |||
191 | /** |
||
192 | * @inheritdoc |
||
193 | */ |
||
194 | 18 | public static function tableName() |
|
195 | { |
||
196 | 18 | return '{{%profile}}'; |
|
197 | 16 | } |
|
198 | |||
199 | 16 | public function scenarios() |
|
205 | } |
||
206 |