public function userRecommendationsAction(Request $request)
 {
     // Check if user is already logged in.
     if (!$this->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY')) {
         return UniversalHelper::getAjaxResponse(false);
     }
     $suggestions = $this->get('suggestions');
     $user = $this->getUser();
     $data = $suggestions->getRecommendations($user, $request->query->all());
     return $this->returnJsonResponse($data, 'suggestions', 'user_course_recommendations');
 }
Esempio n. 2
0
 /**
  * Returns a json object containing the course details. Originally designed for
  * wordpres short code
  * @param Request $request
  * @param $courseId
  */
 public function courseDetailsAction(Request $request, $courseId)
 {
     $em = $this->getDoctrine()->getManager();
     $cache = $this->get('Cache');
     $courseId = intval($courseId);
     $course = $cache->get('course_' . $courseId, array($this, 'getCourseDetails'), array($courseId, $em));
     if (!$course || $course['status'] == 100) {
         return UniversalHelper::getAjaxResponse(false);
     }
     $data = array('name' => $course['name'], 'displayDate' => $course['nextOffering']['displayDate'], 'url' => $course['nextOffering']['url']);
     return UniversalHelper::getAjaxResponse(true, $data);
 }
Esempio n. 3
0
 public function getCredential($xseries)
 {
     $credential = new Credential();
     $credential->setName($xseries['title']);
     $credential->setPricePeriod(Credential::CREDENTIAL_PRICE_PERIOD_TOTAL);
     $credential->setPrice(0);
     $credential->setSlug(UniversalHelper::getSlug($credential->getName()) . '-xseries');
     $credential->setInitiative($this->initiative);
     $credential->setUrl($xseries['url']);
     $credential->setOneLiner($xseries['field_xseries_subtitle']);
     $credential->setSubTitle($xseries['field_xseries_subtitle_short']);
     $credential->setDescription($xseries['body']['value'] . $xseries['field_xseries_overview']['value']);
     return $credential;
 }
Esempio n. 4
0
 /**
  * Ajax call to save the course and list id in the session, before showing the signup form action
  * @param Request $request
  * @param $courseId
  * @param $listId
  * @return Response
  */
 public function preSignupAddToLibraryAction(Request $request, $courseId, $listId)
 {
     $this->get('user_session')->saveSignupReferralDetails(array('listId' => $listId, 'courseId' => $courseId));
     return UniversalHelper::getAjaxResponse(true);
 }
 public function saveAction(Request $request, $credentialId)
 {
     $em = $this->getDoctrine()->getManager();
     $userSession = $this->container->get('user_session');
     $user = $this->getUser();
     $credential = $em->getRepository('ClassCentralCredentialBundle:Credential')->find($credentialId);
     if (!$credential) {
         return UniversalHelper::getAjaxResponse(false, "Credential not found");
     }
     // Get the Json post data
     $content = $this->getRequest("request")->getContent();
     if (empty($content)) {
         return UniversalHelper::getAjaxResponse(false, "Error retrieving form details");
     }
     $reviewData = json_decode($content, true);
     $cr = new CredentialReview();
     $cr->setCredential($credential);
     // check if the rating valid
     if (!isset($reviewData['rating']) && !is_numeric($reviewData['rating'])) {
         return UniversalHelper::getAjaxResponse(false, 'Rating is required and expected to be a number');
     }
     // Check if the rating is in range
     if (!($reviewData['rating'] >= 1 && $reviewData['rating'] <= 5)) {
         return UniversalHelper::getAjaxResponse(false, 'Rating should be between 1 to 5');
     }
     $cr->setRating($reviewData['rating']);
     // If review exists its length should be atleast 20 words
     if (!empty($reviewData['reviewText']) && str_word_count($reviewData['reviewText']) < 20) {
         return UniversalHelper::getAjaxResponse(false, 'Review should be at least 20 words long');
     }
     $cr->setText($reviewData['reviewText']);
     // If Review exist so does title
     if (!empty($reviewData['reviewText']) && empty($reviewData['title'])) {
         return UniversalHelper::getAjaxResponse(false, "Title cannot be empty");
     }
     $cr->setTitle($reviewData['title']);
     // Progress is mandatory
     if (empty($reviewData['progress'])) {
         return UniversalHelper::getAjaxResponse(false, "Progress cannot be empty");
     }
     $progress = $reviewData['progress'];
     if (in_array($progress, array_keys(CredentialReview::$progressListDropdown))) {
         $cr->setProgress($progress);
     } else {
         $cr->setDateCompleted(new \DateTime($progress));
         $cr->setProgress(CredentialReview::PROGRESS_TYPE_COMPLETED);
     }
     // Link
     $cr->setLink($reviewData['certificateLink']);
     /******
      * Could you say a little more about the course
      */
     if (isset($reviewData['topicCoverage']) && $reviewData['topicCoverage'] >= 1 && $reviewData['topicCoverage'] <= 5) {
         $cr->setTopicCoverage($reviewData['topicCoverage']);
     }
     if (isset($reviewData['jobReadiness']) && $reviewData['jobReadiness'] >= 1 && $reviewData['jobReadiness'] <= 5) {
         $cr->setJobReadiness($reviewData['jobReadiness']);
     }
     if (isset($reviewData['support']) && $reviewData['support'] >= 1 && $reviewData['support'] <= 5) {
         $cr->setSupport($reviewData['support']);
     }
     if (!empty($reviewData['effort']) && is_numeric($reviewData['effort'])) {
         $cr->setEffort($reviewData['effort']);
     }
     if (!empty($reviewData['duration']) && is_numeric($reviewData['duration'])) {
         $cr->setDuration($reviewData['duration']);
     }
     /******
      * About Me
      */
     // Validate email
     if (!$user) {
         $email = $reviewData['email'];
         if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
             // invalid email
             return UniversalHelper::getAjaxResponse(false, 'Valid email is required');
         } else {
             $cr->setReviewerEmail($email);
         }
     } else {
         $cr->setUser($user);
     }
     if (!empty($reviewData['name'])) {
         $cr->setReviewerName($reviewData['name']);
     }
     if (!empty($reviewData['highestDegree'])) {
         $degreeId = intval($reviewData['highestDegree']);
         if (isset(Profile::$degrees[$degreeId])) {
             $cr->setReviewerHighestDegree(Profile::$degrees[$degreeId]);
         }
     }
     $cr->setReviewerJobTitle($reviewData['jobTitle']);
     if (!empty($reviewData['fieldOfStudy'])) {
         $cr->setReviewerFieldOfStudy($reviewData['fieldOfStudy']);
     }
     $em->persist($cr);
     $em->flush();
     $userSession->notifyUser(UserSession::FLASH_TYPE_SUCCESS, 'Review Created', "Your review for <i>{$credential->getName()}</i> was saved successfully");
     $message = 'New Review for ' . $credential->getName();
     // Send a message on Slack.
     $this->container->get('slack_client')->to('#cc-activity-user')->from('Credential Review')->send($message);
     // If not a user, then save the session in the activity
     if (!$user) {
         $this->get('user_session')->saveAnonActivity('credential_review', $cr->getId());
     }
     return UniversalHelper::getAjaxResponse(true, $cr->getId());
 }
 public function preFollowAction(Request $request, $item, $itemId)
 {
     $userSession = $this->get('user_session');
     $userSession->saveAnonActivity('follow', "{$item}-{$itemId}");
     return UniversalHelper::getAjaxResponse(true);
 }
 /**
  * Ajax call for review status update
  * @param Request $request
  * @param $reviewId
  * @param $statusId
  * @return Response
  */
 public function reviewStatusUpdateAction(Request $request, $reviewId, $statusId)
 {
     $em = $this->getDoctrine()->getManager();
     $review = $em->getRepository('ClassCentralSiteBundle:Review')->find($reviewId);
     if (!$review) {
         return UniversalHelper::getAjaxResponse(false, 'Review Does not exist');
     }
     $review->setStatus($statusId);
     $em->persist($review);
     $em->flush();
     return UniversalHelper::getAjaxResponse(true);
 }
 /**
  * Create and save the user
  * @param Request $request
  */
 public function createUserAction(Request $request)
 {
     $userService = $this->get('user_service');
     $form = $this->createForm(new SignupType(), new User(), array('action' => $this->generateUrl('signup_create_user')));
     $form->handleRequest($request);
     $modal = $form["modal"]->getData();
     // if modal = 1, it means the form has been submitted through a signup modal via AJAX
     if ($form->isValid()) {
         $user = $form->getData();
         $src = $request->query->get('src');
         $url = $userService->createUser($user, true, $src);
         if ($modal) {
             return UniversalHelper::getAjaxResponse(true);
         } else {
             return $this->redirect($url);
         }
     }
     if ($modal) {
         // Get the error message
         $error = 'Some error occurred';
         $errorMessages = $this->getErrorMessages($form);
         foreach ($errorMessages as $errorMessage) {
             $error = $errorMessage[0];
             break;
         }
         return UniversalHelper::getAjaxResponse(false, $error);
     } else {
         return $this->signUpAction($form);
     }
     // Form is not valid
     return $this->signUpAction($form);
 }
 /**
  * Marks a user record for deletion. This is an Ajax call
  */
 public function deleteProfileAction(Request $request)
 {
     $user = $this->container->get('security.context')->getToken()->getUser();
     $em = $this->getDoctrine()->getManager();
     $userService = $this->get('user_service');
     // Get the json request
     $content = $this->getRequest("request")->getContent();
     if (empty($content)) {
         return UniversalHelper::getAjaxResponse(false, "Invalid Request. Please try again later");
     }
     $data = json_decode($content, true);
     $currentPassword = $data['currentPassword'];
     // Confirm if the current password is valid
     if (!$this->isPasswordValid($currentPassword, $user)) {
         return UniversalHelper::getAjaxResponse(false, 'Invalid current password');
     }
     // Mark the user for deletion
     $userService->updatePreference($user, UserPreference::USER_PROFILE_DELETE_ACCOUNT, json_encode(array('user_id' => $user->getId())));
     // Notify the user that he has 7 days to live
     $this->get('user_session')->notifyUser(UserSession::FLASH_TYPE_SUCCESS, 'Account marked for deletion', 'Your profile and all related data will be deleted within 7 days');
     return UniversalHelper::getAjaxResponse(true);
 }
 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;
 }