/** * Constructs a new model index table * @param zibo\library\orm\definition\ModelTable $table Table containing the indexes * @param string $indexAction URL to the action for the index * @return null */ public function __construct(ModelTable $table, $indexAction = null) { $indexes = $table->getIndexes(); if (!$indexes) { $indexes = array(); } parent::__construct($indexes); $this->setId(self::STYLE_ID); $this->addDecorator(new ZebraDecorator(new IndexDecorator($indexAction))); }
/** * 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); } }
public function testAddIndex() { $table = new ModelTable('table'); $field = new PropertyField('field', 'type'); $index = new Index('index', array($field)); $table->addField($field); $table->addIndex($index); $indexes = $table->getIndexes(); $expected = array($index->getName() => $index); $this->assertEquals($expected, $indexes); }