@@ -12,84 +12,84 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class Tools extends Model { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Return random string |
|
| 17 | - * |
|
| 18 | - * @param int $length |
|
| 19 | - * @param string $characters |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - public static function randomString($length = 20, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { |
|
| 15 | + /** |
|
| 16 | + * Return random string |
|
| 17 | + * |
|
| 18 | + * @param int $length |
|
| 19 | + * @param string $characters |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + public static function randomString($length = 20, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { |
|
| 23 | 23 | $charactersLength = strlen($characters); |
| 24 | 24 | $randomString = ''; |
| 25 | 25 | for ($i = 0; $i < $length; $i++) { |
| 26 | - $randomString .= $characters[rand(0, $charactersLength - 1)]; |
|
| 26 | + $randomString .= $characters[rand(0, $charactersLength - 1)]; |
|
| 27 | 27 | } |
| 28 | 28 | return $randomString; |
| 29 | - } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Clean and return user query params |
|
| 33 | - * |
|
| 34 | - * @param string $uri |
|
| 35 | - * @return array |
|
| 36 | - */ |
|
| 37 | - public static function uriParse($uri) { |
|
| 31 | + /** |
|
| 32 | + * Clean and return user query params |
|
| 33 | + * |
|
| 34 | + * @param string $uri |
|
| 35 | + * @return array |
|
| 36 | + */ |
|
| 37 | + public static function uriParse($uri) { |
|
| 38 | 38 | $answerPos = strpos($uri, '?'); |
| 39 | 39 | $params = array_slice(explode('/', substr($uri, 0, $answerPos ? $answerPos : strlen($uri) )), 1); |
| 40 | 40 | |
| 41 | 41 | foreach ($params as $key => $param) { |
| 42 | - if ($param != '') { |
|
| 42 | + if ($param != '') { |
|
| 43 | 43 | $params[$key] = urldecode($param); |
| 44 | - } else { |
|
| 44 | + } else { |
|
| 45 | 45 | unset($params[$key]); |
| 46 | - } |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | return $params; |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Recursive create dir |
|
| 53 | - * |
|
| 54 | - * @param string $path |
|
| 55 | - * @return boolean |
|
| 56 | - */ |
|
| 57 | - public static function createDir($path) { |
|
| 51 | + /** |
|
| 52 | + * Recursive create dir |
|
| 53 | + * |
|
| 54 | + * @param string $path |
|
| 55 | + * @return boolean |
|
| 56 | + */ |
|
| 57 | + public static function createDir($path) { |
|
| 58 | 58 | if (file_exists($path)) |
| 59 | - return true; |
|
| 59 | + return true; |
|
| 60 | 60 | |
| 61 | 61 | $path = explode('/', $path); |
| 62 | 62 | $cur = ''; |
| 63 | 63 | foreach ($path as $item) { |
| 64 | - $cur .= $item . '/'; |
|
| 65 | - if (!file_exists($cur)) { |
|
| 64 | + $cur .= $item . '/'; |
|
| 65 | + if (!file_exists($cur)) { |
|
| 66 | 66 | mkdir($cur); |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | } |
| 69 | 69 | return true; |
| 70 | - } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Resize image in path |
|
| 74 | - * |
|
| 75 | - * @param string $img_path |
|
| 76 | - * @param int $max_width |
|
| 77 | - * @param int $max_height |
|
| 78 | - * @param string|false $crop |
|
| 79 | - * @param string $pos |
|
| 80 | - * @return string |
|
| 81 | - */ |
|
| 82 | - public static function resizeImage($img_path, $max_width = 1000, $max_height = 1000, $crop = false, $pos = 'center') { |
|
| 72 | + /** |
|
| 73 | + * Resize image in path |
|
| 74 | + * |
|
| 75 | + * @param string $img_path |
|
| 76 | + * @param int $max_width |
|
| 77 | + * @param int $max_height |
|
| 78 | + * @param string|false $crop |
|
| 79 | + * @param string $pos |
|
| 80 | + * @return string |
|
| 81 | + */ |
|
| 82 | + public static function resizeImage($img_path, $max_width = 1000, $max_height = 1000, $crop = false, $pos = 'center') { |
|
| 83 | 83 | ini_set("gd.jpeg_ignore_warning", 1); |
| 84 | 84 | list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($img_path); |
| 85 | 85 | switch ($img_type) { |
| 86 | - case 1: |
|
| 86 | + case 1: |
|
| 87 | 87 | $img_type = 'gif'; |
| 88 | 88 | break; |
| 89 | - case 3: |
|
| 89 | + case 3: |
|
| 90 | 90 | $img_type = 'png'; |
| 91 | 91 | break; |
| 92 | - case 2: |
|
| 92 | + case 2: |
|
| 93 | 93 | default: |
| 94 | 94 | $img_type = 'jpeg'; |
| 95 | 95 | break; |
@@ -97,55 +97,55 @@ discard block |
||
| 97 | 97 | $imagecreatefromX = "imagecreatefrom{$img_type}"; |
| 98 | 98 | $src_res = $imagecreatefromX($img_path); |
| 99 | 99 | if (!$src_res) { |
| 100 | - return false; |
|
| 100 | + return false; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | if ($img_width / $max_width > $img_height / $max_height) |
| 104 | - $separator = $img_width / $max_width; |
|
| 104 | + $separator = $img_width / $max_width; |
|
| 105 | 105 | else |
| 106 | - $separator = $img_height / $max_height; |
|
| 106 | + $separator = $img_height / $max_height; |
|
| 107 | 107 | |
| 108 | 108 | if ($crop === true || $crop == 'q') { |
| 109 | - if ($img_width > $img_height) { |
|
| 109 | + if ($img_width > $img_height) { |
|
| 110 | 110 | $imgX = floor(( $img_width - $img_height ) / 2); |
| 111 | 111 | $imgY = 0; |
| 112 | 112 | $img_width = $img_height; |
| 113 | 113 | $new_width = $max_width; |
| 114 | 114 | $new_height = $max_height; |
| 115 | - } else { |
|
| 115 | + } else { |
|
| 116 | 116 | $imgX = 0; |
| 117 | 117 | $imgY = floor(( $img_height - $img_width ) / 2); |
| 118 | 118 | $img_height = $img_width; |
| 119 | 119 | $new_width = $max_width; |
| 120 | 120 | $new_height = $max_height; |
| 121 | - } |
|
| 122 | - if ($pos == 'top') { |
|
| 121 | + } |
|
| 122 | + if ($pos == 'top') { |
|
| 123 | 123 | $imgY = 0; |
| 124 | - } |
|
| 124 | + } |
|
| 125 | 125 | } elseif ($crop == 'c') { |
| 126 | 126 | //Вычисляем некий коэффициент масштабирования |
| 127 | - $k1 = $img_width / $max_width; |
|
| 128 | - $k2 = $img_height / $max_height; |
|
| 129 | - $k = $k1 > $k2 ? $k2 : $k1; |
|
| 130 | - $ow = $img_width; |
|
| 131 | - $oh = $img_height; |
|
| 127 | + $k1 = $img_width / $max_width; |
|
| 128 | + $k2 = $img_height / $max_height; |
|
| 129 | + $k = $k1 > $k2 ? $k2 : $k1; |
|
| 130 | + $ow = $img_width; |
|
| 131 | + $oh = $img_height; |
|
| 132 | 132 | //Вычисляем размеры области для нового изображения |
| 133 | - $img_width = intval($max_width * $k); |
|
| 134 | - $img_height = intval($max_height * $k); |
|
| 135 | - $new_width = $max_width; |
|
| 136 | - $new_height = $max_height; |
|
| 133 | + $img_width = intval($max_width * $k); |
|
| 134 | + $img_height = intval($max_height * $k); |
|
| 135 | + $new_width = $max_width; |
|
| 136 | + $new_height = $max_height; |
|
| 137 | 137 | //Находим начальные координаты (центрируем новое изображение) |
| 138 | - $imgX = (int) (($ow / 2) - ($img_width / 2) ); |
|
| 139 | - if ($pos == 'center') { |
|
| 138 | + $imgX = (int) (($ow / 2) - ($img_width / 2) ); |
|
| 139 | + if ($pos == 'center') { |
|
| 140 | 140 | $imgY = (int) (($oh / 2) - ($img_height / 2)); |
| 141 | - } else { |
|
| 141 | + } else { |
|
| 142 | 142 | $imgY = 0; |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | } else { |
| 145 | - $imgX = 0; |
|
| 146 | - $imgY = 0; |
|
| 147 | - $new_width = floor($img_width / $separator); |
|
| 148 | - $new_height = floor($img_height / $separator); |
|
| 145 | + $imgX = 0; |
|
| 146 | + $imgY = 0; |
|
| 147 | + $new_width = floor($img_width / $separator); |
|
| 148 | + $new_height = floor($img_height / $separator); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | $new_res = imagecreatetruecolor($new_width, $new_height); |
@@ -154,128 +154,128 @@ discard block |
||
| 154 | 154 | imagecopyresampled($new_res, $src_res, 0, 0, $imgX, $imgY, $new_width, $new_height, $img_width, $img_height); |
| 155 | 155 | |
| 156 | 156 | if ($img_type == 'jpeg') { |
| 157 | - imageinterlace($new_res, 1); // чересстрочное формирование изображение |
|
| 158 | - imagejpeg($new_res, $img_path, 85); |
|
| 157 | + imageinterlace($new_res, 1); // чересстрочное формирование изображение |
|
| 158 | + imagejpeg($new_res, $img_path, 85); |
|
| 159 | 159 | } else { |
| 160 | - $imageX = "image{$img_type}"; |
|
| 161 | - $imageX($new_res, $img_path); |
|
| 160 | + $imageX = "image{$img_type}"; |
|
| 161 | + $imageX($new_res, $img_path); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | imagedestroy($new_res); |
| 165 | 165 | imagedestroy($src_res); |
| 166 | 166 | return $img_type; |
| 167 | - } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Send mail |
|
| 171 | - * |
|
| 172 | - * @param string $from |
|
| 173 | - * @param string $to |
|
| 174 | - * @param string $subject |
|
| 175 | - * @param string $text |
|
| 176 | - * @param string $charset |
|
| 177 | - * @param string $ctype |
|
| 178 | - * @return boolean |
|
| 179 | - */ |
|
| 180 | - public static function sendMail($from, $to, $subject, $text, $charset = 'utf-8', $ctype = 'text/html') { |
|
| 169 | + /** |
|
| 170 | + * Send mail |
|
| 171 | + * |
|
| 172 | + * @param string $from |
|
| 173 | + * @param string $to |
|
| 174 | + * @param string $subject |
|
| 175 | + * @param string $text |
|
| 176 | + * @param string $charset |
|
| 177 | + * @param string $ctype |
|
| 178 | + * @return boolean |
|
| 179 | + */ |
|
| 180 | + public static function sendMail($from, $to, $subject, $text, $charset = 'utf-8', $ctype = 'text/html') { |
|
| 181 | 181 | $msg = compact('from', 'to', 'subject', 'text', 'charset', 'ctype'); |
| 182 | 182 | $msg = Inji::$inst->event('sendMail', $msg); |
| 183 | 183 | if (is_array($msg)) { |
| 184 | - $headers = "From: {$msg['from']}\r\n"; |
|
| 185 | - $headers .= "Content-type: {$msg['ctype']}; charset={$msg['charset']}\r\n"; |
|
| 186 | - $headers .= "Mime-Version: 1.0\r\n"; |
|
| 187 | - return mail($msg['to'], $msg['subject'], $msg['text'], $headers); |
|
| 184 | + $headers = "From: {$msg['from']}\r\n"; |
|
| 185 | + $headers .= "Content-type: {$msg['ctype']}; charset={$msg['charset']}\r\n"; |
|
| 186 | + $headers .= "Mime-Version: 1.0\r\n"; |
|
| 187 | + return mail($msg['to'], $msg['subject'], $msg['text'], $headers); |
|
| 188 | 188 | } |
| 189 | 189 | return $msg; |
| 190 | - } |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Redirect user from any place of code |
|
| 194 | - * |
|
| 195 | - * Also add message to message query for view |
|
| 196 | - * |
|
| 197 | - * @param string $href |
|
| 198 | - * @param string $text |
|
| 199 | - * @param string $status |
|
| 200 | - */ |
|
| 201 | - public static function redirect($href = null, $text = false, $status = 'info') { |
|
| 192 | + /** |
|
| 193 | + * Redirect user from any place of code |
|
| 194 | + * |
|
| 195 | + * Also add message to message query for view |
|
| 196 | + * |
|
| 197 | + * @param string $href |
|
| 198 | + * @param string $text |
|
| 199 | + * @param string $status |
|
| 200 | + */ |
|
| 201 | + public static function redirect($href = null, $text = false, $status = 'info') { |
|
| 202 | 202 | if ($href === null) { |
| 203 | - $href = $_SERVER['REQUEST_URI']; |
|
| 203 | + $href = $_SERVER['REQUEST_URI']; |
|
| 204 | 204 | } |
| 205 | 205 | if ($text !== false) { |
| 206 | - Msg::add($text, $status); |
|
| 206 | + Msg::add($text, $status); |
|
| 207 | 207 | } |
| 208 | 208 | if (!headers_sent()) { |
| 209 | - header("Location: {$href}"); |
|
| 209 | + header("Location: {$href}"); |
|
| 210 | 210 | } else { |
| 211 | - echo '\'"><script>window.location="' . $href . '";</script>'; |
|
| 211 | + echo '\'"><script>window.location="' . $href . '";</script>'; |
|
| 212 | 212 | } |
| 213 | 213 | exit("Перенаправление на: <a href = '{$href}'>{$href}</a>"); |
| 214 | - } |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - /** |
|
| 217 | - * Функция возвращает окончание для множественного числа слова на основании числа и массива окончаний |
|
| 218 | - * @param $number Integer Число на основе которого нужно сформировать окончание |
|
| 219 | - * @param $endingsArray Array Массив слов или окончаний для чисел (1, 4, 5), |
|
| 220 | - * например array('яблоко', 'яблока', 'яблок') |
|
| 221 | - * @return String |
|
| 222 | - */ |
|
| 223 | - public static function getNumEnding($number, $endingArray) { |
|
| 216 | + /** |
|
| 217 | + * Функция возвращает окончание для множественного числа слова на основании числа и массива окончаний |
|
| 218 | + * @param $number Integer Число на основе которого нужно сформировать окончание |
|
| 219 | + * @param $endingsArray Array Массив слов или окончаний для чисел (1, 4, 5), |
|
| 220 | + * например array('яблоко', 'яблока', 'яблок') |
|
| 221 | + * @return String |
|
| 222 | + */ |
|
| 223 | + public static function getNumEnding($number, $endingArray) { |
|
| 224 | 224 | $number = $number % 100; |
| 225 | 225 | if ($number >= 11 && $number <= 19) { |
| 226 | - $ending = $endingArray[2]; |
|
| 226 | + $ending = $endingArray[2]; |
|
| 227 | 227 | } else { |
| 228 | - $i = $number % 10; |
|
| 229 | - switch ($i) { |
|
| 228 | + $i = $number % 10; |
|
| 229 | + switch ($i) { |
|
| 230 | 230 | case (1): $ending = $endingArray[0]; |
| 231 | - break; |
|
| 231 | + break; |
|
| 232 | 232 | case (2): |
| 233 | 233 | case (3): |
| 234 | 234 | case (4): $ending = $endingArray[1]; |
| 235 | - break; |
|
| 235 | + break; |
|
| 236 | 236 | default: $ending = $endingArray[2]; |
| 237 | - } |
|
| 237 | + } |
|
| 238 | 238 | } |
| 239 | 239 | return $ending; |
| 240 | - } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * Clean request path |
|
| 244 | - * |
|
| 245 | - * @param string $path |
|
| 246 | - * @return string |
|
| 247 | - */ |
|
| 248 | - public static function parsePath($path) { |
|
| 242 | + /** |
|
| 243 | + * Clean request path |
|
| 244 | + * |
|
| 245 | + * @param string $path |
|
| 246 | + * @return string |
|
| 247 | + */ |
|
| 248 | + public static function parsePath($path) { |
|
| 249 | 249 | $path = str_replace('\\', '/', $path); |
| 250 | 250 | $pathArray = explode('/', $path); |
| 251 | 251 | $cleanPathArray = []; |
| 252 | 252 | do { |
| 253 | - $changes = 0; |
|
| 254 | - foreach ($pathArray as $pathItem) { |
|
| 253 | + $changes = 0; |
|
| 254 | + foreach ($pathArray as $pathItem) { |
|
| 255 | 255 | if (trim($pathItem) === '' || $pathItem == '.') { |
| 256 | - $changes++; |
|
| 257 | - continue; |
|
| 256 | + $changes++; |
|
| 257 | + continue; |
|
| 258 | 258 | } |
| 259 | 259 | if ($pathItem == '..') { |
| 260 | - array_pop($cleanPathArray); |
|
| 261 | - $changes++; |
|
| 262 | - continue; |
|
| 260 | + array_pop($cleanPathArray); |
|
| 261 | + $changes++; |
|
| 262 | + continue; |
|
| 263 | 263 | } |
| 264 | 264 | $cleanPathArray[] = $pathItem; |
| 265 | - } |
|
| 266 | - $pathArray = $cleanPathArray; |
|
| 267 | - $cleanPathArray = []; |
|
| 265 | + } |
|
| 266 | + $pathArray = $cleanPathArray; |
|
| 267 | + $cleanPathArray = []; |
|
| 268 | 268 | } while ($changes); |
| 269 | 269 | return (strpos($path, '/') === 0 ? '/' : '') . implode('/', $pathArray); |
| 270 | - } |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * Show date in rus |
|
| 274 | - * |
|
| 275 | - * @param string $date |
|
| 276 | - * @return string |
|
| 277 | - */ |
|
| 278 | - public static function toRusDate($date) { |
|
| 272 | + /** |
|
| 273 | + * Show date in rus |
|
| 274 | + * |
|
| 275 | + * @param string $date |
|
| 276 | + * @return string |
|
| 277 | + */ |
|
| 278 | + public static function toRusDate($date) { |
|
| 279 | 279 | $yy = (int) substr($date, 0, 4); |
| 280 | 280 | $mm = (int) substr($date, 5, 2); |
| 281 | 281 | $dd = (int) substr($date, 8, 2); |
@@ -284,114 +284,114 @@ discard block |
||
| 284 | 284 | |
| 285 | 285 | $month = array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'); |
| 286 | 286 | if (empty($month[$mm - 1])) { |
| 287 | - return 'Не указано'; |
|
| 287 | + return 'Не указано'; |
|
| 288 | 288 | } |
| 289 | 289 | return ($dd > 0 ? $dd . " " : '') . $month[$mm - 1] . " " . $yy . " " . $hours; |
| 290 | - } |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * Set header |
|
| 294 | - * |
|
| 295 | - * @param string $code |
|
| 296 | - * @param boolean $exit |
|
| 297 | - */ |
|
| 298 | - public static function header($code, $exit = false) { |
|
| 292 | + /** |
|
| 293 | + * Set header |
|
| 294 | + * |
|
| 295 | + * @param string $code |
|
| 296 | + * @param boolean $exit |
|
| 297 | + */ |
|
| 298 | + public static function header($code, $exit = false) { |
|
| 299 | 299 | if (!headers_sent()) { |
| 300 | - switch ($code) { |
|
| 300 | + switch ($code) { |
|
| 301 | 301 | case '404': |
| 302 | 302 | header('HTTP/1.1 404 Not Found'); |
| 303 | - break; |
|
| 303 | + break; |
|
| 304 | 304 | default : |
| 305 | 305 | header($code); |
| 306 | - } |
|
| 306 | + } |
|
| 307 | 307 | } |
| 308 | 308 | if ($exit) { |
| 309 | - exit; |
|
| 309 | + exit; |
|
| 310 | + } |
|
| 310 | 311 | } |
| 311 | - } |
|
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * Return exist path from array |
|
| 315 | - * |
|
| 316 | - * If no exist path in array - return default |
|
| 317 | - * |
|
| 318 | - * @param array $paths |
|
| 319 | - * @param string|false $default |
|
| 320 | - * @return string|false |
|
| 321 | - */ |
|
| 322 | - public static function pathsResolve($paths = [], $default = false) { |
|
| 313 | + /** |
|
| 314 | + * Return exist path from array |
|
| 315 | + * |
|
| 316 | + * If no exist path in array - return default |
|
| 317 | + * |
|
| 318 | + * @param array $paths |
|
| 319 | + * @param string|false $default |
|
| 320 | + * @return string|false |
|
| 321 | + */ |
|
| 322 | + public static function pathsResolve($paths = [], $default = false) { |
|
| 323 | 323 | foreach ($paths as $path) { |
| 324 | - if (file_exists($path)) { |
|
| 324 | + if (file_exists($path)) { |
|
| 325 | 325 | return $path; |
| 326 | - } |
|
| 326 | + } |
|
| 327 | 327 | } |
| 328 | 328 | return $default; |
| 329 | - } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * Convert acronyms to bites |
|
| 333 | - * |
|
| 334 | - * @param string $val |
|
| 335 | - * @return int |
|
| 336 | - */ |
|
| 337 | - public static function toBytes($val) { |
|
| 331 | + /** |
|
| 332 | + * Convert acronyms to bites |
|
| 333 | + * |
|
| 334 | + * @param string $val |
|
| 335 | + * @return int |
|
| 336 | + */ |
|
| 337 | + public static function toBytes($val) { |
|
| 338 | 338 | $val = trim($val); |
| 339 | 339 | $last = strtolower($val[strlen($val) - 1]); |
| 340 | 340 | switch ($last) { |
| 341 | - case 'g': |
|
| 341 | + case 'g': |
|
| 342 | 342 | $val *= 1024; |
| 343 | - case 'm': |
|
| 343 | + case 'm': |
|
| 344 | 344 | $val *= 1024; |
| 345 | - case 'k': |
|
| 345 | + case 'k': |
|
| 346 | 346 | $val *= 1024; |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | return $val; |
| 350 | - } |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - /** |
|
| 353 | - * Recursive copy directories and files |
|
| 354 | - * |
|
| 355 | - * @param string $from |
|
| 356 | - * @param string $to |
|
| 357 | - */ |
|
| 358 | - public static function copyFiles($from, $to) { |
|
| 352 | + /** |
|
| 353 | + * Recursive copy directories and files |
|
| 354 | + * |
|
| 355 | + * @param string $from |
|
| 356 | + * @param string $to |
|
| 357 | + */ |
|
| 358 | + public static function copyFiles($from, $to) { |
|
| 359 | 359 | $from = rtrim($from, '/'); |
| 360 | 360 | $to = rtrim($to, '/'); |
| 361 | 361 | self::createDir($to); |
| 362 | 362 | $files = scandir($from); |
| 363 | 363 | foreach ($files as $file) { |
| 364 | - if (in_array($file, ['.', '..'])) { |
|
| 364 | + if (in_array($file, ['.', '..'])) { |
|
| 365 | 365 | continue; |
| 366 | - } |
|
| 367 | - if (is_dir($from . '/' . $file)) { |
|
| 366 | + } |
|
| 367 | + if (is_dir($from . '/' . $file)) { |
|
| 368 | 368 | self::copyFiles($from . '/' . $file, $to . '/' . $file); |
| 369 | - } else { |
|
| 369 | + } else { |
|
| 370 | 370 | copy($from . '/' . $file, $to . '/' . $file); |
| 371 | - } |
|
| 371 | + } |
|
| 372 | + } |
|
| 372 | 373 | } |
| 373 | - } |
|
| 374 | 374 | |
| 375 | - /** |
|
| 376 | - * Translit function |
|
| 377 | - * |
|
| 378 | - * @param string $str |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - public static function translit($str) { |
|
| 375 | + /** |
|
| 376 | + * Translit function |
|
| 377 | + * |
|
| 378 | + * @param string $str |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + public static function translit($str) { |
|
| 382 | 382 | $rus = array('А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я'); |
| 383 | 383 | $lat = array('A', 'B', 'V', 'G', 'D', 'E', 'E', 'Gh', 'Z', 'I', 'Y', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'H', 'C', 'Ch', 'Sh', 'Sch', 'Y', 'Y', 'Y', 'E', 'Yu', 'Ya', 'a', 'b', 'v', 'g', 'd', 'e', 'e', 'gh', 'z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh', 'sch', 'y', 'y', 'y', 'e', 'yu', 'ya'); |
| 384 | 384 | return str_replace($rus, $lat, $str); |
| 385 | - } |
|
| 385 | + } |
|
| 386 | 386 | |
| 387 | - /** |
|
| 388 | - * get youtube video ID from URL |
|
| 389 | - * |
|
| 390 | - * @author http://stackoverflow.com/a/6556662 |
|
| 391 | - * @param string $url |
|
| 392 | - * @return string Youtube video id or FALSE if none found. |
|
| 393 | - */ |
|
| 394 | - public static function youtubeIdFromUrl($url) { |
|
| 387 | + /** |
|
| 388 | + * get youtube video ID from URL |
|
| 389 | + * |
|
| 390 | + * @author http://stackoverflow.com/a/6556662 |
|
| 391 | + * @param string $url |
|
| 392 | + * @return string Youtube video id or FALSE if none found. |
|
| 393 | + */ |
|
| 394 | + public static function youtubeIdFromUrl($url) { |
|
| 395 | 395 | $pattern = '%^# Match any youtube URL |
| 396 | 396 | (?:https?://)? # Optional scheme. Either http or https |
| 397 | 397 | (?:www\.)? # Optional www subdomain |
@@ -409,20 +409,20 @@ discard block |
||
| 409 | 409 | ; |
| 410 | 410 | $result = preg_match($pattern, $url, $matches); |
| 411 | 411 | if (false !== $result) { |
| 412 | - return $matches[1]; |
|
| 412 | + return $matches[1]; |
|
| 413 | 413 | } |
| 414 | 414 | return false; |
| 415 | - } |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | - /** |
|
| 418 | - * check array is associative |
|
| 419 | - * |
|
| 420 | - * @author http://stackoverflow.com/a/173479 |
|
| 421 | - * @param array $arr |
|
| 422 | - * @return boolean |
|
| 423 | - */ |
|
| 424 | - public static function isAssoc(&$arr) { |
|
| 417 | + /** |
|
| 418 | + * check array is associative |
|
| 419 | + * |
|
| 420 | + * @author http://stackoverflow.com/a/173479 |
|
| 421 | + * @param array $arr |
|
| 422 | + * @return boolean |
|
| 423 | + */ |
|
| 424 | + public static function isAssoc(&$arr) { |
|
| 425 | 425 | return array_keys($arr) !== range(0, count($arr) - 1); |
| 426 | - } |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | 428 | } |
@@ -13,52 +13,52 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Slide extends \Model { |
| 15 | 15 | |
| 16 | - public static $objectName = "Слайд"; |
|
| 17 | - public static $cols = [ |
|
| 18 | - 'name' => ['type' => 'text'], |
|
| 19 | - 'link' => ['type' => 'text'], |
|
| 20 | - 'description' => ['type' => 'html'], |
|
| 21 | - 'image_file_id' => ['type' => 'image'], |
|
| 22 | - 'preview_image_file_id' => ['type' => 'image'], |
|
| 23 | - 'slider_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'slider'], |
|
| 24 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
| 25 | - 'weight' => ['type' => 'number'], |
|
| 26 | - 'date_create' => ['type' => 'dateTime'], |
|
| 27 | - ]; |
|
| 28 | - public static $labels = [ |
|
| 29 | - 'name' => 'Имя', |
|
| 30 | - 'link' => 'Ссылка', |
|
| 31 | - 'description' => 'Описание', |
|
| 32 | - 'date_create' => 'Дата создания', |
|
| 33 | - 'slider_id' => 'Слайдер', |
|
| 34 | - 'user_id' => 'Создатель', |
|
| 35 | - 'weight' => 'Вес', |
|
| 36 | - 'image_file_id' => 'Изображение', |
|
| 37 | - 'preview_image_file_id' => 'Превью Изображения', |
|
| 38 | - ]; |
|
| 39 | - public static $dataManagers = [ |
|
| 40 | - 'manager' => [ |
|
| 41 | - 'name' => 'Слайды', |
|
| 42 | - 'cols' => [ |
|
| 43 | - 'image_file_id', 'name', 'link', 'date_create' |
|
| 44 | - ], |
|
| 45 | - 'filters' => [ |
|
| 46 | - 'slider_id', 'name', 'link', 'description', 'date_create' |
|
| 47 | - ], |
|
| 48 | - 'sortMode' => true |
|
| 49 | - ], |
|
| 50 | - ]; |
|
| 51 | - public static $forms = [ |
|
| 52 | - 'manager' => [ |
|
| 53 | - 'map' => [ |
|
| 54 | - ['name', 'link'], |
|
| 55 | - ['preview_image_file_id', 'image_file_id'], |
|
| 56 | - ['description'], |
|
| 57 | - ], |
|
| 58 | - ], |
|
| 59 | - ]; |
|
| 16 | + public static $objectName = "Слайд"; |
|
| 17 | + public static $cols = [ |
|
| 18 | + 'name' => ['type' => 'text'], |
|
| 19 | + 'link' => ['type' => 'text'], |
|
| 20 | + 'description' => ['type' => 'html'], |
|
| 21 | + 'image_file_id' => ['type' => 'image'], |
|
| 22 | + 'preview_image_file_id' => ['type' => 'image'], |
|
| 23 | + 'slider_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'slider'], |
|
| 24 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
| 25 | + 'weight' => ['type' => 'number'], |
|
| 26 | + 'date_create' => ['type' => 'dateTime'], |
|
| 27 | + ]; |
|
| 28 | + public static $labels = [ |
|
| 29 | + 'name' => 'Имя', |
|
| 30 | + 'link' => 'Ссылка', |
|
| 31 | + 'description' => 'Описание', |
|
| 32 | + 'date_create' => 'Дата создания', |
|
| 33 | + 'slider_id' => 'Слайдер', |
|
| 34 | + 'user_id' => 'Создатель', |
|
| 35 | + 'weight' => 'Вес', |
|
| 36 | + 'image_file_id' => 'Изображение', |
|
| 37 | + 'preview_image_file_id' => 'Превью Изображения', |
|
| 38 | + ]; |
|
| 39 | + public static $dataManagers = [ |
|
| 40 | + 'manager' => [ |
|
| 41 | + 'name' => 'Слайды', |
|
| 42 | + 'cols' => [ |
|
| 43 | + 'image_file_id', 'name', 'link', 'date_create' |
|
| 44 | + ], |
|
| 45 | + 'filters' => [ |
|
| 46 | + 'slider_id', 'name', 'link', 'description', 'date_create' |
|
| 47 | + ], |
|
| 48 | + 'sortMode' => true |
|
| 49 | + ], |
|
| 50 | + ]; |
|
| 51 | + public static $forms = [ |
|
| 52 | + 'manager' => [ |
|
| 53 | + 'map' => [ |
|
| 54 | + ['name', 'link'], |
|
| 55 | + ['preview_image_file_id', 'image_file_id'], |
|
| 56 | + ['description'], |
|
| 57 | + ], |
|
| 58 | + ], |
|
| 59 | + ]; |
|
| 60 | 60 | |
| 61 | - public static function relations() { |
|
| 61 | + public static function relations() { |
|
| 62 | 62 | return [ |
| 63 | 63 | 'slider' => [ |
| 64 | 64 | 'model' => 'Sliders\Slider', |
@@ -77,6 +77,6 @@ discard block |
||
| 77 | 77 | 'col' => 'user_id' |
| 78 | 78 | ] |
| 79 | 79 | ]; |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | } |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | |
| 14 | 14 | class Type extends \Model { |
| 15 | 15 | |
| 16 | - public static $cols = [ |
|
| 17 | - 'dir' => ['type' => 'text'], |
|
| 18 | - 'ext' => ['type' => 'text'], |
|
| 19 | - 'group' => ['type' => 'text'], |
|
| 20 | - 'allow_resize' => ['type' => 'bool'], |
|
| 21 | - 'options' => ['type' => 'textarea'], |
|
| 22 | - 'date_create' => ['type' => 'dateTime'], |
|
| 23 | - ]; |
|
| 16 | + public static $cols = [ |
|
| 17 | + 'dir' => ['type' => 'text'], |
|
| 18 | + 'ext' => ['type' => 'text'], |
|
| 19 | + 'group' => ['type' => 'text'], |
|
| 20 | + 'allow_resize' => ['type' => 'bool'], |
|
| 21 | + 'options' => ['type' => 'textarea'], |
|
| 22 | + 'date_create' => ['type' => 'dateTime'], |
|
| 23 | + ]; |
|
| 24 | 24 | |
| 25 | 25 | } |
@@ -10,58 +10,58 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class Files extends Module { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Загрузка файлов |
|
| 15 | - * |
|
| 16 | - * $file - масив из переменной $_FILES[{input name}] |
|
| 17 | - * $options - массив из опций заливки |
|
| 18 | - * -- [file_code]: уникальный код для системы медиаданых |
|
| 19 | - * -- [allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext) |
|
| 20 | - */ |
|
| 21 | - public function upload($file, $options = []) { |
|
| 13 | + /** |
|
| 14 | + * Загрузка файлов |
|
| 15 | + * |
|
| 16 | + * $file - масив из переменной $_FILES[{input name}] |
|
| 17 | + * $options - массив из опций заливки |
|
| 18 | + * -- [file_code]: уникальный код для системы медиаданых |
|
| 19 | + * -- [allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext) |
|
| 20 | + */ |
|
| 21 | + public function upload($file, $options = []) { |
|
| 22 | 22 | |
| 23 | 23 | $sitePath = App::$primary->path; |
| 24 | 24 | |
| 25 | 25 | if (!is_uploaded_file($file['tmp_name'])) |
| 26 | - return 0; |
|
| 26 | + return 0; |
|
| 27 | 27 | |
| 28 | 28 | $fileinfo = pathinfo($file['name']); |
| 29 | 29 | if (empty($fileinfo['extension'])) |
| 30 | - return 0; |
|
| 30 | + return 0; |
|
| 31 | 31 | |
| 32 | 32 | $type = Files\Type::get($fileinfo['extension'], 'ext'); |
| 33 | 33 | if (!$type) |
| 34 | - return 0; |
|
| 34 | + return 0; |
|
| 35 | 35 | |
| 36 | 36 | if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) { |
| 37 | - return 0; |
|
| 37 | + return 0; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $fileObject = new Files\File(); |
| 41 | 41 | if (!empty($options['file_code'])) { |
| 42 | - $fileObject = Files\File::get($options['file_code'], 'code'); |
|
| 43 | - if (!$fileObject) { |
|
| 42 | + $fileObject = Files\File::get($options['file_code'], 'code'); |
|
| 43 | + if (!$fileObject) { |
|
| 44 | 44 | $fileObject = new Files\File(); |
| 45 | 45 | $fileObject->code = $options['file_code']; |
| 46 | - } |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | $fileObject->name = $fileinfo['filename']; |
| 49 | 49 | $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension']; |
| 50 | 50 | if ($fileObject->id && file_exists($sitePath . $fileObject->path)) |
| 51 | - unlink($sitePath . $fileObject->path); |
|
| 51 | + unlink($sitePath . $fileObject->path); |
|
| 52 | 52 | |
| 53 | 53 | Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/'); |
| 54 | 54 | |
| 55 | 55 | if (!move_uploaded_file($file['tmp_name'], $sitePath . $fileObject->path)) { |
| 56 | - return false; |
|
| 56 | + return false; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | if ($type->allow_resize && $type->options && json_decode($type->options, true)) { |
| 60 | - $typeOptions = json_decode($type->options, true); |
|
| 61 | - list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path); |
|
| 62 | - if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) { |
|
| 60 | + $typeOptions = json_decode($type->options, true); |
|
| 61 | + list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path); |
|
| 62 | + if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) { |
|
| 63 | 63 | Tools::resizeImage($sitePath . $fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']); |
| 64 | - } |
|
| 64 | + } |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $fileObject->type_id = $type->pk(); |
@@ -70,60 +70,60 @@ discard block |
||
| 70 | 70 | $fileObject->save(); |
| 71 | 71 | |
| 72 | 72 | return $fileObject->id; |
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Загрузка файлов по урл |
|
| 77 | - * |
|
| 78 | - * $url - адрес файла |
|
| 79 | - * $options - массив из опций заливки |
|
| 80 | - * -- [file_code]: уникальный код для системы медиаданых |
|
| 81 | - * -- [allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext) |
|
| 82 | - */ |
|
| 83 | - public function uploadFromUrl($url, $options = []) { |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Загрузка файлов по урл |
|
| 77 | + * |
|
| 78 | + * $url - адрес файла |
|
| 79 | + * $options - массив из опций заливки |
|
| 80 | + * -- [file_code]: уникальный код для системы медиаданых |
|
| 81 | + * -- [allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext) |
|
| 82 | + */ |
|
| 83 | + public function uploadFromUrl($url, $options = []) { |
|
| 84 | 84 | $sitePath = App::$primary->path; |
| 85 | 85 | |
| 86 | 86 | $fileinfo = pathinfo($url); |
| 87 | 87 | if (empty($fileinfo['extension'])) |
| 88 | - return 0; |
|
| 88 | + return 0; |
|
| 89 | 89 | |
| 90 | 90 | $type = Files\Type::get($fileinfo['extension'], 'ext'); |
| 91 | 91 | if (!$type) |
| 92 | - return 0; |
|
| 92 | + return 0; |
|
| 93 | 93 | |
| 94 | 94 | if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) { |
| 95 | - return 0; |
|
| 95 | + return 0; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | $fileObject = new Files\File(); |
| 99 | 99 | if (!empty($options['file_code'])) { |
| 100 | - $fileObject = Files\File::get($options['file_code'], 'code'); |
|
| 101 | - if (!$fileObject) { |
|
| 100 | + $fileObject = Files\File::get($options['file_code'], 'code'); |
|
| 101 | + if (!$fileObject) { |
|
| 102 | 102 | $fileObject = new Files\File(); |
| 103 | 103 | $fileObject->code = $options['file_code']; |
| 104 | - } |
|
| 104 | + } |
|
| 105 | 105 | } |
| 106 | 106 | $fileObject->name = $fileinfo['filename']; |
| 107 | 107 | $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension']; |
| 108 | 108 | if ($fileObject->id && file_exists($sitePath . $fileObject->path)) |
| 109 | - unlink($sitePath . $fileObject->path); |
|
| 109 | + unlink($sitePath . $fileObject->path); |
|
| 110 | 110 | |
| 111 | 111 | Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/'); |
| 112 | 112 | |
| 113 | 113 | $file = @file_get_contents($url); |
| 114 | 114 | if ($file === false) { |
| 115 | - return 0; |
|
| 115 | + return 0; |
|
| 116 | 116 | } |
| 117 | 117 | if (!file_put_contents($sitePath . $fileObject->path, $file)) { |
| 118 | - return 0; |
|
| 118 | + return 0; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | if ($type->allow_resize && $type->options && json_decode($type->options, true)) { |
| 122 | - $typeOptions = json_decode($type->options, true); |
|
| 123 | - list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path); |
|
| 124 | - if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) { |
|
| 122 | + $typeOptions = json_decode($type->options, true); |
|
| 123 | + list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path); |
|
| 124 | + if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) { |
|
| 125 | 125 | Tools::resizeImage($sitePath . $fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']); |
| 126 | - } |
|
| 126 | + } |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $fileObject->type_id = $type->pk(); |
@@ -132,6 +132,6 @@ discard block |
||
| 132 | 132 | $fileObject->save(); |
| 133 | 133 | |
| 134 | 134 | return $fileObject->id; |
| 135 | - } |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | 137 | } |
@@ -13,30 +13,30 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Mysql extends \Object { |
| 15 | 15 | |
| 16 | - public $config = []; // настройки подключения выбраной базы |
|
| 17 | - public $connect = FALSE; // ярлык соединения с MySQL |
|
| 18 | - public $encoding = 'utf-8'; // установленная кодировка |
|
| 19 | - public $db_name = 'test'; // выбраная в данный момент база |
|
| 20 | - public $table_prefix = 'inji_'; // префикс названий таблиц |
|
| 21 | - public $pdo = NULL; |
|
| 22 | - public $lastQuery = ''; |
|
| 23 | - public $last_error = ''; |
|
| 24 | - public $noConnectAbort = false; |
|
| 25 | - public $dbInstance = null; |
|
| 16 | + public $config = []; // настройки подключения выбраной базы |
|
| 17 | + public $connect = FALSE; // ярлык соединения с MySQL |
|
| 18 | + public $encoding = 'utf-8'; // установленная кодировка |
|
| 19 | + public $db_name = 'test'; // выбраная в данный момент база |
|
| 20 | + public $table_prefix = 'inji_'; // префикс названий таблиц |
|
| 21 | + public $pdo = NULL; |
|
| 22 | + public $lastQuery = ''; |
|
| 23 | + public $last_error = ''; |
|
| 24 | + public $noConnectAbort = false; |
|
| 25 | + public $dbInstance = null; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Подключение к MySQL |
|
| 29 | - */ |
|
| 30 | - public function init($connect_options) { |
|
| 27 | + /** |
|
| 28 | + * Подключение к MySQL |
|
| 29 | + */ |
|
| 30 | + public function init($connect_options) { |
|
| 31 | 31 | extract($connect_options); |
| 32 | 32 | if (isset($db_name)) |
| 33 | - $this->db_name = $db_name; |
|
| 33 | + $this->db_name = $db_name; |
|
| 34 | 34 | if (isset($encoding)) |
| 35 | - $this->encoding = $encoding; |
|
| 35 | + $this->encoding = $encoding; |
|
| 36 | 36 | if (isset($table_prefix)) |
| 37 | - $this->table_prefix = $table_prefix; |
|
| 37 | + $this->table_prefix = $table_prefix; |
|
| 38 | 38 | if (isset($noConnectAbort)) |
| 39 | - $this->noConnectAbort = $noConnectAbort; |
|
| 39 | + $this->noConnectAbort = $noConnectAbort; |
|
| 40 | 40 | |
| 41 | 41 | $dsn = "mysql:host=$host;port=$port;dbname=$db_name;charset=$encoding"; |
| 42 | 42 | $dt = new \DateTime(); |
@@ -50,21 +50,21 @@ discard block |
||
| 50 | 50 | $this->pdo = new \PDO($dsn, $user, $pass, $opt); |
| 51 | 51 | $error = $this->pdo->errorInfo(); |
| 52 | 52 | if ((int) $error[0]) { |
| 53 | - if ($this->noConnectAbort) { |
|
| 53 | + if ($this->noConnectAbort) { |
|
| 54 | 54 | return false; |
| 55 | - } else { |
|
| 55 | + } else { |
|
| 56 | 56 | INJI_SYSTEM_ERROR($error[2], true); |
| 57 | - } |
|
| 57 | + } |
|
| 58 | 58 | } else { |
| 59 | - $this->connect = true; |
|
| 60 | - $query = new Mysql\Query($this); |
|
| 61 | - $query->query("SET SQL_BIG_SELECTS=1"); |
|
| 62 | - $query->query("SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
| 63 | - return true; |
|
| 59 | + $this->connect = true; |
|
| 60 | + $query = new Mysql\Query($this); |
|
| 61 | + $query->query("SET SQL_BIG_SELECTS=1"); |
|
| 62 | + $query->query("SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
| 63 | + return true; |
|
| 64 | + } |
|
| 64 | 65 | } |
| 65 | - } |
|
| 66 | 66 | |
| 67 | - public function getTableCols($table_name) { |
|
| 67 | + public function getTableCols($table_name) { |
|
| 68 | 68 | $query = new Mysql\Query($this); |
| 69 | 69 | $old_db = $this->db_name; |
| 70 | 70 | $old_prefix = $this->table_prefix; |
@@ -77,35 +77,35 @@ discard block |
||
| 77 | 77 | $this->db_name = $old_db; |
| 78 | 78 | $this->table_prefix = $old_prefix; |
| 79 | 79 | return $result->getArray('COLUMN_NAME'); |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public function tableExist($tableName) { |
|
| 82 | + public function tableExist($tableName) { |
|
| 83 | 83 | $query = new Mysql\Query($this); |
| 84 | 84 | return (bool) $query->query("SHOW TABLES FROM `{$this->db_name}` LIKE '{$this->table_prefix}{$tableName}'")->getArray(); |
| 85 | - } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - public function addCol($table = false, $name = false, $param = 'TEXT NOT NULL') { |
|
| 87 | + public function addCol($table = false, $name = false, $param = 'TEXT NOT NULL') { |
|
| 88 | 88 | if (!$table || !$name) { |
| 89 | - return false; |
|
| 89 | + return false; |
|
| 90 | 90 | } |
| 91 | 91 | if ($param == 'pk') { |
| 92 | - $param = "int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`{$name}`)"; |
|
| 92 | + $param = "int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`{$name}`)"; |
|
| 93 | 93 | } |
| 94 | 94 | $query = new Mysql\Query($this); |
| 95 | 95 | return $query->query("ALTER TABLE `{$this->db_name}`.`{$this->table_prefix}{$table}` ADD `{$name}` {$param}"); |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - public function delCol($table = false, $name = false) { |
|
| 98 | + public function delCol($table = false, $name = false) { |
|
| 99 | 99 | if (!$table || !$name) { |
| 100 | - return false; |
|
| 100 | + return false; |
|
| 101 | 101 | } |
| 102 | 102 | $query = new Mysql\Query($this); |
| 103 | 103 | return $query->query("ALTER TABLE `{$this->db_name}`.`{$this->table_prefix}{$table}` DROP `{$name}`"); |
| 104 | - } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - public function getTables() { |
|
| 106 | + public function getTables() { |
|
| 107 | 107 | $query = new Mysql\Query($this); |
| 108 | 108 | return $query->query("SHOW TABLES")->getArray(); |
| 109 | - } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | 111 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | ], '', true); |
| 11 | 11 | $buttons = $dataManager->getButtons($params, $model); |
| 12 | 12 | if ($buttons) { |
| 13 | - ?> |
|
| 13 | + ?> |
|
| 14 | 14 | <h3 class="dataManager-title"><?= $dataManager->name; ?> |
| 15 | 15 | <div class ='pull-right dataManager-managerButtons'> |
| 16 | 16 | <div class="btn-group"> |
@@ -26,13 +26,13 @@ discard block |
||
| 26 | 26 | 'style' => '' |
| 27 | 27 | ]; |
| 28 | 28 | if (!empty($dataManager->managerOptions['categorys'])) { |
| 29 | - $mainCol['style'].='margin-left:260px;'; |
|
| 30 | - echo '<div class ="pull-left dataManager-categorys" style = "width:250px;">'; |
|
| 31 | - $this->widget('Ui\DataManager/categorys', compact('dataManager')); |
|
| 32 | - echo '</div>'; |
|
| 29 | + $mainCol['style'].='margin-left:260px;'; |
|
| 30 | + echo '<div class ="pull-left dataManager-categorys" style = "width:250px;">'; |
|
| 31 | + $this->widget('Ui\DataManager/categorys', compact('dataManager')); |
|
| 32 | + echo '</div>'; |
|
| 33 | 33 | } |
| 34 | 34 | if (!empty($dataManager->managerOptions['filters'])) { |
| 35 | - ?> |
|
| 35 | + ?> |
|
| 36 | 36 | <div class="modal fade" id = "<?= $dataManager->managerId; ?>_filters" > |
| 37 | 37 | <div class="modal-dialog modal-lg"> |
| 38 | 38 | <div class="modal-content"> |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | continue; |
| 47 | 47 | } |
| 48 | 48 | if(++$i && !($i%2)){ |
| 49 | - echo '</div><div class="row">'; |
|
| 49 | + echo '</div><div class="row">'; |
|
| 50 | 50 | } |
| 51 | 51 | echo '<div class="col-md-6">'; |
| 52 | 52 | if (!empty($colInfo['colParams']['type'])) { |
@@ -139,40 +139,40 @@ discard block |
||
| 139 | 139 | ?> |
| 140 | 140 | <div class="filter_form_field filter_select"> |
| 141 | 141 | <?php |
| 142 | - if (!empty($_GET['datamanagerFilters'][$col]['value'])) { |
|
| 143 | - $value = 1; |
|
| 144 | - } elseif (isset($_GET['datamanagerFilters'][$col]['value'])) { |
|
| 145 | - $value = 0; |
|
| 146 | - } else { |
|
| 147 | - $value = ''; |
|
| 148 | - } |
|
| 149 | - $inputOptions = ['value' => $value, 'values' => [ |
|
| 150 | - '' => 'Не важно', |
|
| 151 | - '1' => $colInfo['label'], |
|
| 152 | - '0' => 'Нет' |
|
| 153 | - ] |
|
| 154 | - ]; |
|
| 155 | - if (!empty($dataManager->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'][$col])) { |
|
| 142 | + if (!empty($_GET['datamanagerFilters'][$col]['value'])) { |
|
| 143 | + $value = 1; |
|
| 144 | + } elseif (isset($_GET['datamanagerFilters'][$col]['value'])) { |
|
| 145 | + $value = 0; |
|
| 146 | + } else { |
|
| 147 | + $value = ''; |
|
| 148 | + } |
|
| 149 | + $inputOptions = ['value' => $value, 'values' => [ |
|
| 150 | + '' => 'Не важно', |
|
| 151 | + '1' => $colInfo['label'], |
|
| 152 | + '0' => 'Нет' |
|
| 153 | + ] |
|
| 154 | + ]; |
|
| 155 | + if (!empty($dataManager->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'][$col])) { |
|
| 156 | 156 | |
| 157 | - $inputOptions['disabled'] = true; |
|
| 158 | - $colOptions = $dataManager->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'][$col]; |
|
| 159 | - if (!empty($colOptions['userCol'])) { |
|
| 160 | - if (strpos($colOptions['userCol'], ':')) { |
|
| 161 | - $rel = substr($colOptions['userCol'], 0, strpos($colOptions['userCol'], ':')); |
|
| 162 | - $param = substr($colOptions['userCol'], strpos($colOptions['userCol'], ':') + 1); |
|
| 157 | + $inputOptions['disabled'] = true; |
|
| 158 | + $colOptions = $dataManager->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'][$col]; |
|
| 159 | + if (!empty($colOptions['userCol'])) { |
|
| 160 | + if (strpos($colOptions['userCol'], ':')) { |
|
| 161 | + $rel = substr($colOptions['userCol'], 0, strpos($colOptions['userCol'], ':')); |
|
| 162 | + $param = substr($colOptions['userCol'], strpos($colOptions['userCol'], ':') + 1); |
|
| 163 | 163 | |
| 164 | - $inputOptions['value'] = \Users\User::$cur->$rel->$param; |
|
| 165 | - } else { |
|
| 166 | - $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
| 167 | - } |
|
| 168 | - } elseif (!empty($colOptions['value'])) { |
|
| 164 | + $inputOptions['value'] = \Users\User::$cur->$rel->$param; |
|
| 165 | + } else { |
|
| 166 | + $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
| 167 | + } |
|
| 168 | + } elseif (!empty($colOptions['value'])) { |
|
| 169 | 169 | |
| 170 | - $inputOptions['value'] = $colOptions['value']; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - $inputOptions['class'] = 'input-sm'; |
|
| 174 | - $form->input('select', "datamanagerFilters[{$col}][value]", $colInfo['label'], $inputOptions); |
|
| 175 | - ?> |
|
| 170 | + $inputOptions['value'] = $colOptions['value']; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + $inputOptions['class'] = 'input-sm'; |
|
| 174 | + $form->input('select', "datamanagerFilters[{$col}][value]", $colInfo['label'], $inputOptions); |
|
| 175 | + ?> |
|
| 176 | 176 | </div> |
| 177 | 177 | |
| 178 | 178 | <?php |
@@ -13,99 +13,99 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Material extends \Model { |
| 15 | 15 | |
| 16 | - public static $objectName = 'Материал'; |
|
| 17 | - public static $categoryModel = 'Materials\Category'; |
|
| 18 | - public static $labels = [ |
|
| 19 | - 'name' => 'Заголовок', |
|
| 20 | - 'category_id' => 'Раздел', |
|
| 21 | - 'preview' => 'Краткое превью', |
|
| 22 | - 'text' => 'Текст страницы', |
|
| 23 | - 'alias' => 'Алиас страницы', |
|
| 24 | - 'template' => 'Шаблон сайта', |
|
| 25 | - 'viewer' => 'Тип страницы', |
|
| 26 | - 'image_file_id' => 'Фото материала', |
|
| 27 | - 'description' => 'Описание для поисковиков', |
|
| 28 | - 'keywords' => 'Ключевые слова', |
|
| 29 | - 'user_id' => 'Создатель', |
|
| 30 | - 'date_create' => 'Дата создания', |
|
| 31 | - 'tag_list' => 'Теги' |
|
| 32 | - ]; |
|
| 33 | - public static $dataManagers = [ |
|
| 34 | - 'manager' => [ |
|
| 35 | - 'cols' => [ |
|
| 36 | - 'name', |
|
| 37 | - 'alias', |
|
| 38 | - 'category_id', |
|
| 39 | - 'date_create', |
|
| 40 | - 'tag_list' |
|
| 41 | - ], |
|
| 42 | - 'sortable' => [ |
|
| 43 | - 'name', |
|
| 44 | - 'alias', |
|
| 45 | - 'category_id', |
|
| 46 | - 'date_create' |
|
| 47 | - ], |
|
| 48 | - 'filters' => [ |
|
| 49 | - 'name', |
|
| 50 | - 'preview', |
|
| 51 | - 'text', |
|
| 52 | - 'alias', |
|
| 53 | - 'template', |
|
| 54 | - 'viewer', |
|
| 55 | - 'description', |
|
| 56 | - 'keywords', |
|
| 57 | - 'user_id', |
|
| 58 | - 'date_create' |
|
| 59 | - ], |
|
| 60 | - 'categorys' => [ |
|
| 61 | - 'model' => 'Materials\Category', |
|
| 62 | - ], |
|
| 63 | - 'sortMode' => true |
|
| 64 | - ] |
|
| 65 | - ]; |
|
| 66 | - public static $cols = [ |
|
| 67 | - 'name' => ['type' => 'text'], |
|
| 68 | - 'alias' => ['type' => 'text'], |
|
| 69 | - 'preview' => ['type' => 'html'], |
|
| 70 | - 'text' => ['type' => 'html'], |
|
| 71 | - 'keywords' => ['type' => 'text'], |
|
| 72 | - 'description' => ['type' => 'text'], |
|
| 73 | - 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
| 74 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
| 75 | - 'template' => ['type' => 'select', 'source' => 'method', 'method' => 'templatesList', 'module' => 'Materials'], |
|
| 76 | - 'viewer' => ['type' => 'select', 'source' => 'method', 'method' => 'viewsList', 'module' => 'Materials'], |
|
| 77 | - 'default' => ['type' => 'bool'], |
|
| 78 | - 'hidden' => ['type' => 'bool'], |
|
| 79 | - 'image_file_id' => ['type' => 'image'], |
|
| 80 | - 'link' => ['type' => 'dataManager', 'relation' => 'links'], |
|
| 81 | - 'tree_path' => ['type' => 'text'], |
|
| 82 | - 'weight' => ['type' => 'number'], |
|
| 83 | - 'date_create' => ['type' => 'dateTime'], |
|
| 84 | - 'tag_list' => ['type' => 'text'], |
|
| 85 | - ]; |
|
| 86 | - public static $forms = [ |
|
| 87 | - 'manager' => [ |
|
| 88 | - 'options' => [ |
|
| 89 | - 'access' => [ |
|
| 90 | - 'groups' => [ |
|
| 91 | - 3 |
|
| 92 | - ] |
|
| 93 | - ] |
|
| 94 | - ], |
|
| 95 | - 'map' => [ |
|
| 96 | - ['name', 'category_id'], |
|
| 97 | - ['alias', 'image_file_id'], |
|
| 98 | - ['template', 'viewer'], |
|
| 99 | - ['keywords', 'description'], |
|
| 100 | - ['tag_list'], |
|
| 101 | - ['preview'], |
|
| 102 | - ['text'], |
|
| 103 | - ['link'], |
|
| 104 | - ] |
|
| 105 | - ] |
|
| 106 | - ]; |
|
| 16 | + public static $objectName = 'Материал'; |
|
| 17 | + public static $categoryModel = 'Materials\Category'; |
|
| 18 | + public static $labels = [ |
|
| 19 | + 'name' => 'Заголовок', |
|
| 20 | + 'category_id' => 'Раздел', |
|
| 21 | + 'preview' => 'Краткое превью', |
|
| 22 | + 'text' => 'Текст страницы', |
|
| 23 | + 'alias' => 'Алиас страницы', |
|
| 24 | + 'template' => 'Шаблон сайта', |
|
| 25 | + 'viewer' => 'Тип страницы', |
|
| 26 | + 'image_file_id' => 'Фото материала', |
|
| 27 | + 'description' => 'Описание для поисковиков', |
|
| 28 | + 'keywords' => 'Ключевые слова', |
|
| 29 | + 'user_id' => 'Создатель', |
|
| 30 | + 'date_create' => 'Дата создания', |
|
| 31 | + 'tag_list' => 'Теги' |
|
| 32 | + ]; |
|
| 33 | + public static $dataManagers = [ |
|
| 34 | + 'manager' => [ |
|
| 35 | + 'cols' => [ |
|
| 36 | + 'name', |
|
| 37 | + 'alias', |
|
| 38 | + 'category_id', |
|
| 39 | + 'date_create', |
|
| 40 | + 'tag_list' |
|
| 41 | + ], |
|
| 42 | + 'sortable' => [ |
|
| 43 | + 'name', |
|
| 44 | + 'alias', |
|
| 45 | + 'category_id', |
|
| 46 | + 'date_create' |
|
| 47 | + ], |
|
| 48 | + 'filters' => [ |
|
| 49 | + 'name', |
|
| 50 | + 'preview', |
|
| 51 | + 'text', |
|
| 52 | + 'alias', |
|
| 53 | + 'template', |
|
| 54 | + 'viewer', |
|
| 55 | + 'description', |
|
| 56 | + 'keywords', |
|
| 57 | + 'user_id', |
|
| 58 | + 'date_create' |
|
| 59 | + ], |
|
| 60 | + 'categorys' => [ |
|
| 61 | + 'model' => 'Materials\Category', |
|
| 62 | + ], |
|
| 63 | + 'sortMode' => true |
|
| 64 | + ] |
|
| 65 | + ]; |
|
| 66 | + public static $cols = [ |
|
| 67 | + 'name' => ['type' => 'text'], |
|
| 68 | + 'alias' => ['type' => 'text'], |
|
| 69 | + 'preview' => ['type' => 'html'], |
|
| 70 | + 'text' => ['type' => 'html'], |
|
| 71 | + 'keywords' => ['type' => 'text'], |
|
| 72 | + 'description' => ['type' => 'text'], |
|
| 73 | + 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
| 74 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
| 75 | + 'template' => ['type' => 'select', 'source' => 'method', 'method' => 'templatesList', 'module' => 'Materials'], |
|
| 76 | + 'viewer' => ['type' => 'select', 'source' => 'method', 'method' => 'viewsList', 'module' => 'Materials'], |
|
| 77 | + 'default' => ['type' => 'bool'], |
|
| 78 | + 'hidden' => ['type' => 'bool'], |
|
| 79 | + 'image_file_id' => ['type' => 'image'], |
|
| 80 | + 'link' => ['type' => 'dataManager', 'relation' => 'links'], |
|
| 81 | + 'tree_path' => ['type' => 'text'], |
|
| 82 | + 'weight' => ['type' => 'number'], |
|
| 83 | + 'date_create' => ['type' => 'dateTime'], |
|
| 84 | + 'tag_list' => ['type' => 'text'], |
|
| 85 | + ]; |
|
| 86 | + public static $forms = [ |
|
| 87 | + 'manager' => [ |
|
| 88 | + 'options' => [ |
|
| 89 | + 'access' => [ |
|
| 90 | + 'groups' => [ |
|
| 91 | + 3 |
|
| 92 | + ] |
|
| 93 | + ] |
|
| 94 | + ], |
|
| 95 | + 'map' => [ |
|
| 96 | + ['name', 'category_id'], |
|
| 97 | + ['alias', 'image_file_id'], |
|
| 98 | + ['template', 'viewer'], |
|
| 99 | + ['keywords', 'description'], |
|
| 100 | + ['tag_list'], |
|
| 101 | + ['preview'], |
|
| 102 | + ['text'], |
|
| 103 | + ['link'], |
|
| 104 | + ] |
|
| 105 | + ] |
|
| 106 | + ]; |
|
| 107 | 107 | |
| 108 | - public static function relations() { |
|
| 108 | + public static function relations() { |
|
| 109 | 109 | return [ |
| 110 | 110 | 'category' => [ |
| 111 | 111 | 'model' => '\Materials\Category', |
@@ -125,43 +125,43 @@ discard block |
||
| 125 | 125 | 'col' => 'material_id' |
| 126 | 126 | ] |
| 127 | 127 | ]; |
| 128 | - } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - public function getHref() { |
|
| 130 | + public function getHref() { |
|
| 131 | 131 | $href = !empty(\App::$primary->config['defaultModule']) && \App::$primary->config['defaultModule'] == 'Materials' ? '' : '/materials'; |
| 132 | 132 | $treePath = array_filter(explode('/', $this->tree_path)); |
| 133 | 133 | if ($treePath) { |
| 134 | - $categorys = Category::getList(['where' => ['id', implode(',', $treePath), 'IN']]); |
|
| 135 | - foreach ($categorys as $category) { |
|
| 134 | + $categorys = Category::getList(['where' => ['id', implode(',', $treePath), 'IN']]); |
|
| 135 | + foreach ($categorys as $category) { |
|
| 136 | 136 | if ($category->alias) { |
| 137 | - $href .="/{$category->alias}"; |
|
| 137 | + $href .="/{$category->alias}"; |
|
| 138 | + } |
|
| 138 | 139 | } |
| 139 | - } |
|
| 140 | 140 | } |
| 141 | 141 | if ((!$href || $href == '/materials') && !$this->alias) { |
| 142 | - return ($href ? $href : '/materials') . '/view/' . $this->pk(); |
|
| 142 | + return ($href ? $href : '/materials') . '/view/' . $this->pk(); |
|
| 143 | 143 | } |
| 144 | 144 | return $href . "/" . ($this->alias ? $this->alias : $this->pk()); |
| 145 | - } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - public function resolveTemplate() { |
|
| 147 | + public function resolveTemplate() { |
|
| 148 | 148 | if ($this->template !== 'inherit') { |
| 149 | - return $this->template; |
|
| 149 | + return $this->template; |
|
| 150 | 150 | } elseif ($this->template == 'inherit' && $this->category) { |
| 151 | - return $this->category->resolveTemplate(true); |
|
| 151 | + return $this->category->resolveTemplate(true); |
|
| 152 | 152 | } else { |
| 153 | - return 'current'; |
|
| 153 | + return 'current'; |
|
| 154 | + } |
|
| 154 | 155 | } |
| 155 | - } |
|
| 156 | 156 | |
| 157 | - public function resolveViewer() { |
|
| 157 | + public function resolveViewer() { |
|
| 158 | 158 | if ($this->viewer !== 'inherit') { |
| 159 | - return $this->viewer; |
|
| 159 | + return $this->viewer; |
|
| 160 | 160 | } elseif ($this->viewer == 'inherit' && $this->category) { |
| 161 | - return $this->category->resolveViewer(true); |
|
| 161 | + return $this->category->resolveViewer(true); |
|
| 162 | 162 | } else { |
| 163 | - return 'default'; |
|
| 163 | + return 'default'; |
|
| 164 | + } |
|
| 164 | 165 | } |
| 165 | - } |
|
| 166 | 166 | |
| 167 | 167 | } |
@@ -13,413 +13,413 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class Query extends \Object { |
| 15 | 15 | |
| 16 | - public $curInstance = null; |
|
| 17 | - public $where = []; |
|
| 18 | - public $whereString = ''; |
|
| 19 | - public $having = []; |
|
| 20 | - public $havingString = ''; |
|
| 21 | - public $cols = []; |
|
| 22 | - public $order = NULL; |
|
| 23 | - public $join = []; |
|
| 24 | - public $group = []; |
|
| 25 | - public $limit = ''; |
|
| 26 | - public $error = ''; |
|
| 27 | - public $query = ''; |
|
| 28 | - public $table = ''; |
|
| 29 | - public $operation = ''; |
|
| 30 | - public $indexes = []; |
|
| 31 | - public $params = []; |
|
| 32 | - public $distinct = false; |
|
| 33 | - |
|
| 34 | - public function __construct($instance = null) { |
|
| 16 | + public $curInstance = null; |
|
| 17 | + public $where = []; |
|
| 18 | + public $whereString = ''; |
|
| 19 | + public $having = []; |
|
| 20 | + public $havingString = ''; |
|
| 21 | + public $cols = []; |
|
| 22 | + public $order = NULL; |
|
| 23 | + public $join = []; |
|
| 24 | + public $group = []; |
|
| 25 | + public $limit = ''; |
|
| 26 | + public $error = ''; |
|
| 27 | + public $query = ''; |
|
| 28 | + public $table = ''; |
|
| 29 | + public $operation = ''; |
|
| 30 | + public $indexes = []; |
|
| 31 | + public $params = []; |
|
| 32 | + public $distinct = false; |
|
| 33 | + |
|
| 34 | + public function __construct($instance = null) { |
|
| 35 | 35 | if (!$instance) { |
| 36 | - $this->curInstance = \App::$cur->db->connection; |
|
| 36 | + $this->curInstance = \App::$cur->db->connection; |
|
| 37 | 37 | } else { |
| 38 | - $this->curInstance = $instance; |
|
| 38 | + $this->curInstance = $instance; |
|
| 39 | + } |
|
| 39 | 40 | } |
| 40 | - } |
|
| 41 | 41 | |
| 42 | - public function insert($table, $data) { |
|
| 42 | + public function insert($table, $data) { |
|
| 43 | 43 | $this->operation = 'INSERT'; |
| 44 | 44 | $this->table = $table; |
| 45 | 45 | $this->cols = $data; |
| 46 | 46 | $this->query(); |
| 47 | 47 | return $this->curInstance->pdo->lastInsertId(); |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function select($table) { |
|
| 50 | + public function select($table) { |
|
| 51 | 51 | $this->operation = 'SELECT'; |
| 52 | 52 | $this->table = $table; |
| 53 | 53 | return $this->query(); |
| 54 | - } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function update($table, $data) { |
|
| 56 | + public function update($table, $data) { |
|
| 57 | 57 | $this->operation = 'UPDATE'; |
| 58 | 58 | $this->table = $table; |
| 59 | 59 | $this->cols = $data; |
| 60 | 60 | $result = $this->query(); |
| 61 | 61 | return $result->pdoResult->rowCount(); |
| 62 | - } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public function delete($table) { |
|
| 64 | + public function delete($table) { |
|
| 65 | 65 | $this->operation = 'DELETE'; |
| 66 | 66 | $this->table = $table; |
| 67 | 67 | $result = $this->query(); |
| 68 | 68 | return $result->pdoResult->rowCount(); |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function createTable($table_name, $cols, $indexes = []) { |
|
| 71 | + public function createTable($table_name, $cols, $indexes = []) { |
|
| 72 | 72 | $this->operation = 'CREATE TABLE'; |
| 73 | 73 | $this->table = $table_name; |
| 74 | 74 | $this->cols = $cols; |
| 75 | 75 | $this->indexes = $indexes; |
| 76 | 76 | return $this->query(); |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - public function cols($cols) { |
|
| 79 | + public function cols($cols) { |
|
| 80 | 80 | if (is_array($cols)) { |
| 81 | - $this->cols = array_merge($this->cols, array_values($cols)); |
|
| 81 | + $this->cols = array_merge($this->cols, array_values($cols)); |
|
| 82 | 82 | } else { |
| 83 | - $this->cols[] = $cols; |
|
| 83 | + $this->cols[] = $cols; |
|
| 84 | + } |
|
| 84 | 85 | } |
| 85 | - } |
|
| 86 | 86 | |
| 87 | - public function join($table, $where = false, $type = 'LEFT', $alias = '') { |
|
| 87 | + public function join($table, $where = false, $type = 'LEFT', $alias = '') { |
|
| 88 | 88 | if (is_array($table)) { |
| 89 | - foreach ($table as $item) { |
|
| 89 | + foreach ($table as $item) { |
|
| 90 | 90 | if (!is_array($item)) { |
| 91 | - call_user_func_array(array($this, 'join'), $table); |
|
| 92 | - break; |
|
| 91 | + call_user_func_array(array($this, 'join'), $table); |
|
| 92 | + break; |
|
| 93 | 93 | } else { |
| 94 | - $this->join($item); |
|
| 94 | + $this->join($item); |
|
| 95 | + } |
|
| 95 | 96 | } |
| 96 | - } |
|
| 97 | 97 | } else { |
| 98 | - $this->join[] = [$table, $where, $type, $alias]; |
|
| 98 | + $this->join[] = [$table, $where, $type, $alias]; |
|
| 99 | + } |
|
| 99 | 100 | } |
| 100 | - } |
|
| 101 | 101 | |
| 102 | - public function where($where = '', $value = '', $operation = false, $concatenation = 'AND') { |
|
| 102 | + public function where($where = '', $value = '', $operation = false, $concatenation = 'AND') { |
|
| 103 | 103 | if (!is_array($where)) { |
| 104 | - $this->where[] = [$where, $value, $operation, $concatenation]; |
|
| 104 | + $this->where[] = [$where, $value, $operation, $concatenation]; |
|
| 105 | 105 | } else { |
| 106 | - $this->where[] = $where; |
|
| 106 | + $this->where[] = $where; |
|
| 107 | + } |
|
| 107 | 108 | } |
| 108 | - } |
|
| 109 | 109 | |
| 110 | - public function having($where = '', $value = '', $operation = false, $concatenation = 'AND') { |
|
| 110 | + public function having($where = '', $value = '', $operation = false, $concatenation = 'AND') { |
|
| 111 | 111 | if (!is_array($where)) { |
| 112 | - $this->having[] = [$where, $value, $operation, $concatenation]; |
|
| 112 | + $this->having[] = [$where, $value, $operation, $concatenation]; |
|
| 113 | 113 | } else { |
| 114 | - $this->having[] = $where; |
|
| 114 | + $this->having[] = $where; |
|
| 115 | + } |
|
| 115 | 116 | } |
| 116 | - } |
|
| 117 | 117 | |
| 118 | - public function group($colname) { |
|
| 118 | + public function group($colname) { |
|
| 119 | 119 | $this->group[] = $colname; |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - public function order($order, $type = 'ASC') { |
|
| 122 | + public function order($order, $type = 'ASC') { |
|
| 123 | 123 | |
| 124 | 124 | |
| 125 | 125 | if (!is_array($order)) { |
| 126 | - $this->order[] = "{$order} {$type}"; |
|
| 126 | + $this->order[] = "{$order} {$type}"; |
|
| 127 | 127 | } else { |
| 128 | - foreach ($order as $item) |
|
| 128 | + foreach ($order as $item) |
|
| 129 | 129 | if (!is_array($item)) { |
| 130 | - call_user_func_array(array($this, 'order'), $order); |
|
| 131 | - break; |
|
| 130 | + call_user_func_array(array($this, 'order'), $order); |
|
| 131 | + break; |
|
| 132 | 132 | } else |
| 133 | - $this->order($item); |
|
| 133 | + $this->order($item); |
|
| 134 | + } |
|
| 134 | 135 | } |
| 135 | - } |
|
| 136 | 136 | |
| 137 | - public function limit($start = 0, $len = 0) { |
|
| 137 | + public function limit($start = 0, $len = 0) { |
|
| 138 | 138 | $start = intval($start); |
| 139 | 139 | $len = intval($len); |
| 140 | 140 | $this->limit = "LIMIT {$start}"; |
| 141 | 141 | if ($len !== 0) |
| 142 | - $this->limit .= ",{$len}"; |
|
| 143 | - } |
|
| 142 | + $this->limit .= ",{$len}"; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - public function buildJoin($table, $where = false, $type = 'LEFT', $alias = '') { |
|
| 145 | + public function buildJoin($table, $where = false, $type = 'LEFT', $alias = '') { |
|
| 146 | 146 | $join = ''; |
| 147 | 147 | if (is_array($table)) { |
| 148 | - $joins = func_get_args(); |
|
| 149 | - foreach ($joins as $joinAr) { |
|
| 148 | + $joins = func_get_args(); |
|
| 149 | + foreach ($joins as $joinAr) { |
|
| 150 | 150 | $join .= call_user_func_array([$this, 'buildJoin'], $joinAr); |
| 151 | - } |
|
| 151 | + } |
|
| 152 | 152 | } else { |
| 153 | - $join .= " {$type} JOIN {$this->curInstance->table_prefix}{$table}"; |
|
| 154 | - if ($alias) |
|
| 153 | + $join .= " {$type} JOIN {$this->curInstance->table_prefix}{$table}"; |
|
| 154 | + if ($alias) |
|
| 155 | 155 | $join .= " AS `{$alias}`"; |
| 156 | - if ($where) |
|
| 156 | + if ($where) |
|
| 157 | 157 | $join .= " ON {$where}"; |
| 158 | 158 | } |
| 159 | 159 | return $join; |
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Build where string |
|
| 164 | - * |
|
| 165 | - * @param string|array $where |
|
| 166 | - * @param mixed $value |
|
| 167 | - * @param string $operation |
|
| 168 | - * @param string $concatenation |
|
| 169 | - */ |
|
| 170 | - public function buildWhere($where = '', $value = '', $operation = '=', $concatenation = 'AND') { |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Build where string |
|
| 164 | + * |
|
| 165 | + * @param string|array $where |
|
| 166 | + * @param mixed $value |
|
| 167 | + * @param string $operation |
|
| 168 | + * @param string $concatenation |
|
| 169 | + */ |
|
| 170 | + public function buildWhere($where = '', $value = '', $operation = '=', $concatenation = 'AND') { |
|
| 171 | 171 | if (!is_array($where)) { |
| 172 | - if (empty($operation)) { |
|
| 172 | + if (empty($operation)) { |
|
| 173 | 173 | $operation = '='; |
| 174 | - } |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - if ($concatenation === false) |
|
| 176 | + if ($concatenation === false) |
|
| 177 | 177 | $concatenation = 'AND'; |
| 178 | - elseif ($concatenation === true) |
|
| 178 | + elseif ($concatenation === true) |
|
| 179 | 179 | $concatenation = ''; |
| 180 | 180 | |
| 181 | - if ($this->whereString == NULL) |
|
| 181 | + if ($this->whereString == NULL) |
|
| 182 | 182 | $this->whereString = ' WHERE '; |
| 183 | 183 | |
| 184 | - if (stristr($operation, 'IN') || stristr($operation, 'NOT IN')) { |
|
| 184 | + if (stristr($operation, 'IN') || stristr($operation, 'NOT IN')) { |
|
| 185 | 185 | if (is_array($value)) { |
| 186 | - $newValue = ''; |
|
| 187 | - foreach ($value as $item) { |
|
| 186 | + $newValue = ''; |
|
| 187 | + foreach ($value as $item) { |
|
| 188 | 188 | if ($newValue) { |
| 189 | - $newValue.=','; |
|
| 189 | + $newValue.=','; |
|
| 190 | 190 | } |
| 191 | 191 | if (is_string($item)) { |
| 192 | - $newValue .='"' . $item . '"'; |
|
| 192 | + $newValue .='"' . $item . '"'; |
|
| 193 | 193 | } else { |
| 194 | - $newValue .=$item; |
|
| 194 | + $newValue .=$item; |
|
| 195 | + } |
|
| 195 | 196 | } |
| 196 | - } |
|
| 197 | - $value = '(' . $newValue . ')'; |
|
| 197 | + $value = '(' . $newValue . ')'; |
|
| 198 | 198 | } elseif (!preg_match('!\(!', $value) && !preg_match('![^0-9,\.\(\) ]!', $value)) { |
| 199 | - $value = "({$value})"; |
|
| 199 | + $value = "({$value})"; |
|
| 200 | 200 | } elseif (preg_match('!\(!', $value) && preg_match('![^0-9,\.\(\) ]!', $value)) { |
| 201 | - $value = "\"{$value}\""; |
|
| 201 | + $value = "\"{$value}\""; |
|
| 202 | 202 | } |
| 203 | - } elseif (!in_array($value, array('CURRENT_TIMESTAMP'))) { |
|
| 203 | + } elseif (!in_array($value, array('CURRENT_TIMESTAMP'))) { |
|
| 204 | 204 | $this->params[] = $value; |
| 205 | 205 | $value = "?"; |
| 206 | - } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - if (substr($this->whereString, -1, 1) == '(' || substr($this->whereString, -2, 2) == 'E ') |
|
| 208 | + if (substr($this->whereString, -1, 1) == '(' || substr($this->whereString, -2, 2) == 'E ') |
|
| 209 | 209 | $this->whereString .= " {$where} {$operation} {$value} "; |
| 210 | - else |
|
| 210 | + else |
|
| 211 | 211 | $this->whereString .= "{$concatenation} {$where} {$operation} {$value} "; |
| 212 | 212 | } |
| 213 | 213 | else { |
| 214 | - $i = -1; |
|
| 215 | - while (isset($where[++$i])) { |
|
| 214 | + $i = -1; |
|
| 215 | + while (isset($where[++$i])) { |
|
| 216 | 216 | $item = $where[$i]; |
| 217 | 217 | if (isset($where[$i + 1]) && !isset($where[$i - 1]) && is_array($where[$i])) { |
| 218 | - if ($this->whereString != NULL && substr($this->whereString, -1, 1) != '(' && $this->whereString != 'WHERE ') { |
|
| 218 | + if ($this->whereString != NULL && substr($this->whereString, -1, 1) != '(' && $this->whereString != 'WHERE ') { |
|
| 219 | 219 | if (!isset($item[3])) { |
| 220 | - $concatenation = 'AND'; |
|
| 220 | + $concatenation = 'AND'; |
|
| 221 | 221 | } else { |
| 222 | - $concatenation = $item[3]; |
|
| 222 | + $concatenation = $item[3]; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | $this->whereString .= "{$concatenation} "; |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - if ($this->whereString != NULL) |
|
| 228 | + if ($this->whereString != NULL) |
|
| 229 | 229 | $this->whereString .= '('; |
| 230 | - else |
|
| 230 | + else |
|
| 231 | 231 | $this->whereString = 'WHERE ('; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | if (!is_array($item)) { |
| 235 | - call_user_func_array(array($this, 'buildWhere'), $where); |
|
| 236 | - break; |
|
| 235 | + call_user_func_array(array($this, 'buildWhere'), $where); |
|
| 236 | + break; |
|
| 237 | 237 | } else { |
| 238 | - $this->buildWhere($item); |
|
| 238 | + $this->buildWhere($item); |
|
| 239 | 239 | } |
| 240 | 240 | if (!isset($where[$i + 1]) && isset($where[$i - 1])) { |
| 241 | - $this->whereString .= ') '; |
|
| 241 | + $this->whereString .= ') '; |
|
| 242 | + } |
|
| 242 | 243 | } |
| 243 | - } |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Build having string |
|
| 249 | - * |
|
| 250 | - * @param string|array $where |
|
| 251 | - * @param mixed $value |
|
| 252 | - * @param string $operation |
|
| 253 | - * @param string $concatenation |
|
| 254 | - */ |
|
| 255 | - public function buildHaving($where = '', $value = '', $operation = '=', $concatenation = 'AND') { |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Build having string |
|
| 249 | + * |
|
| 250 | + * @param string|array $where |
|
| 251 | + * @param mixed $value |
|
| 252 | + * @param string $operation |
|
| 253 | + * @param string $concatenation |
|
| 254 | + */ |
|
| 255 | + public function buildHaving($where = '', $value = '', $operation = '=', $concatenation = 'AND') { |
|
| 256 | 256 | if (!is_array($where)) { |
| 257 | - if (empty($operation)) { |
|
| 257 | + if (empty($operation)) { |
|
| 258 | 258 | $operation = '='; |
| 259 | - } |
|
| 260 | - if ($concatenation === false) |
|
| 259 | + } |
|
| 260 | + if ($concatenation === false) |
|
| 261 | 261 | $concatenation = 'AND'; |
| 262 | - elseif ($concatenation === true) |
|
| 262 | + elseif ($concatenation === true) |
|
| 263 | 263 | $concatenation = ''; |
| 264 | 264 | |
| 265 | - if ($this->havingString == NULL) |
|
| 265 | + if ($this->havingString == NULL) |
|
| 266 | 266 | $this->havingString = ' HAVING '; |
| 267 | 267 | |
| 268 | - if (stristr($operation, 'IN') || stristr($operation, 'NOT IN')) { |
|
| 268 | + if (stristr($operation, 'IN') || stristr($operation, 'NOT IN')) { |
|
| 269 | 269 | if (is_array($value)) { |
| 270 | - $newValue = ''; |
|
| 271 | - foreach ($value as $item) { |
|
| 270 | + $newValue = ''; |
|
| 271 | + foreach ($value as $item) { |
|
| 272 | 272 | if ($newValue) { |
| 273 | - $newValue.=','; |
|
| 273 | + $newValue.=','; |
|
| 274 | 274 | } |
| 275 | 275 | if (is_string($item)) { |
| 276 | - $newValue .='"' . $item . '"'; |
|
| 276 | + $newValue .='"' . $item . '"'; |
|
| 277 | 277 | } else { |
| 278 | - $newValue .=$item; |
|
| 278 | + $newValue .=$item; |
|
| 279 | + } |
|
| 279 | 280 | } |
| 280 | - } |
|
| 281 | - $value = '(' . $newValue . ')'; |
|
| 281 | + $value = '(' . $newValue . ')'; |
|
| 282 | 282 | } elseif (!preg_match('!\(!', $value) && !preg_match('![^0-9,\.\(\) ]!', $value)) { |
| 283 | - $value = "({$value})"; |
|
| 283 | + $value = "({$value})"; |
|
| 284 | 284 | } elseif (preg_match('!\(!', $value) && preg_match('![^0-9,\.\(\) ]!', $value)) { |
| 285 | - $value = "\"{$value}\""; |
|
| 285 | + $value = "\"{$value}\""; |
|
| 286 | 286 | } |
| 287 | - } elseif (!in_array($value, array('CURRENT_TIMESTAMP'))) { |
|
| 287 | + } elseif (!in_array($value, array('CURRENT_TIMESTAMP'))) { |
|
| 288 | 288 | $this->params[] = $value; |
| 289 | 289 | $value = "?"; |
| 290 | - } |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - if (substr($this->havingString, -1, 1) == '(' || substr($this->havingString, -2, 2) == 'E ') |
|
| 292 | + if (substr($this->havingString, -1, 1) == '(' || substr($this->havingString, -2, 2) == 'E ') |
|
| 293 | 293 | $this->havingString .= " {$where} {$operation} {$value} "; |
| 294 | - else |
|
| 294 | + else |
|
| 295 | 295 | $this->havingString .= "{$concatenation} {$where} {$operation} {$value} "; |
| 296 | 296 | } |
| 297 | 297 | else { |
| 298 | - $i = -1; |
|
| 299 | - while (isset($where[++$i])) { |
|
| 298 | + $i = -1; |
|
| 299 | + while (isset($where[++$i])) { |
|
| 300 | 300 | $item = $where[$i]; |
| 301 | 301 | if (isset($where[$i + 1]) && !isset($where[$i - 1]) && is_array($where[$i])) { |
| 302 | - if ($this->havingString != NULL && substr($this->havingString, -1, 1) != '(' && $this->havingString != 'HAVING ') { |
|
| 302 | + if ($this->havingString != NULL && substr($this->havingString, -1, 1) != '(' && $this->havingString != 'HAVING ') { |
|
| 303 | 303 | if (!isset($item[3])) { |
| 304 | - $concatenation = 'AND'; |
|
| 304 | + $concatenation = 'AND'; |
|
| 305 | 305 | } else { |
| 306 | - $concatenation = $item[3]; |
|
| 306 | + $concatenation = $item[3]; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | $this->havingString .= "{$concatenation} "; |
| 310 | - } |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | - if ($this->havingString != NULL) |
|
| 312 | + if ($this->havingString != NULL) |
|
| 313 | 313 | $this->havingString .= '('; |
| 314 | - else |
|
| 314 | + else |
|
| 315 | 315 | $this->havingString = 'HAVING ('; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | if (!is_array($item)) { |
| 319 | - call_user_func_array(array($this, 'buildHaving'), $where); |
|
| 320 | - break; |
|
| 319 | + call_user_func_array(array($this, 'buildHaving'), $where); |
|
| 320 | + break; |
|
| 321 | 321 | } else { |
| 322 | - $this->buildHaving($item); |
|
| 322 | + $this->buildHaving($item); |
|
| 323 | 323 | } |
| 324 | 324 | if (!isset($where[$i + 1]) && isset($where[$i - 1])) { |
| 325 | - $this->havingString .= ') '; |
|
| 325 | + $this->havingString .= ') '; |
|
| 326 | 326 | } |
| 327 | - } |
|
| 327 | + } |
|
| 328 | + } |
|
| 328 | 329 | } |
| 329 | - } |
|
| 330 | 330 | |
| 331 | - public function buildQuery() { |
|
| 331 | + public function buildQuery() { |
|
| 332 | 332 | $query = $this->operation; |
| 333 | 333 | $this->operation = strtoupper($this->operation); |
| 334 | 334 | |
| 335 | 335 | switch ($this->operation) { |
| 336 | - case 'SELECT': |
|
| 336 | + case 'SELECT': |
|
| 337 | 337 | $query .= ' ' . ($this->distinct ? 'DISTINCT' : ''); |
| 338 | 338 | $query .= ' ' . (!$this->cols ? '*' : ((is_array($this->cols) ? implode(',', $this->cols) : $this->cols))); |
| 339 | - case 'DELETE': |
|
| 339 | + case 'DELETE': |
|
| 340 | 340 | $query .= ' FROM'; |
| 341 | 341 | break; |
| 342 | - case 'INSERT': |
|
| 342 | + case 'INSERT': |
|
| 343 | 343 | $query .= ' INTO'; |
| 344 | 344 | break; |
| 345 | 345 | } |
| 346 | 346 | $query .= " `{$this->curInstance->db_name}`.`{$this->curInstance->table_prefix}{$this->table}`"; |
| 347 | 347 | if ($this->join) { |
| 348 | - $query .= $this->buildJoin($this->join); |
|
| 348 | + $query .= $this->buildJoin($this->join); |
|
| 349 | 349 | } |
| 350 | 350 | switch ($this->operation) { |
| 351 | - case 'INSERT': |
|
| 351 | + case 'INSERT': |
|
| 352 | 352 | $this->params = array_merge($this->params, array_values($this->cols)); |
| 353 | 353 | $colsStr = ''; |
| 354 | 354 | if ($this->cols) { |
| 355 | - $colsStr = '`' . implode('`,`', array_keys($this->cols)) . '`'; |
|
| 355 | + $colsStr = '`' . implode('`,`', array_keys($this->cols)) . '`'; |
|
| 356 | 356 | } |
| 357 | 357 | $query .= ' (' . $colsStr . ') VALUES (' . rtrim(str_repeat('?,', count($this->cols)), ',') . ')'; |
| 358 | 358 | break; |
| 359 | - case 'CREATE TABLE': |
|
| 359 | + case 'CREATE TABLE': |
|
| 360 | 360 | $query .= " ("; |
| 361 | 361 | foreach ($this->cols as $col_name => $param) { |
| 362 | - if ($param == 'pk') { |
|
| 362 | + if ($param == 'pk') { |
|
| 363 | 363 | $param = "int(11) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (`{$col_name}`)"; |
| 364 | - } |
|
| 365 | - $query .= " `{$col_name}` {$param},"; |
|
| 364 | + } |
|
| 365 | + $query .= " `{$col_name}` {$param},"; |
|
| 366 | 366 | } |
| 367 | 367 | $query = rtrim($query, ','); |
| 368 | 368 | if ($this->indexes) { |
| 369 | - $query .= ', ' . implode(',', $this->indexes); |
|
| 369 | + $query .= ', ' . implode(',', $this->indexes); |
|
| 370 | 370 | } |
| 371 | 371 | $query .= ") ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_general_ci"; |
| 372 | 372 | break; |
| 373 | - case 'UPDATE': |
|
| 373 | + case 'UPDATE': |
|
| 374 | 374 | $updates = []; |
| 375 | 375 | foreach ($this->cols as $key => $item) { |
| 376 | - if (!in_array($item, array('CURRENT_TIMESTAMP'))) { |
|
| 376 | + if (!in_array($item, array('CURRENT_TIMESTAMP'))) { |
|
| 377 | 377 | $this->params[] = $item; |
| 378 | 378 | $updates[] = "`{$key}` = ?"; |
| 379 | - } else { |
|
| 379 | + } else { |
|
| 380 | 380 | $updates[] = "`{$key}` = {$item}"; |
| 381 | - } |
|
| 381 | + } |
|
| 382 | 382 | } |
| 383 | 383 | $update = implode(',', $updates); |
| 384 | 384 | $query .=" SET {$update}"; |
| 385 | - case 'SELECT': |
|
| 385 | + case 'SELECT': |
|
| 386 | 386 | case 'DELETE': |
| 387 | 387 | $this->buildWhere($this->where); |
| 388 | 388 | if ($this->whereString) { |
| 389 | - $query .= ' ' . $this->whereString; |
|
| 389 | + $query .= ' ' . $this->whereString; |
|
| 390 | 390 | } |
| 391 | 391 | break; |
| 392 | 392 | } |
| 393 | 393 | if ($this->group) { |
| 394 | - $query .= ' GROUP BY ' . implode(',', $this->group); |
|
| 394 | + $query .= ' GROUP BY ' . implode(',', $this->group); |
|
| 395 | 395 | } |
| 396 | 396 | $this->buildHaving($this->having); |
| 397 | 397 | if ($this->havingString) { |
| 398 | - $query .= ' ' . $this->havingString; |
|
| 398 | + $query .= ' ' . $this->havingString; |
|
| 399 | 399 | } |
| 400 | 400 | if ($this->order) { |
| 401 | - $query .= ' ORDER BY ' . implode(',', $this->order); |
|
| 401 | + $query .= ' ORDER BY ' . implode(',', $this->order); |
|
| 402 | 402 | } |
| 403 | 403 | if ($this->limit) { |
| 404 | - $query .= ' ' . $this->limit; |
|
| 404 | + $query .= ' ' . $this->limit; |
|
| 405 | 405 | } |
| 406 | 406 | return ['query' => $query, 'params' => $this->params]; |
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Execute query |
|
| 411 | - * |
|
| 412 | - * @param string|array $query |
|
| 413 | - * @return \Db\Mysql\Result |
|
| 414 | - */ |
|
| 415 | - public function query($query = []) { |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Execute query |
|
| 411 | + * |
|
| 412 | + * @param string|array $query |
|
| 413 | + * @return \Db\Mysql\Result |
|
| 414 | + */ |
|
| 415 | + public function query($query = []) { |
|
| 416 | 416 | if (!$query) { |
| 417 | - $this->params = []; |
|
| 418 | - $query = $this->buildQuery(); |
|
| 417 | + $this->params = []; |
|
| 418 | + $query = $this->buildQuery(); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | if (is_string($query)) { |
| 422 | - $query = ['query' => $query, 'params' => $this->params]; |
|
| 422 | + $query = ['query' => $query, 'params' => $this->params]; |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | $prepare = $this->curInstance->pdo->prepare($query['query']); |
@@ -429,10 +429,10 @@ discard block |
||
| 429 | 429 | $result = new Result(); |
| 430 | 430 | $result->pdoResult = $prepare; |
| 431 | 431 | if ($this->curInstance->dbInstance && $this->curInstance->dbInstance->curQuery && $this->curInstance->dbInstance->curQuery === $this) { |
| 432 | - $this->curInstance->dbInstance->curQuery = null; |
|
| 432 | + $this->curInstance->dbInstance->curQuery = null; |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | return $result; |
| 436 | - } |
|
| 436 | + } |
|
| 437 | 437 | |
| 438 | 438 | } |