function indexAction($id = null)
 {
     $p = Tools::getValue('page', 1);
     if (!empty($id)) {
         $sql = "select ID, Name, MetaKeywords, MetaRobots, Description from ArticleCategories where (ID = {$id}) and (IsDeleted = 0);";
         $category = GetMainConnection()->query($sql)->fetch();
         if (empty($category['ID'])) {
             return AddAlertMessage('danger', 'Категории статей не существует.', '/');
         }
         $CategoryName = $category['Name'];
         $sql = "SELECT count(*) as RecordCount " . "FROM Articles a " . "WHERE a.CategoryID = {$id} " . "AND a.isActive = 1 " . "AND a.IsDeleted = 0";
         $rec = GetMainConnection()->query($sql)->fetch();
         $total = ceil($rec['RecordCount'] / ARTICLES_PER_PAGE);
         $sql = "SELECT a.ID, a.CategoryID, a.Name, a.ShortDescription, a.count_likes, a.CountComments, MainImageExt " . "FROM Articles a " . "WHERE a.CategoryID = {$id} " . "AND a.isActive = 1 " . "AND a.IsDeleted = 0 " . "ORDER BY a.CreateDate DESC, a.ID DESC " . "LIMIT " . ($p > 0 ? $p - 1 : 0) * ARTICLES_PER_PAGE . ", " . ARTICLES_PER_PAGE;
         $articles = GetMainConnection()->query($sql)->fetchAll();
     } else {
         $category = null;
         $CategoryName = 'Все статьи';
         $article = new Articles($this->context);
         $total = ceil($article->getArticles($p, null, true) / ARTICLES_PER_PAGE);
         $articles = $article->getArticles($p);
     }
     $this->view->setVars(array('CategoryName' => $CategoryName, 'articles' => $articles, 'pagination' => array('total_pages' => $total, 'current' => $p)));
     $this->view->breadcrumbs = array(array('url' => '/category', 'title' => 'Все статьи'));
     if (isset($category)) {
         $this->view->breadcrumbs[] = array('url' => '/articles/c-' . $id, 'title' => $CategoryName);
         $this->view->meta = array('meta_title' => $CategoryName, 'meta_description' => $category['Description'], 'meta_keywords' => $category['MetaKeywords']);
     } else {
         $this->view->meta = array('meta_title' => $CategoryName, 'meta_description' => $CategoryName, 'meta_keywords' => $CategoryName);
     }
     $this->view->generate();
 }
Exemple #2
0
 public function getContent()
 {
     //статическая часть контента
     echo '<div class="container">
 <!-- Example row of columns -->
 <div class="row">
     <div class="col-md-9">
     <div class="articles">';
     //динамическая часть
     //        $result = DB::query("SELECT id, title, description, date, img_src FROM  articles ORDER BY date DESC");
     //        $this->getMessageQueryErr($result, __FUNCTION__);
     $result = Articles::getArticles(0, 5);
     foreach ($result as $key => $value) {
         printf("<article class='media'>\n                        <h2 class='media-heading'>%s</h2>\n                        <p>%s</p>\n                        <div class='media-body'>\n                            <img class='img-responsive'  src='%s' >\n                            <p>%s </p>\n                            <p><a class='btn btn-default' href='?option=view&id_article=%s' role='button'>View details &raquo;</a></p>\n                        </div>\n                   </article>", $value[title], $value[date], $value[img_src], $value[description], $value[id]);
     }
     echo "</div>";
     echo "<button class='btn btn-primary btn-lg next'>Показать еще</button>";
     /*while ($content = $result->fetch_object()) {
                 printf("<article class='media'>
                             <h2 class='media-heading'>%s</h2>
                             <p>%s</p>
     
                             <div class='media-body'>
                                 <img class='img-responsive'  src='%s' >
                                 <p>%s </p>
                                 <p><a class='btn btn-default' href='?option=view&id_article=%s' role='button'>View details &raquo;</a></p>
                             </div>
                        </article>", $content->title,$content->date, $content->img_src, $content->description, $content->id);
             }*/
     //статическая часть
     echo "</div>";
 }
 function indexAction()
 {
     $p = Tools::getValue('page', 1);
     $q = Tools::getValue('q', '');
     $AuthorID = Tools::getValue('author', null);
     $articles = new Articles($this->context);
     if ($AuthorID != null) {
         $sql = "SELECT ID, Name FROM Authors WHERE ID = {$AuthorID};";
         $author = GetMainConnection()->query($sql)->fetch();
         if (empty($author['ID'])) {
             return AddAlertMessage('danger', 'Такого автора не существует.', '/');
         }
         $AuthorName = $author['Name'];
         $total = ceil($articles->getArticles($p, 'AuthorID = ' . $AuthorID, true) / ARTICLES_PER_PAGE);
         $articles = $total > 0 ? $articles->getArticles($p, 'AuthorID = ' . $AuthorID) : null;
     } else {
         $AuthorName = '';
         $AddWhere = empty($q) ? '' : '(Name LIKE "%' . $q . '%" OR Description LIKE "%' . $q . '%")';
         $total = ceil($articles->getArticles($p, $AddWhere, true) / ARTICLES_PER_PAGE);
         $articles = $total > 0 ? $articles->getArticles($p, $AddWhere) : null;
     }
     $this->view->setVars(array('q' => $q, 'AuthorName' => $AuthorName, 'articles' => $articles, 'pagination' => array('total_pages' => $total, 'current' => $p)));
     $this->view->breadcrumbs = array(array('url' => '/search', 'title' => 'Поиск'));
     $this->view->generate();
 }
Exemple #4
0
<?php

/**
 * Created by PhpStorm.
 * User: Vladislav
 * Date: 23.11.2015
 * Time: 20:05
 */
require_once "classes/articles.class.php";
require_once "classes/Comments.class.php";
try {
    $response = array();
    $start = $_GET[start];
    $step = $_GET[step];
    if (isset($_GET[id])) {
        $id_article = $_GET[id];
    }
    switch ($_GET['action']) {
        case 'get_next_articles':
            $response = Articles::getArticles($start, $step);
            break;
        case 'get_next_comments':
            $response = Comments::getComments($id_article, $start, $step);
            break;
        default:
            throw new Exception('Wrong action');
    }
    echo json_encode($response);
} catch (Exception $e) {
    die(json_encode(array('error' => $e->getMessage())));
}