public function sendNewCourseToSlack(Course $course, Initiative $initiative)
 {
     try {
         $providerInfo = PageHeaderFactory::get($initiative);
         $coursePageUrl = $this->scraper->getContainer()->getParameter('baseurl') . $this->scraper->getContainer()->get('router')->generate('ClassCentralSiteBundle_mooc', array('id' => $course->getId(), 'slug' => $course->getSlug()));
         $logo = $this->scraper->getContainer()->getParameter('rackspace_cdn_base_url') . $providerInfo->getImageUrl();
         $message = "[New Course] *{$course->getName()}*\n" . $coursePageUrl;
         $this->scraper->getContainer()->get('slack_client')->to('#cc-activity-data')->from($initiative->getName())->withIcon($logo)->send($message);
     } catch (\Exception $e) {
     }
 }
 /**
  * Takes a course entity and builds an array so that
  * it can be serialized and saved in a cache
  * @param Course $course
  */
 public function getCourseArray(Course $course)
 {
     $courseDetails = array();
     $courseDetails['id'] = $course->getId();
     $courseDetails['name'] = $course->getName();
     $courseDetails['videoIntro'] = $course->getVideoIntro();
     $courseDetails['videoEmbedUrl'] = $this->getVideoEmbedUrl($course->getVideoIntro());
     $courseDetails['length'] = $course->getLength();
     $courseDetails['slug'] = $course->getSlug();
     $courseDetails['url'] = $course->getUrl();
     $courseDetails['nextOffering'] = null;
     $courseDetails['imageUrl'] = CourseUtility::getImageUrl($course);
     $courseDetails['status'] = $course->getStatus();
     $courseDetails['certificate'] = $course->getCertificate();
     $courseDetails['verifiedCertificate'] = $course->getVerifiedCertificate();
     $courseDetails['workloadMin'] = $course->getWorkloadMin();
     $courseDetails['workloadMax'] = $course->getWorkloadMax();
     // Calculate the workload
     $workload = '';
     if ($course->getWorkloadMin() && $course->getWorkloadMax()) {
         if ($course->getWorkloadMin() == $course->getWorkloadMax()) {
             $workload = $course->getWorkloadMin() . ' hours/week';
         } else {
             $workload = $course->getWorkloadMin() . "-" . $course->getWorkloadMax() . ' hours/week';
         }
     }
     $courseDetails['workload'] = $workload;
     // Get the descriptions
     $desc = null;
     $shortDesc = $course->getDescription();
     // this text only. No html. Goes in the head description
     $longDesc = $course->getLongDescription();
     //html
     $syllabus = $course->getSyllabus();
     // html
     if (empty($longDesc)) {
         $desc = nl2br($shortDesc);
     } else {
         $desc = $longDesc;
     }
     if (strlen($shortDesc) > 500) {
         $shortDesc = substr($shortDesc, 0, 497) . '...';
     }
     $courseDetails['shortDesc'] = $shortDesc;
     $courseDetails['syllabus'] = $syllabus;
     $courseDetails['longDesc'] = $longDesc;
     $courseDetails['desc'] = $desc;
     $nextOffering = $course->getNextOffering();
     if ($nextOffering) {
         $courseDetails['nextOffering']['displayDate'] = $nextOffering->getDisplayDate();
         $courseDetails['nextOffering']['id'] = $nextOffering->getId();
         $courseDetails['nextOffering']['url'] = $nextOffering->getUrl();
         // Get the state of this session
         $courseDetails['state'] = null;
         $states = array_intersect(array('past', 'ongoing', 'selfpaced', 'upcoming'), CourseUtility::getStates($nextOffering));
         if (!empty($states)) {
             $courseDetails['nextOffering']['state'] = array_pop($states);
         }
     }
     $courseDetails['tags'] = array();
     foreach ($course->getTags() as $tag) {
         $name = $tag->getName();
         if (!empty($name)) {
             $courseDetails['tags'][] = $name;
         }
     }
     $courseDetails['listed'] = $this->getListedCount($course);
     // Stream
     $stream = $course->getStream();
     $courseDetails['stream']['name'] = $stream->getName();
     $courseDetails['stream']['slug'] = $stream->getSlug();
     $courseDetails['stream']['showInNav'] = $stream->getShowInNav();
     // Initiative
     $initiative = $course->getInitiative();
     $courseDetails['initiative']['name'] = '';
     if ($initiative != null) {
         $courseDetails['initiative']['name'] = $initiative->getName();
         $courseDetails['initiative']['url'] = $initiative->getUrl();
         $courseDetails['initiative']['tooltip'] = $initiative->getTooltip();
         $courseDetails['initiative']['code'] = strtolower($initiative->getCode());
     } else {
         $courseDetails['initiative']['name'] = 'Independent';
         $courseDetails['initiative']['code'] = 'independent';
         $courseDetails['initiative']['tooltip'] = 'Independent';
     }
     // Language
     $lang = array();
     if ($course->getLanguage()) {
         $l = $course->getLanguage();
         $lang['name'] = $l->getName();
         $lang['slug'] = $l->getSlug();
         $lang['code'] = $l->getCode();
     }
     $courseDetails['lang'] = $lang;
     // Institutions
     $courseDetails['institutions'] = array();
     foreach ($course->getInstitutions() as $institution) {
         $courseDetails['institutions'][] = array('name' => $institution->getName(), 'url' => $institution->getUrl(), 'slug' => $institution->getSlug(), 'isUniversity' => $institution->getIsUniversity());
     }
     // Instructors
     $courseDetails['instructors'] = array();
     foreach ($course->getInstructors() as $instructor) {
         $courseDetails['instructors'][] = $instructor->getName();
     }
     $courseDetails['instructorsSingleLineDisplay'] = $this->getInstructorsSingleLineDisplay($courseDetails['instructors']);
     // Check if the course has a duplicate course id
     if ($course->getDuplicateCourse()) {
         $duplicate = $course->getDuplicateCourse();
         $courseDetails['duplicate'] = array('id' => $duplicate->getId(), 'slug' => $duplicate->getSlug());
     }
     // Build an array for indepth review
     $indepthReview = array();
     if ($course->getIndepthReview()) {
         $ir = $course->getIndepthReview();
         $irUser = $ir->getUser();
         $indepthReview = array('summary' => $ir->getSummary(), 'rating' => $ir->getRating(), 'url' => $ir->getUrl(), 'user' => array('name' => $irUser->getDisplayName(), 'id' => $irUser->getId(), 'handle' => $irUser->getHandle()));
     }
     $courseDetails['indepthReview'] = $indepthReview;
     // Save interview data if exists
     $interview = array();
     if ($course->getInterview()) {
         $i = $course->getInterview();
         $interview = array('id' => $i->getId(), 'title' => $i->getTitle(), 'summary' => $i->getSummary(), 'instructorName' => $i->getInstructorName(), 'instructorPhoto' => $i->getInstructorPhoto(), 'url' => $i->getUrl());
     }
     $courseDetails['interview'] = $interview;
     // Credential details
     // Get the Credential
     $credential = array();
     if (!$course->getCredentials()->isEmpty()) {
         $cred = $course->getCredentials()->first();
         if ($cred->getStatus() < 100) {
             $credential['id'] = $cred->getId();
             $credential['name'] = $cred->getName();
             $credential['slug'] = $cred->getSlug();
             $credential['certificateName'] = '';
             $credential['certificateSlug'] = '';
             $formatter = $cred->getFormatter();
             $credential['certificateName'] = $formatter->getCertificateName();
             $credential['certificateSlug'] = $formatter->getCertificateSlug();
         }
     }
     $courseDetails['credential'] = $credential;
     return $courseDetails;
 }
 public function emailFormat(Course $course)
 {
     $router = $this->container->get('router');
     $url = 'https://www.class-central.com' . $router->generate('ClassCentralSiteBundle_mooc', array('id' => $course->getId(), 'slug' => $course->getSlug()));
     return sprintf("<li><a href='%s'>%s</a></li>", $url, $course->getName());
 }