6 const VISIBLE_REGISTER_USER = 2;
7 const VISIBLE_ONLY_OWNER = 1;
8 const VISIBLE_ONLY_ADMIN = 0;
11 const REQUIRED_NO = 0;
12 const REQUIRED_YES_SHOW_REG = 1;
13 const REQUIRED_NO_SHOW_REG = 2;
14 const REQUIRED_YES_NOT_SHOW_REG = 3;
38 public static function model($className = __CLASS__)
48 return Yii::app()->getModule(
'user')->tableProfileFields;
59 array(
'varname, title, field_type',
'required'),
60 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.")),
61 array(
'varname',
'unique',
'message' =>
UserModule::t(
"This field already exists.")),
62 array(
'varname, widget',
'length',
'max' => 50),
63 array(
'field_type',
'length',
'max' => 50),
64 array(
'field_size, field_size_min, required, position, visible',
'numerical',
'integerOnly' =>
true),
65 array(
'title, match, error_message, other_validator, default, widget',
'length',
'max' => 255),
66 array(
'range, widgetparams',
'length',
'max' => 5000),
67 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'),
107 public function scopes()
111 'condition' =>
'visible=' . self::VISIBLE_ALL,
112 'order' =>
'position',
115 'condition' =>
'visible>=' . self::VISIBLE_REGISTER_USER,
116 'order' =>
'position',
119 'condition' =>
'visible>=' . self::VISIBLE_ONLY_OWNER,
120 'order' =>
'position',
123 'condition' =>
'visible>=' . self::VISIBLE_ONLY_ADMIN,
124 'order' =>
'position',
126 'forRegistration' => array(
127 'condition' =>
'required=' . self::REQUIRED_NO_SHOW_REG .
' OR required=' . self::REQUIRED_YES_SHOW_REG,
128 'order' =>
'position',
131 'order' =>
'position',
142 if ($this->widget && class_exists($this->widget)) {
143 $widgetClass =
new $this->widget;
145 $arr = $this->widgetparams;
147 $newParams = $widgetClass->params;
148 $arr = (array)CJavaScript::jsonDecode($arr);
149 foreach ($arr as $p => $v) {
150 if (isset($newParams[$p])) $newParams[$p] = $v;
152 $widgetClass->params = $newParams;
155 if (method_exists($widgetClass,
'viewAttribute')) {
156 return $widgetClass->viewAttribute($model, $this);
162 public function widgetEdit($model, $params = array())
164 if ($this->widget && class_exists($this->widget)) {
165 $widgetClass =
new $this->widget;
167 $arr = $this->widgetparams;
169 $newParams = $widgetClass->params;
170 $arr = (array)CJavaScript::jsonDecode($arr);
171 foreach ($arr as $p => $v) {
172 if (isset($newParams[$p])) $newParams[$p] = $v;
174 $widgetClass->params = $newParams;
177 if (method_exists($widgetClass,
'editAttribute')) {
178 return $widgetClass->editAttribute($model, $this, $params);
184 public static function itemAlias($type, $code = NULL)
187 'field_type' => array(
199 self::REQUIRED_NO_SHOW_REG =>
UserModule::t(
'No, but show on registration form'),
200 self::REQUIRED_YES_SHOW_REG =>
UserModule::t(
'Yes and show on registration form'),
205 self::VISIBLE_REGISTER_USER =>
UserModule::t(
'Registered users'),
212 return isset($_items[$type][$code]) ? $_items[$type][$code] :
false;
214 return isset($_items[$type]) ? $_items[$type] :
false;
226 $criteria =
new CDbCriteria;
228 $criteria->compare(
'id', $this->
id);
229 $criteria->compare(
'varname', $this->varname,
true);
230 $criteria->compare(
'title', $this->title,
true);
231 $criteria->compare(
'field_type', $this->field_type,
true);
232 $criteria->compare(
'field_size', $this->field_size);
234 $criteria->compare(
'required', $this->required);
235 $criteria->compare(
'match', $this->match,
true);
236 $criteria->compare(
'range', $this->range,
true);
237 $criteria->compare(
'error_message', $this->error_message,
true);
238 $criteria->compare(
'other_validator', $this->other_validator,
true);
239 $criteria->compare(
'default', $this->
default,
true);
240 $criteria->compare(
'widget', $this->widget,
true);
241 $criteria->compare(
'widgetparams', $this->widgetparams,
true);
242 $criteria->compare(
'position', $this->position);
243 $criteria->compare(
'visible', $this->visible);
245 return new CActiveDataProvider($this, array(
246 'criteria' => $criteria,
247 'pagination' => array(
248 'pageSize' => Yii::app()->getModule(
'user')->fields_page_size,
251 'defaultOrder' =>
'position',