/** * {@inheritdoc} */ public function save(Album $album) { $data = $album->getArrayCopy(); if (null === $album->getId()) { return $this->db->insert('album', $data); } else { return $this->db->update('album', ['artist' => $data['artist'], 'title' => $data['title']], ['id' => $data['id']]); } }
/** * {@inheritdoc} */ public function addAlbum(array $data) { $this->form->setData($data); if ($this->form->isValid()) { $album = new Album(); $album->exchangeArray($data); if (!$this->repository->save($album)) { throw new \Exception('Unable to save the album'); } return true; } return false; }
/** * @param Album $album * @return int */ public function delete(Album $album) { return $this->db->delete('album', ['id' => $album->getId()]); }