6 const VISIBLE_REGISTER_USER = 2;
7 const VISIBLE_ONLY_OWNER = 1;
10 const REQUIRED_NO = 0;
11 const REQUIRED_YES_SHOW_REG = 1;
12 const REQUIRED_NO_SHOW_REG = 2;
13 const REQUIRED_YES_NOT_SHOW_REG = 3;
37 public static function model($className = __CLASS__)
47 return Yii::app()->getModule(
'user')->tableProfileFields;
58 array(
'varname, title, field_type',
'required'),
59 array(
'varname',
'match',
'pattern' =>
'/^[A-Za-z_0-9]+$/u',
'message' =>
UserModule::t(
"Variable name may consist of A-z, 0-9, underscores, begin with a letter.")),
60 array(
'varname',
'unique',
'message' =>
UserModule::t(
"This field already exists.")),
61 array(
'varname, widget',
'length',
'max' => 50),
62 array(
'field_type',
'length',
'max' => 50),
63 array(
'field_size, field_size_min, required, position, visible',
'numerical',
'integerOnly' =>
true),
64 array(
'title, match, error_message, other_validator, default, widget',
'length',
'max' => 255),
65 array(
'range, widgetparams',
'length',
'max' => 5000),
66 array(
'id, varname, title, field_type, field_size, field_size_min, required, match, range, error_message, other_validator, default, widget, widgetparams, position, visible',
'safe',
'on'=>
'search'),
106 public function scopes()
110 'condition' =>
'visible=' . self::VISIBLE_ALL,
111 'order' =>
'position',
114 'condition' =>
'visible>=' . self::VISIBLE_REGISTER_USER,
115 'order' =>
'position',
118 'condition' =>
'visible>=' . self::VISIBLE_ONLY_OWNER,
119 'order' =>
'position',
121 'forRegistration' => array(
122 'condition' =>
'required=' . self::REQUIRED_NO_SHOW_REG .
' OR required=' . self::REQUIRED_YES_SHOW_REG,
123 'order' =>
'position',
126 'order' =>
'position',
137 if ($this->widget && class_exists($this->widget)) {
138 $widgetClass =
new $this->widget;
140 $arr = $this->widgetparams;
142 $newParams = $widgetClass->params;
143 $arr = (array)CJavaScript::jsonDecode($arr);
144 foreach ($arr as $p => $v) {
145 if (isset($newParams[$p])) $newParams[$p] = $v;
147 $widgetClass->params = $newParams;
150 if (method_exists($widgetClass,
'viewAttribute')) {
151 return $widgetClass->viewAttribute($model, $this);
157 public function widgetEdit($model, $params = array())
159 if ($this->widget && class_exists($this->widget)) {
160 $widgetClass =
new $this->widget;
162 $arr = $this->widgetparams;
164 $newParams = $widgetClass->params;
165 $arr = (array)CJavaScript::jsonDecode($arr);
166 foreach ($arr as $p => $v) {
167 if (isset($newParams[$p])) $newParams[$p] = $v;
169 $widgetClass->params = $newParams;
172 if (method_exists($widgetClass,
'editAttribute')) {
173 return $widgetClass->editAttribute($model, $this, $params);
179 public static function itemAlias($type, $code = NULL)
182 'field_type' => array(
194 self::REQUIRED_NO_SHOW_REG =>
UserModule::t(
'No, but show on registration form'),
195 self::REQUIRED_YES_SHOW_REG =>
UserModule::t(
'Yes and show on registration form'),
200 self::VISIBLE_REGISTER_USER =>
UserModule::t(
'Registered users'),
206 return isset($_items[$type][$code]) ? $_items[$type][$code] :
false;
208 return isset($_items[$type]) ? $_items[$type] :
false;
220 $criteria =
new CDbCriteria;
222 $criteria->compare(
'id', $this->
id);
223 $criteria->compare(
'varname', $this->varname,
true);
224 $criteria->compare(
'title', $this->title,
true);
225 $criteria->compare(
'field_type', $this->field_type,
true);
226 $criteria->compare(
'field_size', $this->field_size);
227 $criteria->compare(
'field_size_min', $this->field_size_min);
228 $criteria->compare(
'required', $this->required);
229 $criteria->compare(
'match', $this->match,
true);
230 $criteria->compare(
'range', $this->range,
true);
231 $criteria->compare(
'error_message', $this->error_message,
true);
232 $criteria->compare(
'other_validator', $this->other_validator,
true);
233 $criteria->compare(
'default', $this->
default,
true);
234 $criteria->compare(
'widget', $this->widget,
true);
235 $criteria->compare(
'widgetparams', $this->widgetparams,
true);
236 $criteria->compare(
'position', $this->position);
237 $criteria->compare(
'visible', $this->visible);
239 return new CActiveDataProvider($this, array(
240 'criteria' => $criteria,
241 'pagination' => array(
242 'pageSize' => Yii::app()->getModule(
'user')->fields_page_size,
245 'defaultOrder' =>
'position',