php class newsActions extends sfActions public function executeIndex s

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
class newsActions extends sfActions
{
public function executeIndex(sfWebRequest $request) {
if ($request['uri']) {
$this->object = InformQuery::create()->filterByVisible(1)->filterByUri($request['uri'])->findOne();
if (!$this->object) $this->forward404();
$this->setTemplate('view');
$this->breadcrumbs[] = [
'title' => $this->object->getTitle(),
'url' => $this->object->getURL()
];
$commentpage = $request['commentpage'] ? $request['commentpage'] : 1;
$this->comments = CommentQuery::create()->orderByCreatedAt(Criteria::DESC)->filterByVisible(1)->filterByCommentId(null)->filterByInformId($this->object->getId())->paginate($commentpage, 20);
$this->getResponse()->setTitle(htmlspecialchars_decode($this->object->getTitle(), ENT_QUOTES), false);
}
else {
$this->curYear = date('Y');
$page = $request['page'];
if($request->isTrigger('filter')) {
$this->setTemplate(false);
$list = array();
$informs = InformQuery::create()->filterByVisible(1)->orderByDateAt(Criteria::DESC);
if($request['year']) $informs->filterByDateAt(strtotime("01.01.".$request['year']." 00:00:00"),Criteria::GREATER_EQUAL)->filterByDateAt(strtotime("31.12.".$request['year']." 23:59:59"),Criteria::LESS_EQUAL);
if($request['month']) $informs->filterByDateAt(strtotime("01.".$request['month'].".".($request['year'] ? $request['year'] : $this->curYear)." 00:00:00"),Criteria::GREATER_EQUAL)->filterByDateAt(strtotime("31.".$request['month'].".".($request['year'] ? $request['year'] : $this->curYear)." 23:59:59"),Criteria::LESS_EQUAL);
if(!$request['month'] && !$request['year']) $informs = $informs->paginate($page,SettingPeer::retrieveByName('news_pager_count','value',20));
else $informs = $informs->find();
foreach($informs as $inf) {
$a['title'] = $inf->getTitle();
$a['description'] = $inf->getLead();
$a['url'] = $inf->getUrl();
$a['img'] = ($inf->getImageId() ? $inf->getImage()->getUri(250,166) : false);
$a['date'] = $inf->getPrettyDate();
$list[] = $a;
}
return $this->renderText(json_encode($list));
}
$this->setTemplate('list');
$query = InformQuery::create()->filterByVisible(1);
$query->orderByDateAt(Criteria::DESC);
$this->list = $query->paginate($page,SettingPeer::retrieveByName('news_pager_count','value',20));
}
}
}