public function index()
 {
     // EVENT
     $tmp = $this->modelConnect->checkConnect();
     $events['top'] = $this->modelEvent->getTop();
     $events['last'] = $this->modelEvent->getLast();
     $events['nbConnect'] = (int) $tmp['COUNT(*)'];
     foreach ($events['top'] as $key => $value) {
         if (strlen($events['top'][$key]['description']) > 200) {
             $events['top'][$key]['description'] = substr($events['top'][$key]['description'], 0, strpos($events['top'][$key]['description'], ' ', 200));
             $events['top'][$key]['description'] .= ' ... ';
         }
     }
     foreach ($events['last'] as $key => $value) {
         if (strlen($events['last'][$key]['description']) > 200) {
             $events['last'][$key]['description'] = substr($events['last'][$key]['description'], 0, strpos($events['last'][$key]['description'], ' ', 200));
             $events['last'][$key]['description'] .= ' ... ';
         }
     }
     $lastUser = $this->userModel->getLastUser();
     // ARTICLE
     $modelArticle = new ArticleModel();
     $article['top'] = $modelArticle->getTop();
     $article['last'] = $modelArticle->getLast();
     $article['top'] = $this->getInfos($article['top']);
     $article['top']['text'] = substr($article['top']['text'], 0, strpos($article['top']['text'], ' ', 1000));
     $article['top']['text'] .= ' ... ';
     foreach ($article['last'] as &$art) {
         $art['text'] = substr($art['text'], 0, strpos($art['text'], ' ', 70));
         $art['text'] .= ' ... ';
         $art = $this->getInfos($art);
     }
     $this->getView()->render('home/index', ['events' => $events, 'article' => $article, 'lastUsers' => $lastUser]);
 }
Example #2
0
 /**
  * @param \App\Forms\ArticleForm $form
  */
 public function articleFormSubmitted(ArticleForm $form)
 {
     $article = $form->getValues(TRUE);
     if ($this->action == 'add') {
         $article['published'] = new \DateTime();
     } else {
         $article['id'] = $this->getParameter('id');
     }
     $this->articleModel->save($article);
     $this->flashMessage('Článok bol úspešne uložený.', 'success');
     $this->redirect('default', $article['id']);
 }
 public function testAll()
 {
     $this->model = new ArticleModel();
     $array = ['user' => '1', 'title' => 'plop', 'text' => 'test', 'image' => 'http://lol.com/lol.png', 'category' => '1'];
     $state = $this->model->insertNews($array);
     $this->assertEquals(true, $state);
     $state = $this->model->getOneNewsByName('plop');
     $this->assertNotEmpty($state);
     $state = $this->model->updateNewsByName('plop', date('Y-m-d G:i:s'), 'Je sais toujours pas');
     $this->assertEquals(true, $state);
     $state = $this->model->deleteNewsByName('plop');
     $this->assertEquals(true, $state);
 }
Example #4
0
 public function editOneArticle($id = 0, $data = array())
 {
     if (empty($id)) {
         return false;
     }
     if (empty($data)) {
         return false;
     }
     $article_model = new ArticleModel();
     $result = $article_model->where('id', $id)->update($data);
     if (!$result) {
         return false;
     }
     $content_id = $article_model->select('content_id')->where('id', $id)->one();
     return $content_id['content_id'];
 }
 public function modifyPOST()
 {
     if (!Authentication::getInstance()->isAuthenticated()) {
         throw new NotAuthenticatedException();
     }
     $form = FormHelper::generate('article', '/article/modify');
     $result = $form->validate(['id' => '', 'title' => 'Titre de l\'Actualité', 'text' => 'Contenu']);
     $article = $this->articleModel->getOneNewsById($result['id']);
     if (empty($article)) {
         throw new ArticleNotFoundException($result['id']);
     }
     if ($article['user'] != Authentication::getInstance()->getUserId() && !(Authentication::getInstance()->getOptionOr('accessLevel', 0) == 1)) {
         throw new NotYourArticleException($result['id']);
     }
     $this->articleModel->updateNews($result);
     $this->getView()->redirect('/article/show/' . $result['id']);
 }