Esempio n. 1
0
 private function getBookPressReviews(Book $book)
 {
     $criteria = array("type" => array(false, "=", PressReviewTypes::ARTICLE), "book" => array(true, "=", $book), "is_validated" => array(false, "=", 1));
     $bookPressReviews = PressReviewSvc::getInstance()->getList($criteria, 3, false);
     // If not enough press reviews associated to book, getting general press reviews
     if (!$bookPressReviews || count($bookPressReviews) < 3) {
         // Get general press reviews
         $criteria = array("type" => array(false, "=", PressReviewTypes::ARTICLE));
         $generalPressReviews = PressReviewSvc::getInstance()->getList($criteria, 3, false);
         if (!$bookPressReviews) {
             $bookPressReviews = $generalPressReviews;
         } else {
             if ($generalPressReviews) {
                 foreach ($generalPressReviews as $generalPressReview) {
                     /* @var $generalPressReview PressReview */
                     $add = true;
                     foreach ($bookPressReviews as $bookPressReview) {
                         /* @var $bookPressReview PressReview */
                         if ($generalPressReview->getId() == $bookPressReview->getId()) {
                             $add = false;
                             break;
                         }
                     }
                     if ($add) {
                         $bookPressReviews[] = $generalPressReview;
                     }
                 }
             }
         }
     }
     if ($bookPressReviews) {
         $bookPressReviews = array_slice($bookPressReviews, 0, 3);
     }
     return $bookPressReviews;
 }
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * Get a chronicle as ChronicleViewModel object for chronicle detail page
  * @param int $nbSimilarChronicles the number of similar chronicles to return , if not passed (null), then no similar chronicles will be returned
  * @param int $nbSameAuthorChronicles number of same author chronicles to return
  * @param int $nbPressReviews number of press reviews to return
  * @param boolean flag to tell to use cache or not
  * @return \Sb\Model\ChronicleViewModel a chronicle as a ChronicleViewModel object
  */
 public function getAsChronicleViewModel($nbSimilarChronicles = null, $nbSameAuthorChronicles = null, $nbPressReviews = null, $useCache = true)
 {
     /* @var $chronicle ChronicleViewModel */
     $chronicleViewModel = new ChronicleViewModel();
     // Set common members
     $this->setChronicleViewModelLight($chronicleViewModel);
     $chronicleViewModel->setText($this->chronicle->getText());
     $chronicleViewModel->setUserName($this->chronicle->getUser()->getUserName());
     $chronicleViewModel->setUserProfileLink(HTTPHelper::Link(Urls::USER_PROFILE, array("uid" => $this->chronicle->getUser()->getId())));
     $chronicleViewModel->setUserImage(UserHelper::getMediumImageTag($this->chronicle->getUser(), __("image chroniqueur", "s1b")));
     $chronicleViewModel->setSource($this->chronicle->getSource());
     // Set book
     $chronicleViewModel->setChronicleHasBook(false);
     if ($this->chronicle->getBook()) {
         $chronicleViewModel->setChronicleHasBook(true);
         $chronicleViewModel->setBook($this->chronicle->getBook());
     }
     // Set link info
     $chronicleViewModel->setLinkCss("chr-link-other");
     $chronicleViewModel->setLinkText(__("En savoir plus", "s1b"));
     switch ($this->chronicle->getLink_type()) {
         case ChronicleLinkType::IMAGE:
             $chronicleViewModel->setLinkCss("chr-link-image");
             $chronicleViewModel->setLinkText(__("Voir la photo", "s1b"));
             break;
         case ChronicleLinkType::PODCAST:
             $chronicleViewModel->setLinkCss("chr-link-podcast");
             $chronicleViewModel->setLinkText(__("Ecouter le podcast", "s1b"));
             break;
         case ChronicleLinkType::PRESS:
             $chronicleViewModel->setLinkCss("chr-link-press");
             $chronicleViewModel->setLinkText(__("Lire l'article", "s1b"));
             break;
         case ChronicleLinkType::URL:
             $chronicleViewModel->setLinkCss("chr-link-url");
             $chronicleViewModel->setLinkText(__("En savoir plus", "s1b"));
             break;
         case ChronicleLinkType::VIDEO:
             $chronicleViewModel->setLinkCss("chr-link-video");
             $linkText = __("Regarder la video", "s1b");
             break;
     }
     // Set type label
     $chronicleViewModel->setTypeLabel(ChronicleHelper::getTypeLabel($this->chronicle->getType_id()));
     // Set similar chronicles or same author chronicles
     if ($nbSimilarChronicles || $nbSameAuthorChronicles) {
         $chroniclesAdapter = new ChronicleListAdapter();
         // Set the similar chronicles
         if ($nbSimilarChronicles) {
             $chroniclesAdapter->setChronicles($this->getSimilarChronicles($nbSimilarChronicles, $useCache));
             $chronicleViewModel->setSimilarChronicles($chroniclesAdapter->getAsChronicleViewModelList());
         }
         // Set the same author chronicles
         if ($nbSameAuthorChronicles) {
             $chroniclesAdapter->setChronicles($this->getSameAuthorChronicles($nbSameAuthorChronicles, $useCache));
             $chronicleViewModel->setSameAuthorChronicles($chroniclesAdapter->getAsChronicleViewModelList());
         }
     }
     // Set press reviews
     if ($nbPressReviews) {
         $pressReviews = null;
         // Get press review with same tag
         if ($this->chronicle->getTag()) {
             $pressReviews = PressReviewSvc::getInstance()->getList(array("tag" => array(true, "=", $this->chronicle->getTag()), "is_validated" => array(false, "=", 1)), $nbPressReviews, $useCache);
         }
         // Get press review with same keywords
         if ((!$pressReviews || count($pressReviews) < $nbPressReviews) && $this->chronicle->getKeywords()) {
             $keyWords = explode(",", $this->chronicle->getKeywords());
             foreach ($keyWords as $keyWord) {
                 // Get press review with same keywords
                 $criteria = array("keywords" => array(false, "LIKE", $keyWord));
                 $pressReviewsWithKeywords = PressReviewSvc::getInstance()->getList($criteria, $nbPressReviews, $useCache);
                 if ($pressReviewsWithKeywords) {
                     if (!$pressReviews) {
                         $pressReviews = $pressReviewsWithKeywords;
                     } else {
                         $pressReviews = EntityHelper::mergeEntities($pressReviews, $pressReviewsWithKeywords);
                     }
                     if (count($pressReviews) >= $nbPressReviews) {
                         break;
                     }
                 }
             }
             if ($pressReviews) {
                 $pressReviews = array_slice($pressReviews, 0, $nbPressReviews);
             }
         }
         $chronicleViewModel->setPressReviews($pressReviews);
     }
     return $chronicleViewModel;
 }
Esempio n. 4
0
 private function getNewsReaderPressReviews()
 {
     // Newsreader
     $criteria = array("type" => array(false, "=", PressReviewTypes::ARTICLE), "is_validated" => array(false, "=", 1));
     $pressReviews = PressReviewSvc::getInstance()->getList($criteria, 50);
     return $pressReviews;
 }
Esempio n. 5
0
 private function getVideoPressReview(Chronicle $chronicle)
 {
     if ($chronicle->getBook()) {
         $criteria = array("type" => array(false, "=", PressReviewTypes::VIDEO), "book" => array(true, "=", $chronicle->getBook()), "is_validated" => array(false, "=", 1));
         $video = PressReviewSvc::getInstance()->getList($criteria, 1, false);
         if ($video && count($video) == 1) {
             return $video[0];
         }
     }
     return null;
 }
 /**
  * Add common items to all actions in model view
  */
 private function addCommonItemsToModelView()
 {
     // Get ad and add it to model view
     $ad = new Ad("", "");
     $this->view->ad = $ad->get();
     // Get press reviews subscription widget and add it to view model
     $pressReviewsSubscriptionWidget = new PressReviewsSubscriptionWidget();
     $this->view->pressReviewsSubscriptionWidget = $pressReviewsSubscriptionWidget->get();
     // Newsreader
     $criteria = array("type" => array(false, "=", PressReviewTypes::ARTICLE), "is_validated" => array(false, "=", 1));
     $pressReviews = PressReviewSvc::getInstance()->getList($criteria, 50);
     if ($pressReviews) {
         $newsReader = new NewsReader($pressReviews);
         $this->view->newsReader = $newsReader->get();
     }
 }