Example #1
0
 public function bookdeleteAction()
 {
     //Redirecting if not logged
     if (!$this->logged) {
         return $this->redirect()->toRoute('application/default', array('controller' => 'index', 'action' => 'index'));
     }
     //Initiate variables
     $sm = $this->getServiceLocator();
     $books = new Books($sm);
     $book_id = (int) $this->params()->fromRoute('id', 0);
     //Load book information
     $filter = array('book_id' => $book_id, 'user_id' => $this->user->user_id);
     $book = new Book($books->listBooks($filter)->current());
     //Redirect if not the owner of the book
     if (!$book->book_id) {
         return $this->redirect()->toRoute('application/default', array('controller' => 'index', 'action' => 'index'));
     }
     //Delete on database
     $message = $books->delBook($book_id);
     //Delete files
     EPUB::delBook($book_id);
     //Return messsage
     return new ViewModel(array('message' => $message));
 }