@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Request{ |
|
| 27 | + class Request { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The value for the super global $_GET |
@@ -90,21 +90,21 @@ discard block |
||
| 90 | 90 | /** |
| 91 | 91 | * Construct new request instance |
| 92 | 92 | */ |
| 93 | - public function __construct(){ |
|
| 93 | + public function __construct() { |
|
| 94 | 94 | $this->get = $_GET; |
| 95 | 95 | $this->post = $_POST; |
| 96 | 96 | $this->server = $_SERVER; |
| 97 | 97 | $this->query = $_REQUEST; |
| 98 | 98 | $this->cookie = $_COOKIE; |
| 99 | 99 | $this->file = $_FILES; |
| 100 | - $this->session =& class_loader('Session', 'classes'); |
|
| 100 | + $this->session = & class_loader('Session', 'classes'); |
|
| 101 | 101 | $this->method = $this->server('REQUEST_METHOD'); |
| 102 | 102 | $this->requestUri = $this->server('REQUEST_URI'); |
| 103 | 103 | $this->header = array(); |
| 104 | - if(function_exists('apache_request_headers')){ |
|
| 104 | + if (function_exists('apache_request_headers')) { |
|
| 105 | 105 | $this->header = apache_request_headers(); |
| 106 | 106 | } |
| 107 | - else if(function_exists('getallheaders')){ |
|
| 107 | + else if (function_exists('getallheaders')) { |
|
| 108 | 108 | $this->header = getallheaders(); |
| 109 | 109 | } |
| 110 | 110 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * Get the request method |
| 114 | 114 | * @return string |
| 115 | 115 | */ |
| 116 | - public function method(){ |
|
| 116 | + public function method() { |
|
| 117 | 117 | return $this->method; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * Get the request URI |
| 122 | 122 | * @return string |
| 123 | 123 | */ |
| 124 | - public function requestUri(){ |
|
| 124 | + public function requestUri() { |
|
| 125 | 125 | return $this->requestUri; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -131,13 +131,13 @@ discard block |
||
| 131 | 131 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 132 | 132 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 133 | 133 | */ |
| 134 | - public function query($key = null, $xss = true){ |
|
| 135 | - if(empty($key)){ |
|
| 134 | + public function query($key = null, $xss = true) { |
|
| 135 | + if (empty($key)) { |
|
| 136 | 136 | //return all |
| 137 | 137 | return $xss ? clean_input($this->query) : $this->query; |
| 138 | 138 | } |
| 139 | 139 | $query = array_key_exists($key, $this->query) ? $this->query[$key] : null; |
| 140 | - if($xss){ |
|
| 140 | + if ($xss) { |
|
| 141 | 141 | $query = clean_input($query); |
| 142 | 142 | } |
| 143 | 143 | return $query; |
@@ -149,13 +149,13 @@ discard block |
||
| 149 | 149 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 150 | 150 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 151 | 151 | */ |
| 152 | - public function get($key = null, $xss = true){ |
|
| 153 | - if(empty($key)){ |
|
| 152 | + public function get($key = null, $xss = true) { |
|
| 153 | + if (empty($key)) { |
|
| 154 | 154 | //return all |
| 155 | 155 | return $xss ? clean_input($this->get) : $this->get; |
| 156 | 156 | } |
| 157 | 157 | $get = array_key_exists($key, $this->get) ? $this->get[$key] : null; |
| 158 | - if($xss){ |
|
| 158 | + if ($xss) { |
|
| 159 | 159 | $get = clean_input($get); |
| 160 | 160 | } |
| 161 | 161 | return $get; |
@@ -167,13 +167,13 @@ discard block |
||
| 167 | 167 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 168 | 168 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 169 | 169 | */ |
| 170 | - public function post($key = null, $xss = true){ |
|
| 171 | - if(empty($key)){ |
|
| 170 | + public function post($key = null, $xss = true) { |
|
| 171 | + if (empty($key)) { |
|
| 172 | 172 | //return all |
| 173 | 173 | return $xss ? clean_input($this->post) : $this->post; |
| 174 | 174 | } |
| 175 | 175 | $post = array_key_exists($key, $this->post) ? $this->post[$key] : null; |
| 176 | - if($xss){ |
|
| 176 | + if ($xss) { |
|
| 177 | 177 | $post = clean_input($post); |
| 178 | 178 | } |
| 179 | 179 | return $post; |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 186 | 186 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 187 | 187 | */ |
| 188 | - public function server($key = null, $xss = true){ |
|
| 189 | - if(empty($key)){ |
|
| 188 | + public function server($key = null, $xss = true) { |
|
| 189 | + if (empty($key)) { |
|
| 190 | 190 | //return all |
| 191 | 191 | return $xss ? clean_input($this->server) : $this->server; |
| 192 | 192 | } |
| 193 | 193 | $server = array_key_exists($key, $this->server) ? $this->server[$key] : null; |
| 194 | - if($xss){ |
|
| 194 | + if ($xss) { |
|
| 195 | 195 | $server = clean_input($server); |
| 196 | 196 | } |
| 197 | 197 | return $server; |
@@ -203,13 +203,13 @@ discard block |
||
| 203 | 203 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 204 | 204 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 205 | 205 | */ |
| 206 | - public function cookie($key = null, $xss = true){ |
|
| 207 | - if(empty($key)){ |
|
| 206 | + public function cookie($key = null, $xss = true) { |
|
| 207 | + if (empty($key)) { |
|
| 208 | 208 | //return all |
| 209 | 209 | return $xss ? clean_input($this->cookie) : $this->cookie; |
| 210 | 210 | } |
| 211 | 211 | $cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null; |
| 212 | - if($xss){ |
|
| 212 | + if ($xss) { |
|
| 213 | 213 | $cookie = clean_input($cookie); |
| 214 | 214 | } |
| 215 | 215 | return $cookie; |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * @param string $key the item key to be fetched |
| 221 | 221 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
| 222 | 222 | */ |
| 223 | - public function file($key){ |
|
| 223 | + public function file($key) { |
|
| 224 | 224 | $file = array_key_exists($key, $this->file) ? $this->file[$key] : null; |
| 225 | 225 | return $file; |
| 226 | 226 | } |
@@ -231,9 +231,9 @@ discard block |
||
| 231 | 231 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 232 | 232 | * @return array|mixed the item value if the key exists or null if the key does not exists |
| 233 | 233 | */ |
| 234 | - public function session($key, $xss = true){ |
|
| 234 | + public function session($key, $xss = true) { |
|
| 235 | 235 | $session = $this->session->get($key); |
| 236 | - if($xss){ |
|
| 236 | + if ($xss) { |
|
| 237 | 237 | $session = clean_input($session); |
| 238 | 238 | } |
| 239 | 239 | return $session; |
@@ -245,9 +245,9 @@ discard block |
||
| 245 | 245 | * @param boolean $xss if need apply some XSS attack rule on the value |
| 246 | 246 | * @return mixed the item value if the key exists or null if the key does not exists |
| 247 | 247 | */ |
| 248 | - public function header($key, $xss = true){ |
|
| 248 | + public function header($key, $xss = true) { |
|
| 249 | 249 | $header = array_key_exists($key, $this->header) ? $this->header[$key] : null; |
| 250 | - if($xss){ |
|
| 250 | + if ($xss) { |
|
| 251 | 251 | $header = clean_input($header); |
| 252 | 252 | } |
| 253 | 253 | return $header; |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * This class represent the event detail to dispatch to correspond listener |
| 29 | 29 | */ |
| 30 | - class EventInfo{ |
|
| 30 | + class EventInfo { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The event name |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public $stop; |
| 56 | 56 | |
| 57 | - public function __construct($name, $payload = array(), $returnBack = false, $stop = false){ |
|
| 57 | + public function __construct($name, $payload = array(), $returnBack = false, $stop = false) { |
|
| 58 | 58 | $this->name = $name; |
| 59 | 59 | $this->payload = $payload; |
| 60 | 60 | $this->returnBack = $returnBack; |
@@ -24,13 +24,13 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class DatabaseQueryResult{ |
|
| 27 | + class DatabaseQueryResult { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The database query result |
| 31 | 31 | * @var mixed |
| 32 | 32 | */ |
| 33 | - private $result = null; |
|
| 33 | + private $result = null; |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param mixed $result the query result |
| 46 | 46 | * @param int $numRows the number of rows returned by the query |
| 47 | 47 | */ |
| 48 | - public function __construct($result = null, $numRows = 0){ |
|
| 48 | + public function __construct($result = null, $numRows = 0) { |
|
| 49 | 49 | $this->result = $result; |
| 50 | 50 | $this->numRows = $numRows; |
| 51 | 51 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @return mixed |
| 58 | 58 | */ |
| 59 | - public function getResult(){ |
|
| 59 | + public function getResult() { |
|
| 60 | 60 | return $this->result; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return object DatabaseQueryResult |
| 68 | 68 | */ |
| 69 | - public function setResult($result){ |
|
| 69 | + public function setResult($result) { |
|
| 70 | 70 | $this->result = $result; |
| 71 | 71 | return $this; |
| 72 | 72 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return int |
| 78 | 78 | */ |
| 79 | - public function getNumRows(){ |
|
| 79 | + public function getNumRows() { |
|
| 80 | 80 | return $this->numRows; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return object DatabaseQueryResult |
| 88 | 88 | */ |
| 89 | - public function setNumRows($numRows){ |
|
| 89 | + public function setNumRows($numRows) { |
|
| 90 | 90 | $this->numRows = $numRows; |
| 91 | 91 | return $this; |
| 92 | 92 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - if(! function_exists('get_ip')){ |
|
| 44 | + if (!function_exists('get_ip')) { |
|
| 45 | 45 | /** |
| 46 | 46 | * Retrieves the user's IP address |
| 47 | 47 | * |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return string the IP address. |
| 52 | 52 | */ |
| 53 | - function get_ip(){ |
|
| 53 | + function get_ip() { |
|
| 54 | 54 | $ip = '127.0.0.1'; |
| 55 | 55 | $ipServerVars = array( |
| 56 | 56 | 'REMOTE_ADDR', |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | 'HTTP_FORWARDED' |
| 62 | 62 | ); |
| 63 | 63 | foreach ($ipServerVars as $var) { |
| 64 | - if(isset($_SERVER[$var])){ |
|
| 64 | + if (isset($_SERVER[$var])) { |
|
| 65 | 65 | $ip = $_SERVER[$var]; |
| 66 | 66 | break; |
| 67 | 67 | } |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Url{ |
|
| 28 | + class Url { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Return the link using base_url config without front controller "index.php" |
| 32 | 32 | * @param string $path the link path or full URL |
| 33 | 33 | * @return string the full link URL |
| 34 | 34 | */ |
| 35 | - public static function base_url($path = ''){ |
|
| 36 | - if(is_url($path)){ |
|
| 35 | + public static function base_url($path = '') { |
|
| 36 | + if (is_url($path)) { |
|
| 37 | 37 | return $path; |
| 38 | 38 | } |
| 39 | 39 | return get_config('base_url') . $path; |
@@ -44,26 +44,26 @@ discard block |
||
| 44 | 44 | * @param string $path the link path or full URL |
| 45 | 45 | * @return string the full link URL |
| 46 | 46 | */ |
| 47 | - public static function site_url($path = ''){ |
|
| 48 | - if(is_url($path)){ |
|
| 47 | + public static function site_url($path = '') { |
|
| 48 | + if (is_url($path)) { |
|
| 49 | 49 | return $path; |
| 50 | 50 | } |
| 51 | 51 | $path = rtrim($path, '/'); |
| 52 | 52 | $baseUrl = get_config('base_url'); |
| 53 | 53 | $frontController = get_config('front_controller'); |
| 54 | 54 | $url = $baseUrl; |
| 55 | - if($frontController){ |
|
| 55 | + if ($frontController) { |
|
| 56 | 56 | $url .= $frontController . '/'; |
| 57 | 57 | } |
| 58 | - if(($suffix = get_config('url_suffix')) && $path){ |
|
| 59 | - if(strpos($path, '?') !== false){ |
|
| 58 | + if (($suffix = get_config('url_suffix')) && $path) { |
|
| 59 | + if (strpos($path, '?') !== false) { |
|
| 60 | 60 | $query = explode('?', $path); |
| 61 | 61 | $query[0] = str_ireplace($suffix, '', $query[0]); |
| 62 | 62 | $query[0] = rtrim($query[0], '/'); |
| 63 | 63 | $query[0] .= $suffix; |
| 64 | 64 | $path = implode('?', $query); |
| 65 | 65 | } |
| 66 | - else{ |
|
| 66 | + else { |
|
| 67 | 67 | $path .= $suffix; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | * Return the current site URL |
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | - public static function current(){ |
|
| 77 | + public static function current() { |
|
| 78 | 78 | $current = '/'; |
| 79 | 79 | $requestUri = get_instance()->request->requestUri(); |
| 80 | - if($requestUri){ |
|
| 80 | + if ($requestUri) { |
|
| 81 | 81 | $current = $requestUri; |
| 82 | 82 | } |
| 83 | 83 | return static::domain() . $current; |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | * @param boolean $lowercase whether to set the final text to lowe case or not |
| 91 | 91 | * @return string the friendly generated text |
| 92 | 92 | */ |
| 93 | - public static function title($str = null, $separator = '-', $lowercase = true){ |
|
| 93 | + public static function title($str = null, $separator = '-', $lowercase = true) { |
|
| 94 | 94 | $str = trim($str); |
| 95 | - $from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ'); |
|
| 96 | - $to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n'); |
|
| 95 | + $from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ'); |
|
| 96 | + $to = array('c', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'n', 'n'); |
|
| 97 | 97 | $str = str_replace($from, $to, $str); |
| 98 | 98 | $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
| 99 | 99 | $str = str_replace('--', $separator, $str); |
| 100 | 100 | //if after process we get something like one-two-three-, need truncate the last separator "-" |
| 101 | - if(substr($str, -1) == $separator){ |
|
| 101 | + if (substr($str, -1) == $separator) { |
|
| 102 | 102 | $str = substr($str, 0, -1); |
| 103 | 103 | } |
| 104 | - if($lowercase){ |
|
| 104 | + if ($lowercase) { |
|
| 105 | 105 | $str = strtolower($str); |
| 106 | 106 | } |
| 107 | 107 | return $str; |
@@ -111,11 +111,11 @@ discard block |
||
| 111 | 111 | * Get the current application domain with protocol |
| 112 | 112 | * @return string the domain name |
| 113 | 113 | */ |
| 114 | - public static function domain(){ |
|
| 114 | + public static function domain() { |
|
| 115 | 115 | $domain = 'localhost'; |
| 116 | 116 | $port = get_instance()->request->server('SERVER_PORT'); |
| 117 | 117 | $protocol = 'http'; |
| 118 | - if(is_https()){ |
|
| 118 | + if (is_https()) { |
|
| 119 | 119 | $protocol = 'https'; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -127,23 +127,23 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | foreach ($domainserverVars as $var) { |
| 129 | 129 | $value = get_instance()->request->server($var); |
| 130 | - if($value){ |
|
| 130 | + if ($value) { |
|
| 131 | 131 | $domain = $value; |
| 132 | 132 | break; |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))){ |
|
| 137 | - $domain .= ':'.$port; |
|
| 136 | + if ($port && ((is_https() && $port != 443) || (!is_https() && $port != 80))) { |
|
| 137 | + $domain .= ':' . $port; |
|
| 138 | 138 | } |
| 139 | - return $protocol.'://'.$domain; |
|
| 139 | + return $protocol . '://' . $domain; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | 143 | * Get the current request query string |
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | - public static function queryString(){ |
|
| 146 | + public static function queryString() { |
|
| 147 | 147 | return get_instance()->request->server('QUERY_STRING'); |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -916,27 +916,27 @@ discard block |
||
| 916 | 916 | if (isset($aresult[1])) { |
| 917 | 917 | $this->setBrowser(self::BROWSER_IE); |
| 918 | 918 | $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); |
| 919 | - if(preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)){ |
|
| 920 | - if($aresult[1] == '3.1'){ |
|
| 919 | + if (preg_match('#trident/([0-9\.]+);#i', $this->_agent, $aresult)) { |
|
| 920 | + if ($aresult[1] == '3.1') { |
|
| 921 | 921 | $this->setVersion('7.0'); |
| 922 | 922 | } |
| 923 | - else if($aresult[1] == '4.0'){ |
|
| 923 | + else if ($aresult[1] == '4.0') { |
|
| 924 | 924 | $this->setVersion('8.0'); |
| 925 | 925 | } |
| 926 | - else if($aresult[1] == '5.0'){ |
|
| 926 | + else if ($aresult[1] == '5.0') { |
|
| 927 | 927 | $this->setVersion('9.0'); |
| 928 | 928 | } |
| 929 | - else if($aresult[1] == '6.0'){ |
|
| 929 | + else if ($aresult[1] == '6.0') { |
|
| 930 | 930 | $this->setVersion('10.0'); |
| 931 | 931 | } |
| 932 | - else if($aresult[1] == '7.0'){ |
|
| 932 | + else if ($aresult[1] == '7.0') { |
|
| 933 | 933 | $this->setVersion('11.0'); |
| 934 | 934 | } |
| 935 | - else if($aresult[1] == '8.0'){ |
|
| 935 | + else if ($aresult[1] == '8.0') { |
|
| 936 | 936 | $this->setVersion('11.0'); |
| 937 | 937 | } |
| 938 | 938 | } |
| 939 | - if(stripos($this->_agent, 'IEMobile') !== false) { |
|
| 939 | + if (stripos($this->_agent, 'IEMobile') !== false) { |
|
| 940 | 940 | $this->setBrowser(self::BROWSER_POCKET_IE); |
| 941 | 941 | $this->setMobile(true); |
| 942 | 942 | } |
@@ -1676,7 +1676,7 @@ discard block |
||
| 1676 | 1676 | 'mac' => self::PLATFORM_APPLE, |
| 1677 | 1677 | 'android' => self::PLATFORM_ANDROID, |
| 1678 | 1678 | 'Silk' => self::PLATFORM_FIRE_OS, |
| 1679 | - 'linux_smarttv' => self::PLATFORM_LINUX .'/'.self::PLATFORM_SMART_TV, |
|
| 1679 | + 'linux_smarttv' => self::PLATFORM_LINUX . '/' . self::PLATFORM_SMART_TV, |
|
| 1680 | 1680 | 'linux' => self::PLATFORM_LINUX, |
| 1681 | 1681 | 'Nokia' => self::PLATFORM_NOKIA, |
| 1682 | 1682 | 'BlackBerry' => self::PLATFORM_BLACKBERRY, |
@@ -1700,9 +1700,9 @@ discard block |
||
| 1700 | 1700 | ); |
| 1701 | 1701 | |
| 1702 | 1702 | foreach ($platformMaps as $name => $value) { |
| 1703 | - if($name == 'linux_smarttv' |
|
| 1703 | + if ($name == 'linux_smarttv' |
|
| 1704 | 1704 | && stripos($this->_agent, 'linux') !== false |
| 1705 | - && stripos($this->_agent, 'SMART-TV') !== false ){ |
|
| 1705 | + && stripos($this->_agent, 'SMART-TV') !== false) { |
|
| 1706 | 1706 | $this->_platform = $value; |
| 1707 | 1707 | break; |
| 1708 | 1708 | } elseif (stripos($this->_agent, $name) !== false) { |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @filesource |
| 40 | 40 | */ |
| 41 | 41 | |
| 42 | - if(! function_exists('get_random_string')){ |
|
| 42 | + if (!function_exists('get_random_string')) { |
|
| 43 | 43 | /** |
| 44 | 44 | * Generate a random string |
| 45 | 45 | * @param string $type the type of generation. It can take the values: "alpha" for alphabetic characters, |
@@ -49,21 +49,21 @@ discard block |
||
| 49 | 49 | * @param boolean $lower if we return the generated string in lowercase (true). By default it's false. |
| 50 | 50 | * @return string the generated string. |
| 51 | 51 | */ |
| 52 | - function get_random_string($type = 'alnum', $length = 10, $lower = false){ |
|
| 52 | + function get_random_string($type = 'alnum', $length = 10, $lower = false) { |
|
| 53 | 53 | $chars = array( |
| 54 | 54 | 'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', |
| 55 | 55 | 'alnum' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', |
| 56 | 56 | 'num' => '1234567890' |
| 57 | 57 | ); |
| 58 | 58 | $str = null; |
| 59 | - if(isset($chars[$type])){ |
|
| 59 | + if (isset($chars[$type])) { |
|
| 60 | 60 | $str = $chars[$type]; |
| 61 | 61 | } |
| 62 | 62 | $random = null; |
| 63 | - for($i = 0; $i < $length; $i++){ |
|
| 63 | + for ($i = 0; $i < $length; $i++) { |
|
| 64 | 64 | $random .= $str[mt_rand() % strlen($str)]; |
| 65 | 65 | } |
| 66 | - if($lower){ |
|
| 66 | + if ($lower) { |
|
| 67 | 67 | $random = strtolower($random); |
| 68 | 68 | } |
| 69 | 69 | return $random; |
@@ -23,94 +23,94 @@ discard block |
||
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | - class DatabaseQueryBuilder{ |
|
| 26 | + class DatabaseQueryBuilder { |
|
| 27 | 27 | /** |
| 28 | 28 | * The SQL SELECT statment |
| 29 | 29 | * @var string |
| 30 | 30 | */ |
| 31 | - private $select = '*'; |
|
| 31 | + private $select = '*'; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * The SQL FROM statment |
| 35 | 35 | * @var string |
| 36 | 36 | */ |
| 37 | - private $from = null; |
|
| 37 | + private $from = null; |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * The SQL WHERE statment |
| 41 | 41 | * @var string |
| 42 | 42 | */ |
| 43 | - private $where = null; |
|
| 43 | + private $where = null; |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * The SQL LIMIT statment |
| 47 | 47 | * @var string |
| 48 | 48 | */ |
| 49 | - private $limit = null; |
|
| 49 | + private $limit = null; |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * The SQL JOIN statment |
| 53 | 53 | * @var string |
| 54 | 54 | */ |
| 55 | - private $join = null; |
|
| 55 | + private $join = null; |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * The SQL ORDER BY statment |
| 59 | 59 | * @var string |
| 60 | 60 | */ |
| 61 | - private $orderBy = null; |
|
| 61 | + private $orderBy = null; |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * The SQL GROUP BY statment |
| 65 | 65 | * @var string |
| 66 | 66 | */ |
| 67 | - private $groupBy = null; |
|
| 67 | + private $groupBy = null; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * The SQL HAVING statment |
| 71 | 71 | * @var string |
| 72 | 72 | */ |
| 73 | - private $having = null; |
|
| 73 | + private $having = null; |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * The full SQL query statment after build for each command |
| 77 | 77 | * @var string |
| 78 | 78 | */ |
| 79 | - private $query = null; |
|
| 79 | + private $query = null; |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * The list of SQL valid operators |
| 83 | 83 | * @var array |
| 84 | 84 | */ |
| 85 | - private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
|
| 85 | + private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>'); |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * The prefix used in each database table |
| 90 | 90 | * @var string |
| 91 | 91 | */ |
| 92 | - private $prefix = null; |
|
| 92 | + private $prefix = null; |
|
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * The PDO instance |
| 97 | 97 | * @var object |
| 98 | 98 | */ |
| 99 | - private $pdo = null; |
|
| 99 | + private $pdo = null; |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * The database driver name used |
| 103 | 103 | * @var string |
| 104 | 104 | */ |
| 105 | - private $driver = null; |
|
| 105 | + private $driver = null; |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * Construct new DatabaseQueryBuilder |
| 110 | 110 | * @param object $pdo the PDO object |
| 111 | 111 | */ |
| 112 | - public function __construct(PDO $pdo = null){ |
|
| 113 | - if (is_object($pdo)){ |
|
| 112 | + public function __construct(PDO $pdo = null) { |
|
| 113 | + if (is_object($pdo)) { |
|
| 114 | 114 | $this->setPdo($pdo); |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | * @param string|array $table the table name or array of table list |
| 121 | 121 | * @return object the current DatabaseQueryBuilder instance |
| 122 | 122 | */ |
| 123 | - public function from($table){ |
|
| 124 | - if (is_array($table)){ |
|
| 123 | + public function from($table) { |
|
| 124 | + if (is_array($table)) { |
|
| 125 | 125 | $froms = ''; |
| 126 | - foreach($table as $key){ |
|
| 126 | + foreach ($table as $key) { |
|
| 127 | 127 | $froms .= $this->getPrefix() . $key . ', '; |
| 128 | 128 | } |
| 129 | 129 | $this->from = rtrim($froms, ', '); |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @param string|array $fields the field name or array of field list |
| 139 | 139 | * @return object the current DatabaseQueryBuilder instance |
| 140 | 140 | */ |
| 141 | - public function select($fields){ |
|
| 141 | + public function select($fields) { |
|
| 142 | 142 | $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
| 143 | 143 | $this->select = (($this->select == '*' || empty($this->select)) ? $select : $this->select . ', ' . $select); |
| 144 | 144 | return $this; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @param string $field the field name to distinct |
| 150 | 150 | * @return object the current DatabaseQueryBuilder instance |
| 151 | 151 | */ |
| 152 | - public function distinct($field){ |
|
| 152 | + public function distinct($field) { |
|
| 153 | 153 | $distinct = ' DISTINCT ' . $field; |
| 154 | 154 | $this->select = (($this->select == '*' || empty($this->select)) ? $distinct : $this->select . ', ' . $distinct); |
| 155 | 155 | return $this; |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @param string $name if is not null represent the alias used for this field in the result |
| 162 | 162 | * @return object the current DatabaseQueryBuilder instance |
| 163 | 163 | */ |
| 164 | - public function count($field = '*', $name = null){ |
|
| 164 | + public function count($field = '*', $name = null) { |
|
| 165 | 165 | return $this->select_min_max_sum_count_avg('COUNT', $field, $name); |
| 166 | 166 | } |
| 167 | 167 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * @param string $name if is not null represent the alias used for this field in the result |
| 172 | 172 | * @return object the current DatabaseQueryBuilder instance |
| 173 | 173 | */ |
| 174 | - public function min($field, $name = null){ |
|
| 174 | + public function min($field, $name = null) { |
|
| 175 | 175 | return $this->select_min_max_sum_count_avg('MIN', $field, $name); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param string $name if is not null represent the alias used for this field in the result |
| 182 | 182 | * @return object the current DatabaseQueryBuilder instance |
| 183 | 183 | */ |
| 184 | - public function max($field, $name = null){ |
|
| 184 | + public function max($field, $name = null) { |
|
| 185 | 185 | return $this->select_min_max_sum_count_avg('MAX', $field, $name); |
| 186 | 186 | } |
| 187 | 187 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * @param string $name if is not null represent the alias used for this field in the result |
| 192 | 192 | * @return object the current DatabaseQueryBuilder instance |
| 193 | 193 | */ |
| 194 | - public function sum($field, $name = null){ |
|
| 194 | + public function sum($field, $name = null) { |
|
| 195 | 195 | return $this->select_min_max_sum_count_avg('SUM', $field, $name); |
| 196 | 196 | } |
| 197 | 197 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param string $name if is not null represent the alias used for this field in the result |
| 202 | 202 | * @return object the current DatabaseQueryBuilder instance |
| 203 | 203 | */ |
| 204 | - public function avg($field, $name = null){ |
|
| 204 | + public function avg($field, $name = null) { |
|
| 205 | 205 | return $this->select_min_max_sum_count_avg('AVG', $field, $name); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -215,18 +215,18 @@ discard block |
||
| 215 | 215 | * @param string $type the type of join (INNER, LEFT, RIGHT) |
| 216 | 216 | * @return object the current DatabaseQueryBuilder instance |
| 217 | 217 | */ |
| 218 | - public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
|
| 218 | + public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') { |
|
| 219 | 219 | $on = $field1; |
| 220 | 220 | $table = $this->getPrefix() . $table; |
| 221 | - if (! is_null($op)){ |
|
| 222 | - $on = (! in_array($op, $this->operatorList) |
|
| 221 | + if (!is_null($op)) { |
|
| 222 | + $on = (!in_array($op, $this->operatorList) |
|
| 223 | 223 | ? ($this->getPrefix() . $field1 . ' = ' . $this->getPrefix() . $op) |
| 224 | 224 | : ($this->getPrefix() . $field1 . ' ' . $op . ' ' . $this->getPrefix() . $field2)); |
| 225 | 225 | } |
| 226 | - if (empty($this->join)){ |
|
| 226 | + if (empty($this->join)) { |
|
| 227 | 227 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 228 | 228 | } |
| 229 | - else{ |
|
| 229 | + else { |
|
| 230 | 230 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
| 231 | 231 | } |
| 232 | 232 | return $this; |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * @see DatabaseQueryBuilder::join() |
| 238 | 238 | * @return object the current DatabaseQueryBuilder instance |
| 239 | 239 | */ |
| 240 | - public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 240 | + public function innerJoin($table, $field1, $op = null, $field2 = '') { |
|
| 241 | 241 | return $this->join($table, $field1, $op, $field2, 'INNER '); |
| 242 | 242 | } |
| 243 | 243 | |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @see DatabaseQueryBuilder::join() |
| 247 | 247 | * @return object the current DatabaseQueryBuilder instance |
| 248 | 248 | */ |
| 249 | - public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 249 | + public function leftJoin($table, $field1, $op = null, $field2 = '') { |
|
| 250 | 250 | return $this->join($table, $field1, $op, $field2, 'LEFT '); |
| 251 | 251 | } |
| 252 | 252 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | * @see DatabaseQueryBuilder::join() |
| 256 | 256 | * @return object the current DatabaseQueryBuilder instance |
| 257 | 257 | */ |
| 258 | - public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 258 | + public function rightJoin($table, $field1, $op = null, $field2 = '') { |
|
| 259 | 259 | return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
| 260 | 260 | } |
| 261 | 261 | |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * @see DatabaseQueryBuilder::join() |
| 265 | 265 | * @return object the current DatabaseQueryBuilder instance |
| 266 | 266 | */ |
| 267 | - public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 267 | + public function fullOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 268 | 268 | return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
| 269 | 269 | } |
| 270 | 270 | |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | * @see DatabaseQueryBuilder::join() |
| 274 | 274 | * @return object the current DatabaseQueryBuilder instance |
| 275 | 275 | */ |
| 276 | - public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 276 | + public function leftOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 277 | 277 | return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @see DatabaseQueryBuilder::join() |
| 283 | 283 | * @return object the current DatabaseQueryBuilder instance |
| 284 | 284 | */ |
| 285 | - public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
| 285 | + public function rightOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
| 286 | 286 | return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
| 287 | 287 | } |
| 288 | 288 | |
@@ -292,13 +292,13 @@ discard block |
||
| 292 | 292 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 293 | 293 | * @return object the current DatabaseQueryBuilder instance |
| 294 | 294 | */ |
| 295 | - public function whereIsNull($field, $andOr = 'AND'){ |
|
| 296 | - if (is_array($field)){ |
|
| 297 | - foreach($field as $f){ |
|
| 295 | + public function whereIsNull($field, $andOr = 'AND') { |
|
| 296 | + if (is_array($field)) { |
|
| 297 | + foreach ($field as $f) { |
|
| 298 | 298 | $this->whereIsNull($f, $andOr); |
| 299 | 299 | } |
| 300 | 300 | } else { |
| 301 | - $this->setWhereStr($field.' IS NULL ', $andOr); |
|
| 301 | + $this->setWhereStr($field . ' IS NULL ', $andOr); |
|
| 302 | 302 | } |
| 303 | 303 | return $this; |
| 304 | 304 | } |
@@ -309,13 +309,13 @@ discard block |
||
| 309 | 309 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 310 | 310 | * @return object the current DatabaseQueryBuilder instance |
| 311 | 311 | */ |
| 312 | - public function whereIsNotNull($field, $andOr = 'AND'){ |
|
| 313 | - if (is_array($field)){ |
|
| 314 | - foreach($field as $f){ |
|
| 312 | + public function whereIsNotNull($field, $andOr = 'AND') { |
|
| 313 | + if (is_array($field)) { |
|
| 314 | + foreach ($field as $f) { |
|
| 315 | 315 | $this->whereIsNotNull($f, $andOr); |
| 316 | 316 | } |
| 317 | 317 | } else { |
| 318 | - $this->setWhereStr($field.' IS NOT NULL ', $andOr); |
|
| 318 | + $this->setWhereStr($field . ' IS NOT NULL ', $andOr); |
|
| 319 | 319 | } |
| 320 | 320 | return $this; |
| 321 | 321 | } |
@@ -330,13 +330,13 @@ discard block |
||
| 330 | 330 | * @param boolean $escape whether to escape or not the $val |
| 331 | 331 | * @return object the current DatabaseQueryBuilder instance |
| 332 | 332 | */ |
| 333 | - public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
|
| 333 | + public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) { |
|
| 334 | 334 | $whereStr = ''; |
| 335 | - if (is_array($where)){ |
|
| 335 | + if (is_array($where)) { |
|
| 336 | 336 | $whereStr = $this->getWhereStrIfIsArray($where, $type, $andOr, $escape); |
| 337 | 337 | } |
| 338 | - else{ |
|
| 339 | - if (is_array($op)){ |
|
| 338 | + else { |
|
| 339 | + if (is_array($op)) { |
|
| 340 | 340 | $whereStr = $this->getWhereStrIfOperatorIsArray($where, $op, $type, $escape); |
| 341 | 341 | } else { |
| 342 | 342 | $whereStr = $this->getWhereStrForOperator($where, $op, $val, $type, $escape); |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | * @see DatabaseQueryBuilder::where() |
| 352 | 352 | * @return object the current DatabaseQueryBuilder instance |
| 353 | 353 | */ |
| 354 | - public function orWhere($where, $op = null, $val = null, $escape = true){ |
|
| 354 | + public function orWhere($where, $op = null, $val = null, $escape = true) { |
|
| 355 | 355 | return $this->where($where, $op, $val, '', 'OR', $escape); |
| 356 | 356 | } |
| 357 | 357 | |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @see DatabaseQueryBuilder::where() |
| 362 | 362 | * @return object the current DatabaseQueryBuilder instance |
| 363 | 363 | */ |
| 364 | - public function notWhere($where, $op = null, $val = null, $escape = true){ |
|
| 364 | + public function notWhere($where, $op = null, $val = null, $escape = true) { |
|
| 365 | 365 | return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
| 366 | 366 | } |
| 367 | 367 | |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | * @see DatabaseQueryBuilder::where() |
| 371 | 371 | * @return object the current DatabaseQueryBuilder instance |
| 372 | 372 | */ |
| 373 | - public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
|
| 373 | + public function orNotWhere($where, $op = null, $val = null, $escape = true) { |
|
| 374 | 374 | return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
| 375 | 375 | } |
| 376 | 376 | |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | * @param string $andOr the multiple conditions separator (AND, OR, etc.) |
| 381 | 381 | * @return object the current DatabaseQueryBuilder instance |
| 382 | 382 | */ |
| 383 | - public function groupStart($type = '', $andOr = ' AND'){ |
|
| 384 | - if (empty($this->where)){ |
|
| 383 | + public function groupStart($type = '', $andOr = ' AND') { |
|
| 384 | + if (empty($this->where)) { |
|
| 385 | 385 | $this->where = $type . ' ('; |
| 386 | 386 | } else { |
| 387 | - if (substr(trim($this->where), -1) == '('){ |
|
| 387 | + if (substr(trim($this->where), -1) == '(') { |
|
| 388 | 388 | $this->where .= $type . ' ('; |
| 389 | 389 | } else { |
| 390 | 390 | $this->where .= $andOr . ' ' . $type . ' ('; |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * @see DatabaseQueryBuilder::groupStart() |
| 399 | 399 | * @return object the current DatabaseQueryBuilder instance |
| 400 | 400 | */ |
| 401 | - public function notGroupStart(){ |
|
| 401 | + public function notGroupStart() { |
|
| 402 | 402 | return $this->groupStart('NOT'); |
| 403 | 403 | } |
| 404 | 404 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | * @see DatabaseQueryBuilder::groupStart() |
| 408 | 408 | * @return object the current DatabaseQueryBuilder instance |
| 409 | 409 | */ |
| 410 | - public function orGroupStart(){ |
|
| 410 | + public function orGroupStart() { |
|
| 411 | 411 | return $this->groupStart('', ' OR'); |
| 412 | 412 | } |
| 413 | 413 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @see DatabaseQueryBuilder::groupStart() |
| 417 | 417 | * @return object the current DatabaseQueryBuilder instance |
| 418 | 418 | */ |
| 419 | - public function orNotGroupStart(){ |
|
| 419 | + public function orNotGroupStart() { |
|
| 420 | 420 | return $this->groupStart('NOT', ' OR'); |
| 421 | 421 | } |
| 422 | 422 | |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | * Close the parenthesis for the grouped SQL |
| 425 | 425 | * @return object the current DatabaseQueryBuilder instance |
| 426 | 426 | */ |
| 427 | - public function groupEnd(){ |
|
| 427 | + public function groupEnd() { |
|
| 428 | 428 | $this->where .= ')'; |
| 429 | 429 | return $this; |
| 430 | 430 | } |
@@ -438,10 +438,10 @@ discard block |
||
| 438 | 438 | * @param boolean $escape whether to escape or not the values |
| 439 | 439 | * @return object the current DatabaseQueryBuilder instance |
| 440 | 440 | */ |
| 441 | - public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
|
| 441 | + public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) { |
|
| 442 | 442 | $_keys = array(); |
| 443 | - foreach ($keys as $k => $v){ |
|
| 444 | - if (is_null($v)){ |
|
| 443 | + foreach ($keys as $k => $v) { |
|
| 444 | + if (is_null($v)) { |
|
| 445 | 445 | $v = ''; |
| 446 | 446 | } |
| 447 | 447 | $_keys[] = (is_numeric($v) ? $v : $this->escape($v, $escape)); |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | * @see DatabaseQueryBuilder::in() |
| 458 | 458 | * @return object the current DatabaseQueryBuilder instance |
| 459 | 459 | */ |
| 460 | - public function notIn($field, array $keys, $escape = true){ |
|
| 460 | + public function notIn($field, array $keys, $escape = true) { |
|
| 461 | 461 | return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
| 462 | 462 | } |
| 463 | 463 | |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | * @see DatabaseQueryBuilder::in() |
| 467 | 467 | * @return object the current DatabaseQueryBuilder instance |
| 468 | 468 | */ |
| 469 | - public function orIn($field, array $keys, $escape = true){ |
|
| 469 | + public function orIn($field, array $keys, $escape = true) { |
|
| 470 | 470 | return $this->in($field, $keys, '', 'OR', $escape); |
| 471 | 471 | } |
| 472 | 472 | |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | * @see DatabaseQueryBuilder::in() |
| 476 | 476 | * @return object the current DatabaseQueryBuilder instance |
| 477 | 477 | */ |
| 478 | - public function orNotIn($field, array $keys, $escape = true){ |
|
| 478 | + public function orNotIn($field, array $keys, $escape = true) { |
|
| 479 | 479 | return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
| 480 | 480 | } |
| 481 | 481 | |
@@ -489,11 +489,11 @@ discard block |
||
| 489 | 489 | * @param boolean $escape whether to escape or not the values |
| 490 | 490 | * @return object the current DatabaseQueryBuilder instance |
| 491 | 491 | */ |
| 492 | - public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
|
| 493 | - if (is_null($value1)){ |
|
| 492 | + public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) { |
|
| 493 | + if (is_null($value1)) { |
|
| 494 | 494 | $value1 = ''; |
| 495 | 495 | } |
| 496 | - if (is_null($value2)){ |
|
| 496 | + if (is_null($value2)) { |
|
| 497 | 497 | $value2 = ''; |
| 498 | 498 | } |
| 499 | 499 | $whereStr = $field . ' ' . $type . ' BETWEEN ' . $this->escape($value1, $escape) . ' AND ' . $this->escape($value2, $escape); |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | * @see DatabaseQueryBuilder::between() |
| 507 | 507 | * @return object the current DatabaseQueryBuilder instance |
| 508 | 508 | */ |
| 509 | - public function notBetween($field, $value1, $value2, $escape = true){ |
|
| 509 | + public function notBetween($field, $value1, $value2, $escape = true) { |
|
| 510 | 510 | return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
| 511 | 511 | } |
| 512 | 512 | |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | * @see DatabaseQueryBuilder::between() |
| 516 | 516 | * @return object the current DatabaseQueryBuilder instance |
| 517 | 517 | */ |
| 518 | - public function orBetween($field, $value1, $value2, $escape = true){ |
|
| 518 | + public function orBetween($field, $value1, $value2, $escape = true) { |
|
| 519 | 519 | return $this->between($field, $value1, $value2, '', 'OR', $escape); |
| 520 | 520 | } |
| 521 | 521 | |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | * @see DatabaseQueryBuilder::between() |
| 525 | 525 | * @return object the current DatabaseQueryBuilder instance |
| 526 | 526 | */ |
| 527 | - public function orNotBetween($field, $value1, $value2, $escape = true){ |
|
| 527 | + public function orNotBetween($field, $value1, $value2, $escape = true) { |
|
| 528 | 528 | return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
| 529 | 529 | } |
| 530 | 530 | |
@@ -537,8 +537,8 @@ discard block |
||
| 537 | 537 | * @param boolean $escape whether to escape or not the values |
| 538 | 538 | * @return object the current DatabaseQueryBuilder instance |
| 539 | 539 | */ |
| 540 | - public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
|
| 541 | - if (empty($data)){ |
|
| 540 | + public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) { |
|
| 541 | + if (empty($data)) { |
|
| 542 | 542 | $data = ''; |
| 543 | 543 | } |
| 544 | 544 | $this->setWhereStr($field . ' ' . $type . ' LIKE ' . ($this->escape($data, $escape)), $andOr); |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | * @see DatabaseQueryBuilder::like() |
| 551 | 551 | * @return object the current DatabaseQueryBuilder instance |
| 552 | 552 | */ |
| 553 | - public function orLike($field, $data, $escape = true){ |
|
| 553 | + public function orLike($field, $data, $escape = true) { |
|
| 554 | 554 | return $this->like($field, $data, '', 'OR', $escape); |
| 555 | 555 | } |
| 556 | 556 | |
@@ -559,7 +559,7 @@ discard block |
||
| 559 | 559 | * @see DatabaseQueryBuilder::like() |
| 560 | 560 | * @return object the current DatabaseQueryBuilder instance |
| 561 | 561 | */ |
| 562 | - public function notLike($field, $data, $escape = true){ |
|
| 562 | + public function notLike($field, $data, $escape = true) { |
|
| 563 | 563 | return $this->like($field, $data, 'NOT ', 'AND', $escape); |
| 564 | 564 | } |
| 565 | 565 | |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | * @see DatabaseQueryBuilder::like() |
| 569 | 569 | * @return object the current DatabaseQueryBuilder instance |
| 570 | 570 | */ |
| 571 | - public function orNotLike($field, $data, $escape = true){ |
|
| 571 | + public function orNotLike($field, $data, $escape = true) { |
|
| 572 | 572 | return $this->like($field, $data, 'NOT ', 'OR', $escape); |
| 573 | 573 | } |
| 574 | 574 | |
@@ -579,14 +579,14 @@ discard block |
||
| 579 | 579 | * @param int $limitEnd the limit count |
| 580 | 580 | * @return object the current DatabaseQueryBuilder instance |
| 581 | 581 | */ |
| 582 | - public function limit($limit, $limitEnd = null){ |
|
| 583 | - if (empty($limit)){ |
|
| 582 | + public function limit($limit, $limitEnd = null) { |
|
| 583 | + if (empty($limit)) { |
|
| 584 | 584 | $limit = 0; |
| 585 | 585 | } |
| 586 | - if (! is_null($limitEnd)){ |
|
| 586 | + if (!is_null($limitEnd)) { |
|
| 587 | 587 | $this->limit = $limit . ', ' . $limitEnd; |
| 588 | 588 | } |
| 589 | - else{ |
|
| 589 | + else { |
|
| 590 | 590 | $this->limit = $limit; |
| 591 | 591 | } |
| 592 | 592 | return $this; |
@@ -598,11 +598,11 @@ discard block |
||
| 598 | 598 | * @param string $orderDir the order direction (ASC or DESC) |
| 599 | 599 | * @return object the current DatabaseQueryBuilder instance |
| 600 | 600 | */ |
| 601 | - public function orderBy($orderBy, $orderDir = ' ASC'){ |
|
| 602 | - if (stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
| 601 | + public function orderBy($orderBy, $orderDir = ' ASC') { |
|
| 602 | + if (stristr($orderBy, ' ') || $orderBy == 'rand()') { |
|
| 603 | 603 | $this->orderBy = empty($this->orderBy) ? $orderBy : $this->orderBy . ', ' . $orderBy; |
| 604 | 604 | } |
| 605 | - else{ |
|
| 605 | + else { |
|
| 606 | 606 | $this->orderBy = empty($this->orderBy) |
| 607 | 607 | ? ($orderBy . ' ' . strtoupper($orderDir)) |
| 608 | 608 | : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
@@ -615,11 +615,11 @@ discard block |
||
| 615 | 615 | * @param string|array $field the field name used or array of field list |
| 616 | 616 | * @return object the current DatabaseQueryBuilder instance |
| 617 | 617 | */ |
| 618 | - public function groupBy($field){ |
|
| 619 | - if (is_array($field)){ |
|
| 618 | + public function groupBy($field) { |
|
| 619 | + if (is_array($field)) { |
|
| 620 | 620 | $this->groupBy = implode(', ', $field); |
| 621 | 621 | } |
| 622 | - else{ |
|
| 622 | + else { |
|
| 623 | 623 | $this->groupBy = $field; |
| 624 | 624 | } |
| 625 | 625 | return $this; |
@@ -633,18 +633,18 @@ discard block |
||
| 633 | 633 | * @param boolean $escape whether to escape or not the values |
| 634 | 634 | * @return object the current DatabaseQueryBuilder instance |
| 635 | 635 | */ |
| 636 | - public function having($field, $op = null, $val = null, $escape = true){ |
|
| 637 | - if (is_array($op)){ |
|
| 636 | + public function having($field, $op = null, $val = null, $escape = true) { |
|
| 637 | + if (is_array($op)) { |
|
| 638 | 638 | $this->having = $this->getHavingStrIfOperatorIsArray($field, $op, $escape); |
| 639 | 639 | } |
| 640 | - else if (! in_array($op, $this->operatorList)){ |
|
| 641 | - if (is_null($op)){ |
|
| 640 | + else if (!in_array($op, $this->operatorList)) { |
|
| 641 | + if (is_null($op)) { |
|
| 642 | 642 | $op = ''; |
| 643 | 643 | } |
| 644 | 644 | $this->having = $field . ' > ' . ($this->escape($op, $escape)); |
| 645 | 645 | } |
| 646 | - else{ |
|
| 647 | - if (is_null($val)){ |
|
| 646 | + else { |
|
| 647 | + if (is_null($val)) { |
|
| 648 | 648 | $val = ''; |
| 649 | 649 | } |
| 650 | 650 | $this->having = $field . ' ' . $op . ' ' . ($this->escape($val, $escape)); |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | * @param boolean $escape whether to escape or not the values |
| 659 | 659 | * @return object the current DatabaseQueryBuilder instance |
| 660 | 660 | */ |
| 661 | - public function insert($data = array(), $escape = true){ |
|
| 661 | + public function insert($data = array(), $escape = true) { |
|
| 662 | 662 | $columns = array_keys($data); |
| 663 | 663 | $column = implode(', ', $columns); |
| 664 | 664 | $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
@@ -673,22 +673,22 @@ discard block |
||
| 673 | 673 | * @param boolean $escape whether to escape or not the values |
| 674 | 674 | * @return object the current DatabaseQueryBuilder instance |
| 675 | 675 | */ |
| 676 | - public function update($data = array(), $escape = true){ |
|
| 676 | + public function update($data = array(), $escape = true) { |
|
| 677 | 677 | $query = 'UPDATE ' . $this->from . ' SET '; |
| 678 | 678 | $values = array(); |
| 679 | - foreach ($data as $column => $val){ |
|
| 679 | + foreach ($data as $column => $val) { |
|
| 680 | 680 | $values[] = $column . ' = ' . ($this->escape($val, $escape)); |
| 681 | 681 | } |
| 682 | 682 | $query .= implode(', ', $values); |
| 683 | - if (! empty($this->where)){ |
|
| 683 | + if (!empty($this->where)) { |
|
| 684 | 684 | $query .= ' WHERE ' . $this->where; |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - if (! empty($this->orderBy)){ |
|
| 687 | + if (!empty($this->orderBy)) { |
|
| 688 | 688 | $query .= ' ORDER BY ' . $this->orderBy; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - if (! empty($this->limit)){ |
|
| 691 | + if (!empty($this->limit)) { |
|
| 692 | 692 | $query .= ' LIMIT ' . $this->limit; |
| 693 | 693 | } |
| 694 | 694 | $this->query = $query; |
@@ -699,22 +699,22 @@ discard block |
||
| 699 | 699 | * Delete the record in database |
| 700 | 700 | * @return object the current DatabaseQueryBuilder instance |
| 701 | 701 | */ |
| 702 | - public function delete(){ |
|
| 702 | + public function delete() { |
|
| 703 | 703 | $query = 'DELETE FROM ' . $this->from; |
| 704 | 704 | $isTruncate = $query; |
| 705 | - if (! empty($this->where)){ |
|
| 705 | + if (!empty($this->where)) { |
|
| 706 | 706 | $query .= ' WHERE ' . $this->where; |
| 707 | 707 | } |
| 708 | 708 | |
| 709 | - if (! empty($this->orderBy)){ |
|
| 709 | + if (!empty($this->orderBy)) { |
|
| 710 | 710 | $query .= ' ORDER BY ' . $this->orderBy; |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - if (! empty($this->limit)){ |
|
| 713 | + if (!empty($this->limit)) { |
|
| 714 | 714 | $query .= ' LIMIT ' . $this->limit; |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - if ($isTruncate == $query && $this->driver != 'sqlite'){ |
|
| 717 | + if ($isTruncate == $query && $this->driver != 'sqlite') { |
|
| 718 | 718 | $query = 'TRUNCATE TABLE ' . $this->from; |
| 719 | 719 | } |
| 720 | 720 | $this->query = $query; |
@@ -727,9 +727,9 @@ discard block |
||
| 727 | 727 | * @param boolean $escaped whether we can do escape of not |
| 728 | 728 | * @return mixed the data after escaped or the same data if not |
| 729 | 729 | */ |
| 730 | - public function escape($data, $escaped = true){ |
|
| 730 | + public function escape($data, $escaped = true) { |
|
| 731 | 731 | $data = trim($data); |
| 732 | - if($escaped){ |
|
| 732 | + if ($escaped) { |
|
| 733 | 733 | return $this->pdo->quote($data); |
| 734 | 734 | } |
| 735 | 735 | return $data; |
@@ -740,31 +740,31 @@ discard block |
||
| 740 | 740 | * Return the current SQL query string |
| 741 | 741 | * @return string |
| 742 | 742 | */ |
| 743 | - public function getQuery(){ |
|
| 743 | + public function getQuery() { |
|
| 744 | 744 | //INSERT, UPDATE, DELETE already set it, if is the SELECT we need set it now |
| 745 | - if(empty($this->query)){ |
|
| 745 | + if (empty($this->query)) { |
|
| 746 | 746 | $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
| 747 | - if (! empty($this->join)){ |
|
| 747 | + if (!empty($this->join)) { |
|
| 748 | 748 | $query .= $this->join; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | - if (! empty($this->where)){ |
|
| 751 | + if (!empty($this->where)) { |
|
| 752 | 752 | $query .= ' WHERE ' . $this->where; |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | - if (! empty($this->groupBy)){ |
|
| 755 | + if (!empty($this->groupBy)) { |
|
| 756 | 756 | $query .= ' GROUP BY ' . $this->groupBy; |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | - if (! empty($this->having)){ |
|
| 759 | + if (!empty($this->having)) { |
|
| 760 | 760 | $query .= ' HAVING ' . $this->having; |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | - if (! empty($this->orderBy)){ |
|
| 763 | + if (!empty($this->orderBy)) { |
|
| 764 | 764 | $query .= ' ORDER BY ' . $this->orderBy; |
| 765 | 765 | } |
| 766 | 766 | |
| 767 | - if (! empty($this->limit)){ |
|
| 767 | + if (!empty($this->limit)) { |
|
| 768 | 768 | $query .= ' LIMIT ' . $this->limit; |
| 769 | 769 | } |
| 770 | 770 | $this->query = $query; |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | * Return the PDO instance |
| 778 | 778 | * @return object |
| 779 | 779 | */ |
| 780 | - public function getPdo(){ |
|
| 780 | + public function getPdo() { |
|
| 781 | 781 | return $this->pdo; |
| 782 | 782 | } |
| 783 | 783 | |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | * @param PDO $pdo the pdo object |
| 787 | 787 | * @return object DatabaseQueryBuilder |
| 788 | 788 | */ |
| 789 | - public function setPdo(PDO $pdo = null){ |
|
| 789 | + public function setPdo(PDO $pdo = null) { |
|
| 790 | 790 | $this->pdo = $pdo; |
| 791 | 791 | return $this; |
| 792 | 792 | } |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | * Return the database table prefix |
| 796 | 796 | * @return string |
| 797 | 797 | */ |
| 798 | - public function getPrefix(){ |
|
| 798 | + public function getPrefix() { |
|
| 799 | 799 | return $this->prefix; |
| 800 | 800 | } |
| 801 | 801 | |
@@ -804,7 +804,7 @@ discard block |
||
| 804 | 804 | * @param string $prefix the new prefix |
| 805 | 805 | * @return object DatabaseQueryBuilder |
| 806 | 806 | */ |
| 807 | - public function setPrefix($prefix){ |
|
| 807 | + public function setPrefix($prefix) { |
|
| 808 | 808 | $this->prefix = $prefix; |
| 809 | 809 | return $this; |
| 810 | 810 | } |
@@ -813,7 +813,7 @@ discard block |
||
| 813 | 813 | * Return the database driver |
| 814 | 814 | * @return string |
| 815 | 815 | */ |
| 816 | - public function getDriver(){ |
|
| 816 | + public function getDriver() { |
|
| 817 | 817 | return $this->driver; |
| 818 | 818 | } |
| 819 | 819 | |
@@ -822,7 +822,7 @@ discard block |
||
| 822 | 822 | * @param string $driver the new driver |
| 823 | 823 | * @return object DatabaseQueryBuilder |
| 824 | 824 | */ |
| 825 | - public function setDriver($driver){ |
|
| 825 | + public function setDriver($driver) { |
|
| 826 | 826 | $this->driver = $driver; |
| 827 | 827 | return $this; |
| 828 | 828 | } |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | * Reset the DatabaseQueryBuilder class attributs to the initial values before each query. |
| 832 | 832 | * @return object the current DatabaseQueryBuilder instance |
| 833 | 833 | */ |
| 834 | - public function reset(){ |
|
| 834 | + public function reset() { |
|
| 835 | 835 | $this->select = '*'; |
| 836 | 836 | $this->from = null; |
| 837 | 837 | $this->where = null; |
@@ -850,12 +850,12 @@ discard block |
||
| 850 | 850 | * |
| 851 | 851 | * @return string |
| 852 | 852 | */ |
| 853 | - protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true){ |
|
| 853 | + protected function getHavingStrIfOperatorIsArray($field, $op = null, $escape = true) { |
|
| 854 | 854 | $x = explode('?', $field); |
| 855 | 855 | $w = ''; |
| 856 | - foreach($x as $k => $v){ |
|
| 857 | - if (!empty($v)){ |
|
| 858 | - if (! isset($op[$k])){ |
|
| 856 | + foreach ($x as $k => $v) { |
|
| 857 | + if (!empty($v)) { |
|
| 858 | + if (!isset($op[$k])) { |
|
| 859 | 859 | $op[$k] = ''; |
| 860 | 860 | } |
| 861 | 861 | $w .= $v . (isset($op[$k]) ? $this->escape($op[$k], $escape) : ''); |
@@ -871,15 +871,15 @@ discard block |
||
| 871 | 871 | * |
| 872 | 872 | * @return string |
| 873 | 873 | */ |
| 874 | - protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true){ |
|
| 874 | + protected function getWhereStrIfIsArray(array $where, $type = '', $andOr = 'AND', $escape = true) { |
|
| 875 | 875 | $_where = array(); |
| 876 | - foreach ($where as $column => $data){ |
|
| 877 | - if (is_null($data)){ |
|
| 876 | + foreach ($where as $column => $data) { |
|
| 877 | + if (is_null($data)) { |
|
| 878 | 878 | $data = ''; |
| 879 | 879 | } |
| 880 | 880 | $_where[] = $type . $column . ' = ' . ($this->escape($data, $escape)); |
| 881 | 881 | } |
| 882 | - $where = implode(' '.$andOr.' ', $_where); |
|
| 882 | + $where = implode(' ' . $andOr . ' ', $_where); |
|
| 883 | 883 | return $where; |
| 884 | 884 | } |
| 885 | 885 | |
@@ -889,12 +889,12 @@ discard block |
||
| 889 | 889 | * |
| 890 | 890 | * @return string |
| 891 | 891 | */ |
| 892 | - protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true){ |
|
| 892 | + protected function getWhereStrIfOperatorIsArray($where, array $op, $type = '', $escape = true) { |
|
| 893 | 893 | $x = explode('?', $where); |
| 894 | 894 | $w = ''; |
| 895 | - foreach($x as $k => $v){ |
|
| 896 | - if (! empty($v)){ |
|
| 897 | - if (isset($op[$k]) && is_null($op[$k])){ |
|
| 895 | + foreach ($x as $k => $v) { |
|
| 896 | + if (!empty($v)) { |
|
| 897 | + if (isset($op[$k]) && is_null($op[$k])) { |
|
| 898 | 898 | $op[$k] = ''; |
| 899 | 899 | } |
| 900 | 900 | $w .= $type . $v . (isset($op[$k]) ? ($this->escape($op[$k], $escape)) : ''); |
@@ -909,15 +909,15 @@ discard block |
||
| 909 | 909 | * |
| 910 | 910 | * @return string |
| 911 | 911 | */ |
| 912 | - protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true){ |
|
| 912 | + protected function getWhereStrForOperator($where, $op = null, $val = null, $type = '', $escape = true) { |
|
| 913 | 913 | $w = ''; |
| 914 | - if (! in_array((string)$op, $this->operatorList)){ |
|
| 915 | - if (is_null($op)){ |
|
| 914 | + if (!in_array((string) $op, $this->operatorList)) { |
|
| 915 | + if (is_null($op)) { |
|
| 916 | 916 | $op = ''; |
| 917 | 917 | } |
| 918 | 918 | $w = $type . $where . ' = ' . ($this->escape($op, $escape)); |
| 919 | 919 | } else { |
| 920 | - if (is_null($val)){ |
|
| 920 | + if (is_null($val)) { |
|
| 921 | 921 | $val = ''; |
| 922 | 922 | } |
| 923 | 923 | $w = $type . $where . $op . ($this->escape($val, $escape)); |
@@ -930,14 +930,14 @@ discard block |
||
| 930 | 930 | * @param string $whereStr the WHERE clause string |
| 931 | 931 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
| 932 | 932 | */ |
| 933 | - protected function setWhereStr($whereStr, $andOr = 'AND'){ |
|
| 934 | - if (empty($this->where)){ |
|
| 933 | + protected function setWhereStr($whereStr, $andOr = 'AND') { |
|
| 934 | + if (empty($this->where)) { |
|
| 935 | 935 | $this->where = $whereStr; |
| 936 | 936 | } else { |
| 937 | - if (substr(trim($this->where), -1) == '('){ |
|
| 937 | + if (substr(trim($this->where), -1) == '(') { |
|
| 938 | 938 | $this->where = $this->where . ' ' . $whereStr; |
| 939 | 939 | } else { |
| 940 | - $this->where = $this->where . ' '.$andOr.' ' . $whereStr; |
|
| 940 | + $this->where = $this->where . ' ' . $andOr . ' ' . $whereStr; |
|
| 941 | 941 | } |
| 942 | 942 | } |
| 943 | 943 | } |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | * @see DatabaseQueryBuilder::avg |
| 954 | 954 | * @return object |
| 955 | 955 | */ |
| 956 | - protected function select_min_max_sum_count_avg($clause, $field, $name = null){ |
|
| 956 | + protected function select_min_max_sum_count_avg($clause, $field, $name = null) { |
|
| 957 | 957 | $clause = strtoupper($clause); |
| 958 | 958 | $func = $clause . '(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
| 959 | 959 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - class Pagination{ |
|
| 27 | + class Pagination { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * The list of loaded config |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | * Create an instance of pagination |
| 43 | 43 | * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php |
| 44 | 44 | */ |
| 45 | - public function __construct(array $overwriteConfig = array()){ |
|
| 46 | - if (file_exists(CONFIG_PATH . 'config_pagination.php')){ |
|
| 45 | + public function __construct(array $overwriteConfig = array()) { |
|
| 46 | + if (file_exists(CONFIG_PATH . 'config_pagination.php')) { |
|
| 47 | 47 | $config = array(); |
| 48 | 48 | require_once CONFIG_PATH . 'config_pagination.php'; |
| 49 | - if (empty($config) || ! is_array($config)){ |
|
| 49 | + if (empty($config) || !is_array($config)) { |
|
| 50 | 50 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
| 51 | 51 | } |
| 52 | - else{ |
|
| 52 | + else { |
|
| 53 | 53 | $config = array_merge($config, $overwriteConfig); |
| 54 | 54 | $this->config = $config; |
| 55 | 55 | //put it gobally |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | unset($config); |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | - else{ |
|
| 60 | + else { |
|
| 61 | 61 | show_error('Unable to find the pagination configuration file'); |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | * config_pagination.php |
| 69 | 69 | * @param array $config the configuration to overwrite |
| 70 | 70 | */ |
| 71 | - public function setConfig(array $config = array()){ |
|
| 72 | - if (! empty($config)){ |
|
| 71 | + public function setConfig(array $config = array()) { |
|
| 72 | + if (!empty($config)) { |
|
| 73 | 73 | $this->config = array_merge($this->config, $config); |
| 74 | 74 | Config::setAll($config); |
| 75 | 75 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | - public function getConfig(){ |
|
| 83 | + public function getConfig() { |
|
| 84 | 84 | return $this->config; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * Return the value of the pagination query string |
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | - public function getPaginationQueryString(){ |
|
| 91 | + public function getPaginationQueryString() { |
|
| 92 | 92 | return $this->paginationQueryString; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @param string $paginationQueryString the new value |
| 98 | 98 | * @return object |
| 99 | 99 | */ |
| 100 | - public function setPaginationQueryString($paginationQueryString){ |
|
| 100 | + public function setPaginationQueryString($paginationQueryString) { |
|
| 101 | 101 | $this->paginationQueryString = $paginationQueryString; |
| 102 | 102 | return $this; |
| 103 | 103 | } |
@@ -108,25 +108,25 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return object |
| 110 | 110 | */ |
| 111 | - public function determinePaginationQueryStringValue(){ |
|
| 111 | + public function determinePaginationQueryStringValue() { |
|
| 112 | 112 | $pageQueryName = $this->config['page_query_string_name']; |
| 113 | 113 | $queryString = Url::queryString(); |
| 114 | 114 | $currentUrl = Url::current(); |
| 115 | 115 | $query = ''; |
| 116 | - if ($queryString == ''){ |
|
| 116 | + if ($queryString == '') { |
|
| 117 | 117 | $query = '?' . $pageQueryName . '='; |
| 118 | 118 | } |
| 119 | - else{ |
|
| 119 | + else { |
|
| 120 | 120 | $tab = explode($pageQueryName . '=', $queryString); |
| 121 | 121 | $nb = count($tab); |
| 122 | - if ($nb == 1){ |
|
| 122 | + if ($nb == 1) { |
|
| 123 | 123 | $query = '?' . $queryString . '&' . $pageQueryName . '='; |
| 124 | 124 | } |
| 125 | - else{ |
|
| 126 | - if ($tab[0] == ''){ |
|
| 125 | + else { |
|
| 126 | + if ($tab[0] == '') { |
|
| 127 | 127 | $query = '?' . $pageQueryName . '='; |
| 128 | 128 | } |
| 129 | - else{ |
|
| 129 | + else { |
|
| 130 | 130 | $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
| 131 | 131 | } |
| 132 | 132 | } |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @return string the pagination link |
| 146 | 146 | */ |
| 147 | - public function getLink($totalRows, $currentPageNumber){ |
|
| 147 | + public function getLink($totalRows, $currentPageNumber) { |
|
| 148 | 148 | $numberOfLink = $this->config['nb_link']; |
| 149 | 149 | $numberOfRowPerPage = $this->config['pagination_per_page']; |
| 150 | - if (empty($this->paginationQueryString)){ |
|
| 150 | + if (empty($this->paginationQueryString)) { |
|
| 151 | 151 | //determine the pagination query string value |
| 152 | 152 | $this->determinePaginationQueryStringValue(); |
| 153 | 153 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $numberOfLink = (int) $numberOfLink; |
| 159 | 159 | $numberOfRowPerPage = (int) $numberOfRowPerPage; |
| 160 | 160 | |
| 161 | - if ($currentPageNumber <= 0){ |
|
| 161 | + if ($currentPageNumber <= 0) { |
|
| 162 | 162 | $currentPageNumber = 1; |
| 163 | 163 | } |
| 164 | 164 | if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0) { |
@@ -173,18 +173,18 @@ discard block |
||
| 173 | 173 | * @param int $numberOfPage the total number of page |
| 174 | 174 | * @return string |
| 175 | 175 | */ |
| 176 | - protected function buildPaginationNavbar($currentPageNumber, $numberOfPage){ |
|
| 176 | + protected function buildPaginationNavbar($currentPageNumber, $numberOfPage) { |
|
| 177 | 177 | $values = $this->getPaginationBeginAndEndNumber($currentPageNumber, $numberOfPage); |
| 178 | 178 | $begin = $values['begin']; |
| 179 | 179 | $end = $values['end']; |
| 180 | 180 | $navbar = null; |
| 181 | - if ($currentPageNumber == 1){ |
|
| 181 | + if ($currentPageNumber == 1) { |
|
| 182 | 182 | $navbar .= $this->buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber); |
| 183 | 183 | } |
| 184 | - else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
| 184 | + else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage) { |
|
| 185 | 185 | $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber); |
| 186 | 186 | } |
| 187 | - else if ($currentPageNumber == $numberOfPage){ |
|
| 187 | + else if ($currentPageNumber == $numberOfPage) { |
|
| 188 | 188 | $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber); |
| 189 | 189 | } |
| 190 | 190 | $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close']; |
@@ -197,32 +197,32 @@ discard block |
||
| 197 | 197 | * @param int $numberOfPage the total number of page |
| 198 | 198 | * @return array the begin and end number |
| 199 | 199 | */ |
| 200 | - protected function getPaginationBeginAndEndNumber($currentPageNumber, $numberOfPage){ |
|
| 200 | + protected function getPaginationBeginAndEndNumber($currentPageNumber, $numberOfPage) { |
|
| 201 | 201 | $start = null; |
| 202 | 202 | $begin = null; |
| 203 | 203 | $end = null; |
| 204 | 204 | $numberOfLink = $this->config['nb_link']; |
| 205 | - if ($numberOfLink % 2 == 0){ |
|
| 205 | + if ($numberOfLink % 2 == 0) { |
|
| 206 | 206 | $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
| 207 | 207 | $end = $currentPageNumber + ($numberOfLink / 2); |
| 208 | 208 | } |
| 209 | - else{ |
|
| 209 | + else { |
|
| 210 | 210 | $start = $currentPageNumber - floor($numberOfLink / 2); |
| 211 | 211 | $end = $currentPageNumber + floor($numberOfLink / 2); |
| 212 | 212 | } |
| 213 | - if ($start <= 1){ |
|
| 213 | + if ($start <= 1) { |
|
| 214 | 214 | $begin = 1; |
| 215 | 215 | $end = $numberOfLink; |
| 216 | 216 | } |
| 217 | - else if ($start > 1 && $end < $numberOfPage){ |
|
| 217 | + else if ($start > 1 && $end < $numberOfPage) { |
|
| 218 | 218 | $begin = $start; |
| 219 | 219 | $end = $end; |
| 220 | 220 | } |
| 221 | - else{ |
|
| 221 | + else { |
|
| 222 | 222 | $begin = ($numberOfPage - $numberOfLink) + 1; |
| 223 | 223 | $end = $numberOfPage; |
| 224 | 224 | } |
| 225 | - if ($numberOfPage <= $numberOfLink){ |
|
| 225 | + if ($numberOfPage <= $numberOfLink) { |
|
| 226 | 226 | $begin = 1; |
| 227 | 227 | $end = $numberOfPage; |
| 228 | 228 | } |
@@ -239,14 +239,14 @@ discard block |
||
| 239 | 239 | * @param int $currentPageNumber the pagination current page number |
| 240 | 240 | * @return string |
| 241 | 241 | */ |
| 242 | - protected function buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber){ |
|
| 242 | + protected function buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber) { |
|
| 243 | 243 | $navbar = null; |
| 244 | 244 | $query = $this->paginationQueryString; |
| 245 | - for($i = $begin; $i <= $end; $i++){ |
|
| 246 | - if ($i == $currentPageNumber){ |
|
| 245 | + for ($i = $begin; $i <= $end; $i++) { |
|
| 246 | + if ($i == $currentPageNumber) { |
|
| 247 | 247 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
| 248 | 248 | } |
| 249 | - else{ |
|
| 249 | + else { |
|
| 250 | 250 | $navbar .= $this->config['digit_open'] |
| 251 | 251 | . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
| 252 | 252 | . $this->config['digit_close']; |
@@ -265,23 +265,23 @@ discard block |
||
| 265 | 265 | * @param int $currentPageNumber the pagination current page number |
| 266 | 266 | * @return string |
| 267 | 267 | */ |
| 268 | - protected function buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber){ |
|
| 268 | + protected function buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber) { |
|
| 269 | 269 | $navbar = null; |
| 270 | 270 | $query = $this->paginationQueryString; |
| 271 | 271 | $navbar .= $this->config['previous_open'] |
| 272 | 272 | . '<a href="' . $query . ($currentPageNumber - 1) . '">' |
| 273 | 273 | . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
| 274 | - for($i = $begin; $i <= $end; $i++){ |
|
| 275 | - if ($i == $currentPageNumber){ |
|
| 274 | + for ($i = $begin; $i <= $end; $i++) { |
|
| 275 | + if ($i == $currentPageNumber) { |
|
| 276 | 276 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
| 277 | 277 | } |
| 278 | - else{ |
|
| 278 | + else { |
|
| 279 | 279 | $navbar .= $this->config['digit_open'] |
| 280 | - . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' |
|
| 280 | + . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
|
| 281 | 281 | . $this->config['digit_close']; |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | - $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close']; |
|
| 284 | + $navbar .= $this->config['next_open'] . "<a href='$query" . ($currentPageNumber + 1) . "'>" . $this->config['next_text'] . "</a>" . $this->config['next_close']; |
|
| 285 | 285 | return $navbar; |
| 286 | 286 | } |
| 287 | 287 | |
@@ -292,19 +292,19 @@ discard block |
||
| 292 | 292 | * @param int $currentPageNumber the pagination current page number |
| 293 | 293 | * @return string |
| 294 | 294 | */ |
| 295 | - protected function buildPaginationLinkForLastPage($begin, $end, $currentPageNumber){ |
|
| 295 | + protected function buildPaginationLinkForLastPage($begin, $end, $currentPageNumber) { |
|
| 296 | 296 | $navbar = null; |
| 297 | 297 | $query = $this->paginationQueryString; |
| 298 | 298 | $navbar .= $this->config['previous_open'] |
| 299 | 299 | . '<a href="' . $query . ($currentPageNumber - 1) . '">' |
| 300 | 300 | . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
| 301 | - for($i = $begin; $i <= $end; $i++){ |
|
| 302 | - if ($i == $currentPageNumber){ |
|
| 301 | + for ($i = $begin; $i <= $end; $i++) { |
|
| 302 | + if ($i == $currentPageNumber) { |
|
| 303 | 303 | $navbar .= $this->config['active_link_open'] |
| 304 | 304 | . $currentPageNumber |
| 305 | 305 | . $this->config['active_link_close']; |
| 306 | 306 | } |
| 307 | - else{ |
|
| 307 | + else { |
|
| 308 | 308 | $navbar .= $this->config['digit_open'] |
| 309 | 309 | . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
| 310 | 310 | . $this->config['digit_close']; |