function AddEmailStreamAction(Request $request)
 {
     $server = $request->post('server');
     $account = $request->post('user');
     $password = $request->post('password');
     $port = $request->post('port');
     $category = $request->post('category');
     $firstUpdate = $request->post('firstUpdate');
     $user = $request->getSession()->get('id');
     $this->loadModel('EmailModel');
     $this->loadModel('CategoryModel');
     /** @var EmailEntity $emailEntity */
     $emailEntity = $this->emailmodel->createEmailStream($server, $account, $password, $port, $firstUpdate);
     if ($emailEntity) {
         /** @var CategoryEntity $categoryEntity */
         $categoryEntity = $this->categorymodel->createCategory($user, $category);
         $streamCategoryEntity = new StreamCategoryEntity();
         $streamCategoryEntity->setCategory($categoryEntity->getId());
         $streamCategoryEntity->setStream($emailEntity->getId());
         $streamCategoryEntity->setStreamType(ArticleModel::EMAIL);
         $streamCategoryEntity->persist();
         $this->redirectToRoute('index');
     } else {
         $this->render('layouts/addStream', array('errors' => array('La connexion avec ce flux n\'a pas pu être établi. Vérifier vos informations.')));
     }
 }
 public function addRSSStreamAction(Request $request)
 {
     $categoryTitle = $request->post('category');
     $firstUpdate = $request->post('firstUpdate');
     $url = $request->post('url_flux');
     var_dump($categoryTitle);
     var_dump($firstUpdate);
     var_dump($url);
     $this->loadModel('CategoryModel');
     $this->loadModel('RssModel');
     $url = $this->rssmodel->resolveFile($url);
     $userId = $request->getSession()->get('id');
     $rssEntity = $this->rssmodel->createStream($url, $firstUpdate);
     if ($rssEntity) {
         $categoryEntity = $this->categorymodel->createCategory($userId, $categoryTitle);
         $streamCategoryEntity = new StreamCategoryEntity();
         $streamCategoryEntity->setCategory($categoryEntity->getId());
         $streamCategoryEntity->setStream($rssEntity->getId());
         $streamCategoryEntity->setStreamType(ArticleModel::RSS);
         $streamCategoryEntity->persist();
         $this->rssmodel->streamCron($rssEntity);
         $this->redirectToRoute('index');
     } else {
         $this->render('layouts/addStream', array('errors' => array('Une erreur est survenue dans la connexion au flux rss. Veuillez réssayer ! ')));
     }
 }
 function addTwitterStreamAction(Request $request)
 {
     $categoryTitle = $request->post('category');
     $firstUpdate = $request->post('firstUpdate');
     $channel = $request->post('channel');
     $userId = $request->getSession()->get('id');
     $channel = str_replace('@', '', $channel);
     $this->loadModel('CategoryModel');
     $this->loadModel('TwitterModel');
     if (!$this->twittermodel->isValidChannel($channel)) {
         $data = array('errors' => array('La chaine n\'existe pas, veuillez spécifier une chaine existante'));
         $this->render('layouts/addStream', $data);
         return;
     }
     $twitterEntity = $this->twittermodel->createStream($channel, $firstUpdate);
     if ($twitterEntity) {
         $categoryEntity = $this->categorymodel->createCategory($userId, $categoryTitle);
         $streamCategoryEntity = new StreamCategoryEntity();
         $streamCategoryEntity->setCategory($categoryEntity->getId());
         $streamCategoryEntity->setStream($twitterEntity->getId());
         $streamCategoryEntity->setStreamType(ArticleModel::TWITTER);
         $streamCategoryEntity->persist();
         $this->twittermodel->streamCron($twitterEntity);
         $this->redirectToRoute('index');
     } else {
         $this->render('layouts/addStream', array('errors' => array('Une erreur est survenue dans la connexion au flux twitter. Veuillez réssayer ! ')));
     }
 }