Esempio n. 1
0
 public function __construct($className, $fieldName, $tableAlias = false)
 {
     $schema = ActiveRecord::getSchemaInstance($className);
     if ($schema->fieldExists($fieldName)) {
         $this->tableName = $tableAlias ? $tableAlias : $schema->getName();
         $this->field = $schema->getField($fieldName);
     } else {
         throw new ARException("Unable to find defined schema or field: " . $className . "." . $fieldName);
     }
 }
Esempio n. 2
0
 private function getNewsPostEntry($row, $params)
 {
     $row['title'] = unserialize($row['title']);
     $row = MultilingualObject::transformArray($row, ActiveRecord::getSchemaInstance('NewsPost'));
     return array('loc' => $this->router->createFullUrl(createNewsPostUrl(array('news' => $row), $this->application)));
 }
Esempio n. 3
0
 public function registerAutoReference($fieldName)
 {
     $foreignClassName = $this->getField($fieldName)->getForeignClassName();
     $this->autoReferences[] = $foreignClassName;
     $this->autoReferencedSchemas[] = ActiveRecord::getSchemaInstance($foreignClassName);
 }
Esempio n. 4
0
 protected function _generateTableDDL($name, $intent = "")
 {
     $comma = ", " . $intent;
     $schema = ActiveRecord::getSchemaInstance($name);
     $table_name = $schema->getName();
     $field_list = $schema->GetFieldList();
     $primary_list = $schema->getPrimaryKeyList();
     $foreign_list = $schema->getForeignKeyList();
     if (count($field_list) < 1) {
         return null;
     }
     if (count($primary_list) > 1) {
         $auto_increment = false;
     } else {
         $auto_increment = true;
     }
     $sql = "CREATE TABLE " . $table_name . " ( " . $intent;
     // fields
     foreach ($field_list as $field) {
         $sql .= $field->getName() . " " . $this->_defineField($field, $auto_increment) . $comma;
         //foreign key
         if ($field instanceof ARForeignKeyField) {
             $sql .= " FOREIGN KEY ( " . $field->getName() . " ) REFERENCES " . $field->getForeignTableName() . "( " . $field->getForeignFieldName() . " ) " . $comma;
         }
     }
     //primary keys
     if (count($primary_list) > 0) {
         $sql .= " PRIMARY KEY ( ";
         foreach ($primary_list as $primary) {
             $sql .= $primary->getName() . $comma;
         }
         $sql = substr($sql, 0, -strlen($comma));
         $sql .= " )" . $comma;
     }
     $sql = substr($sql, 0, -strlen($comma));
     return $sql . " )";
 }