Completed
Push — master ( 185e5e...dc5aa9 )
by Alexander
03:43
created

PageHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B pageBySlug() 0 27 3
1
<?php
2
/**
3
 * @author Oleksandr Torosh <[email protected]>
4
 */
5
6
namespace Page\Model\Helper;
7
8
use Application\Cache\Keys;
9
use Page\Model\Page;
10
11
class PageHelper extends Page
12
{
13
14
    public function pageBySlug($slug, $lang = null, $lifeTime = 60)
15
    {
16
        $lang = ($lang) ? $lang : LANG;
17
18
        $pageResult = $this->getDi()->get('cacheManager')->load([
19
            Keys::PAGE,
20
            $slug,
21
            $lang
22
23
        ], function() use ($slug, $lang, $lifeTime) {
24
            $columns = ['p.*'];
25
            foreach($this->translateFields as $field) {
26
                $columns[] = "(SELECT t.value FROM [$this->translateModel] AS t WHERE t.foreign_id = p.id AND t.lang = '$lang' AND t.key = '$field') AS $field";
27
            }
28
29
            $qb = $this->modelsManager->createBuilder()
0 ignored issues
show
Bug introduced by
The property modelsManager does not seem to exist. Did you mean _modelsManager?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
30
                ->columns($columns)
31
                ->addFrom('Page\Model\Page', 'p')
32
                ->where('p.slug = :slug:', ['slug' => $slug]);
33
34
            $result = $qb->getQuery()->execute()->getFirst();
35
            return $result;
36
37
        }, $lifeTime);
38
39
        return $pageResult;
40
    }
41
42
}