diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..42d77d16 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: php +php: + - "5.5" + - "5.4" + - "5.3" \ No newline at end of file diff --git a/config/autoload/global.php b/config/autoload/global.php index 1473720f..bd28f061 100644 --- a/config/autoload/global.php +++ b/config/autoload/global.php @@ -10,7 +10,25 @@ * control, so do not include passwords or other sensitive information in this * file. */ - +/* return array( // ... ); +*/ + + array( + 'driver' => 'Pdo', +// 'dsn' => 'mysql:dbname=wingman;host=wingman-db.my.phpcloud.com', + 'driver_options' => array( + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' + ), + ), + 'service_manager' => array( + 'factories' => array( + 'Zend\Db\Adapter\Adapter' + => 'Zend\Db\Adapter\AdapterServiceFactory', + ), + ), +); \ No newline at end of file diff --git a/module/Album/Module.php b/module/Album/Module.php index a1740307..31072251 100644 --- a/module/Album/Module.php +++ b/module/Album/Module.php @@ -1,6 +1,12 @@ array( + 'Album\Model\AlbumTable' => function($sm) { + $tableGateway = $sm->get('AlbumTableGateway'); + $table = new AlbumTable($tableGateway); + return $table; + }, + 'AlbumTableGateway' => function ($sm) { + $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); + $resultSetPrototype = new ResultSet(); + $resultSetPrototype->setArrayObjectPrototype(new Album()); + return new TableGateway('album', $dbAdapter, null, $resultSetPrototype); + }, + ), + ); + } } \ No newline at end of file diff --git a/module/Album/src/Album/Model/Album.php b/module/Album/src/Album/Model/Album.php new file mode 100644 index 00000000..dcf72cf9 --- /dev/null +++ b/module/Album/src/Album/Model/Album.php @@ -0,0 +1,16 @@ +id = (isset($data['id'])) ? $data['id'] : null; + $this->artist = (isset($data['artist'])) ? $data['artist'] : null; + $this->title = (isset($data['title'])) ? $data['title'] : null; + } +} \ No newline at end of file diff --git a/module/Album/src/Album/Model/AlbumTable.php b/module/Album/src/Album/Model/AlbumTable.php new file mode 100644 index 00000000..90f178c0 --- /dev/null +++ b/module/Album/src/Album/Model/AlbumTable.php @@ -0,0 +1,55 @@ +tableGateway = $tableGateway; + } + + public function fetchAll() + { + $resultSet = $this->tableGateway->select(); + return $resultSet; + } + + public function getAlbum($id) + { + $id = (int) $id; + $rowset = $this->tableGateway->select(array('id' => $id)); + $row = $rowset->current(); + if (!$row) { + throw new \Exception("Could not find row $id"); + } + return $row; + } + + public function saveAlbum(Album $album) + { + $data = array( + 'artist' => $album->artist, + 'title' => $album->title, + ); + + $id = (int)$album->id; + if ($id == 0) { + $this->tableGateway->insert($data); + } else { + if ($this->getAlbum($id)) { + $this->tableGateway->update($data, array('id' => $id)); + } else { + throw new \Exception('Form id does not exist'); + } + } + } + + public function deleteAlbum($id) + { + $this->tableGateway->delete(array('id' => $id)); + } +} \ No newline at end of file