as_array() public method

Return the raw data wrapped by this ORM instance as an associative array. Column names may optionally be supplied as arguments, if so, only those keys will be returned.
public as_array ( )
Ejemplo n.º 1
0
 /**
  * Returns an array of all the '_col' members. The keys will be the name
  * of the member with the '_col' chopped off the end.
  *
  * @todo update to work with $this->_orm
  * @return array
  */
 public function as_array()
 {
     if ($this->_orm) {
         $data = $this->_orm->as_array();
     } else {
         $data = array();
         foreach ($this as $key => $val) {
             if (substr($key, -4) == '_col' && $val) {
                 $data[substr($key, 0, -4)] = $val;
             }
         }
     }
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * Validates and optionally saves a new user record from an array.
  *
  * @param  array    values to check
  * @param  boolean  save the record when validation succeeds
  * @return boolean
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('type', 'required', 'length[0,255]')->add_rules('version', 'required', 'length[0,255]')->add_rules('major_version', 'length[0,255]')->add_rules('minor_version', 'length[0,255]')->add_rules('agent_detail', 'required', 'length[0,255]')->add_rules('ip', 'required', 'numeric')->add_rules('quantity', 'numeric')->add_rules('date_add', 'required', 'length[1,255]')->add_rules('date_upd', 'required', 'length[1,255]');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         return FALSE;
     }
 }
Ejemplo n.º 3
0
 /**
  * Validates and optionally saves a new user record from an array.
  *
  * @param  array    values to check
  * @param  boolean  save the record when validation succeeds
  * @return boolean
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('name', 'required', 'length[1,200]')->add_rules('resource', 'required', 'length[1,200]')->add_rules('parent_id', 'numeric')->add_rules('order', 'numeric');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         return FALSE;
     }
 }
Ejemplo n.º 4
0
 /**
  * Validates and optionally saves a new user record from an array.
  *
  * @param  array    values to check
  * @param  boolean  save[Optional] the record when validation succeeds
  * @param  string   error info
  * @return boolean
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('name', 'required', 'length[1,250]')->add_rules('username', 'required', 'length[1,250]')->add_rules('email', 'required', 'length[1,320]')->add_rules('password', 'required', 'length[1,100]')->add_rules('address', 'length[0,255]')->add_rules('role_id', 'numeric')->add_rules('site_num', 'required', 'numeric')->add_rules('contact_name', 'length[0,250]')->add_rules('phone', 'length[0,250]')->add_rules('mobile_phone', 'length[0,100]')->add_rules('postcode', 'length[0,20]')->add_rules('fax', 'length[0,255]')->add_rules('country', 'length[0,255]')->add_rules('province', 'length[0,255]')->add_rules('city', 'length[0,255]')->add_rules('township', 'length[0,255]')->add_rules('is_admin', 'digit')->add_rules('type', 'numeric')->add_rules('active', 'numeric');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         return FALSE;
     }
 }
Ejemplo n.º 5
0
 /**
  * Validates and optionally saves a new user record from an array.
  *
  * @param  array    values to check
  * @param  boolean  save the record when validation succeeds
  * @return boolean
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('name', 'required', 'length[1,255]')->add_rules('title', 'required', 'length[1,255]')->add_rules('content', 'required', 'length[1,65536]')->add_rules('mail_category_id', 'required', 'numeric');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         return FALSE;
     }
 }
Ejemplo n.º 6
0
 public function validate(array &$array, $save = FALSE, &$errors = '')
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('order_id', 'required', 'numeric')->add_rules('uid', 'required', 'numeric')->add_rules('type', 'required', 'numeric')->add_rules('price', 'required', 'numeric')->add_rules('model', 'length[0,255]')->add_rules('model_name', 'length[0,255]')->add_rules('preview', 'length[0,255]')->add_rules('preview_name', 'length[0,255]')->add_rules('size', 'length[0,100]')->add_rules('material', 'length[0,100]')->add_rules('color', 'length[0,100]')->add_rules('precision', 'length[0,100]')->add_rules('quantity', 'numeric')->add_rules('draft', 'length[0,255]')->add_rules('message', 'length[0,65535]')->add_rules('front_money', 'required', 'numeric')->add_rules('status', 'required', 'numeric');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         return FALSE;
     }
 }
Ejemplo n.º 7
0
 /**
  * Validates and optionally saves a new user record from an array.
  *
  * @param  array    values to check
  * @param  boolean  save the record when validation succeeds
  * @return boolean
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('name', 'required', 'length[1,200]')->add_rules('domain', 'required', 'length[0,320]')->add_rules('site_title', 'length[0,250]')->add_rules('logo', 'length[0,250]')->add_rules('site_email', 'required', 'length[0,320]')->add_rules('theme_id', 'required', 'numeric')->add_rules('active', 'numeric')->add_rules('wholesale', 'numeric')->add_rules('is_wholesale', 'numeric')->add_rules('https', 'numeric')->add_rules('memo', 'length[0,255]');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         return FALSE;
     }
 }
Ejemplo n.º 8
0
 public function validate(array &$array, $save = FALSE, &$errors = '')
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('username', 'required', 'length[0,20]')->add_rules('passwd', 'required', 'length[0,50]')->add_rules('email', 'required', 'length[0,100]')->add_rules('mobile', 'length[0,20]')->add_rules('name', 'length[0,10]')->add_rules('avatar', 'length[0,200]')->add_rules('tk', 'required', 'length[0,32]')->add_rules('lastlogin_time', 'required', 'length[0,200]')->add_rules('status', 'required', 'numeric');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         return FALSE;
     }
 }
Ejemplo n.º 9
0
 /**
  * Validates and optionally saves a new user record from an array.
  *
  * @param  array    values to check
  * @param  boolean  save the record when validation succeeds
  * @return boolean
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('site_id', 'required', 'numeric')->add_rules('parent_id', 'numeric')->add_rules('sub_folder_ids', 'length[0,1024]')->add_rules('name', 'required', 'length[1,255]')->add_rules('level_depth', 'required', 'numeric')->add_rules('date_add', 'required', 'length[1,255]')->add_rules('date_upd', 'required', 'length[1,255]');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         return FALSE;
     }
 }
Ejemplo n.º 10
0
 /**
  * Validates and optionally saves a new user record from an array.
  *
  * @param  array    values to check
  * @param  boolean  save the record when validation succeeds
  * @return boolean
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('site_id', 'required', 'numeric')->add_rules('kc_folder_id', 'required', 'numeric')->add_rules('attach_id', 'required', 'length[1,50]')->add_rules('image_type', 'length[0,25]')->add_rules('image_size', 'required', 'numeric')->add_rules('image_name', 'required', 'length[1,255]')->add_rules('image_mime', 'length[0,100]')->add_rules('date_add', 'required', 'length[1,255]')->add_rules('date_upd', 'required', 'length[1,255]');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         return FALSE;
     }
 }
Ejemplo n.º 11
0
 /**
  * Validates and optionally saves a new delivery category from an array.
  *
  * @param array value to check
  * @param boolean save the record when validation succeeds
  * @return boolean      
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('name', 'required', 'length[1,255]')->add_rules('ename', 'required', 'length[1,255]')->add_rules('description', 'length[1,1000]')->add_rules('edescription', 'length[1,1000]');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         log::write('form_error', $errors, __FILE__, __LINE__);
         return FALSE;
     }
 }
Ejemplo n.º 12
0
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('status', 'numeric')->add_rules('manager_id', 'numeric')->add_rules('user_log_type', 'numeric')->add_rules('ip', 'length[0,255]')->add_rules('method', 'length[0,255]')->add_rules('memo', 'length[0,512]');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         log::write('form_error', $errors, __FILE__, __LINE__);
         return FALSE;
     }
 }
Ejemplo n.º 13
0
 /**
  * Validates and optionally saves a new user record from an array.
  *
  * @param  array    values to check
  * @param  boolean  save the record when validation succeeds
  * @return boolean
  */
 public function validate(array &$array, $save = FALSE, &$errors)
 {
     $fields = parent::as_array();
     $array = array_merge($fields, $array);
     $array = Validation::factory($array)->pre_filter('trim')->add_rules('host', 'required', 'length[0,255]')->add_rules('port', 'required', 'numeric')->add_rules('username', 'required', 'length[0,255]')->add_rules('password', 'required', 'length[0,255]');
     if (parent::validate($array, $save)) {
         return TRUE;
     } else {
         $errors = $array->errors();
         log::write('Smtp_queue_form_error', $errors, __FILE__, __LINE__);
         return FALSE;
     }
 }
 /**
  * Does the same as as_array
  * but also load the ids of has_many ans has_many_though relations
  * Careful: this does extra queries!
  * @return type
  */
 public function as_map()
 {
     $map = parent::as_array();
     foreach ($this->has_many() as $key => $data) {
         $items = $this->{$key}->find_all();
         $ids = array();
         foreach ($items as $item) {
             $ids[] = $item->id;
         }
         $map[$key] = $ids;
     }
     return $map;
 }
Ejemplo n.º 15
0
 private function _setDataFromObject(ORM $dataObject)
 {
     $data = $dataObject->as_array();
     foreach ($data as $key => $value) {
         if (array_key_exists($key, $this->_dataOptional)) {
             $this->_dataOptional[$key] = $value;
         }
         if (array_key_exists($key, $this->_dataRequired)) {
             $this->_dataRequired[$key] = $value;
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * 
  * @return array
  */
 public function as_array()
 {
     $object = parent::as_array();
     $object['layout'] = $this->layout();
     return $object;
 }
Ejemplo n.º 17
0
	/**
	 * Load fields into the form
	 *
	 * @access public
	 * @param mixed ORM $model
	 * @param mixed array $fields. (default: NULL)
	 * @return void
	 */
	public function load(ORM $model, array $fields = NULL, $skip_fields = FALSE)
	{
		$this->model = $model;
		$this->_config = Kohana::$config->load('formo_kohana');
		$this->_make_fields($fields, $skip_fields);
		$this->_load_meta();

		foreach ($model->as_array() as $alias => $value)
		{
			if ($this->_use_field($alias) === FALSE)
				// If the field is supposed to be skipped, ignore it altogether
				continue;

			// The bool that tracks whether the field is relational
			$relational_field = FALSE;
			// Create the array
			$options = array();
			// The default is the value from the table
			$options['value'] = $this->model->$alias;
			// If the field is a belongs_to field, do some extra processing
			$foreign_key = $this->_process_belongs_to($alias, $options);
			// Add meta data for the field
			$this->_add_meta($alias, $options, $foreign_key);

			if (empty($options['driver']))
			{
				// Default to the default driver
				$options['driver'] = $this->_config()->drivers['default'];
			}

			$this->_form
				->add($alias, $options);
		}

		$this->_add_has_relationships();

		return $this->_form;
	}
Ejemplo n.º 18
0
 /**
  * @return array
  */
 public function transform()
 {
     return $this->_orm->as_array();
 }
Ejemplo n.º 19
0
 public function __construct(ORM $orm_obj)
 {
     foreach ($orm_obj->as_array() as $key => $value) {
         $this->{$key} = $value;
     }
 }