public function render(Model $model) { $content = Form::select($this->name, $this->options, $model->get($this->name), array()); $layout = $this->get_layout($model->app()); $layout->name = $this->name; $layout->field = $content; return $layout->render(); }
/** * * @param type $data * @return Model */ protected function load_model($data) { if ($data == null) { return null; } $model = $this->model->app()->models->factory($this->model_name); $model->from_array($data); return $model; }
public function set($column, $value) { if ($column == 'password') { $value = $this->app()->auth->hash($value); } parent::set($column, $value); }
/** * * @return integer * @throws Kohana_Exception */ public function count() { if (Arr::get($this->relation1, 'store') !== false) { if (isset($this->relation1['field'])) { $field = $this->relation1['field']; $arr = $this->model1->{$field}; return count($arr); } else { $id = "{$this->model1->get_model_name()}:{$this->model1->pk()}:{$this->field1}"; $self_collection = self::COLLECTION; $code = "function(){return db.{$self_collection}.find({'_id':'{$id}'}).limit(1)[0].ids.length}"; $return_value = 0; try { $return_value = intval($this->model1->db()->execute($code)); } catch (Exception $ex) { } return $return_value; } } elseif (isset($this->relation2) && Arr::get($this->relation2, 'store') !== false) { if (isset($this->relation2['field'])) { return $this->model2->get_collection()->count(array($this->relation2['field'] => $this->model1->pk())); } else { return $this->model2->db()->selectCollection(self::COLLECTION)->count(array("ids" => $this->model1->pk(), 'model' => $this->relation2['model'], 'field' => $this->field2)); } } else { throw new Kohana_Exception("can`t get ids for this relation"); } }
protected function field_cfg_from_string($name) { $edit_field_cfg = array('name' => $name); if ($this->model == null) { throw new Exception('model not set'); } $field = Arr::get($this->model->fields(), $name); $relation = Arr::get($this->model->get_relations(), $name); if ($field !== null) { switch ($field['type']) { case Type::BOOLEAN: $edit_field_cfg['type'] = 'boolean'; break; case Type::DOUBLE: case Type::INTEGER: case Type::STRING: $edit_field_cfg['type'] = 'text'; break; case Type::DATE: $edit_field_cfg['type'] = 'date'; break; default: throw new Exception('not implemented'); } } elseif ($relation !== null && $relation['model'] == 'Image') { if ($relation['type'] == Relation::MANY_TO_ONE) { $edit_field_cfg['type'] = 'image'; } elseif ($relation['type'] == Relation::MANY_TO_MANY) { $edit_field_cfg['type'] = 'gallery'; } else { throw new Exception('bad relation ' . $name); } } elseif ($relation !== null) { switch ($relation['type']) { case Relation::MANY_TO_MANY: $edit_field_cfg['type'] = 'tags'; break; default: throw new Exception('relation not implemented'); } } else { throw new Exception('property not found'); } return $edit_field_cfg; }
public function initialize() { parent::initialize(); $this->_fields += array('extension' => array('type' => 'string'), 'title' => array('type' => 'string'), 'description' => array('type' => 'string'), 'width' => array('type' => 'integer'), 'height' => array('type' => 'integer'), 'presentations' => array('type' => 'array')); }
protected function initialize() { parent::initialize(); $this->_fields += array('name' => array('type' => 'string'), 'description' => array('type' => 'string')); $this->_relations += array('users' => array('model' => 'User', 'type' => 'many_to_many', 'store' => false, 'foreignKey' => 'roles')); }
public function initialize() { parent::initialize(); $this->_fields += array('user_id' => array('type' => 'string'), 'token' => array('type' => 'string'), 'created' => array('type' => 'date'), 'expires' => array('type' => 'date'), 'user_agent' => array('type' => 'string')); $this->_relations += array('user' => array('model' => 'User', 'type' => 'many_to_one', 'field' => 'user_id', 'foreignKey' => 'tokens')); }