Îðëà
Îáëàñòè
Êîìïàíèé
Ïîëüçîâàòåëè
Ãàëåðåÿ
Ôèêñèðîâàííûå íîâîñòè
Îðëà
Îòçûâû î ôèðìàõ
Òàðèôû
Ïîëüçîâàòåëè
Îáëàñòè
Áàíêîìàòû
Òîðãîâûå òî÷êè
Äîñêà îáúÿâëåíèé
Êóðñû âàëþò
Ñêèäêè
îðãàíèçàöèè Îðëà
îðãàíèçàöèè îáëàñòè
òîâàðû
ñàéòû
ñàéòû Îðåë
Äàííûå
Ðàçäåëû
Ïîèñê
Ïîèñê çàïðîñû
Ñòàòèñòèêà
Ïîêàçû êàòàëîãà îðãàíèçàöèé
Ñòàòèñòèêà êëèåíòû
Ïîëüçîâàòåëè
Ñàéòû
Óïðàâëåíèå ñàéòîì
Àíêåòà
Àïòåêè
Àôèøà
Àôèøà íîâàÿ
Áàííåðû
Áèçíåñ >
Âèêòîðèíà
Ãîëîñîâàíèå
Ãîñòü íà ñàéòå
Èñòîðèè
Êàëåíäàðü ñîáûòèé
Êàòàëîãè >
Êîíêóðñ êðàñîòû
Êîíêóðñ àóäèî
Êîíñóëüòàöèè
Ìåíþ
Íîâîå íà ñàéòå
Íîâîñòè >
Îðãàíèçàöèè >
Ïðîãðàììà ÒÂ
Ïóáëèêàöèè
Ðàçäåëû ñàéòà
Ðàññûëêà
Ðåñòîðàíû
Ñåêðåò ôèðìû >
Ñåðâèñû >
Ññûëêè
Òåñòû
Ôàéëîâûé ìåíåäæåð
Ôîðóì
Ôîòîãàëåðåÿ
Îáðàòíàÿ ñâÿçü
Íåäâèæèìîñòü
Íîâûé ãîä
Òåêñòû
Ïîëüçîâàòåëè
Þðèäè÷åñêèé ðåéòèíã
Îòçûâû íà òîâàðû
Áàí ïîëüçîâàòåëåé
Æàëîáû
Íîâûå òåñòû
Êîðîíàâèðóñ
Ôàéëîâûé ìåíåäæåð
Èìÿ ôàéëà
NewsReader.php
Ñîäåðæèìîå
<?php namespace app\news; use app\BaseModel; use app\core\helpers\ArrayHelper; use app\users\User; /** * Кла�� дл� чтени� ново�тей на �айте. * @since 2.0 * Class News */ class NewsReader { /** * Ма��ив идентификаторов категорий, в которых мы ищем ново�ти. * @var array */ private $_categories = []; /** * Идентификатор активной �траницы * @var int */ private $_page = 1; /** * * Сколько запи�ей пропу�каем дл� Limit. * Е�ли offset === false, тогда мы игнорируем �ту переменную. * @var int|bool */ private $_offset = false; /** * Сколько запи�ей выводим. * @var int */ private $_limit = 25; /** * Идентификаторы �тату�ов, по которым ищем ново�ти. * @var array */ private $_statuses = []; /** * Идентификаторы рубрик, по которым ищем ново�ти * @var array */ private $_rubriks = []; /** * Выводить только главные ново�ти * @var null */ private $_important = null; private $_archiv = null; private $_firmaNull = false; private $_pdo; private $_exclusive = false; private $_excludedRubriks = []; private $_excludedCategories = []; private $fixNewsRepository; /** * Ма��ив ID ново�тей, которые нужно убрать из вывода news.id NOT IN(....)... * @var array */ private $_excludedIds = []; private $_select = []; private $_withUser = false; private $_userFields = []; private $_orderBy = ['news.data DESC']; private $_dateFrom = null; private $_dateTo = null; private $_newsIds = []; public function __construct() { $this->_pdo = &\App::$pdo; $this->fixNewsRepository = new FixNewsRepository(); } public function setCategoryId($categoryId) { if ($categoryId === null || (int)$categoryId == 0) { return $this; } $this->_categories[] = (int)$categoryId; return $this; } public function setCategoryIds(array $categories) { foreach ($categories as $category) { $this->setCategoryId($category); } return $this; } public function setRubrikId($rubrikId) { if ($rubrikId === null || (int)$rubrikId == 0) { return $this; } $this->_rubriks[] = (int)$rubrikId; return $this; } public function setPage($page) { $this->_page = (int)$page; return $this; } public function setDateTo($dateTo) { if ($dateTo == null || strtotime($dateTo) == 0) { return $this; } $this->_dateTo = date('Y-m-d', strtotime($dateTo)); return $this; } public function setDateFrom($dateFrom) { if ($dateFrom == null || strtotime($dateFrom) == 0) { return $this; } $this->_dateFrom = date('Y-m-d', strtotime($dateFrom)); return $this; } public function getDateTo() { return $this->_dateTo; } public function getDateFrom() { return $this->_dateFrom; } public function setLimit($limit) { $this->_limit = (int)$limit; return $this; } public function setStatus($statusId) { $this->_statuses[] = (int)$statusId; return $this; } public function firmaNull() { $this->_firmaNull = true; return $this; } public function exclusive() { $this->_exclusive = true; return $this; } public function excludeRubriks(array $rubriks) { $this->_excludedRubriks = $rubriks; return $this; } /** * Функци� и�ключает из �пи�ка ID ново�тей. * @param array $ids * @return $this */ public function excludeNewsIds(array $ids) { $this->_excludedIds = $ids; return $this; } public function excludedCategories(array $categories) { $this->_excludedCategories = $categories; return $this; } public function select(array $select) { $this->_select = $select; return $this; } public function withUser(array $fields) { $this->_withUser = true; $this->_userFields = $fields; return $this; } public function orderBy($array = ['news.data DESC']) { $this->_orderBy = $array; return $this; } public function setNewsId($newsId) { $this->_newsIds[] = (int)$newsId; return $this; } public function setNewsIds(array $newsIds) { foreach ($newsIds as $newsId) { $this->setNewsId($newsId); } return $this; } /** * @param $value * @return $this */ public function setVazhno($value) { $this->_important = $value; return $this; } public function setArchiv($value) { $this->_archiv = $value; return $this; } private function makeWhereFragment() { $statusFragment = ''; $categoryFragment = ''; $rubrikFragment = ''; $vazhnoFragment = ''; $archivFragment = ''; $firmaNullFragment = ''; $exclusiveFragment = ''; $excludedRubriksFragment = ''; $excludedCategoriesFragment = ''; $excludedNewsIdsFragment = ''; $newsDateBetweenFragment = ''; $newsIdsFragment = ''; if (count($this->_statuses) > 0) { $statusFragment = ' AND (news.status IN (' . implode(',', $this->_statuses) . ')) '; } if (count($this->_categories) > 0) { $categoryFragment = ' AND (news.razdel IN (' . implode(',', $this->_categories) . ')) '; } if (count($this->_rubriks) > 0) { $rubrikFragment = ' AND (news.id_rubrik IN (' . implode(',', $this->_rubriks) . ')) '; } if ($this->_important !== null) { $vazhnoFragment = ' AND (news.vazhno = ' . $this->_important .')'; } if ($this->_archiv !== null) { $archivFragment = ' AND (news.archiv = "' . $this->_archiv .'")'; } if ($this->_firmaNull === true) { $firmaNullFragment = ' AND (news.firma_id IS NULL)'; } if ($this->_exclusive === true) { $exclusiveFragment = ' AND (news.exclusiv = 1)'; } if (count($this->_excludedRubriks) > 0) { $excludedRubriksFragment = ' AND (news.id_rubrik NOT IN (' . implode(',', $this->_excludedRubriks) . '))'; } if (count($this->_excludedIds) > 0) { $excludedNewsIdsFragment = ' AND (news.id NOT IN (' . implode(',', $this->_excludedIds) . '))'; } if (count($this->_excludedCategories) > 0) { $excludedCategoriesFragment = ' AND (news.razdel NOT IN (' . implode(',', $this->_excludedCategories) . '))'; } if ($this->_dateFrom != null && $this->_dateTo != null) { $newsDateBetweenFragment = ' AND (DATE(news.data) BETWEEN "' . $this->_dateFrom . '" AND "' . $this->_dateTo . '")'; } if (count($this->_newsIds) > 0) { $newsIdsFragment = ' AND (news.id IN (' . implode(',', $this->_newsIds) . '))'; } $where = 'news.data <= NOW() ' . $statusFragment . $categoryFragment . $rubrikFragment . $vazhnoFragment . $archivFragment . $firmaNullFragment . $exclusiveFragment . $excludedRubriksFragment . $excludedNewsIdsFragment . $excludedCategoriesFragment . $newsDateBetweenFragment . $newsIdsFragment; if (count($this->_categories) == 0) { $where .= ' AND ((news.razdel = 25 AND news.id_rubrik != 5) OR (news.razdel != 25))'; } return $where; } public function setOffset($value) { $this->_offset = $value; return $this; } public function all() { if ($this->_offset === false) { $offset = ($this->_page - 1) * $this->_limit; if ($this->fixNewsRepository->findTotalActive() > 0 && $this->_page > 1) { $offset -= 1; } $limit = 'LIMIT ' . $offset . ',' . $this->_limit ; } else { $limit = 'LIMIT ' . $this->_offset . ','.$this->_limit; } if (count($this->_select) > 0) { $select = implode(',', $this->_select); } else { $select = 'news.id, news.data, news.img_foto_author, news.news_header, news.news_short, news.pokaz_img, news.archiv, news.status, news.razdel, news.view_count, news.id_rubrik, news.img_index, news.vazhno, news.photo_count, news.video_count, news.firma_id, news.user_id, news.exclusiv, news.photonewsletter, news.url, news.save_iterator, news.erid'; } $sql = ' SELECT ' . $select . ', razdel.name as razdel_name FROM `news` LEFT JOIN news_razdel razdel ON razdel.id = news.razdel WHERE '.$this->makeWhereFragment() . ' ORDER BY '.implode(',', $this->_orderBy).' '.$limit.' '; $sth = $this->_pdo->prepare($sql); $sth->execute(); $news = $sth->fetchAll(); $idNews = array_map(function ($item) { return $item['id']; }, $news); if ($this->_withUser == true) { $users = \App::$user->getUsersByIds(ArrayHelper::arrayColumn($news, 'user_id'), $this->_userFields); foreach ($news as $key => $item) { $news[$key]['user'] = isset($users[$item['user_id']]) ? $users[$item['user_id']] : null; } } $discuss = new NewsDiscuss(); $discussArray = $discuss->getDiscussCount($idNews); foreach ($news as $key => $item) { $news[$key]['discuss_count'] = $discussArray[$item['id']]; $news[$key]['image'] = NewsImage::getSrc($item); } return $news; } public function total() { $sql = ' SELECT COUNT(*) as total FROM news WHERE '.$this->makeWhereFragment() .' '; $sth = $this->_pdo->prepare($sql); $sth->execute(); $data = $sth->fetch(); return $data['total']; } }
/app/news/
Èìÿ
Äàòà
Ðàçìåð
..
2026-10-01
entity
2019-01-30
forms
2017-03-15
helpers
2019-01-31
posting
2019-01-31
vk
2019-02-01
FixNewsRepository.php
2021-03-29
856 áàéò
FixNewsService.php
2021-03-29
1 êá.
News.php
2021-03-29
4 êá.
NewsCategory.php
2017-08-15
3 êá.
NewsCommentsLikes.php
2017-09-19
4 êá.
NewsCompany.php
2017-06-29
1012 áàéò
NewsDiscuss.php
2017-09-19
7 êá.
NewsImage.php
2016-12-22
387 áàéò
NewsPhotos.php
2017-02-07
350 áàéò
NewsReader.php
2023-08-29
10 êá.
NewsReader.php~
2021-03-29
10 êá.
NewsReaderRazdel.php
2017-02-01
2 êá.
NewsSliders.php
2017-02-22
1 êá.
NewsSlidersPhotos.php
2017-02-22
472 áàéò
NewsTags.php
2017-09-19
2 êá.
RelatedTagsNews.php
2019-09-02
2 êá.
/app/news
Çàãðóçèòü ôàéëû
Ôàéë 1
Ôàéë 2
Ôàéë 3