/** * Get the list of rpess review from SQL * @param int $pressReviewType * @param int $tagId * @param string $searchTerm * @param boolean $useCache * @return Ambigous <NULL, multitype:, mixed, false, boolean, string> */ private function getPressReviews($pressReviewTypeId, $tagId, $searchTerm, $useCache) { $tag = null; if ($tagId) { $tag = TagDao::getInstance()->get($tagId); } // Initialize criteria array $criteria = array("type" => array(false, "=", $pressReviewTypeId)); // Add tag criteria if ($tag) { $criteria["tag"] = array(true, "=", $tag); } // Add keywords criteria if ($searchTerm) { $criteria["keywords"] = array(false, "LIKE", $searchTerm); } // Add is_validated criteria $criteria["is_validated"] = array(false, "=", 1); $result = PressReviewSvc::getInstance()->getList($criteria, 100, $useCache); return $result; }
/** * Get list of tags with chronicles * @return array of Tag list of tags */ public function getTagsForChronicles($orderColumn = "label") { try { $data = null; $dataKey = self::TAGS_CHRONICLES; $data = $this->getData($dataKey); if (!isset($data) || $data === false) { $data = TagDao::getInstance()->getTagsForChronicles($orderColumn); $this->setData($dataKey, $data); } return $data; } catch (\Exception $exc) { $this->logException(get_class(), __FUNCTION__, $exc); } return null; }
/** * Get the books with the same tag as the book passed, the list is cached for 1 day * @param type $bookId * @return a array of Book */ public function getBooksWithSameTags($bookId, $useCache = true) { $result = null; if ($useCache) { $key = self::BOOKS_SAME_TAGS . "_bid_" . $bookId; $result = $this->getData($key); } if (!isset($result) || $result === false) { // Get the tags for the current book $tags = TagDao::getInstance()->getTagsForBook($bookId); if (count($tags) > 0) { $tagsId = array_map(array(&$this, "getId"), $tags); // Get the book with these tags $booksWithTags = BookDao::getInstance()->getListWithTags($tagsId); if (count($booksWithTags) > 0) { // Setting the current viewed book $this->currentViewedBook = BookDao::getInstance()->get($bookId); $result = $booksWithTags; // Removing the current viewed book $result = array_filter($result, array(&$this, "isNotCurrentViewedBook")); // Removing the books with same authors $result = array_filter($result, array(&$this, "hasNotSameContributors")); } } if ($useCache) { $this->setData($key, $result); } } return $this->getRandomNumber($result, 5); }
private function setChronicleData(ChronicleForm $form, Chronicle $chronicle) { $globalContext = new \Sb\Context\Model\Context(); $book = BookDao::getInstance()->get($form->getChronicleBookId()); $chronicle->setBook($book); $group = GroupDao::getInstance()->get($form->getChronicleGroupId()); $chronicle->setGroup($group); if ($form->getChronicleImage()) { $fullImageName = $this->getImageUrl($form->getChronicleGroupId()) . "/" . $form->getChronicleImage(); $chronicle->setImage($fullImageName); } $chronicle->setIs_validated(true); $chronicle->setKeywords($form->getChronicleKeywords()); $chronicle->setLink($form->getChronicleLink()); $tag = TagDao::getInstance()->get($form->getChronicleTagId()); $chronicle->setTag($tag); $chronicle->setText($form->getChronicleText()); $chronicle->setTitle($form->getChronicleTitle()); $chronicle->setType_id($form->getChronicleType()); $chronicle->setUser($globalContext->getConnectedUser()); $chronicle->setLink_type($form->getChronicleLinkType()); }
/** * Get a collection of chronicle with a tag specified * @param array of int $tagIds the tag ids to search * @param int $numberOfChronicles number of maximum chronicle to get * @return Collection of Chronicle */ public function getChroniclesWithTags($tagIds, $numberOfChronicles, $useCache = true) { try { $results = null; if ($useCache) { $key = self::CHRONICLES_WITH_TAG . "_tid_" . implode("_", $tagIds) . "_m_" . $numberOfChronicles; $results = $this->getData($key); } if (!isset($results) || $results === false) { /* @var $dao ChronicleDao */ $dao = $this->getDao(); $criteria = array(); // Add tag criteria $tags = TagDao::getInstance()->getList(array("id" => array(false, "IN", implode(",", $tagIds))), null, null); $criteria["tag"] = array(true, "IN", $tags); // Add is_validated criteria $criteria["is_validated"] = array(false, "=", 1); $orderBy = array("creation_date" => "DESC"); $results = $dao->getList($criteria, $orderBy, $numberOfChronicles); if ($useCache) { $this->setData($key, $results); } } return $results; } catch (\Exception $e) { $this->logException(get_class(), __FUNCTION__, $e); } }
public function submitAction() { try { /* @var $globalContext \Sb\Context\Model\Context */ $globalContext = new \Sb\Context\Model\Context(); /* @var $user Sb\Db\Model\User */ $user = $globalContext->getConnectedUser(); // getting form data $userBookForm = new UserBookForm($_POST); // getting userbook in DB $userBook = UserBookDao::getInstance()->get($userBookForm->getId()); // Getting the events related to the userbook changes $userEvents = UserEventSvc::getInstance()->prepareUserBookEvents($userBook, $userBookForm); // On vérifit la correspondance du user if ($user->getId() != $userBook->getUser()->getId()) { Flash::addItem(__("Le livre que vous souhaitez éditer ne correspond pas à l'utilisateur connecté.", "share1book")); HTTPHelper::redirectToLibrary(); } // updating userbook members $userBook->setReview($userBookForm->getReview()); $userBook->setIsBlowOfHeart($userBookForm->getIsBlowOfHeart()); $userBook->setIsOwned($userBookForm->getIsOwned()); $userBook->setIsWished($userBookForm->getIsWished()); $userBook->setRating($userBookForm->getRating()); $userBook->setNb_of_pages($userBookForm->getNb_of_pages()); $userBook->setNb_of_pages_read($userBookForm->getNb_of_pages_read()); $readingState = ReadingStateDao::getInstance()->get($userBookForm->getReadingStateId()); if ($userBookForm->getReadingDate()) { $userBook->setReadingDate($userBookForm->getReadingDate()); } $userBook->setReadingState($readingState); $userBook->setHyperlink($userBookForm->getHyperLink()); if ($userBookForm->getTags()) { $tags = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($userBookForm->getTags() as $tagId) { $tag = TagDao::getInstance()->get($tagId); $tags->add($tag); } $userBook->setTags($tags); } // Mise à jour du UserBook if (UserBookDao::getInstance()->update($userBook)) { // persisting the userevent related to the userbook changes UserEventSvc::getInstance()->persistAll($userEvents); // Add review as chronicle if ($this->_reviewIsModified($userEvents) && $user->IsBlogger()) { ChronicleSvc::getInstance()->addOrUpdateFromUserBook($userBook); } Flash::addItem(sprintf(__('Le livre "%s" a été mis à jour.', "s1b"), urldecode($userBook->getBook()->getTitle()))); } else { Flash::addItem(__('Une erreur s\'est produite lors de la mise à jour de votre fiche de lecture', 's1b')); } $referer = ArrayHelper::getSafeFromArray($_POST, "referer", null); if ($referer) { HTTPHelper::redirectToUrl($referer); } else { HTTPHelper::redirectToLibrary(); } } catch (\Exception $e) { Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", MESSAGE : %s , TRACE : %s\"", get_class(), __FUNCTION__, $e->getMessage(), $e->getTraceAsString())); $this->forward("error", "error", "default"); } }