예제 #1
0
 public function testGetDatabaseTable()
 {
     $field1 = new PropertyField('field1', 'type');
     $field2 = new PropertyField('field2', 'type');
     $field3 = new HasManyField('field3', 'model');
     $index = new Index('field2', array($field2));
     $modelTable = new ModelTable('table');
     $modelTable->addField($field1);
     $modelTable->addField($field2);
     $modelTable->addField($field3);
     $modelTable->addIndex($index);
     $pk = new PropertyField('id', 'pk');
     $pk->setIsAutonumbering(true);
     $pk->setIsPrimaryKey(true);
     $databaseTable = new Table('table');
     $databaseTable->addField($pk);
     $databaseTable->addField($field1);
     $databaseTable->addField($field2);
     $databaseTable->addIndex($index);
     $this->assertEquals($databaseTable, $modelTable->getDatabaseTable());
 }
예제 #2
0
 public function testRegisterModelWithLocalizationRegistersLocalizedModel()
 {
     $field1 = new PropertyField('field1', 'string');
     $field1->setIsLocalized(true);
     $field2 = new PropertyField('field2', 'string');
     $model = $this->createModel('model', array($field1, $field2));
     $this->register->registerModel($model);
     try {
         $model = $this->register->getModel($model->getName());
         $localizedModel = $this->register->getModel($model->getName() . LocalizedModel::MODEL_SUFFIX);
         $dataField = $localizedModel->getMeta()->getField(LocalizedModel::FIELD_DATA);
         $localeField = $localizedModel->getMeta()->getField(LocalizedModel::FIELD_LOCALE);
         $localizedField = $localizedModel->getMeta()->getField('field1');
         $this->assertFalse($localizedModel->getMeta()->hasField('field2'));
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
 }
예제 #3
0
 /**
  * Construct this model definition
  * @param string $name name of the model
  * @param boolean $isLogged set to true to log this model
  * @return null
  */
 public function __construct($name, $isLogged = false)
 {
     $this->setName($name);
     $this->setIsLogged($isLogged);
     $this->isLocalized = false;
     $this->fields = array();
     $this->indexes = array();
     $this->dataFormats = array();
     $this->willBlockDeleteWhenUsed = false;
     $primaryKey = new PropertyField(self::PRIMARY_KEY, Field::TYPE_PRIMARY_KEY);
     $primaryKey->setIsAutoNumbering(true);
     $primaryKey->setIsPrimaryKey(true);
     $this->addField($primaryKey);
 }
예제 #4
0
 /**
  * Get the ModelField from a property field element
  * @param DOMElement $fieldElement field element in the model element
  * @param zibo\library\filesystem\File $file the file which is being read
  * @param string $modelName the model which is currently being processed
  * @param string $fieldName the field which is currently being processed
  * @param string $fieldType the type of the field which is currently being processed
  * @return zibo\library\orm\definition\field\ModelField
  */
 protected function getPropertyFieldFromElement(DOMElement $fieldElement, File $file, $modelName, $fieldName, $fieldType)
 {
     $field = new PropertyField($fieldName, $fieldType);
     $default = $fieldElement->hasAttribute(self::ATTRIBUTE_DEFAULT) ? $fieldElement->getAttribute(self::ATTRIBUTE_DEFAULT) : null;
     $field->setDefaultValue($default);
     $unique = $fieldElement->hasAttribute(self::ATTRIBUTE_UNIQUE) ? Boolean::getBoolean($fieldElement->getAttribute(self::ATTRIBUTE_UNIQUE)) : false;
     $field->setIsUnique($unique);
     return $field;
 }