22 public static function model($className = __CLASS__)
32 return Yii::app()->getModule(
'user')->tableProfiles;
49 foreach ($model as $field) {
50 $field_rule = array();
52 array_push($required, $field->varname);
54 if ($field->field_type ==
'FLOAT') {
55 array_push($float, $field->varname);
57 if ($field->field_type ==
'DECIMAL') {
58 array_push($decimal, $field->varname);
60 if ($field->field_type ==
'INTEGER') {
61 array_push($numerical, $field->varname);
63 if ($field->field_type ==
'VARCHAR' || $field->field_type ==
'TEXT') {
64 $field_rule = array($field->varname,
'length',
'max' => $field->field_size,
'min' => $field->field_size_min);
65 if ($field->error_message) {
66 $field_rule[
'message'] =
UserModule::t($field->error_message);
68 array_push($rules, $field_rule);
70 if ($field->other_validator) {
71 if (strpos($field->other_validator,
'{') === 0) {
72 $validator = (array) CJavaScript::jsonDecode($field->other_validator);
73 foreach ($validator as $name => $val) {
74 $field_rule = array($field->varname, $name);
75 $field_rule = array_merge($field_rule, (array) $validator[$name]);
76 if ($field->error_message) {
77 $field_rule[
'message'] =
UserModule::t($field->error_message);
79 array_push($rules, $field_rule);
82 $field_rule = array($field->varname, $field->other_validator);
83 if ($field->error_message) {
84 $field_rule[
'message'] =
UserModule::t($field->error_message);
86 array_push($rules, $field_rule);
88 } elseif ($field->field_type ==
'DATE') {
89 $field_rule = array($field->varname,
'type',
'type' =>
'date',
'dateFormat' =>
'yyyy-mm-dd',
'allowEmpty' =>
true);
90 if ($field->error_message) {
91 $field_rule[
'message'] =
UserModule::t($field->error_message);
93 array_push($rules, $field_rule);
96 $field_rule = array($field->varname,
'match',
'pattern' => $field->match);
97 if ($field->error_message) {
98 $field_rule[
'message'] =
UserModule::t($field->error_message);
100 array_push($rules, $field_rule);
103 $field_rule = array($field->varname,
'in',
'range' => self::rangeRules($field->range));
104 if ($field->error_message) {
105 $field_rule[
'message'] =
UserModule::t($field->error_message);
107 array_push($rules, $field_rule);
111 array_push($rules, array(implode(
',', $required),
'required'));
112 array_push($rules, array(implode(
',', $numerical),
'numerical',
'integerOnly' =>
true));
113 array_push($rules, array(implode(
',', $float),
'type',
'type' =>
'float'));
114 array_push($rules, array(implode(
',', $decimal),
'match',
'pattern' =>
'/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/'));
115 $this->_rules = $rules;
129 'user' => array(self::HAS_ONE,
'User',
'id'),
131 if (isset(Yii::app()->getModule(
'user')->profileRelations)) {
132 $relations = array_merge($relations, Yii::app()->getModule(
'user')->profileRelations);
148 foreach ($model as $field) {
149 $labels[$field->varname] = ((Yii::app()->getModule(
'user')->fieldsMessage) ?
UserModule::t($field->title, array(), Yii::app()->getModule(
'user')->fieldsMessage) :
UserModule::t($field->title));
157 $rules = explode(
';', $str);
158 for (
$i = 0;
$i<count($rules);
$i++) {
159 $rules[
$i] = current(explode(
"==", $rules[
$i]));
165 public static function range($str, $fieldValue = null)
167 $rules = explode(
';', $str);
169 for (
$i = 0;
$i<count($rules);
$i++) {
170 $item = explode(
"==", $rules[
$i]);
171 if (isset($item[0])) {
172 $array[$item[0]] = ((isset($item[1])) ? $item[1] : $item[0]);
175 if (isset($fieldValue)) {
176 if (isset($array[$fieldValue])) {
177 return $array[$fieldValue];
191 foreach ($model as $field) {
192 if ($field->widget) {
193 $data[$field->varname] = $field->widget;
205 foreach ($model as $field) {
206 if ($field->widget) {
207 $data[$field->varname] = $field->widgetparams;
211 return $data[$fieldName];
216 if ($this->regMode) {
217 if (!$this->_modelReg) {
223 if (!$this->_model) {