wikipoints/ground/controllers/PageController.php

110 lines
3.6 KiB
PHP

<?php
class PageController extends Controller
{
static function actionPoints()
{
self::$layout = 'layoutPage.php';
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::addStyle('/css/bootstrap.min.css');
self::addStyle('/css/bootstrap-theme.min.css');
$param['order']='id DESC';
$param['where']=App::getParam('category') ? 'categoryId = '.(int)App::getParam('category') : '';
$points = Point::model()->getAll($param);
$categories = Category::model()->getAll(array('order' => 'ord ASC'));
$result = array();
foreach ($points as $point) {
$id = $point->id;
$result[$id]['id'] = $point->id;
$result[$id]['name'] = $point->name;
$result[$id]['lat'] = $point->lat;
$result[$id]['lng'] = $point->lng;
$result[$id]['author'] = $point->authorUser->nick;
$result[$id]['categoryId'] = $point->categoryId;
$result[$id]['categoryIcon'] = $categories[$point->categoryId]->icon;
}
$res = App::DB()->query("SELECT COUNT(`id`) pointsCount FROM `points`")->fetch(PDO::FETCH_ASSOC);
App::setConfig('title', $res['pointsCount'] . ' или даже больше поводов не сидеть дома');
self::render('pointsTemplate.php', array(
'categories' => $categories,
'user' => App::$user,
'points' => $result,
));
}
static function actionPoint()
{
self::$layout = 'layoutPage.php';
$pointId = (int) App::getParam('id');
if ($pointId)
{
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?ver=' . App::getConfig('version'));
self::addScript('/js/fotorama.js');
self::addStyle('/css/style.css?ver=' . App::getConfig('version'));
self::addStyle('/css/bootstrap.min.css');
self::addStyle('/css/bootstrap-theme.min.css');
self::addStyle('/css/fotorama.css');
$point = Point::model()->getByPK($pointId);
if ($point->id == NULL)
{
App::error404();
}
$point->descriptionHtml = nl2br($point->description);
$point->name = htmlspecialchars($point->name);
App::setConfig('title', $point->name. ' - wikipoints.ru');
$categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true));
$point->categoryIcon = $categories[$point->categoryId]['icon'];
$point->categoryName = $categories[$point->categoryId]['name'];
$point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml);
preg_match_all("/.*?(([.?!](?:\s|$))|$)/s", $point->descriptionHtml, $items);
$similarPoints = Point::model()->getAll(array('where' => 'categoryId = '.$point->categoryId.' AND `id` <> '.$point->id.' ORDER BY RAND() LIMIT 6;'));
$closestPoints = Point::model()->getClosestPoints($pointId);
$randomPoint = Point::model()->getRandom();
$randomPoint->description = mb_substr($randomPoint->description, 0, 400, 'UTF-8');
$randomPoint->description = Helper::replaceLinks($randomPoint->description);
self::render('point.php', array(
'point' => $point,
'text' => $items[0],
'randomPoint' => $randomPoint,
'similarPoints' => $similarPoints,
'closestPoints' => $closestPoints,
'categories' => $categories,
'photos' => $point->photos,
'countInFavs' => Favorite::model()->countInFavs($pointId),
'countLikes' => Like::model()->countLikes($pointId),
'og' => Helper::buildOG($point),
));
} else
{
App::error404();
}
}
static function action404($message)
{
self::renderPartial('error404.php', array(
'point' => Point::model()->getRandom(),
));
}
}