/** * Book Submit * * Expect details about the book to save on the database * * @return Ambigous <\Zend\Http\Response, \Zend\Stdlib\ResponseInterface>|\Zend\View\Model\ViewModel */ public function booksubmitAction() { //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); $request = $this->getRequest(); $fields = $request->getPost(); //Load book information $filter = array('book_id' => $fields['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')); } //Update values if ($request->isPost()) { $book = $fields; $book->author = $book->author == "-1" ? $fields->other_author : $book->author; $book->serie = $book->serie == "-1" ? $fields->other_serie : $book->serie; $book->language = $book->language == "-1" ? $fields->other_language : $book->language; $book->date = date("Y-m-d"); $book->status = 'ok'; $genres = $fields->genre; $file_sent = !empty($_FILES['file']['name']); $file_ok = $_FILES["file"]["error"] > 0 ? false : true; $file_ext = end(explode(".", $_FILES["file"]["name"])); $file_ok = $file_ext == "jpg" || $file_ext == "jpeg" ? $file_ok : false; } if ($file_sent && !$file_ok) { $message = "Erro: Problems with the file"; } else { $message = 'The book "' . $book->title . '" was successfully saved'; //Save updated values $book = $books->editBook($book, $genres); //Change Picture if ($file_sent) { $epub = new EPUB($this->getServiceLocator()->get('config')['uploadFolder'] . $book->book_id . ".epub", $this->getServiceLocator()->get('config')['uploadFolder']); $epub->changeCover($_FILES["file"]["tmp_name"]); $imagine = $this->getServiceLocator()->get('my_image_service'); $epub->saveCover($book->book_id, $imagine); $epub->saveBook($book->book_id); } } return new ViewModel(array('message' => $message)); }