forked from wingman007/fmi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2397209
commit 3536d2e
Showing
5 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: php | ||
php: | ||
- "5.5" | ||
- "5.4" | ||
- "5.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
namespace Album\Model; | ||
|
||
class Album | ||
{ | ||
public $id; | ||
public $artist; | ||
public $title; | ||
|
||
public function exchangeArray($data) | ||
{ | ||
$this->id = (isset($data['id'])) ? $data['id'] : null; | ||
$this->artist = (isset($data['artist'])) ? $data['artist'] : null; | ||
$this->title = (isset($data['title'])) ? $data['title'] : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace Album\Model; | ||
|
||
use Zend\Db\TableGateway\TableGateway; | ||
|
||
class AlbumTable | ||
{ | ||
protected $tableGateway; | ||
|
||
public function __construct(TableGateway $tableGateway) | ||
{ | ||
$this->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)); | ||
} | ||
} |