wikipoints/ground/controllers/PageController.php

88 lines
2.4 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');
$categoryId = (int)App::getParam('category');
$where = $categoryId ? 'categoryId = '.$categoryId : '';
$points = new Point();
$points = $points->getAll($where, 'id DESC');
$categories = new Category();
$categories = $categories->getAll('', 'ord');
$users = new User();
$users = $users->getAll();
$result = array();
foreach ($points as $point)
{
$result[$point['id']]['id'] = $point['id'];
$result[$point['id']]['name'] = $point['name'];
$result[$point['id']]['img'] = $point['img'];
$result[$point['id']]['categoryIcon'] = $categories[$point['categoryId']]['icon'];
$result[$point['id']]['author'] = $users[$point['author']]['nick'];
}
$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';
$id = (int) App::getParam('id');
if ($id)
{
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::addStyle('/css/style.css?ver=' . App::getConfig('version'));
self::addStyle('/css/bootstrap.min.css');
self::addStyle('/css/bootstrap-theme.min.css');
$point = new Point();
$point = $point->getByPK($id);
$point->descriptionHtml = nl2br($point->description);
$point->name = htmlspecialchars($point->name);
$categories = new Category();
$categories = $categories->getAll();
$point->categoryIcon = $categories[$point->categoryId]['icon'];
$point->categoryName = $categories[$point->categoryId]['name'];
self::render('point.php', array(
'point' => $point,
'categories' => $categories,
)
);
} else
{
App::error404();
}
}
}