Ejemplo n.º 1
0
 /**
  * 
  * @param Model $model
  * @param string $relation
  */
 public function __construct(Model $model, $relation_name)
 {
     $this->model1 = $model;
     $this->field1 = $relation_name;
     $this->relation1 = Arr::get($this->model1->get_relations(), $relation_name);
     if (isset($this->relation1['foreignKey'])) {
         $this->field2 = $this->relation1['foreignKey'];
         $this->model2 = $this->model1->app()->models->factory($this->relation1['model']);
         $this->relation2 = Arr::get($this->model2->get_relations(), $this->field2);
     }
 }
Ejemplo n.º 2
0
 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;
 }