/**
  * @param integer $mangaGenreId
  */
 public function delete($mangaGenreId)
 {
     if (!$this->application->request->isDelete()) {
         throw new Exception('Method not allowed', 405);
     }
     if (!$this->isAllowed()) {
         throw new Exception('User not authorized', 401);
     }
     $mg = MangaGenre::findFirst($mangaGenreId);
     if (!$mg) {
         throw new Exception('MangaGenre not found', 404);
     }
     if (!$mg->delete()) {
         throw new Exception('MangaGenre not deleted', 409);
     }
     return array('code' => 204, 'content' => 'MangaGenre deleted');
 }
Example #2
0
 /**
  * @param text $statusName
  */
 public function getList($statusName)
 {
     if (!$this->application->request->isGet()) {
         throw new Exception('Method not allowed', 405);
     }
     $statuses = Status::find();
     $sArr = $statuses->toArray('name');
     if (!in_array($statusName, $sArr)) {
         throw new Exception('Invalid parameter', 405);
     }
     $status = Status::findFirst(array('conditions' => "name = :name:", 'bind' => array('name' => $statusName)));
     $mangas = Manga::find(array('conditions' => "status_id = :id:", 'bind' => array('id' => $status->getId()), 'order' => 'name ASC'));
     if (!$mangas) {
         throw new Exception('Query not executed', 500);
     }
     if ($mangas->count() == 0) {
         return array('code' => 204, 'content' => 'No matching Manga instance found');
     }
     $output = array();
     foreach ($mangas as $m) {
         $mArr = $manga->toArray();
         $mgNames = array();
         foreach ($mArr['genres'] as $mg) {
             $mg = MangaGenre::findFirst($mg);
             array_push($mgNames, $mg->getName());
         }
         $mArr['genres'] = $mgNames;
         array_push($output, $mArr);
     }
     return array('code' => 200, 'content' => $output);
 }