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 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()
 {
     $body = array();
     $credentialService = $this->container->get('credential');
     $c = $this->entity;
     // Alias for entity
     $formatter = $c->getFormatter();
     $body['name'] = $c->getName();
     $body['id'] = $c->getId();
     $body['slug'] = $c->getSlug();
     $body['oneLiner'] = $c->getOneLiner();
     $body['subTitle'] = $c->getSubTitle();
     $body['price'] = $c->getPrice();
     $body['pricePeriod'] = $c->getPricePeriod();
     $body['displayPrice'] = $formatter->getPrice();
     $body['durationMin'] = $c->getDurationMin();
     $body['durationMax'] = $c->getDurationMax();
     $body['displayDuration'] = $formatter->getDuration();
     $body['workloadMin'] = $c->getWorkloadMin();
     $body['workloadMax'] = $c->getDurationMax();
     $body['workloadType'] = $c->getWorkloadType();
     $body['displayWorkload'] = $formatter->getWorkload();
     $body['url'] = $c->getUrl();
     $body['description'] = $c->getDescription();
     $body['status'] = $c->getStatus();
     $body['image'] = $credentialService->getImage($c);
     $body['cardImage'] = $credentialService->getCardImage($c);
     $body['subjectSlug'] = null;
     $body['subject'] = null;
     if ($c->getSubject()) {
         $body['subjectSlug'] = $c->getSubject();
         $body['subject'] = Credential::$SUBJECTS[$c->getSubject()];
     }
     $orgs = array();
     // Array of names of organizations who are involved in creating the credential
     // Provider
     $body['provider'] = array();
     if ($c->getInitiative()) {
         $provider = $c->getInitiative();
         $body['certificateName'] = $formatter->getCertificateName();
         $body['certificateSlug'] = $formatter->getCertificateSlug();
         $bulletOrg = "{$formatter->getCertificateName()} via ";
         $orgs[] = $provider->getName();
         // Populate the organization list
     } else {
         // create an independent provider
         $provider = new Initiative();
         $provider->setName('Independent');
         $provider->setCode('independent');
     }
     $pDoc = new ProviderDocumentType($provider, $this->container);
     $body['provider'] = $pDoc->getBody();
     // Institutions
     $body['institutions'] = array();
     $institutions = array();
     foreach ($c->getInstitutions() as $ins) {
         $iDoc = new InstitutionDocumentType($ins, $this->container);
         $body['institutions'][] = $iDoc->getBody();
         $orgs[] = $ins->getName();
         // Populate the organization list
     }
     // Get the ratings
     $rating = $credentialService->calculateAverageRating($this->entity);
     $body['rating'] = $rating['rating'];
     $body['formattedRating'] = ReviewUtility::formatRating($rating['rating']);
     // Rounds the rating to the nearest 0.5
     $body['numRatings'] = $rating['numRatings'];
     $courses = array();
     foreach ($this->entity->getCourses() as $course) {
         $cDoc = new CourseDocumentType($course, $this->container);
         $courses[] = $cDoc->getBody();
     }
     $body['courses'] = $courses;
     $body['isSponsered'] = $c->isSponsored();
     // Build the bullet points in the array
     $bulletPoints = array();
     $bulletPoints[] = $bulletOrg . UniversalHelper::commaSeparateList($orgs);
     // Bullet Price and Duration
     $bulletPriceAndDuration = $formatter->getPrice();
     $displayDuration = $formatter->getDuration();
     if ($displayDuration) {
         $bulletPriceAndDuration .= ' for ' . $displayDuration;
     }
     $bulletPoints[] = $bulletPriceAndDuration;
     // Bullet effort
     $effort = $formatter->getWorkload();
     if ($effort) {
         $bulletPoints[] = $effort . ' of effort';
     }
     if ($provider->getName() == 'Coursera') {
         $bulletPoints[] = count($body['courses']) - 1 . ' courses + capstone project ';
     } elseif ($provider->getName() == 'HBX') {
         $bulletPoints[] = '3 courses and a final exam. Application Required';
     }
     if ($formatter->getEnrollment()) {
         $bulletPoints[] = $formatter->getEnrollment();
     }
     $body['bulletPoints'] = $bulletPoints;
     return $body;
 }