Example #1
0
 public static function footerWidget()
 {
     $model = new ArticleTableModel();
     $model->setTable('article');
     $model->readAllRecords('id, title, main_image, created_time', 'ORDER BY created_time LIMIT 4');
     return $model->getAllRecords();
 }
Example #2
0
 public function getAllArticlesWidget($fields = '*', $condition = '')
 {
     $model = new ArticleTableModel();
     $model->setTable('article');
     $model->readAllRecords($fields, $condition);
     $records = $model->getAllRecords();
     $userModel = new UserTableModel();
     foreach ($records as $key => $record) {
         $userModel->setId($record['author']);
         $userModel->setTable('user');
         $records[$key]['author_name'] = $userModel->readRecordsById('id', 'username')[0]['username'];
     }
     return $records;
 }
Example #3
0
 public function viewAction()
 {
     $fc = FrontController::getInstance();
     $model = new FrontModel();
     $articleModel = new ArticleTableModel();
     $userModel = new UserTableModel();
     $id = filter_var($fc->getParams()['id'], FILTER_SANITIZE_NUMBER_INT);
     if (!$id) {
         header('Location: /admin/notFound');
         exit;
     }
     $articleModel->setId($id);
     $articleModel->setTable('article');
     $article = $articleModel->readRecordsById();
     $userModel->setId($article[0]['author']);
     $userModel->setTable('user');
     $model->setData(['article' => $article, 'author' => $userModel->readRecordsById('id', 'id, username')]);
     $output = $model->render('../views/blog/view.php', 'withoutSlider');
     $fc->setPage($output);
 }
Example #4
0
 public function deleteArticleAction()
 {
     header('Content-type: text/plain; charset=utf-8');
     header('Cache-Control: no-store, no-cache');
     header('Expires: ' . date('r'));
     if (filter_has_var(INPUT_POST, 'id')) {
         $id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
     }
     $model = new ArticleTableModel();
     $model->setId($id);
     $model->setTable('article');
     echo $model->deleteRecord();
 }
 public function addArticleAction()
 {
     $fc = FrontController::getInstance();
     $model = new AdminModel('Блог', 'Новая статья');
     $articleModel = new ArticleTableModel();
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $articleModel->setData();
         $articleModel->addRecord();
         Session::setMsg('Статья успешно добавлена', 'success');
         header('Location: /admin/blog');
         exit;
     } else {
         $output = $model->render('../views/admin/blog/addarticle.php', 'admin');
         $fc->setPage($output);
     }
 }