/** * Initialize file fields * * @return void */ protected function _initialize_file_fields() { // Init file fields $def_config = self::$default_file_config; if (empty($def_config['dir_chmod'])) { $def_config['dir_chmod'] = Ku_Upload::$default_dir_chmod; } if (empty($def_config['file_chmod'])) { $def_config['file_chmod'] = Ku_Upload::$default_file_chmod; } if (empty($def_config['path'])) { $def_config['path'] = Ku_Upload::$default_directory; } foreach ($this->_file_fields as $field => $config) { if (empty($config['path'])) { $config['path'] = $def_config['path'] . DIRECTORY_SEPARATOR . $this->_orm->object_name() . DIRECTORY_SEPARATOR . $field; } $config += $def_config; if ($config['uri'] === NULL) { $config['uri'] = str_replace('\\', '/', $config['path']); if (strlen($config['uri']) > strlen(DOCROOT)) { $config['uri'] = str_replace(str_replace('\\', '/', DOCROOT), '', $config['uri']); } } $config['uri'] = trim($config['uri'], '/'); $this->_file_fields[$field] = $config; } }
public static function exclude_hidden(ORM $orm, $is_master_site) { if (!$is_master_site) { $hided_list = ORM::factory('hided_List')->where('object_name', '=', $orm->object_name())->find_all()->as_array(NULL, 'element_id'); if (!empty($hided_list)) { $orm->where($orm->primary_key(), 'NOT IN', $hided_list); } } }
public function __construct(ORM $orm, array $columns = array(), $options = array()) { $this->_options = $options; $this->set_name($orm->object_name()); foreach ($columns as $name => $column) { if (!is_array($column)) { $column = array('type' => $column); } $column_cfg = array('name' => $name, 'header' => Arr::get($orm->labels(), $name), 'params' => Arr::get($column, 'params', array())); $column = Arr::merge($column_cfg, (array) $column); $column = Grid_Column::factory($column); $this[$name] = $column; } $this->_orm = $orm; }
protected function __construct(ORM $object, array $fields = array()) { $this->_object = $object; $this->set_name($object->object_name()); $hash = ''; foreach ($fields as $name => $field) { if (!is_array($field)) { $field = array('type' => $field); } $field_cfg = array('name' => $name, 'label' => Arr::get($object->labels(), $name), 'value' => $object[$name]); $field = Arr::merge($field_cfg, (array) $field); $field = Form_Field::factory($field); $field->set_object($object); $this[$name] = $field; $hash .= $field->hash(); } $this->_hash = md5($hash); }
private function save_file($file_path, ORM $album_orm, $to_head) { $orm_helper = ORM_Helper::factory('photo'); try { $orm_helper->save(array('owner' => $album_orm->object_name(), 'owner_id' => $album_orm->id, 'title' => Arr::path($_FILES, 'file.name', ''), 'image' => $file_path, 'active' => 1, 'creator_id' => $this->user->id)); if ($to_head) { $config = Arr::get($orm_helper->position_fields(), 'position'); $position = Session::instance()->get('multiupload_position', $config['step']); $orm_helper->position_set('position', $position); Session::instance()->set('multiupload_position', $position + $config['step']); } } catch (ORM_Validation_Exception $e) { return implode('. ', $e->errors('')); } catch (Exception $e) { Kohana::$log->add(Log::ERROR, 'Multiupload error. Exception occurred: :exception', array(':exception' => $e->getMessage())); return 'Save error'; } return TRUE; }
/** * Read operation * * @param int $id * @return ORM */ public function read($id) { return $this->orm->where($this->orm->object_name() . '.' . $this->orm->primary_key(), '=', $id)->find(); }
/** * Creates a new MAttach. * * $mattach = new MAttach($user,$log); * * @param ORM Model * @param ORM/String Model to Save * @return void */ public function __construct(ORM $model, $smodel) { if ($smodel instanceof ORM) { try { $this->model = $smodel; $this->model->model_id = $model->pk(); $this->model->model_name = $model->object_name(); } catch (Exception $e) { throw $e; } } elseif (is_string($smodel)) { try { $this->model = ORM::factory($smodel); $this->model->model_id = $model->pk(); $this->model->model_name = $model->object_name(); } catch (Exception $e) { throw $e; } } else { throw new Exception('WTF?'); } }
/** * @param ORM $obj */ public static function get($obj) { return ORM::factory('Seo')->where('model', '=', strtolower($obj->object_name()))->where('pk', '=', $obj->pk())->find(); }
public function set_owner(ORM $owner) { $this->owner_id = $owner->id; $this->owner_object_name = $owner->object_name(); }