Exemple #1
0
 public static function _init()
 {
     $format_options = conf('form.formats.options', 'news');
     static::$_properties['format']['form']['options'] = $format_options;
     static::$_properties['format']['validation']['in_array'][] = array_keys($format_options);
     if (\Config::get('news.category.isEnabled')) {
         static::$_properties['news_category_id']['label'] = term('news.category.simple');
         $news_category_id_options = \Util_Orm::conv_cols2assoc(Model_NewsCategory::get_all(array('sort_order' => 'asc')), 'id', 'label');
         static::$_properties['news_category_id']['form']['options'] = $news_category_id_options;
         static::$_properties['news_category_id']['validation']['in_array'][] = array_keys($news_category_id_options);
     } else {
         static::$_properties['news_category_id']['form']['type'] = false;
     }
     //if (!Site_Util::check_editor_enabled('html_editor') || !(conf('image.isEnabled', 'news') && conf('image.isInsertBody', 'news')))
     //{
     //	static::$_properties['body']['validation'][] = 'required';
     //}
     if (conf('form.isSecure.isEnabled', 'news')) {
         $is_secure_options = \Site_Form::get_form_options4config('term.isSecure.options');
         static::$_properties['is_secure']['form']['type'] = 'radio';
         static::$_properties['is_secure']['label'] = term('isSecure.label');
         static::$_properties['is_secure']['form']['options'] = $is_secure_options;
         static::$_properties['is_secure']['validation'] = array('required');
         static::$_properties['is_secure']['validation']['in_array'][] = array_keys($is_secure_options);
     }
 }
Exemple #2
0
 public static function get_member_ids4config_value($config_name, $config_value, $target_member_ids = array(), $is_fill_default_value = true)
 {
     if (!is_array($target_member_ids)) {
         $target_member_ids = (array) $target_member_ids;
     }
     $member_configs = Util_Orm::conv_cols2assoc(Model_MemberConfig::get4name_and_member_ids($config_name, $target_member_ids), 'member_id', 'value');
     $return_member_ids = array();
     foreach ($target_member_ids as $member_id) {
         if (isset($member_configs[$member_id])) {
             $value = $member_configs[$member_id];
         } else {
             if (!$is_fill_default_value) {
                 continue;
             }
             $value = self::get_config_default($config_name);
         }
         if ($value != $config_value) {
             continue;
         }
         $return_member_ids[] = $member_id;
     }
     return $return_member_ids;
 }
Exemple #3
0
 private static function set_values_as_assoc()
 {
     $objs = self::query()->get();
     self::$values = Util_Orm::conv_cols2assoc($objs, 'name', 'value');
 }
Exemple #4
0
 public function set_validation($add_fields = array(), $fieldset = 'default')
 {
     $this->validation = \Validation::forge($fieldset);
     // member
     $this->set_validation_member_field('name');
     $this->set_validation_member_field('sex');
     $this->set_validation_member_field_birthday();
     // member_profile
     foreach ($this->profiles as $profile) {
         $member_profile = $this->member_profiles_profile_id_indexed[$profile->id];
         $rules = array();
         if ($profile->is_required) {
             $rules[] = 'required';
         }
         switch ($profile->form_type) {
             case 'input':
             case 'textarea':
                 $type = 'text';
                 if ($profile->value_type == 'email') {
                     $type = 'email';
                     $rules[] = 'valid_email';
                 } elseif ($profile->value_type == 'integer') {
                     $type = 'number';
                     $rules[] = array('valid_string', 'numeric');
                 } elseif ($profile->value_type == 'url') {
                     $type = 'url';
                     $rules[] = 'valid_url';
                 } elseif ($profile->value_type == 'regexp') {
                     $rules[] = array('match_pattern', $profile->value_regexp);
                 }
                 if ($profile->form_type == 'textarea') {
                     $type = 'textarea';
                 }
                 if ($profile->value_min) {
                     $rule_name = $profile->value_type == 'integer' ? 'numeric_min' : 'min_length';
                     $rules[] = array($rule_name, $profile->value_min);
                 }
                 if ($profile->value_max) {
                     $rule_name = $profile->value_type == 'integer' ? 'numeric_max' : 'max_length';
                     $rules[] = array($rule_name, $profile->value_max);
                 }
                 if ($profile->is_unique) {
                     $rules[] = array('unique', 'member_profile.value', array(array('profile_id', $profile->id)));
                 }
                 $value = !is_null($member_profile) ? $member_profile->value : '';
                 $this->validation->add($profile->name, $profile->caption, array('type' => $type, 'value' => $value, 'placeholder' => $profile->placeholder), $rules);
                 break;
             case 'select':
             case 'radio':
                 $type = $profile->form_type;
                 $options = Util_Orm::conv_cols2assoc($profile->profile_option, 'id', 'label');
                 if (is_null($member_profile)) {
                     $options_keys = array_keys($options);
                     $value = array_shift($options_keys);
                 } else {
                     $value = $member_profile->profile_option_id;
                 }
                 $rules[] = array('valid_string', 'numeric');
                 $rules[] = array('in_array', array_keys($options));
                 $this->validation->add($profile->name, $profile->caption, array('type' => $type, 'value' => $value, 'options' => $options), $rules);
                 break;
             case 'checkbox':
                 $type = $profile->form_type;
                 $options = Util_Orm::conv_cols2assoc($profile->profile_option, 'id', 'label');
                 $value = !is_null($member_profile) ? Util_Orm::conv_col2array($member_profile, 'profile_option_id') : array();
                 $rules[] = array('checkbox_val', $options);
                 if ($profile->is_required) {
                     $rules[] = array('checkbox_require', 1);
                 }
                 $this->validation->add($profile->name, $profile->caption, array('type' => $type, 'value' => $value, 'options' => $options), $rules);
                 break;
         }
     }
     foreach ($add_fields as $name => $params) {
         $this->add_field($name, $params);
     }
 }
Exemple #5
0
 public static function get_assoc($key_col, $value_col, $params = array(), $order_by = array(), $limit = 0)
 {
     $query = self::query()->select($key_col, $value_col);
     if ($params) {
         $query = static::set_where($query, $params);
     }
     if ($order_by) {
         $query->order_by($order_by);
     }
     if ($limit) {
         $query->rows_limit($limit);
     }
     return \Util_Orm::conv_cols2assoc($query->get(), $key_col, $value_col);
 }