Example #1
0
 /**
  * Load the metadata for a table.
  *
  * @param Table $table
  */
 protected function loadMetadataForTable(Table $table)
 {
     $tblName = $table->getName();
     if (isset($this->defaultAliases[$tblName])) {
         $className = $this->defaultAliases[$tblName];
     } else {
         $className = $tblName;
         $this->unmapped[] = $tblName;
     }
     $contentKey = $table->getOption('alias');
     $this->metadata[$className] = [];
     $this->metadata[$className]['identifier'] = $table->getPrimaryKey();
     $this->metadata[$className]['table'] = $table->getName();
     $this->metadata[$className]['boltname'] = $contentKey;
     foreach ($table->getColumns() as $colName => $column) {
         $mapping = ['fieldname' => $column->getName(), 'type' => $column->getType()->getName(), 'fieldtype' => $this->getFieldTypeFor($table->getOption('alias'), $column), 'length' => $column->getLength(), 'nullable' => $column->getNotnull(), 'platformOptions' => $column->getPlatformOptions(), 'precision' => $column->getPrecision(), 'scale' => $column->getScale(), 'default' => $column->getDefault(), 'columnDefinition' => $column->getColumnDefinition(), 'autoincrement' => $column->getAutoincrement()];
         $this->metadata[$className]['fields'][$colName] = $mapping;
         if (isset($this->contenttypes[$contentKey]['fields'][$colName])) {
             $this->metadata[$className]['fields'][$colName]['data'] = $this->contenttypes[$contentKey]['fields'][$colName];
         }
     }
     // This loop checks the contenttypes definition for any non-db fields and adds them.
     if ($contentKey) {
         $this->setRelations($contentKey, $className, $table);
         $this->setIncomingRelations($contentKey, $className);
         $this->setTaxonomies($contentKey, $className, $table);
         $this->setTemplatefields($contentKey, $className, $table);
         $this->setRepeaters($contentKey, $className, $table);
     }
     foreach ($this->getAliases() as $alias => $table) {
         if (array_key_exists($table, $this->metadata)) {
             $this->metadata[$alias] = $this->metadata[$table];
         }
     }
 }
 public function testBuilderOptions()
 {
     $table = new Table("foo");
     $table->addOption("foo", "bar");
     $this->assertTrue($table->hasOption("foo"));
     $this->assertEquals("bar", $table->getOption("foo"));
 }