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

BaseFinder::getResultsFor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 17
rs 9.4285
cc 2
eloc 14
nc 2
nop 3
1
<?php
2
3
namespace xbanners\src\UrlFinder\Finders;
4
5
use xbanners\src\UrlFinder\Results\Result;
6
7
abstract class 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;
11
12
    protected $translations;
13
14
    protected $nameColumn;
15
16
    protected $urlColumn;
17
18
    protected $categoryUrlColumn;
19
20
    protected $langColumn;
21
22
    /**
23
     * @param string $word
24
     * @param string $language
25
     * @param integer $limit
26
     */
27
    public function getResultsFor($word, $language, $limit = 10) {
28
        /* @var $db \CI_DB_active_record */
29
        $db = \CI::$APP->db;
30
        $results = $db->select("$this->nameColumn, $this->urlColumn")
31
            ->from($this->table)
32
            ->join($this->translations, "{$this->table}.id = {$this->translations}.id")
33
            ->like($this->nameColumn, $word)
34
            ->where($this->langColumn, $language)
35
            ->limit($limit)
36
            ->get()
37
            ->result_array();
38
        $result = new Result($this->getGroupName());
39
        foreach ($results as $oneResult) {
40
            $result->addResult($oneResult['name'], $this->formUrl($oneResult['url']));
41
        }
42
        return $result;
43
    }
44
45
    /**
46
     * Returns locale id
47
     *
48
     * @param string $locale
49
     * @return id
50
     */
51
    protected function correctLocale($locale) {
52
        /* @var $db \CI_DB_active_record */
53
        $db = \CI::$APP->db;
54
        $res = $db
55
            ->where('identif', $locale)
56
            ->get('languages')
57
            ->first_row();
58
        return $res->id;
59
    }
60
61
    /**
62
     * @param string $url
63
     * @return string
64
     */
65
    abstract public function formUrl($url);
66
67
    /**
68
     * Product Banner etc.
69
     *
70
     * @return string
71
     */
72
    abstract public function getGroupName();
73
74
}