예제 #1
0
 /**
  * Makes sure the model table is parsed so the data for the methods of this object are initialized
  * @return null
  */
 public function parseMeta()
 {
     if ($this->isParsed) {
         return;
     }
     $this->localizedFields = array();
     $this->properties = array();
     $this->belongsTo = array();
     $this->hasOne = array();
     $this->hasMany = array();
     $this->relations = array();
     $modelManager = ModelManager::getInstance();
     $fields = $this->table->getFields();
     foreach ($fields as $fieldName => $field) {
         if ($fieldName != VersionField::NAME && $field->isLocalized()) {
             $this->localizedFields[$fieldName] = $field;
         }
         if ($field instanceof HasField) {
             $this->parseHasField($field, $modelManager);
         } elseif ($field instanceof BelongsToField) {
             $this->parseBelongsToField($field, $modelManager);
         } else {
             $this->parsePropertyField($field);
         }
     }
     $this->isParsed = true;
 }
예제 #2
0
 /**
  * Constructs a new model field table
  * @param zibo\library\orm\definition\ModelTable $table Table containing the fields
  * @param string $fieldAction URL to the action of a field
  * @param string $modelAction URL to the action of a model
  * @return null
  */
 public function __construct(ModelTable $table, $tableAction, $fieldAction = null, $modelAction = null)
 {
     $fields = $table->getFields();
     unset($fields[ModelTable::PRIMARY_KEY]);
     parent::__construct($fields, $tableAction, self::NAME);
     $this->addDecorator(new ZebraDecorator(new ModelFieldDecorator($fieldAction, $modelAction)));
     $this->addDecorator(new ModelFieldLabelDecorator());
     $this->addDecorator(new ModelFieldFlagsDecorator());
 }
 /**
  * Constructs a new model field table
  * @param zibo\library\orm\definition\ModelTable $table Table containing the fields
  * @param string $fieldAction URL to the action for the field
  * @return null
  */
 public function __construct(ModelTable $table, $fieldAction = null)
 {
     $fields = $table->getFields();
     unset($fields[ModelTable::PRIMARY_KEY]);
     parent::__construct($fields);
     $this->setId(self::STYLE_ID);
     $this->addDecorator(new ZebraDecorator(new ModelFieldDecorator($fieldAction)));
     $this->addDecorator(new ModelFieldLabelDecorator());
 }
예제 #4
0
 /**
  * Copies a model table into another
  * @param zibo\library\orm\definition\ModelTable $source
  * @param zibo\library\orm\definition\ModelTable $destination
  * @return null
  */
 private function copyModel(ModelTable $source, ModelTable $destination)
 {
     $destination->setWillBlockDeleteWhenUsed($source->willBlockDeleteWhenUsed);
     $fields = $source->getFields();
     foreach ($fields as $field) {
         if ($field->getName() == ModelTable::PRIMARY_KEY) {
             continue;
         }
         $destination->addField($field);
     }
     $indexes = $source->getIndexes();
     foreach ($indexes as $index) {
         $destination->addIndex($index);
     }
     $dataFormats = $source->getDataFormats();
     foreach ($dataFormats as $name => $format) {
         $destination->setDataFormat($name, $format);
     }
 }
예제 #5
0
 public function testOrderFields()
 {
     $table = new ModelTable('table');
     $table->addField(new PropertyField('name1', 'type'));
     $table->addField(new PropertyField('name2', 'type'));
     $table->addField(new PropertyField('name3', 'type'));
     $table->addField(new PropertyField('name4', 'type'));
     $fields = $table->getFields();
     $this->assertEquals(array('id', 'name1', 'name2', 'name3', 'name4'), array_keys($fields));
     $table->orderFields(array('name3', 'name2'));
     $fields = $table->getFields();
     $this->assertEquals(array('id', 'name3', 'name2', 'name1', 'name4'), array_keys($fields));
     $table->orderFields(array('name4', 'name3', 'id', 'name2', 'name1'));
     $fields = $table->getFields();
     $this->assertEquals(array('id', 'name4', 'name3', 'name2', 'name1'), array_keys($fields));
 }