public function personalizationAction(Request $request)
 {
     $cache = $this->get('cache');
     $userSession = $this->get('user_session');
     $providerController = new InitiativeController();
     $providersData = $providerController->getProvidersList($this->container);
     $insController = new InstitutionController();
     $insData = $insController->getInstitutions($this->container, true);
     $subjectsController = new StreamController();
     $subjects = $cache->get('stream_list_count', array($subjectsController, 'getSubjectsList'), array($this->container));
     $childSubjects = array();
     foreach ($subjects['parent'] as $parent) {
         if (!empty($subjects['children'][$parent['id']])) {
             foreach ($subjects['children'][$parent['id']] as $child) {
                 $childSubjects[] = $child;
             }
         }
     }
     // Count follows.
     $follows = $userSession->getFollows();
     $numSubjectsFollowed = count($follows[Item::ITEM_TYPE_SUBJECT]);
     $numInstitutionsFollowed = count($follows[Item::ITEM_TYPE_INSTITUTION]);
     $numProvidersFollowed = count($follows[Item::ITEM_TYPE_PROVIDER]);
     $numFollows = count($this->getUser()->getFollows());
     $isFollowingASubject = $this->getUser()->isFollowingASubject();
     return $this->render('ClassCentralSiteBundle:Follow:personalization.html.twig', array('providers' => $providersData['providers'], 'followProviderItem' => Item::ITEM_TYPE_PROVIDER, 'institutions' => $insData['institutions'], 'followInstitutionItem' => Item::ITEM_TYPE_INSTITUTION, 'page' => 'Personalization', 'subjects' => $subjects, 'childSubjects' => $childSubjects, 'followSubjectItem' => Item::ITEM_TYPE_SUBJECT, 'numSubjectsFollowed' => $numSubjectsFollowed, 'numInstitutionFollowed' => $numInstitutionsFollowed, 'numProvidersFollowed' => $numProvidersFollowed, 'numFollows' => $numFollows, 'isFollowingASubject' => $isFollowingASubject));
 }
 public function stepFollowInstitutionsAction(Request $request)
 {
     $user = $this->getUser();
     $userSession = $this->get('user_session');
     $cache = $this->get('cache');
     $insController = new InstitutionController();
     $insData = $insController->getInstitutions($this->container, true);
     $providerController = new InitiativeController();
     $providersData = $providerController->getProvidersList($this->container);
     $html = $this->render('ClassCentralSiteBundle:Onboarding:followInstitutions.html.twig', array('user' => $user, 'followInstitutionItem' => Item::ITEM_TYPE_INSTITUTION, 'followProviderItem' => Item::ITEM_TYPE_PROVIDER, 'institutions' => $insData['institutions'], 'providers' => $providersData['providers']))->getContent();
     $response = array('modal' => $html);
     return new Response(json_encode($response));
 }
 /**
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $indexer = $this->getContainer()->get('es_indexer');
     $indexer->setContainer($this->getContainer());
     $em = $this->getContainer()->get('doctrine')->getManager();
     $cache = $this->getContainer()->get('cache');
     /****
      * Index courses
      */
     $offset = 0;
     $limit = 100;
     $count = 0;
     do {
         unset($courses);
         $courses = $this->getContainer()->get('doctrine')->getManager()->getRepository('ClassCentralSiteBundle:Course')->findBy(array(), array(), 100, $offset);
         foreach ($courses as $course) {
             $indexer->index($course);
             $count++;
         }
         $output->writeLn("{$count} courses indexed");
         $offset += $limit;
     } while ($courses);
     /****
      * Index Credentials
      */
     $credentials = $this->getContainer()->get('doctrine')->getManager()->getRepository('ClassCentralCredentialBundle:Credential')->findAll();
     foreach ($credentials as $credential) {
         $indexer->index($credential);
     }
     $output->writeln("All Credentials indexed");
     /***
      * Index languages
      */
     $langController = new LanguageController();
     $languages = $cache->get('language_list_count', array($langController, 'getLanguagesList'), array($this->getContainer()));
     foreach ($languages as $language) {
         $indexer->index($language);
     }
     $output->writeln("All Languages indexed");
     /***
      * Index universities/institutions
      */
     $insController = new InstitutionController();
     // Get institutions
     $data = $insController->getInstitutions($this->getContainer(), false);
     $institutions = $data['institutions'];
     // Get Universities
     $data = $insController->getInstitutions($this->getContainer(), true);
     $universities = $data['institutions'];
     $all = array_merge($institutions, $universities);
     foreach ($all as $ins) {
         if ($ins['count'] > 0) {
             $i = $em->getRepository('ClassCentralSiteBundle:Institution')->findOneBy(array('slug' => $ins['slug']));
             $i->setCount($ins['count']);
             $indexer->index($i);
         }
     }
     $output->writeln("All Institutions indexed");
     /****
      * Index providers
      */
     $providerController = new InitiativeController();
     $data = $providerController->getProvidersList($this->getContainer());
     foreach ($data['providers'] as $provider) {
         if ($provider['count'] > 0) {
             if ($provider['code'] == 'independent') {
                 $p = new Initiative();
                 $p->setCode('independent');
                 $p->setName('Independent');
             } else {
                 $p = $em->getRepository('ClassCentralSiteBundle:Initiative')->findOneBy(array('code' => $provider['code']));
             }
             $p->setCount($provider['count']);
             $indexer->index($p);
         }
     }
     $output->writeln("All Providers indexed");
     /****
      * Index subjects
      */
     $subjectRepository = $em->getRepository('ClassCentralSiteBundle:Stream');
     $subjects = $cache->get('stream_list_count', array(new StreamController(), 'getSubjectsList'), array($this->getContainer()));
     foreach ($subjects['parent'] as $subject) {
         $indexer->index($subjectRepository->find($subject['id']));
     }
     foreach ($subjects['children'] as $childSubjects) {
         foreach ($childSubjects as $subject) {
             $indexer->index($subjectRepository->find($subject['id']));
         }
     }
     $output->writeln("All subjects indexed");
 }