Ejemplo n.º 1
0
 /**
  * Builds an array for the review object that can be serialized
  * @param Review $review
  */
 public static function getReviewArray(Review $review)
 {
     $rd = new ReadableDate();
     $r = array();
     $r['id'] = $review->getId();
     $r['rating'] = $review->getRating();
     $r['reviewText'] = nl2br(preg_replace("/[\r\n]+/", "\n\n", $review->getReview()));
     $r['reviewSummary'] = $review->getReviewSummary() ? $review->getReviewSummary()->getSummary() : null;
     $r['hours'] = $review->getHours();
     $r['difficultyId'] = $review->getDifficultyId();
     $r['levelId'] = $review->getLevelId();
     $r['listId'] = $review->getListId();
     $r['created'] = $review->getCreated();
     $r['displayDate'] = $rd->get($review->getCreated()->getTimestamp());
     $r['publishedDate'] = $review->getCreated()->format('Y-m-d');
     $r['modified'] = $review->getModified();
     $r['reviewTitle'] = self::getReviewTitle($review);
     $r['externalReviewerName'] = $review->getReviewerName();
     $r['externalReviewLink'] = $review->getExternalLink();
     // Review feedback
     $r['fb']['total'] = 0;
     $r['fb']['positive'] = 0;
     $r['fb']['negative'] = 0;
     $fb = $review->getFbSummary();
     if ($fb) {
         $r['fb']['total'] = $fb->getTotal();
         $r['fb']['positive'] = $fb->getPositive();
         $r['fb']['negative'] = $fb->getNegative();
     }
     $user = $review->getUser();
     $u = array();
     $u['id'] = $user->getId();
     $u['name'] = $user->getDisplayName();
     $u['handle'] = $user->getHandle();
     $u['isPrivate'] = $user->getIsPrivate();
     $u['email'] = $user->getEmail();
     $r['user'] = $u;
     $course = $review->getCourse();
     $c = array();
     $c['name'] = $course->getName();
     $c['id'] = $course->getId();
     $c['slug'] = $course->getSlug();
     $r['course'] = $c;
     return $r;
 }
Ejemplo n.º 2
0
 public function getReviewFeedbackDetails(\ClassCentral\SiteBundle\Entity\Review $review)
 {
     $rsm = new ResultSetMapping();
     $em = $this->container->get('doctrine')->getManager();
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('positive', 'positive');
     $rsm->addScalarResult('negative', 'negative');
     $rsm->addScalarResult('total', 'total');
     $q = $em->createNativeQuery("SELECT\n                SUM(if(helpful =0,1,0)) as negative,\n                SUM(if (helpful =1,1,0)) as positive,\n                count(*) as total FROM reviews_feedback\n                WHERE review_id = " . $review->getId(), $rsm);
     $result = $q->getResult();
     return $result[0];
 }