Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
TaoSearchDriver
0.00% covered (danger)
0.00%
0 / 29
0.00% covered (danger)
0.00%
0 / 10
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 dbCommand
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 escape
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getEmpty
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 quote
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 reserved
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 random
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 groupAggregation
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 like
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 notLike
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/*
4 * To change this license header, choose License Headers in Project Properties.
5 * To change this template file, choose Tools | Templates
6 * and open the template in the editor.
7 */
8
9namespace  oat\generis\model\kernel\persistence\smoothsql\search\driver;
10
11use common_persistence_SqlPersistence;
12use oat\oatbox\service\ServiceManager;
13use oat\search\base\Query\EscaperAbstract;
14
15/**
16 * Description of TaoSearchDriver
17 *
18 * @author Christophe GARCIA <christopheg@taotesting.com>
19 */
20class TaoSearchDriver extends EscaperAbstract
21{
22    /**
23     * @var common_persistence_SqlPersistence
24     */
25    protected $persistence;
26
27    public function __construct()
28    {
29        $this->persistence = ServiceManager::getServiceManager()
30                ->get(\common_persistence_Manager::SERVICE_ID)
31                ->getPersistenceById('default');
32    }
33
34    /**
35     * @inherit
36     */
37    public function dbCommand($stringValue)
38    {
39        return strtoupper($stringValue);
40    }
41    /**
42     * @inherit
43     */
44    public function escape($stringValue)
45    {
46        return $stringValue;
47    }
48
49    /**
50     * return quoted empty string
51     */
52    public function getEmpty()
53    {
54        return $this->quote('');
55    }
56
57    /**
58     * @inherit
59     */
60    public function quote($stringValue)
61    {
62        return $this->persistence->quote($stringValue);
63    }
64
65    /**
66     * @inherit
67     */
68    public function reserved($stringValue)
69    {
70        return $this->persistence->getPlatForm()->quoteIdentifier($stringValue);
71    }
72
73    /**
74     * @inherit
75     */
76    public function random()
77    {
78        $random = [
79            'mysql'      => 'RAND()',
80            'postgresql' => 'random()',
81            'mssql'      => 'NEWID()',
82            ];
83        $name = $this->persistence->getPlatForm()->getName();
84        return $random[$name];
85    }
86
87    public function groupAggregation($variable, $separator)
88    {
89
90        $group = [
91            'mysql'      => 'GROUP_CONCAT',
92            'postgresql' => 'string_agg',
93        ];
94
95        $name = $this->persistence->getPlatForm()->getName();
96        return $group[$name] . '(' . $variable . ',' . $this->escape($this->quote($separator)) . ')';
97    }
98
99    /**
100     * return case insensitive like operator
101     * @return string
102     */
103    public function like()
104    {
105        $like = [
106            'mysql'      => 'LIKE',
107            'postgresql' => 'ILIKE',
108            'gcp-spanner' => 'LIKE'
109        ];
110
111        $name = $this->persistence->getPlatForm()->getName();
112        return $like[$name];
113    }
114
115    /**
116     * return case insensitive like operator
117     * @return string
118     */
119    public function notLike()
120    {
121        return 'NOT ' . $this->like() ;
122    }
123}