{ // Only to be used during testing! $this->dropOnCreate(); // Table name $this->setName('galleryitems'); // Table columns $this->addColumn('id', 'int', self::COL_AUTO | self::KEY_PRIMARY); $this->addColumn('name', 'varchar:160'); $this->addColumn('uuid', 'char:37', self::COL_FIXED); $this->addColumn('src', 'varchar:200'); // Indexes $this->addIndex('uuidkey', array('uuid'), self::KEY_UNIQUE); $this->addIndex('srckey', array('src'), self::KEY_UNIQUE); } } SqlTableSchema::apply(new GalleryItemsTable()); /** * @class Gallery * @package lepton.media * @brief Gallery Management * */ class Gallery { static function get($selection, $paginator = null) { return new GalleryCollection($selection, $paginator); } static function getTagStatus() { // Return a lsit of all the tags applied
function apply(SqlTableSchema $schema) { $sdef = $schema->getDefinition(); $tname = $sdef['name']; $tdrop = $sdef['drop']; $tcols = $sdef['columns']; $tkeys = $sdef['keys']; // Create table $sql = 'CREATE TABLE ' . $tname . " ("; foreach ($tcols as $col) { $sql .= $col['name'] . ' ' . $this->getColType($col['type'], $col['opts']); if ($col['default'] != null) { $sql .= 'DEFAULT ' . $col['default']; } if ($col != end($tcols)) { $sql .= ', '; } } foreach ($tkeys as $key) { switch ($key['type']) { case SqlTableSchema::KEY_PRIMARY: $keystr = ', PRIMARY KEY '; break; case SqlTableSchema::KEY_UNIQUE: $keystr = ', UNIQUE KEY '; break; case SqlTableSchema::KEY_FULLTEXT: $keystr = ', FULLTEXT INDEX '; break; case SqlTableSchema::KEY_INDEX: $keystr = ', KEY '; break; } $keystr .= sprintf('%s(%s)', $key['name'], join(',', $key['cols'])); $sql .= $keystr; } $sql .= ')'; if ($tdrop) { $this->conn->exec('DROP TABLE IF EXISTS ' . $tname); } $this->conn->exec($sql); }