Exemplo n.º 1
0
 public function migrate()
 {
     $this->output->writeln("Starting data migration version 5");
     $this->output->writeln('Migrating MOOC tracker courses');
     $em = $this->container->get('Doctrine')->getManager();
     $moocTrackerCourses = $em->getRepository('ClassCentralSiteBundle:MoocTrackerCourse')->findAll();
     foreach ($moocTrackerCourses as $mtc) {
         $uc = new UserCourse();
         $uc->setUser($mtc->getUser());
         $uc->setCourse($mtc->getCourse());
         $uc->setCreated($mtc->getCreated());
         $uc->setListId(UserCourse::LIST_TYPE_INTERESTED);
         $em->persist($uc);
     }
     $em->flush();
     $this->output->writeln('Creating MOOC Tracker preferences');
     // Creating user preferences for mooc tracker courses and search terms
     $users = $em->getRepository('ClassCentralSiteBundle:User')->findAll();
     foreach ($users as $user) {
         $upCourses = new UserPreference();
         $upCourses->setUser($user);
         $upCourses->setType(UserPreference::USER_PREFERENCE_MOOC_TRACKER_COURSES);
         $upCourses->setValue("1");
         $upSearchTerms = new UserPreference();
         $upSearchTerms->setUser($user);
         $upSearchTerms->setType(UserPreference::USER_PREFERENCE_MOOC_TRACKER_SEARCH_TERM);
         $upSearchTerms->setValue("1");
         $em->persist($upCourses);
         $em->persist($upSearchTerms);
     }
     $em->flush();
 }
Exemplo n.º 2
0
 /**
  * Adds a course to the users interested list.
  * A course can be added only once.
  * @param \ClassCentral\SiteBundle\Entity\User $user
  * @param Course $course
  * @param $listId
  */
 public function addCourse(\ClassCentral\SiteBundle\Entity\User $user, Course $course, $listId)
 {
     $em = $this->container->get('doctrine')->getManager();
     // Check if the list id is valid
     if (!array_key_exists($listId, UserCourse::$lists)) {
         throw new \Exception("List id {$listId} is not valid");
     }
     // Remove the course if it exists
     $this->removeCourse($user, $course, $listId);
     //Save it if it does not exist
     $uc = new UserCourse();
     $uc->setCourse($course);
     $uc->setUser($user);
     $uc->setListId($listId);
     // Add course to user
     $user->addUserCourse($uc);
     $em->persist($uc);
     $em->flush();
     return $uc;
 }
Exemplo n.º 3
0
 public static function getUserList($params)
 {
     if (empty($params) || empty($params['list'])) {
         return UserCourse::getListTypes();
     }
     return explode(',', $params['list']);
 }