Отдельная страница для ленты статей
This commit is contained in:
parent
edd23ce6a0
commit
49a0c4d358
|
|
@ -121,7 +121,7 @@ class PageController extends Controller
|
||||||
|
|
||||||
App::setConfig('title', App::$defaultTitle);
|
App::setConfig('title', App::$defaultTitle);
|
||||||
|
|
||||||
self::render('pointsTemplate.php', array(
|
self::render('page/points.php', array(
|
||||||
'categories' => $categories,
|
'categories' => $categories,
|
||||||
'points' => $result,
|
'points' => $result,
|
||||||
'pointsCount' => $pointsCount,
|
'pointsCount' => $pointsCount,
|
||||||
|
|
@ -133,6 +133,99 @@ class PageController extends Controller
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function actionArticles()
|
||||||
|
{
|
||||||
|
self::$layout = 'layouts/page.php';
|
||||||
|
self::addStyle('/css/style.css?ver=' . App::getConfig('version'));
|
||||||
|
self::addStyle('/css/pageStyle.css?ver=' . App::getConfig('version'));
|
||||||
|
self::addScript('/js/jquery-2.1.0.min.js');
|
||||||
|
self::addScript('/js/jquery-ui-1.10.4.custom.min.js');
|
||||||
|
self::addScript('/js/bootstrap.min.js');
|
||||||
|
self::addScript('/js/app.js');
|
||||||
|
self::addStyle('/css/bootstrap.min.css');
|
||||||
|
self::addStyle('/css/bootstrap-theme.min.css');
|
||||||
|
|
||||||
|
$param = array();
|
||||||
|
$param['order'] = '`pubDate` ASC';
|
||||||
|
$param['where'] = '`status` = "published"';
|
||||||
|
|
||||||
|
$articlesCount = Article::model()->getCount($param);
|
||||||
|
$pagesCount = intval(ceil($articlesCount/self::elementsByPage));
|
||||||
|
$fullPagesCount = intval(floor($articlesCount/self::elementsByPage));
|
||||||
|
$residue = $articlesCount - ($fullPagesCount * self::elementsByPage);
|
||||||
|
|
||||||
|
if ($residue < self::minElementsByPage) {
|
||||||
|
$pagesCount = $fullPagesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$page = isset($_GET['page']) ? abs((int)$_GET['page']) : $pagesCount;
|
||||||
|
|
||||||
|
$pages = array();
|
||||||
|
|
||||||
|
// Заполняем страницы от большей к меньшей - добавляем 3 штуки
|
||||||
|
for ($index = $pagesCount; (($index > $pagesCount-3) && ($index > 0)); $index--) {
|
||||||
|
$pages[$index] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Заполняем страницы от 3 к 1 - добавляем 3 штуки
|
||||||
|
if ($pagesCount >= 3) {
|
||||||
|
for ($index = 3; $index > 0; $index--) {
|
||||||
|
$pages[$index] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($page > $pagesCount) {
|
||||||
|
$page = $pagesCount;
|
||||||
|
} else if ($page < 1) {
|
||||||
|
$page = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Заполняем страницы вокруг текущей. +/- 2 штуки.
|
||||||
|
$topIndex = ($page+2 > $pagesCount) ? $pagesCount : $page+2;
|
||||||
|
$bottomIndex = ($page-3 < 1) ? 1 : $page-3;
|
||||||
|
for ($index = $topIndex; $index > $bottomIndex; $index--) {
|
||||||
|
$pages[$index] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
krsort($pages);
|
||||||
|
|
||||||
|
if ($page == $pagesCount && $residue < self::minElementsByPage) {
|
||||||
|
$param['limit'] = self::elementsByPage + $residue;
|
||||||
|
} else {
|
||||||
|
$param['limit'] = self::elementsByPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($page) {
|
||||||
|
$param['offset'] = self::elementsByPage * ($page - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$articles = Article::model()->getAll($param);
|
||||||
|
$articles = array_reverse($articles);
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
foreach ($articles as $article) {
|
||||||
|
$id = $article->id;
|
||||||
|
$result[$id]['id'] = $article->id;
|
||||||
|
$result[$id]['title'] = $article->title;
|
||||||
|
$result[$id]['text'] = mb_substr(Markdown::getClear($article->text), 0, 400, 'UTF-8');
|
||||||
|
$result[$id]['photoId'] = $article->photoId;
|
||||||
|
$result[$id]['img'] = $article->getImg('middle');
|
||||||
|
$result[$id]['author'] = $article->authorUser->nick;
|
||||||
|
}
|
||||||
|
|
||||||
|
App::setConfig('title', App::$defaultTitle);
|
||||||
|
|
||||||
|
self::render('page/articles.php', array(
|
||||||
|
'articles' => $result,
|
||||||
|
'articlesCount' => $articlesCount,
|
||||||
|
'page' => $page,
|
||||||
|
'pagesCount' => $pagesCount,
|
||||||
|
'pages' => $pages,
|
||||||
|
'randomPoint' => Point::model()->getRandom(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
static function actionPoint()
|
static function actionPoint()
|
||||||
{
|
{
|
||||||
$pointId = (int) App::getParam('id');
|
$pointId = (int) App::getParam('id');
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
|
|
@ -40,6 +40,8 @@
|
||||||
<a href="/user/<?= $item->author ?>" style="float: right;"><?= $item->authorUser->nick ?></a>
|
<a href="/user/<?= $item->author ?>" style="float: right;"><?= $item->authorUser->nick ?></a>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach;?>
|
<?php endforeach;?>
|
||||||
|
<br/>
|
||||||
|
<a href="/page/articles/"><h4 style="text-align: center;">Тут целая лента статей!</h4></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
$oldIndex = $pagesCount+1;
|
||||||
|
?>
|
||||||
|
<div id="pageSmoothBackground" style="background-image: url(<?= $randomPoint->getImg('middle') ?>);"></div>
|
||||||
|
|
||||||
|
<div class="container" style="background-color: rgba(255,255,255, 0.8);margin-top: -10px;padding-bottom: 30px;">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h1 style="text-align: right;">Лента статей</h1>
|
||||||
|
<div class="coords-container">
|
||||||
|
Перейти: <a href="/">на карту</a> или <a href="/page/points">к точкам</a>
|
||||||
|
</div>
|
||||||
|
<div style="text-align: justify;">
|
||||||
|
<div class="pointsWall">
|
||||||
|
<?php foreach ($articles as $article): ?>
|
||||||
|
<a href="/article/<?= $article['id'] ?>">
|
||||||
|
<div style="background-image: url('<?= $article['photoId']>0?$article['img']:'/img/no-background.png' ?>');" class="point">
|
||||||
|
<span class="header">
|
||||||
|
<?= $article['title'] ?>
|
||||||
|
</span>
|
||||||
|
<?php if($article['photoId'] == 0): ?>
|
||||||
|
<div>
|
||||||
|
<?= $article['text'] ?>… <nobr>читать далее »</nobr>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php if ($pagesCount > 1):?>
|
||||||
|
<nav>
|
||||||
|
<ul class="pagination">
|
||||||
|
<li class="<?= ($page >= $pagesCount) ? 'disabled' : '' ?>">
|
||||||
|
<a href="<?= ($page >= $pagesCount) ? '#' : '?page='.($page+1) ?>" aria-label="Previous">
|
||||||
|
<span aria-hidden="true">«</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php foreach ($pages as $index => $val): ?>
|
||||||
|
<?php if ($oldIndex-$index != 1):?>
|
||||||
|
<li><a href="?page=<?= $index + ceil(($oldIndex-$index)/2) ?>" style="<?= $index==$page ? 'background-color: #eeeeed;' : '' ?>">...</a></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
<li><a href="?page=<?= $index ?>" style="<?= $index==$page ? 'background-color: #eeeeed;' : '' ?>"><?= $index ?></a></li>
|
||||||
|
<?php $oldIndex = $index; ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<li class="<?= ($page <= 1) ? 'disabled' : '' ?>">
|
||||||
|
<a href="<?= ($page <= 1) ? '#' : '?page='.($page-1) ?>" aria-label="Next">
|
||||||
|
<span aria-hidden="true">»</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<?php else: ?>
|
||||||
|
<br/>
|
||||||
|
<?php endif; ?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12" style="text-align: center;">
|
||||||
|
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
||||||
|
<!-- Point - DOWN -->
|
||||||
|
<ins class="adsbygoogle"
|
||||||
|
style="display:block"
|
||||||
|
data-ad-client="ca-pub-0069680015252793"
|
||||||
|
data-ad-slot="4972494746"
|
||||||
|
data-ad-format="auto"></ins>
|
||||||
|
<script>
|
||||||
|
(adsbygoogle = window.adsbygoogle || []).push({});
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr/>
|
||||||
|
<?= self::renderPartial('randomPoint.php', array('randomPoint'=>$randomPoint), true)?>
|
||||||
|
</div>
|
||||||
|
|
@ -14,7 +14,7 @@ $oldIndex = $pagesCount+1;
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h1 style="text-align: right;">Списки точек по категориям</h1>
|
<h1 style="text-align: right;">Списки точек по категориям</h1>
|
||||||
<div class="coords-container">
|
<div class="coords-container">
|
||||||
Перейти: <a href="/">на карту</a>
|
Перейти: <a href="/">на карту</a> или <a href="/page/articles">к статьям</a>
|
||||||
<?php if (App::getParam('user')): ?>
|
<?php if (App::getParam('user')): ?>
|
||||||
/ <a href="/user/<?=$user->id?>">страница <?=$user->nick?></a>.
|
/ <a href="/user/<?=$user->id?>">страница <?=$user->nick?></a>.
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
Loading…
Reference in New Issue