コード例 #1
0
 /**
  * Constructs a new data format table
  * @param zibo\library\orm\definition\ModelTable $table Table containing the data formats
  * @param string $formatAction URL to the action for the format
  * @return null
  */
 public function __construct(ModelTable $table, $formatAction = null)
 {
     $formats = $table->getDataFormats();
     parent::__construct($formats);
     $this->setId(self::STYLE_ID);
     $this->addDecorator(new ZebraDecorator(new DataFormatDecorator($formatAction)));
 }
コード例 #2
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);
     }
 }
コード例 #3
0
 public function testGetDataFormats()
 {
     $name = 'name';
     $table = new ModelTable('table');
     $formats = $table->getDataFormats(false);
     $this->assertTrue(is_array($formats));
     $this->assertEquals(0, count($formats));
     $formats = $table->getDataFormats(true);
     $this->assertTrue(is_array($formats));
     $this->assertEquals(1, count($formats));
     $this->assertTrue(array_key_exists(DataFormatter::FORMAT_TITLE, $formats));
     $table->setDataFormat(new DataFormat($name, 'format'));
     $formats = $table->getDataFormats(true);
     $this->assertTrue(is_array($formats));
     $this->assertEquals(2, count($formats));
     $this->assertTrue(array_key_exists(DataFormatter::FORMAT_TITLE, $formats));
     $this->assertTrue(array_key_exists($name, $formats));
     $formats = $table->getDataFormats(false);
     $this->assertTrue(is_array($formats));
     $this->assertEquals(1, count($formats));
     $this->assertFalse(array_key_exists(DataFormatter::FORMAT_TITLE, $formats));
     $this->assertTrue(array_key_exists($name, $formats));
     $table->setDataFormat(new DataFormat(DataFormatter::FORMAT_TITLE, 'format'));
     $formats = $table->getDataFormats(true);
     $this->assertTrue(is_array($formats));
     $this->assertEquals(2, count($formats));
     $this->assertTrue(array_key_exists(DataFormatter::FORMAT_TITLE, $formats));
     $this->assertTrue(array_key_exists($name, $formats));
     $formats = $table->getDataFormats(false);
     $this->assertTrue(is_array($formats));
     $this->assertEquals(2, count($formats));
     $this->assertTrue(array_key_exists(DataFormatter::FORMAT_TITLE, $formats));
     $this->assertTrue(array_key_exists($name, $formats));
 }