Exemplo n.º 1
0
 public function indexAction()
 {
     $this->view->book = $subject = Engine_Api::_()->core()->getSubject();
     $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
     if ($viewer->isAdmin() || $subject->isBookAuthor($viewer) || $subject->user_id == $viewer->getIdentity()) {
         $photoTbl = new Book_Model_DbTable_Photos();
         $select = $photoTbl->select()->where('parent_object_type = ?', $subject->getType())->where('parent_object_id = ?', $subject->getIdentity());
         $this->view->photos = $photos = $photoTbl->fetchAll($select);
         return;
     }
     return $this->setNoRender();
 }
Exemplo n.º 2
0
 protected function _postDelete()
 {
     parent::_postDelete();
     $bookPhotoTbl = new Book_Model_DbTable_Photos();
     $bookPhotoTbl->delete(array('parent_object_type = ?' => $this->getType(), 'parent_object_id = ?' => $this->getIdentity()));
     $bookAuthorTbl = new Book_Model_DbTable_BookAuthor();
     $bookAuthorTbl->delete(array('book_id = ?' => $this->getIdentity()));
     $bookFavTbl = new Book_Model_DbTable_Favorites();
     $bookFavTbl->delete(array('parent_object_type = ?' => $this->getType(), 'parent_object_id = ?' => $this->getIdentity()));
     $bookPostTbl = new Book_Model_DbTable_Posts();
     $bookPostTbl->update(array('parent_id' => NULL, 'parent_type' => NULL), array('parent_id = ?' => $this->getIdentity(), 'parent_type = ?' => $this->getType()));
     $bookRatingTbl = new Book_Model_DbTable_Ratings();
     $bookRatingTbl->delete(array('parent_object_type = ?' => $this->getType(), 'parent_object_id = ?' => $this->getIdentity()));
     $popularityTbl = new Book_Model_DbTable_Popularities();
     $popularity = $popularityTbl->delete(array('resource_id = ?' => $this->getIdentity(), 'resource_type = ?' => $this->getType()));
 }
Exemplo n.º 3
0
 public function deletePhotoAction()
 {
     $book = $this->_getBook();
     if (isset($book) && is_object($book)) {
         $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
         $authors = $book->getAuthors();
         $allowDelete = false;
         if ($viewer->isAdmin() || $viewer->getIdentity() != $book->user_id) {
             $allowDelete = true;
         } else {
             foreach ($authors as $author) {
                 if ($viewer->isSelf($author)) {
                     $allowDelete = true;
                 }
             }
         }
         if ($allowDelete) {
             $photoId = $this->_getParam('photo_id');
             if ($photoId) {
                 $db = Engine_Db_Table::getDefaultAdapter();
                 $db->beginTransaction();
                 try {
                     $photoTbl = new Book_Model_DbTable_Photos();
                     $select = $photoTbl->select()->where("photo_id = ?", $photoId);
                     $photo = $photoTbl->fetchRow($select);
                     $photo->delete();
                     $db->commit();
                 } catch (Exception $e) {
                     $db->rollBack();
                     throw $e;
                 }
                 $this->view->status = 1;
                 $this->view->message = Zend_Registry::get('Zend_Translate')->_('The photo is deleted successfully !');
             }
         }
     }
 }
Exemplo n.º 4
0
 public function getAllApprovedPhotos()
 {
     $photoTbl = new Book_Model_DbTable_Photos();
     $select = $photoTbl->select();
     $select->where("parent_object_type = ?", $this->getType())->where("parent_object_id = ?", $this->getIdentity())->where("approved = ?", 1);
     $select->order('default DESC');
     $photos = array();
     $storageApi = Engine_Api::_()->storage();
     foreach ($photoTbl->fetchAll($select) as $photo) {
         $file = $storageApi->get($photo->file_id);
         if (!empty($file)) {
             array_push($photos, $file->storage_path);
         }
     }
     return $photos;
 }
Exemplo n.º 5
0
 public function importRawBooks()
 {
     try {
         $bookTbl = new Book_Model_DbTable_Books();
         $select = $bookTbl->select();
         $select->from($bookTbl->info('name'), new Zend_Db_Expr('MAX(`rawbook_id`) as max_rawbook_id'));
         $data = $select->query()->fetch();
         $maxRawbookId = (int) $data['max_rawbook_id'];
         $userTbl = new User_Model_DbTable_Users();
         $rawBookTbl = new Book_Model_DbTable_Rawbooks();
         $rawBookSelect = $rawBookTbl->select();
         $rawBookSelect->where('rawbook_id > ?', $maxRawbookId);
         $rawBookSelect->order('rawbook_id ASC');
         $rawBookSelect->limit(self::DEFAULT_LIMIT);
         $rawBooks = $rawBookTbl->fetchAll($rawBookSelect);
         foreach ($rawBooks as $rawBook) {
             if (!empty($rawBook['publisher'])) {
                 $publisherSelect = $userTbl->select()->where('displayname LIKE ?', $rawBook['publisher']);
                 $publisher = $userTbl->fetchRow($publisherSelect);
             }
             if (!empty($rawBook['book_company'])) {
                 $bookCompanySelect = $userTbl->select()->where('displayname LIKE ?', $rawBook['book_company']);
                 $bookCompany = $userTbl->fetchRow($bookCompanySelect);
             }
             $data = array('book_name' => $rawBook->book_name, 'published_date' => date('Y-m-d H:i:s', $rawBook->published_date), 'price' => $rawBook->price, 'num_page' => $rawBook->num_page, 'description' => $rawBook->description, 'rawbook_id' => $rawBook->getIdentity(), 'user_id' => 1);
             if (isset($publisher) && !empty($publisher)) {
                 $data['publisher_id'] = $publisher->getIdentity();
             }
             if (isset($bookCompany) && !empty($bookCompany)) {
                 $data['book_company_id'] = $bookCompany->getIdentity();
             }
             $book = $bookTbl->createRow($data);
             $book->save();
             if (!empty($rawBook['photo'])) {
                 $image = Engine_Image::factory();
                 $name = basename($rawBook['photo']);
                 $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary';
                 $params = array('parent_id' => $book->getIdentity(), 'parent_type' => $book->getType(), 'user_id' => 1);
                 // Save
                 $storage = Engine_Api::_()->storage();
                 $image->open($rawBook['photo'])->write($path . '/m_' . $name)->destroy();
                 // Store
                 $iMain = $storage->create($path . '/m_' . $name, $params);
                 // Remove temp files
                 @unlink($path . '/m_' . $name);
                 $book->photo_id = $iMain->getIdentity();
                 $book->save();
                 $photoTbl = new Book_Model_DbTable_Photos();
                 $photo = $photoTbl->createRow(array('parent_object_type' => $book->getType(), 'parent_object_id' => $book->getIdentity(), 'file_id' => $iMain->getIdentity(), 'user_id' => 1, 'approved' => 1, 'default' => 1));
                 $photo->save();
             }
         }
         return true;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 6
0
 public function createBookAction()
 {
     if (!$this->_helper->requireUser()->isValid()) {
         return;
     }
     $viewer = Engine_Api::_()->user()->getViewer();
     $this->view->form = $form = new Book_Form_Book_Create();
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $values = $form->getValues();
     $bookTable = new Book_Model_DbTable_Books();
     $bookAuthorTable = new Book_Model_DbTable_BookAuthor();
     $db = Engine_Db_Table::getDefaultAdapter();
     $db->beginTransaction();
     try {
         $book = $bookTable->createRow($values);
         $book->creation_date = date('Y-m-d H:i:s');
         $book->modified_date = $book->creation_date;
         $book->category_id = $this->_getParam('category_id_0', 0);
         $book->user_id = $viewer->getIdentity();
         $book->save();
         if (!empty($values['photo'])) {
             try {
                 $book->setPhoto($form->photo);
                 $bookPhotoTable = new Book_Model_DbTable_Photos();
                 $bookPhoto = $bookPhotoTable->createRow(array('parent_type' => $book->getType(), 'parent_id' => $book->getIdentity(), 'file_id' => $book->photo_id, 'approved' => 1, 'default' => 1));
                 $bookPhoto->save();
             } catch (Engine_Image_Adapter_Exception $e) {
                 Zend_Registry::get('Zend_Log')->log($e->__toString(), Zend_Log::WARN);
             }
         }
         $authorIds = explode(',', $values['toValues']);
         foreach ($authorIds as $authorId) {
             $bookAuthor = $bookAuthorTable->createRow();
             $bookAuthor->book_id = $book->getIdentity();
             $bookAuthor->author_id = $authorId;
             $bookAuthor->save();
         }
         $photoTbl = new Book_Model_DbTable_Photos();
         $photo = $photoTbl->createRow(array('parent_object_type' => $book->getType(), 'parent_object_id' => $book->getIdentity(), 'file_id' => $book->photo_id, 'user_id' => $viewer->getIdentity(), 'default' => 1, 'approved' => 1));
         $photo->save();
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     $this->_redirectCustom($book->getHref());
 }