/**
  * @param Application $app
  * @param Request $req
  *
  * @return Response
  */
 public function addAction(Application $app, Request $req)
 {
     $type = $req->get('type', null);
     $eventId = $req->get('id', null);
     if (is_null($type) || is_null($eventId) || !is_numeric($type)) {
         return new Response('Wrong parameter', 404);
     }
     if ($app['odbc_aster'] === false) {
         return new Response('Could not connect to the DB', 404);
     }
     $interested = 0;
     $not_interested = 0;
     switch ($type) {
         case 0:
             // 0,1
             $not_interested = 1;
             break;
         case 1:
             // 0,0 is ok
             break;
         case 2:
             // 1,0
             $interested = 1;
             break;
         default:
             return new Response('Not valid type', 404);
             break;
     }
     /** @var $user User */
     $user = $app['security.token_storage']->getToken()->getUser();
     $userId = $user->getId();
     /**@var $userIntProvider UserInterestProvider */
     $userIntProvider = new UserInterestProvider($app['odbc_aster']);
     if ($userIntProvider->addUserInterest($userId, $eventId, $interested, $not_interested)) {
         // try to insert
         return new Response('Ok', 200);
     } else {
         if ($userIntProvider->updateUserInterest($userId, $eventId, $interested, $not_interested)) {
             // try to update
             return new Response('Ok', 200);
         } else {
             return new Response('Could not add the event to interest', 404);
         }
     }
 }
 /**
  * @param Application $app
  * @param Request $req
  *
  * @return string
  */
 public function indexAction(Application $app, Request $req)
 {
     $errors = array();
     $eventsRec = array();
     $events = array();
     $eventsInt = array();
     /** @var $token TokenInterface */
     $token = $app['security.token_storage']->getToken();
     /** @var $user User */
     $user = $token->getUser();
     $id = $user->getId();
     $page = $req->get('page', 0);
     if (!is_numeric($page) || $page < 0) {
         $page = 0;
     }
     if ($app['odbc_aster'] !== false) {
         // recommended events
         $userRecProvider = new UserRecommendationProvider($app['odbc_aster']);
         $eventsRec = $userRecProvider->getUserRecommendations($id, self::NUM_EVENTS_TO_RETRIEVE, $page * self::NUM_EVENTS_TO_RETRIEVE);
         if ($eventsRec === false) {
             $errors[] = "Error while retrieving recommended events for the user! (Bad Query?)";
         }
         // general events
         $eventsProvider = new EventProvider($app['odbc_aster']);
         $events = $eventsProvider->getEventsWithInterests($id, self::NUM_EVENTS_TO_RETRIEVE, $page * self::NUM_EVENTS_TO_RETRIEVE);
         if ($events === false) {
             $errors[] = "Error while retrieving events! (Bad Query?)";
         }
         // interested events
         $userIntProvider = new UserInterestProvider($app['odbc_aster']);
         $eventsInt = $userIntProvider->getUserInterests($id, self::NUM_EVENTS_TO_RETRIEVE, $page * self::NUM_EVENTS_TO_RETRIEVE);
         if ($eventsInt === false) {
             $errors[] = "Error while retrieving interested events for the user! (Bad Query?)";
         }
     } else {
         $errors[] = "Could not connect to the DB!";
     }
     return $app['twig']->render('app.twig', array('user' => $user, 'rec_events' => $eventsRec, 'events' => $events, 'int_events' => $eventsInt, 'p' => $page + 1, 'error' => $errors, 'page' => 'discover'));
 }