Ejemplo n.º 1
0
 /**
  * Add ability to run methods against validation object
  *
  * @access public
  * @param mixed $method
  * @param mixed $args
  * @return void
  */
 public function __call($method, $args)
 {
     if (is_callable(array($this->_validation, $method))) {
         // Run validation methods inside the validation object
         $method = new ReflectionMethod($this->_validation, $method);
         $method->invokeArgs($this->_validation, $args);
         return $this;
     }
     return parent::__call($method, $args);
 }
Ejemplo n.º 2
0
	/**
	 * Set all field's values to correspond with formo values
	 *
	 * @access public
	 * @param mixed Formo $field
	 * @param mixed $value
	 * @return object
	 */
	public function set_field(Formo_Container $field, $value)
	{
		// Empty values should be NULL
		($value === '' AND $value = NULL);

		$alias = $field->alias();
		$in_model = TRUE;

		if (
				! array_key_exists($alias, $this->model->as_array())
				AND ! isset($this->_belongs_to['definitions'][$alias])
				AND ! isset($this->_has_many['definitions'][$alias])
			)
			// Don't add fields that aren't in the model
			return;

		// First check is has_many
		if ($definitions = Arr::get($this->_has_many['definitions'], $alias) AND $definitions['through'] === NULL)
		{
			$this->_has_many_relationship($alias, $value);
			return;
		}
		// Then habtm
		elseif ($definitions)
		{
			// Remove any relationships that have been removed
			foreach ($this->model->$alias->find_all() as $row)
			{
				$primary_key = $row->primary_key();
				if ( ! in_array($primary_key, $value))
				{
					$this->_habtm_relationship($alias, 'remove', $row);
				}
			}

			foreach ($value as $_value)
			{
				$record = ORM::factory($definitions['model'], $_value);
				$this->_habtm_relationship($alias, 'add', $record);
			}

			return;
		}

		if ($definitions = Arr::get($this->_has_one['definitions'], $alias))
		{
			$record = $this->model->$alias;

			if ($record->pk() != $value)
			{
				$this->_has_one_relationship($alias, $value);
			}

			return;
		}

		if ($definitions = Arr::get($this->_belongs_to['definitions'], $alias))
		{
			$field = $definitions['foreign_key'];
			$this->model->$field = $value;

			return;
		}

		// By default, simply set the value of the field to the form field value
		$this->model->$alias = $value;
	}
Ejemplo n.º 3
0
 /**
  * Set all field's values to correspond with formo values
  * 
  * @access public
  * @param mixed Formo $field
  * @param mixed $value
  * @return object
  */
 public function set_field(Formo_Container $field, $value)
 {
     $column = $field->get('alias');
     if (!$column) {
         return $this;
     }
     $data = $this->model->meta()->fields($column);
     if ($data instanceof Jelly_Field_ManyToMany or $data instanceof Jelly_Field_HasMany) {
         // Run through each possibility and add/remove as necessary
         foreach (Jelly::select($field->foreign['model'])->execute() as $record) {
             // Determine whether to add or remove the record
             $method = in_array($record->{$record->meta()->primary_key()}, (array) $value) ? 'add' : 'remove';
             // Run the add/remove method
             $this->model->{$method}($column, $record);
         }
         return $this;
     }
     // Simple field, just set the data
     $this->model->{$column} = $value;
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Add a subform to the form
  *
  * @access protected
  * @param mixed Formo $subform
  * @return object
  */
 protected function add_object(Formo_Container $subform)
 {
     $subform instanceof Formo_Form and $subform->bind('_settings', 'input', $this->_settings['input']);
     $this->append($subform);
     return $this;
 }