PublicationWidget   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 1
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A lastNews() 0 21 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.net)
4
 * @author Aleksandr Torosh <[email protected]>
5
 */
6
7
namespace Publication\Widget;
8
9
use Application\Widget\AbstractWidget;
10
use Publication\Model\Helper\PublicationHelper;
11
12
class PublicationWidget extends AbstractWidget
13
{
14
15
    public function lastNews($limit = 5)
16
    {
17
        $publicationHelper = new PublicationHelper();
18
        $fields = $publicationHelper->translateFieldsSubQuery();
19
20
        $columns = ['p.*', 't_slug' => 't.slug'];
21
        $columns = array_merge($columns, $fields);
22
23
        $qb = $this->modelsManager->createBuilder()
24
            ->columns($columns)
25
            ->addFrom('Publication\Model\Publication', 'p')
26
            ->leftJoin('Publication\Model\Type', null, 't')
27
            ->andWhere('t.slug = :type:', ['type' => 'news'])
28
            ->andWhere('p.date <= NOW()')
29
            ->orderBy('p.date DESC')
30
            ->limit($limit);
31
32
        $entries = $qb->getQuery()->execute();
33
34
        $this->widgetPartial('widget/last-news', ['entries' => $entries]);
35
    }
36
37
}