/** * HTML format for the blog * @param Course $course */ public function blogFormat(Course $course) { $router = $this->container->get('router'); $rs = $this->container->get('review'); $line1 = ''; // Course name $line2 = ''; // Institution name $line3 = ''; // Next Session $ratings = $rs->getRatings($course->getId()); $reviews = $rs->getReviews($course->getId()); // LINE 1 $url = 'https://www.class-central.com' . $router->generate('ClassCentralSiteBundle_mooc', array('id' => $course->getId(), 'slug' => $course->getSlug())); $name = $course->getName(); $line1 = "<a href='{$url}'><b>{$name}</b></a>"; // LINE 2 if ($course->getInstitutions()->count() > 0) { $ins = $course->getInstitutions()->first(); $insName = $ins->getName(); $line2 = "{$insName}"; } if ($course->getInitiative()) { $line2 .= ' via ' . $course->getInitiative()->getName(); } else { $line2 .= ' via Independent'; } $line2 = "<i>{$line2}</i>"; // LINE 3 $nextOffering = CourseUtility::getNextSession($course); if ($nextOffering) { $displayDate = $nextOffering->getDisplayDate(); $directUrl = $nextOffering->getUrl(); $states = CourseUtility::getStates($nextOffering); if (in_array('past', $states)) { $displayDate = 'TBA'; } if (in_array('selfpaced', $states)) { $displayDate = 'Self Paced'; } $ratingsLine = ''; if ($ratings > 0) { $formattedRatings = ReviewUtility::getRatingStars($ratings); $numRatings = $reviews['ratingCount']; $post = $numRatings == 1 ? 'rating' : 'ratings'; $ratingsLine = " | {$formattedRatings} (<a href='{$url}#course-all-reviews'>{$numRatings} {$post}</a>) "; } $lineDesc = ''; if ($course->getOneliner()) { $lineDesc = $course->getOneliner() . "<br/>"; } elseif ($course->getDescription()) { $lineDesc = $course->getDescription() . "<br/>"; } $line3 = "<b> <a href='{$directUrl}' target='_blank'>Go To Class</a> {$ratingsLine} | Next Session : {$displayDate} </b><br/>"; } return $line1 . '<br/>' . $line2 . '<br/>' . $lineDesc . $line3 . '<br/>'; }
/** * Boost the weight of courses that are upcoming or recent * @param Course $course */ private function getCourseWeight(Course $course) { $weight = 0; $ns = CourseUtility::getNextSession($course); if ($ns) { $states = CourseUtility::getStates($ns); $date = $ns->getStartDate(); if (in_array('recent', $states)) { if (in_array('ongoing', $states)) { return 23; // this means it has already started. Push it slightly down } return 25; } if (in_array('upcoming', $states)) { $dt = new \DateTime(); $dt->add(new \DateInterval('P30D')); if ($date < $dt) { return 15; } // Upcoming but later than a month return 10; } if (in_array('selfpaced', $states)) { return 14; } } return $weight; }
public function getBody() { $indexer = $this->container->get('es_indexer'); $em = $this->container->get('doctrine')->getManager(); $rs = $this->container->get('review'); $body = array(); $c = $this->entity; // Alias for entity $body['name'] = $c->getName(); $body['id'] = $c->getId(); $body['videoIntro'] = $c->getVideoIntro(); $body['length'] = $c->getLength(); $body['slug'] = $c->getSlug(); $body['description'] = $c->getDescription(); $body['longDescription'] = $c->getLongDescription(); $body['syllabus'] = $c->getSyllabus(); $body['searchDesc'] = $c->getSearchDesc(); $body['status'] = $c->getStatus(); $body['certificate'] = $c->getCertificate(); $body['verifiedCertificate'] = $c->getVerifiedCertificate(); $body['url'] = $c->getUrl(); if ($c->getCreated()) { $body['created'] = $c->getCreated()->format(DATE_ISO8601); } // Tags $tags = array(); foreach ($c->getTags() as $tag) { $tags[] = strtolower($tag->getName()); } $body['tags'] = $tags; // Instructors $body['instructors'] = array(); foreach ($c->getInstructors() as $instructor) { $body['instructors'][] = $instructor->getName(); } // Language $body['language'] = array(); $lang = $c->getLanguage(); if ($lang) { $body['language']['name'] = $lang->getName(); $body['language']['id'] = $lang->getId(); $body['language']['slug'] = $lang->getSlug(); } else { // Set the default to english $l = $em->getRepository('ClassCentralSiteBundle:Language')->findOneBy(array('slug' => 'english')); $body['language']['name'] = $l->getName(); $body['language']['id'] = $l->getId(); $body['language']['slug'] = $l->getSlug(); } // Institutions $body['institutions'] = array(); foreach ($c->getInstitutions() as $ins) { $iDoc = new InstitutionDocumentType($ins, $this->container); $body['institutions'][] = $iDoc->getBody(); } // Provider $body['provider'] = array(); if ($c->getInitiative()) { $provider = $c->getInitiative(); } else { // create an independent provider $provider = new Initiative(); $provider->setName('Independent'); $provider->setCode('independent'); } $pDoc = new ProviderDocumentType($provider, $this->container); $body['provider'] = $pDoc->getBody(); // Get the next session $body['nextSession'] = array(); $ns = CourseUtility::getNextSession($c); if ($ns) { $nsDoc = new SessionDocumentType($ns, $this->container); $body['nextSession'] = $nsDoc->getBody(); } // Subject $subjects = array(); $sub = $c->getStream(); if ($sub->getParentStream()) { // Add the parent stream first $psDoc = new SubjectDocumentType($sub->getParentStream(), $this->container); $subjects[] = $psDoc->getBody(); } $sDoc = new SubjectDocumentType($sub, $this->container); $subjects[] = $sDoc->getBody(); $body['subjects'] = $subjects; // Sessions. Add sessions to the records $sessions = array(); $body['sessions'] = array(); foreach ($c->getOfferings() as $session) { // Ignore invalid session if ($session->getStatus() == Offering::COURSE_NA) { continue; } $sDoc = new SessionDocumentType($session, $this->container); $sessions[] = $sDoc->getBody(); } $body['sessions'] = $sessions; $body['numSessions'] = count($sessions); $body['rating'] = $rs->getRatings($c->getId()); $body['ratingSort'] = $rs->getBayesianAverageRating($c->getId()); $rArray = $rs->getReviewsArray($c->getId()); $body['reviewsCount'] = $rArray['count']; $body['ratingStars'] = ReviewUtility::getRatingStars($body['rating']); $body['formattedRating'] = ReviewUtility::formatRating($body['rating']); // Get Followed count $courseRepo = $this->container->get('doctrine')->getManager()->getRepository('ClassCentralSiteBundle:Course'); $body['followed'] = intval($courseRepo->getListedCount($c)); // Check if the course being offered is new // Definition of new - created 30 days ago $oneMonthAgo = new \DateTime(); $oneMonthAgo->sub(new \DateInterval("P30D")); $newCourse = false; if ($c->getCreated() >= $oneMonthAgo) { $newCourse = true; } $body['new'] = intval($newCourse); $startingSoon = false; $oneMonthLater = new \DateTime(); $oneMonthLater->add(new \DateInterval("P30D")); if ($ns && !in_array('selfpaced', $body['nextSession']['states']) && in_array('upcoming', $body['nextSession']['states'])) { if ($ns->getStartDate() < $oneMonthLater and $ns->getStatus() != Offering::START_DATES_UNKNOWN) { $startingSoon = true; } } $body['startingSoon'] = intval($startingSoon); // Get the Credential $credential = array(); if (!$c->getCredentials()->isEmpty()) { $cred = $c->getCredentials()->first(); if ($cred->getStatus() < 100) { $credential['id'] = $cred->getId(); $credential['name'] = $cred->getName(); $credential['slug'] = $cred->getSlug(); $credential['certificateName'] = ''; $credential['certificateSlug'] = ''; $credFormatter = $cred->getFormatter(); $credential['certificateName'] = $credFormatter->getCertificateName(); $credential['certificateSlug'] = $credFormatter->getCertificateSlug(); } } $body['credential'] = $credential; return $body; }
public function getBody() { $indexer = $this->container->get('es_indexer'); $em = $this->container->get('doctrine')->getManager(); $rs = $this->container->get('review'); $body = array(); $c = $this->entity; // Alias for entity $body['name'] = $c->getName(); $body['id'] = $c->getId(); $body['videoIntro'] = $c->getVideoIntro(); $body['length'] = $c->getLength(); $body['slug'] = $c->getSlug(); $body['description'] = $c->getDescription(); $body['longDescription'] = $c->getLongDescription(); $body['syllabus'] = $c->getSyllabus(); $body['searchDesc'] = $c->getSearchDesc(); $body['status'] = $c->getStatus(); $body['certificate'] = $c->getCertificate(); $body['verifiedCertificate'] = $c->getVerifiedCertificate(); $body['url'] = $c->getUrl(); // Tags $tags = array(); foreach ($c->getTags() as $tag) { $tags[] = strtolower($tag->getName()); } $body['tags'] = $tags; // Instructors $body['instructors'] = array(); foreach ($c->getInstructors() as $instructor) { $body['instructors'][] = $instructor->getName(); } // Language $body['language'] = array(); $lang = $c->getLanguage(); if ($lang) { $body['language']['name'] = $lang->getName(); $body['language']['id'] = $lang->getId(); $body['language']['slug'] = $lang->getSlug(); } else { // Set the default to english $l = $em->getRepository('ClassCentralSiteBundle:Language')->findOneBy(array('slug' => 'english')); $body['language']['name'] = $l->getName(); $body['language']['id'] = $l->getId(); $body['language']['slug'] = $l->getSlug(); } // Institutions $body['institutions'] = array(); foreach ($c->getInstitutions() as $ins) { $iDoc = new InstitutionDocumentType($ins, $this->container); $body['institutions'][] = $iDoc->getBody(); } // Provider $body['provider'] = array(); if ($c->getInitiative()) { $provider = $c->getInitiative(); } else { // create an independent provider $provider = new Initiative(); $provider->setName('Independent'); $provider->setCode('independent'); } $pDoc = new ProviderDocumentType($provider, $this->container); $body['provider'] = $pDoc->getBody(); // Get the next session $body['nextSession'] = array(); $ns = CourseUtility::getNextSession($c); if ($ns) { $nsDoc = new SessionDocumentType($ns, $this->container); $body['nextSession'] = $nsDoc->getBody(); } // Subject $subjects = array(); $sub = $c->getStream(); if ($sub->getParentStream()) { // Add the parent stream first $psDoc = new SubjectDocumentType($sub->getParentStream(), $this->container); $subjects[] = $psDoc->getBody(); } $sDoc = new SubjectDocumentType($sub, $this->container); $subjects[] = $sDoc->getBody(); $body['subjects'] = $subjects; // Sessions. Add sessions to the records $sessions = array(); $body['sessions'] = array(); foreach ($c->getOfferings() as $session) { // Ignore invalid session if ($session->getStatus() == Offering::COURSE_NA) { continue; } $sDoc = new SessionDocumentType($session, $this->container); $sessions[] = $sDoc->getBody(); } $body['sessions'] = $sessions; $body['rating'] = $rs->getRatings($c->getId()); $body['ratingSort'] = $rs->getBayesianAverageRating($c->getId()); $rArray = $rs->getReviewsArray($c->getId()); $body['reviewsCount'] = $rArray['count']; $body['ratingStars'] = ReviewUtility::getRatingStars($body['rating']); $body['formattedRating'] = ReviewUtility::formatRating($body['rating']); // Get the Credential $credential = array(); if (!$c->getCredentials()->isEmpty()) { $cred = $c->getCredentials()->first(); if ($cred->getStatus() < 100) { $credential['id'] = $cred->getId(); $credential['name'] = $cred->getName(); $credential['slug'] = $cred->getSlug(); $credential['certificateName'] = ''; $credential['certificateSlug'] = ''; $credFormatter = $cred->getFormatter(); $credential['certificateName'] = $credFormatter->getCertificateName(); $credential['certificateSlug'] = $credFormatter->getCertificateSlug(); } } $body['credential'] = $credential; return $body; }
public function testGetNextSession() { $c = new Course(); // Finished offerings $fo1 = $this->buildOffering(1, new \DateTime("2012-06-03"), Offering::START_DATES_KNOWN); $fo2 = $this->buildOffering(2, new \DateTime("2012-05-03"), Offering::START_DATES_KNOWN); $fo3 = $this->buildOffering(3, new \DateTime("2012-07-03"), Offering::START_DATES_KNOWN); // Ongoing session $oodt1 = new \DateTime(); $oodt1->sub(new \DateInterval("P10D")); $oo1 = $this->buildOffering(4, $oodt1, Offering::START_DATES_KNOWN); // Self paced session $so1 = $this->buildOffering(5, new \DateTime("2012-07-03"), Offering::COURSE_OPEN); // Upcoming sessions $uo1 = $this->buildOffering(6, $this->getFutureDateUtility("P20D"), Offering::START_DATES_KNOWN); $uo2 = $this->buildOffering(7, $this->getFutureDateUtility("P10D"), Offering::START_DATES_KNOWN); $uo3 = $this->buildOffering(8, $this->getFutureDateUtility("P30D"), Offering::START_DATES_KNOWN); // Course with single finished offering $c->addOffering($fo1); $next = CourseUtility::getNextSession($c); $this->assertEquals($fo1->getId(), $next->getId()); // Course with multiple finished offering $c->addOffering($fo2); $c->addOffering($fo3); $next = CourseUtility::getNextSession($c); $this->assertEquals($fo3->getId(), $next->getId()); // Course with ongoing sessions $c->addOffering($oo1); $next = CourseUtility::getNextSession($c); $this->assertEquals($oo1->getId(), $next->getId()); // Course with with self paced sessions $c->addOffering($so1); $next = CourseUtility::getNextSession($c); $this->assertEquals($so1->getId(), $next->getId()); // Course with single upcoming session $c->addOffering($uo1); $next = CourseUtility::getNextSession($c); $this->assertEquals($uo1->getId(), $next->getId()); // Course with multiple upcoming sessions $c->addOffering($uo2); $c->addOffering($uo3); $next = CourseUtility::getNextSession($c); $this->assertEquals($uo2->getId(), $next->getId()); }
public function tableRowFormat(Course $course) { $followColumn = ''; $courseNameColumn = ''; $startDateColumn = ''; $ratingColumn = ''; $router = $this->container->get('router'); $rs = $this->container->get('review'); // $courseUrl = 'https://www.class-central.com' . $router->generate('ClassCentralSiteBundle_mooc', array('id' => $course->getId(), 'slug' => $course->getSlug())); $courseName = $course->getName(); // COLUMN 1 - FOLLOW $followUrl = $courseUrl . '?follow=true'; $followColumn = "<td width='30px' style='vertical-align: top'><a href='{$followUrl}' style='color: red;font-size: 25px;text-decoration: none' target='_blank'>♥</a></td>"; // COLUMN 2 - COURSE NAME $providerLine = ''; if ($course->getInstitutions()->count() > 0) { $ins = $course->getInstitutions()->first(); $providerLine = $ins->getName(); $providerLine = "{$providerLine}"; } if ($course->getInitiative()) { $providerLine .= ' via ' . $course->getInitiative()->getName(); } else { $providerLine .= ' via Independent'; } $providerLine = "<i>{$providerLine}</i>"; $courseNameColumn = "<td><a href='{$courseUrl}'>{$courseName}</a><br/>{$providerLine}</td>"; // COLUMN 3 - START DATE $nextOffering = CourseUtility::getNextSession($course); if (!$nextOffering) { return ''; } $displayDate = $nextOffering->getDisplayDate(); $states = CourseUtility::getStates($nextOffering); if (in_array('past', $states)) { $displayDate = 'TBA'; } if (in_array('selfpaced', $states)) { $displayDate = 'Self Paced'; } $startDateColumn = "<td>{$displayDate}</td>"; // COLUMN 4 - RATING $ratings = $rs->getRatings($course->getId()); $reviews = $rs->getReviews($course->getId()); $ratingsLine = ReviewUtility::getRatingStars(0); // Default value if ($ratings > 0) { $formattedRatings = ReviewUtility::getRatingStars($ratings); $numRatings = $reviews['ratingCount']; $post = $numRatings == 1 ? 'rating' : 'ratings'; $ratingsLine = "{$formattedRatings} (<a href='{$courseUrl}#reviews'>{$numRatings}</a>) "; } $ratingColumn = "<td>{$ratingsLine}</td>"; return "<tr>" . $followColumn . $courseNameColumn . $ratingColumn . "</tr>"; }