|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Publication\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Application\Mvc\Controller; |
|
6
|
|
|
use Publication\Model\Helper\PublicationHelper; |
|
7
|
|
|
use Publication\Model\Publication; |
|
8
|
|
|
use Phalcon\Exception; |
|
9
|
|
|
use Publication\Model\Type; |
|
10
|
|
|
|
|
11
|
|
|
class IndexController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
public function indexAction() |
|
15
|
|
|
{ |
|
16
|
|
|
$type = $this->dispatcher->getParam('type', 'string'); |
|
|
|
|
|
|
17
|
|
|
$typeModel = Type::getCachedBySlug($type); |
|
|
|
|
|
|
18
|
|
|
if (!$typeModel) { |
|
19
|
|
|
throw new Exception("Publication hasn't type = '$type''"); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
$typeLimit = ($typeModel->getLimit()) ? $typeModel->getLimit() : 10; |
|
23
|
|
|
$limit = $this->request->getQuery('limit', 'string', $typeLimit); |
|
24
|
|
|
if ($limit != 'all') { |
|
25
|
|
|
$paginatorLimit = (int)$limit; |
|
26
|
|
|
} else { |
|
27
|
|
|
$paginatorLimit = 9999; |
|
28
|
|
|
} |
|
29
|
|
|
$page = $this->request->getQuery('page', 'int', 1); |
|
30
|
|
|
|
|
31
|
|
|
/*$publications = Publication::find(array( |
|
32
|
|
|
"type_id = {$typeModel->getId()}", |
|
33
|
|
|
"order" => "date DESC", |
|
34
|
|
|
));*/ |
|
35
|
|
|
|
|
36
|
|
|
$publicationHelper = new PublicationHelper(); |
|
37
|
|
|
$fields = $publicationHelper->translateFieldsSubQuery(); |
|
38
|
|
|
|
|
39
|
|
|
$columns = ['p.*', 't_slug' => 't.slug']; |
|
40
|
|
|
$columns = array_merge($columns, $fields); |
|
41
|
|
|
|
|
42
|
|
|
$qb = $this->modelsManager->createBuilder() |
|
43
|
|
|
->columns($columns) |
|
44
|
|
|
->addFrom('Publication\Model\Publication', 'p') |
|
45
|
|
|
->leftJoin('Publication\Model\Type', null, 't') |
|
46
|
|
|
->andWhere('t.slug = :type:', ['type' => $type]) |
|
47
|
|
|
->andWhere('p.date <= NOW()') |
|
48
|
|
|
->orderBy('p.date DESC'); |
|
49
|
|
|
|
|
50
|
|
|
$paginator = new \Phalcon\Paginator\Adapter\QueryBuilder([ |
|
51
|
|
|
"builder" => $qb, |
|
52
|
|
|
"limit" => $paginatorLimit, |
|
53
|
|
|
"page" => $page |
|
54
|
|
|
]); |
|
55
|
|
|
|
|
56
|
|
|
$this->view->paginate = $paginator->getPaginate(); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
$this->helper->title()->append($typeModel->getHeadTitle()); |
|
59
|
|
|
if ($page > 1) { |
|
60
|
|
|
$this->helper->title()->append($this->helper->translate('Страница №') . ' ' . $page); |
|
61
|
|
|
} |
|
62
|
|
|
$this->view->title = $typeModel->getTitle(); |
|
|
|
|
|
|
63
|
|
|
$this->view->format = $typeModel->getFormat(); |
|
|
|
|
|
|
64
|
|
|
$this->view->type = $type; |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$this->helper->menu->setActive($type); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function publicationAction() |
|
70
|
|
|
{ |
|
71
|
|
|
$slug = $this->dispatcher->getParam('slug', 'string'); |
|
|
|
|
|
|
72
|
|
|
$type = $this->dispatcher->getParam('type', 'string'); |
|
73
|
|
|
|
|
74
|
|
|
$publicationHelper = new PublicationHelper(); |
|
75
|
|
|
$publicationResult = $publicationHelper->publicationBySlug($slug); |
|
76
|
|
|
if (!$publicationResult) { |
|
77
|
|
|
throw new Exception("Publication '$slug.html' not found"); |
|
78
|
|
|
} |
|
79
|
|
|
if ($publicationResult->p->getTypeSlug() != $type) { |
|
80
|
|
|
throw new Exception("Publication type <> $type"); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->helper->title()->append($publicationResult->meta_title); |
|
84
|
|
|
$this->helper->meta()->set('description', $publicationResult->meta_description); |
|
85
|
|
|
$this->helper->meta()->set('keywords', $publicationResult->meta_keywords); |
|
86
|
|
|
|
|
87
|
|
|
$this->helper->menu->setActive($type); |
|
88
|
|
|
|
|
89
|
|
|
$this->view->publicationResult = $publicationResult; |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: