Ejemplo n.º 1
0
 /**
  * @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());
         }
     }
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 /**
  * @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;
 }
Ejemplo n.º 4
0
 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());
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
    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;
    }
Ejemplo n.º 7
0
 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";
 }
Ejemplo n.º 8
0
Archivo: DBAL.php Proyecto: cti/storage
 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;
 }
Ejemplo n.º 9
0
 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');
 }