/**
  * Returns an array with fields required to render
  * create/edit review form
  * @param Course $course
  */
 private function getReviewFormData(Course $course)
 {
     $em = $this->getDoctrine()->getManager();
     $offerings = $em->getRepository('ClassCentralSiteBundle:Offering')->findAllByCourseIds(array($course->getId()));
     $offeringTypesOrder = array('ongoing', 'selfpaced', 'past');
     $offeringCount = 0;
     $offering = null;
     // If there is only one offering this will keep track of it
     // offering count
     foreach ($offerings as $type => $ot) {
         if (in_array($type, $offeringTypesOrder)) {
             foreach ($ot as $o) {
                 $offering = $o;
                 $offeringCount++;
             }
         }
     }
     return array('progress' => UserCourse::$progress, 'difficulty' => Review::$difficulty, 'course' => $course, 'levels' => Review::$levels, 'offerings' => $offerings, 'offeringTypes' => Offering::$types, 'offeringCount' => $offeringCount, 'offering' => $offering, 'offeringTypesOrder' => $offeringTypesOrder, 'reviewStatuses' => Review::$statuses, 'isAdmin' => $this->get('security.context')->isGranted('ROLE_ADMIN'));
 }
Пример #2
0
 private function uploadImageIfNecessary($imageUrl, Course $course)
 {
     $kuber = $this->container->get('kuber');
     $uniqueKey = basename($imageUrl);
     if ($kuber->hasFileChanged(Kuber::KUBER_ENTITY_COURSE, Kuber::KUBER_TYPE_COURSE_IMAGE, $course->getId(), $uniqueKey)) {
         // Upload the file
         $filePath = '/tmp/course_' . $uniqueKey;
         file_put_contents($filePath, file_get_contents($imageUrl));
         $kuber->upload($filePath, Kuber::KUBER_ENTITY_COURSE, Kuber::KUBER_TYPE_COURSE_IMAGE, $course->getId(), null, $uniqueKey);
     }
 }
 /**
  * Gets the count of number of times the course has been
  * added to the users list
  */
 public function getListedCount(Course $course)
 {
     $query = $this->getEntityManager()->createQueryBuilder();
     $query->add('select', 'count(uc.id) as listed')->add('from', 'ClassCentralSiteBundle:UserCourse uc')->join('uc.course', 'c')->andWhere('c.id = :id')->setParameter('id', $course->getId());
     $listed = $query->getQuery()->getSingleScalarResult();
     return $listed;
 }
Пример #4
0
 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) {
     }
 }
 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());
 }
Пример #6
0
 /**
  * Retrives the userCourse
  * There can be only one course added per user. So ignoring the list id
  * @param \ClassCentral\SiteBundle\Entity\User $user
  * @param Course $course
  * @param $listId
  */
 private function getUserCourseId(\ClassCentral\SiteBundle\Entity\User $user, Course $course, $listId)
 {
     $em = $this->container->get('doctrine')->getManager();
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('id', 'id');
     $query = $em->createNativeQuery("SELECT id FROM users_courses WHERE user_id = ? AND course_id = ?", $rsm);
     $query->setParameter('1', $user->getId());
     $query->setParameter('2', $course->getId());
     //$query->setParameter('3', $listId);
     $result = $query->getResult();
     if (empty($result)) {
         return null;
     } else {
         return $result[0]["id"];
     }
 }