Ejemplo n.º 1
0
 public function outOffering(Offering $offering)
 {
     $course = $offering->getCourse();
     $rs = $this->container->get('review');
     // Figure out whether the course is new
     $oneMonthAgo = new \DateTime();
     $oneMonthAgo->sub(new \DateInterval("P30D"));
     $newCourse = false;
     if ($course->getCreated() >= $oneMonthAgo) {
         $newCourse = true;
     }
     // Is it being offered for he first time
     if (count($course->getOfferings()) == 1 and $offering->getCreated() > $oneMonthAgo) {
         $newCourse = true;
     }
     if (count($course->getOfferings()) == 1 and $offering->getStatus() != Offering::COURSE_OPEN) {
         $newCourse = true;
     }
     $name = '[' . $offering->getCourse()->getName() . ']' . '(' . $offering->getUrl() . ')';
     if ($offering->getInitiative() == null) {
         $initiative = 'Others';
     } else {
         $initiative = $offering->getInitiative()->getName();
     }
     $startDate = $offering->getDisplayDate();
     $startDate = array_shift(explode(',', $startDate));
     // Do not show the year to save characters
     $length = 'NA';
     if ($offering->getCourse()->getLength() != 0) {
         $length = $offering->getCourse()->getLength();
     }
     // Rating
     $courseRating = round($rs->getRatings($offering->getCourse()->getId()), 1);
     $courseReviews = $rs->getReviewsArray($offering->getCourse()->getId());
     $reviewText = '';
     if ($courseRating == 0) {
         $courseRating = 'NA';
     } else {
         $reviewText = sprintf("(%d)", $courseReviews['count']);
     }
     $url = 'https://www.class-central.com' . $this->router->generate('reviews_short_url', array('courseId' => $offering->getCourse()->getId()));
     //$url .= '#reviews';
     $ratingStars = ReviewUtility::getRatingStars($courseRating);
     if ($courseRating > 0) {
         $rating = "{$ratingStars} [{$reviewText}]({$url})";
     } else {
         $rating = "{$ratingStars}";
     }
     $new = '';
     if ($newCourse) {
         $new = "[NEW]";
     }
     $this->output->writeln("{$new} {$name} via **{$initiative}**|{$startDate}|{$length}|{$rating}");
 }
Ejemplo n.º 2
0
 /**
  * By default the offering state is upcoming;
  * @param Offering $offering
  * @param \DateTime $now
  * @return int|string
  */
 public static function calculateStateWithDate(Offering $offering, \DateTime $now)
 {
     $state = 0;
     // Ignore offerings that are no longer available
     if ($offering->getStatus() == Offering::COURSE_NA) {
         return $state;
     }
     $twoWeeksAgo = clone $now;
     $twoWeeksAgo->sub(new \DateInterval('P14D'));
     $twoWeeksLater = clone $now;
     $twoWeeksLater->add(new \DateInterval('P14D'));
     $yesterday = clone $now;
     $yesterday->sub(new \DateInterval('P1D'));
     $startDate = $offering->getStartDate();
     $endDate = $offering->getEndDate();
     // Check if its recent
     if ($offering->getStatus() == Offering::START_DATES_KNOWN && $startDate >= $twoWeeksAgo && $startDate <= $twoWeeksLater) {
         $state += Offering::STATE_RECENT;
     }
     // Check if its recently added
     if ($offering->getCreated() >= $twoWeeksAgo) {
         $state += Offering::STATE_JUST_ANNOUNCED;
     }
     // Check if its self paced
     if ($offering->getStatus() == Offering::COURSE_OPEN) {
         $state += Offering::STATE_SELF_PACED;
         return $state;
     }
     // Check if its finished
     if ($endDate != null && $endDate < $now) {
         $state += Offering::STATE_FINISHED;
         return $state;
     }
     // Check if its ongoing
     if ($offering->getStatus() == Offering::START_DATES_KNOWN && $yesterday > $startDate) {
         $state += Offering::STATE_IN_PROGRESS;
         return $state;
     }
     // If it has reached here it means its upcoming.
     $state += Offering::STATE_UPCOMING;
     return $state;
 }