/** * @param \Cti\Storage\Component\Model $linkModel */ public function getOppositeModel($linkModel) { foreach ($linkModel->getReferences() as $reference) { if ($reference->getDestination() != $this->model->getName()) { return $this->schema->getModel($reference->getDestination()); } } }
public function convert(Schema $schema) { $result = array('models' => array()); foreach ($schema->getModels() as $model) { $result['models'][$model->getName()] = $this->modelAsArray($model); } return $result; }
public function getUsages() { $usages = array(); if ($this->hasRelation()) { $model = $this->schema->getModel($this->property->getRelation()->getDestination()); $usages[] = sprintf('use %s as %s;', $model->getModelClass(), $model->getClassName()); } return $usages; }
/** * @param Schema $schema * @return $this */ function process(Schema $schema) { $source = $schema->getModel($this->source); $destination = $schema->getModel($this->destination); foreach ($destination->getPk() as $key) { $property = $destination->getProperty($key); $behaviour = $property->getBehaviour(); if (!$behaviour instanceof \Cti\Storage\Behaviour\Log) { $name = $this->getDestinationAlias() != $this->getDestination() ? $key . '_' . $this->getDestinationAlias() : $key; $comment = ucfirst($this->getDestinationAlias()); if ($this->getDestination() == $this->getDestinationAlias()) { $comment = $schema->getModel($this->getDestination())->getComment(); } $this->properties[$name] = $source->addProperty($name, new Property(array('name' => $name, 'foreignName' => $key, 'comment' => $comment, 'type' => $property->getType(), 'relation' => $this, 'readonly' => true))); } } $destination->addReference($this); return $this; }
public function testIndexCreateAndRemove() { $person = $this->schema->getModel("person"); // create index $person->createIndex("hash", "salt"); $indexMap = array(); $hashSaltIndex = null; foreach ($person->getIndexes() as $index) { $fields = $index->getFields(); $indexMap[] = implode(':', $fields); if (in_array('hash', $fields) && in_array('salt', $fields)) { $hashSaltIndex = $index; } } $this->assertNotNull($hashSaltIndex); $this->assertContains("hash:salt", $indexMap); $this->assertCount(2, $indexMap); // remove index $person->removeIndex($hashSaltIndex); $this->assertCount(1, $person->getIndexes()); }
public function convert(\Cti\Storage\Schema $inputSchema) { $schema = new \Doctrine\DBAL\Schema\Schema(); foreach ($inputSchema->getModels() as $model) { $table = $schema->createTable($model->getName()); foreach ($model->getProperties() as $property) { $params = array('comment' => $property->getComment(), 'notnull' => $property->getRequired()); $type = $property->getType(); if ($type === 'char') { $type = 'string'; $params['length'] = 1; } $table->addColumn($property->getName(), $type, $params); } $table->setPrimaryKey($model->getPk()); foreach ($model->getIndexes() as $index) { $table->addIndex($index->getFields()); } } foreach ($inputSchema->getModels() as $model) { $table = $schema->getTable($model->getName()); foreach ($model->getOutReferences() as $reference) { if ($inputSchema->getModel($reference->getDestination())->getBehaviour("log")) { continue; } $destination = $schema->getTable($reference->getDestination()); $foreignProperties = array(); foreach ($reference->getProperties() as $property) { $foreignProperties[] = $property->getForeignName(); } $localProperties = array_keys($reference->getProperties()); $table->addForeignKeyConstraint($destination, $localProperties, $foreignProperties); } } foreach ($inputSchema->getSequences() as $sequence) { $schema->createSequence($sequence->getName()); } return $schema; }
public function getTabConfigModifyCode() { $code = ""; foreach ($this->model->getLinks() as $link) { $tabName = $link->getComment(); foreach ($link->getOutReferences() as $reference) { if ($reference->getDestination() != $this->model->getName()) { $tabName = $this->schema->getModel($reference->getDestination())->getComment(); } } $code .= " config.items.push\r\n title: '{$tabName}'\r\n name: '" . $link->getName() . "_tab'\r\n items: [\r\n Ext.create 'Editor." . $link->getClassName() . "', parentWindow: this\r\n ]\r\n"; } return $code; }
function getGeneratedCode() { $list = array(); foreach ($this->schema->getModels() as $model) { if (!$model->hasBehaviour('link')) { $list[] = "splashClass: 'Grid." . $model->getClassName() . "'"; } } $list = implode(PHP_EOL . ' ,' . PHP_EOL . ' ', $list); return <<<COFFEE Ext.define 'Generated.Master' extend: 'Cti.Splash' title: 'Доступные модели' token: '/_master' initComponent: -> @list = [ {$list} ] @callParent arguments COFFEE; }
public function process(Schema $schema) { $schema->setNamespace('scheduler'); $job = $schema->createModel('job', 'Job', array('name' => 'Name', 'status' => 'Status', array('system', 'integer', 'System command'))); $schedule = $schema->createModel('schedule', 'Schedule', array('type' => 'Type', 'month' => 'Month', 'day' => 'Day', 'hour' => 'Hour', 'minute' => 'Minute', 'dt_next' => 'Date for next running')); $job->hasOne($schedule); $command = $schema->createModel('command', 'Job Command', array('command' => 'Command', array('priority', 'integer', 'Priority'))); $command->hasOne($job); // New, Active, Complete, Fail $task = $schema->createModel('task', 'Task', array('dt_scheduled' => 'Scheduled start date', 'dt_start' => 'Fact start date', 'dt_end' => 'Fact end date', 'status' => 'Status', array('success', 'integer', 'Success'))); $task->hasOne($job); $log = $schema->createModel('log', 'Log', array('output' => 'Output', 'dt_log' => 'Log date')); $log->hasOne($task); }
public function renderRelationProperty() { $property = $this->property; $relation = $property->getRelation(); $foreignModel = $this->schema->getModel($relation->getDestination()); $name = $relation->getDestinationAlias() ? $relation->getDestinationAlias() : $foreignModel->getName(); $model_class = $foreignModel->getModelClass(); return <<<RELATION /** * {$name} property * @var {$model_class} */ protected \${$name}; RELATION; }
public function getConditionDefinition() { /** * @var \Cti\Storage\Component\Reference[] $references */ $references = array_values($this->model->getOutReferences()); /** * @var \Cti\Storage\Component\Model[] $referencesModels */ $referencesModels = array(); $referenceProperties = array(); $referencesModels[] = $this->schema->getModel($references[0]->getDestination()); $referenceProperties[] = $references[0]->getProperties(); $referencesModels[] = $this->schema->getModel($references[1]->getDestination()); $referenceProperties[] = $references[1]->getProperties(); $referenceProperties[0] = array_shift($referenceProperties[0]); $referenceProperties[1] = array_shift($referenceProperties[1]); return " if @record instanceof Model." . $referencesModels[0]->getClassName() . "\r\n condition =\r\n " . $referenceProperties[0]->getName() . ": record.data.id_" . $referencesModels[0]->getName() . "\r\n else if @record instanceof Model." . $referencesModels[1]->getClassName() . "\r\n condition =\r\n " . $referenceProperties[1]->getName() . ": record.data.id_" . $referencesModels[1]->getName() . "\r\n"; }
public function process(Schema $schema) { $schema->setNamespace('public'); $person = $schema->createModel('person', 'Пользователь', array('login' => array('comment' => 'Имя пользователя', 'required' => true), 'salt' => 'Соль для вычисления хэша', 'hash' => 'Полученный хэш', 'status' => array('type' => 'char', 'comment' => 'Статус'))); $person->createIndex('login'); $person->addBehaviour('log'); $module = $schema->createModel('module', 'Модуль', array('name' => 'Наименование')); // favorite modules link $favorite_module = $schema->createLink(array($person, 'favorite_module' => $module)); $favorite_module->addProperty('rating', array('comment' => 'Рейтинг', 'type' => 'integer', 'max' => 100, 'min' => 0)); // module developers link $schema->createLink(array($module, 'developer' => $person)); // default user module $schema->getModel('person')->hasOne('module')->usingAlias('default_module')->referencedBy('default_user')->setStrategy('merge'); // module owner $module->hasOne('person')->usingAlias('owner')->referencedBy('own_module'); // isolate model // $exchange = $schema->createModel('exchange', 'Точка обмена', array( // 'key' => 'Ключ', // 'value' => 'Значение' // )); // $exchange->setNamespace('other'); }