Ejemplo n.º 1
0
 public static function load(Jelly_Model $model, Formo $form, array $fields = NULL)
 {
     $skip_fields = array();
     if ($fields and in_array('*', $fields)) {
         $skip_fields = $fields;
         $fields = NULL;
     }
     foreach ($model->meta()->fields() as $column => $field) {
         if (in_array($column, $skip_fields)) {
             continue;
         }
         if ($fields and !in_array($column, $fields)) {
             continue;
         }
         $options = (array) $field + array('value' => $model->get($column));
         // Fetch the validation key names from the config file
         $validation_keys = Kohana::config('formo_jelly')->validation_keys;
         // Add specific rules
         if ($options['unique'] === TRUE) {
             // If the field is set to unique, add the rule to check for other records
             $options[$validation_keys['rules']][':model::unique'] = array($column);
         }
         // Look for validation rules as defined by the config file
         foreach ($validation_keys as $key => $value) {
             // If they are using the assumed names, do nothing
             if ($key === $value) {
                 continue;
             }
             // Only grab the proper validation settings from jelly field definition
             $options[$key] = !empty($options[$value]) ? $options[$value] : array();
             // No need to carry duplicates for a rule
             unset($options[$value]);
         }
         // NOTE: This shouldn't really happen until pre_render
         /*
         			$options = array('value' => $model->get($column));
         			
         			$add_options = array('driver', 'rules', 'filters', 'triggers', 'post_filters');
         			
         			foreach ($add_options as $option)
         			{
         				if ( ! empty($field->$option))
         				{
         					$options[$option] = $field->$option;
         				}
         			}
         */
         $form->add($column, $options);
     }
 }
Ejemplo n.º 2
0
 protected static function _process_has_many($alias, Kohana_ORM $model, stdClass $std, Formo $form)
 {
     if (empty($std->has_many)) {
         // No need to process non-has-many fields here
         return NULL;
     }
     foreach (Arr::get($std->has_many, 'definitions', array()) as $key => $values) {
         if (Arr::get($values, 'formo') === true) {
             $rs_all = ORM::factory($values['model'])->find_all();
             $foreign_model = ORM::factory($values['model']);
             $rs_in = $foreign_model->where($values['foreign_key'], '=', $model->pk())->find_all();
             $opts = static::select_list($rs_all, $foreign_model->primary_key(), static::_get_field_name($foreign_model));
             $val = static::select_list($rs_in, $foreign_model->primary_key(), $foreign_model->primary_key());
             $form->add($key, 'checkboxes', $val, array('opts' => $opts));
         } else {
             $form->add($key, 'checkboxes', null, array('render' => false));
         }
     }
 }