Completed
Push — development ( eb9524...db4517 )
by Andrij
28:49 queued 02:09
created

Pages::formUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace xbanners\src\UrlFinder\Finders;
4
5
use xbanners\src\UrlFinder\Results\Result;
6
7
final class Pages extends BaseFinder
8
{
0 ignored issues
show
introduced by
Opening brace of a class must be on the same line as the definition
Loading history...
9
10
    protected $table = 'content';
11
12
    protected $nameColumn = 'content.title';
13
14
    protected $urlColumn = 'content.url';
15
16
    protected $categoryUrlColumn = 'content.cat_url';
17
18
    protected $langColumn = 'content.lang';
19
20
    public function getGroupName() {
21
        return lang('Pages', 'xbanners');
22
    }
23
24
    /**
25
     * @param string $word
26
     * @param string $language
27
     * @param integer $limit
28
     * @return Result
29
     */
30
    public function getResultsFor($word, $language, $limit = 10) {
31
        $languageId = $this->correctLocale($language);
32
        /* @var $db \CI_DB_active_record */
33
        $db = \CI::$APP->db;
34
        $results = $db->select("$this->nameColumn, $this->urlColumn, $this->categoryUrlColumn")
35
            ->from($this->table)
36
            ->like($this->nameColumn, $word)
37
            ->where($this->langColumn, $languageId)
38
            ->limit($limit)
39
            ->get()
40
            ->result_array();
41
        $result = new Result($this->getGroupName());
42
        foreach ($results as $oneResult) {
43
            $result->addResult($oneResult['title'], $this->formUrl($oneResult['cat_url'] . $oneResult['url']));
44
        }
45
        return $result;
46
    }
47
48
    /**
49
     * @param string $url
50
     * @return string
51
     */
52
    public function formUrl($url) {
53
        return '/' . $url;
54
    }
55
56
}