public function validate(CM_Form_Abstract $form) { if ($this->_extra_validation) { $values = array(); foreach ($form->get_values() as $name => $value) { $values[$name] = $value->get_raw(); $this->_extra_validation->label($name, $form->get_field($name)->get_label()); } // Validation только read-only, поэтому создаем новый объект $this->_extra_validation = $this->_extra_validation->copy($values); } try { $this->get_model()->check($this->_extra_validation); } catch (ORM_Validation_Exception $e) { $errors = $e->errors('validation'); if ($external = arr::get($errors, '_external')) { $errors = arr::merge($errors, $external); unset($errors['_external']); } foreach ($errors as $name => $error) { $form->get_field($name)->set_error($error); } return FALSE; } return TRUE; }
public function validate(CM_Form_Abstract $form) { if (!$form->get_field($this->_field_name)->is_valid()) { $form->get_field($this->_field_name)->set_error('Неверный код'); return FALSE; } return TRUE; }
public function construct_form(CM_Form_Abstract $form, $user) { if ($user->id == Auth::instance()->get_user()->id) { $form->get_field('roles')->set_role_disabled('admin'); } if (!Auth::instance()->logged_in('admin')) { $form->get_field('roles')->set_role_disabled('admin'); } }
public function populate(CM_Form_Abstract $form) { $date_from = $form->get_field($this->get_field_name())->get_value()->get_date_from(); $date_to = $form->get_field($this->get_field_name())->get_value()->get_date_to(); if ($date_from->is_valid() and !is_null($date_from->get_raw())) { $this->get_model()->where($this->get_field_name(), '>=', $date_from->get_raw() . ' 00:00:00'); } if ($date_to->is_valid() and !is_null($date_to->get_raw())) { $this->get_model()->where($this->get_field_name(), '<=', $date_to->get_raw() . ' 23:59:59'); } }
public function populate(CM_Form_Abstract $form) { $value = $form->get_field($this->get_field_name())->get_value()->get_raw(); if ($value == '') { return; } if (empty($value) && $value != 0 && !$this->_allow_empty) { return; } if (!is_null($value) && $value or $this->_allow_null or $value == 0) { if (is_object($this->get_model()->{$this->get_field_name()})) { $ids = array(); foreach (DB::select()->from($this->_relation_table)->where($this->_related_field, '=', $value)->execute()->as_array() as $model) { $ids[] = $model[$this->_relation_field]; } if ($ids) { $this->get_model()->where('id', 'IN', $ids); } elseif ($value != '') { $this->get_model()->where('id', '=', '-1'); } } elseif ($value || $value == 0) { $this->get_model()->where($this->get_field_name(), is_null($value) ? 'IS' : '=', $value); } } }
public function after_submit(CM_Form_Abstract $form) { $values = unserialize($form->get_field($this->_field_name)->get_value()->get_raw()); foreach ($this->get_db_values() as $db_value) { if (!isset($values[$db_value->index])) { $db_value->delete(); } else { if (is_null($values[$db_value->index])) { unset($values[$db_value->index]); $db_value->delete(); } else { $db_value->value = $values[$db_value->index]; $db_value->save(); unset($values[$db_value->index]); } } } foreach ($values as $index => $value) { if (is_null($value)) { continue; } $db_value = clone $this->_value_model; $db_value->index = $index; $db_value->value = $value; $db_value->{$this->_parent_field} = $this->get_model(); $db_value->save(); } }
public function populate(CM_Form_Abstract $form) { $value = $form->get_field($this->get_field_name())->get_value()->get_raw(); if ($value) { $this->get_model()->where($this->get_field_name(), 'LIKE', '%' . $value . '%'); } }
public function populate(CM_Form_Abstract $form) { $values = array(); foreach ($this->_item->get_fieldschema()->get_field_names() as $name) { $values[$name] = $form->get_field($name)->get_value(); } $this->_item->set_values($values); }
public function construct_form(CM_Form_Abstract $form, $param) { foreach ($this->_labels as $name => $label) { if ($form->has_field($name)) { $form->get_field($name)->set_label($label); } } }
public function after_submit(CM_Form_Abstract $form) { $this->_model->save(); if (!trim($form->get_field('url')->get_value()->get_raw()) && $this->_model->name != 'Главная страница') { $this->_model->url = Extasy_Text::to_url($form->get_field('name')->get_value()->get_raw()); } if (!trim($form->get_field('s_title')->get_value()->get_raw())) { $this->_model->s_title = $this->_model->name; } $number_of_dashes = substr_count($this->_model->url, '--'); $replacement_string = ''; for ($i = 0; $i < $number_of_dashes; $i++) { $replacement_string .= '--'; } $this->_model->url = str_replace($replacement_string, '-', $this->_model->url); $this->_model->save(); parent::after_submit($form); }
public function construct_form(CM_Form_Abstract $form, $params) { $this->set_model($params); foreach ($form->get_field_names() as $name) { if ($label = arr::get($this->get_model()->labels(), $name)) { $form->get_field($name)->set_label($label); } } }
public function populate(CM_Form_Abstract $form) { $date = $form->get_field($this->get_field_name())->get_value(); $date_value = $date->get_raw(); if ($date->is_valid() && !empty($date_value)) { $this->get_model()->where($this->get_field_name(), '>=', $date->get_raw() . ' 00:00:00'); $this->get_model()->where($this->get_field_name(), '<=', $date->get_raw() . ' 23:59:59'); } }
public function populate(CM_Form_Abstract $form) { $value = $form->get_field($this->get_field_name())->get_value()->get_raw(); if (!is_null($value)) { $value = preg_replace('#\\*{2,}#', '*', $value); $value = strtr($value, array('%' => '\\%', '_' => '\\_')); if (!empty($value)) { $this->get_model()->where($this->get_field_name(), 'LIKE', str_replace('*', '%', $value)); } } }
public function render(CM_Form_Abstract $form) { $fieldgroups = array(); foreach ($this->_fieldgroups as $fieldgroup) { $fieldgroups[$fieldgroup] = array(); } foreach ($form->get_field_names() as $name) { $fieldgroup = arr::get($this->_fields_fieldgroups, $name, 'Default'); $fieldgroups[$fieldgroup][$name] = $form->get_field($name); } foreach ($fieldgroups as $fieldgroup_name => $fields) { if (empty($fields)) { unset($fieldgroups[$fieldgroup_name]); } } return View::factory('cm/form/fieldgroups', array('fieldgroups' => $fieldgroups, 'form' => $form)); }
public function validate(CM_Form_Abstract $form) { $values = array(); foreach ($form->get_values() as $name => $value) { $values[$name] = $value->get_raw(); $this->_validation->label($name, $form->get_field($name)->get_label()); } // Validation только read-only, поэтому создаем новый объект $this->_validation = $this->_validation->copy($values); if ($this->_validation->check()) { return TRUE; } foreach ($this->_validation->errors('validation') as $name => $error) { $form->set_error($name, $error); } return FALSE; }
public function construct_form(CM_Form_Abstract $form, $param) { foreach ($this->_fields as $name) { $form->get_field($name)->set_raw_value(html_entity_decode($form->get_field($name)->get_value()->get_raw(), ENT_COMPAT, 'UTF-8')); } }