@@ -218,6 +218,7 @@ |
||
| 218 | 218 | * @param $number Integer Число на основе которого нужно сформировать окончание |
| 219 | 219 | * @param $endingsArray Array Массив слов или окончаний для чисел (1, 4, 5), |
| 220 | 220 | * например array('яблоко', 'яблока', 'яблок') |
| 221 | + * @param string[] $endingArray |
|
| 221 | 222 | * @return String |
| 222 | 223 | */ |
| 223 | 224 | public static function getNumEnding($number, $endingArray) { |
@@ -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 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public static function uriParse($uri) { |
| 38 | 38 | $answerPos = strpos($uri, '?'); |
| 39 | - $params = array_slice(explode('/', substr($uri, 0, $answerPos ? $answerPos : strlen($uri) )), 1); |
|
| 39 | + $params = array_slice(explode('/', substr($uri, 0, $answerPos ? $answerPos : strlen($uri))), 1); |
|
| 40 | 40 | |
| 41 | 41 | foreach ($params as $key => $param) { |
| 42 | 42 | if ($param != '') { |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $path = explode('/', $path); |
| 62 | 62 | $cur = ''; |
| 63 | 63 | foreach ($path as $item) { |
| 64 | - $cur .= $item . '/'; |
|
| 64 | + $cur .= $item.'/'; |
|
| 65 | 65 | if (!file_exists($cur)) { |
| 66 | 66 | mkdir($cur); |
| 67 | 67 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 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 | - list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($img_path); |
|
| 84 | + list($img_width, $img_height, $img_type, $img_tag) = getimagesize($img_path); |
|
| 85 | 85 | switch ($img_type) { |
| 86 | 86 | case 1: |
| 87 | 87 | $img_type = 'gif'; |
@@ -107,14 +107,14 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | if ($crop === true || $crop == 'q') { |
| 109 | 109 | if ($img_width > $img_height) { |
| 110 | - $imgX = floor(( $img_width - $img_height ) / 2); |
|
| 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 | 115 | } else { |
| 116 | 116 | $imgX = 0; |
| 117 | - $imgY = floor(( $img_height - $img_width ) / 2); |
|
| 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; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | $new_width = $max_width; |
| 136 | 136 | $new_height = $max_height; |
| 137 | 137 | //Находим начальные координаты (центрируем новое изображение) |
| 138 | - $imgX = (int) (($ow / 2) - ($img_width / 2) ); |
|
| 138 | + $imgX = (int) (($ow / 2) - ($img_width / 2)); |
|
| 139 | 139 | if ($pos == 'center') { |
| 140 | 140 | $imgY = (int) (($oh / 2) - ($img_height / 2)); |
| 141 | 141 | } else { |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | if (!headers_sent()) { |
| 209 | 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 | } |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | $pathArray = $cleanPathArray; |
| 267 | 267 | $cleanPathArray = []; |
| 268 | 268 | } while ($changes); |
| 269 | - return (strpos($path, '/') === 0 ? '/' : '') . implode('/', $pathArray); |
|
| 269 | + return (strpos($path, '/') === 0 ? '/' : '').implode('/', $pathArray); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | if (empty($month[$mm - 1])) { |
| 287 | 287 | return 'Не указано'; |
| 288 | 288 | } |
| 289 | - return ($dd > 0 ? $dd . " " : '') . $month[$mm - 1] . " " . $yy . " " . $hours; |
|
| 289 | + return ($dd > 0 ? $dd." " : '').$month[$mm - 1]." ".$yy." ".$hours; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -364,10 +364,10 @@ discard block |
||
| 364 | 364 | if (in_array($file, ['.', '..'])) { |
| 365 | 365 | continue; |
| 366 | 366 | } |
| 367 | - if (is_dir($from . '/' . $file)) { |
|
| 368 | - self::copyFiles($from . '/' . $file, $to . '/' . $file); |
|
| 367 | + if (is_dir($from.'/'.$file)) { |
|
| 368 | + self::copyFiles($from.'/'.$file, $to.'/'.$file); |
|
| 369 | 369 | } else { |
| 370 | - copy($from . '/' . $file, $to . '/' . $file); |
|
| 370 | + copy($from.'/'.$file, $to.'/'.$file); |
|
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | } |
@@ -55,8 +55,9 @@ discard block |
||
| 55 | 55 | * @return boolean |
| 56 | 56 | */ |
| 57 | 57 | public static function createDir($path) { |
| 58 | - if (file_exists($path)) |
|
| 59 | - return true; |
|
| 58 | + if (file_exists($path)) { |
|
| 59 | + return true; |
|
| 60 | + } |
|
| 60 | 61 | |
| 61 | 62 | $path = explode('/', $path); |
| 62 | 63 | $cur = ''; |
@@ -100,10 +101,11 @@ discard block |
||
| 100 | 101 | return false; |
| 101 | 102 | } |
| 102 | 103 | |
| 103 | - if ($img_width / $max_width > $img_height / $max_height) |
|
| 104 | - $separator = $img_width / $max_width; |
|
| 105 | - else |
|
| 106 | - $separator = $img_height / $max_height; |
|
| 104 | + if ($img_width / $max_width > $img_height / $max_height) { |
|
| 105 | + $separator = $img_width / $max_width; |
|
| 106 | + } else { |
|
| 107 | + $separator = $img_height / $max_height; |
|
| 108 | + } |
|
| 107 | 109 | |
| 108 | 110 | if ($crop === true || $crop == 'q') { |
| 109 | 111 | if ($img_width > $img_height) { |
@@ -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 | } |
@@ -1,39 +1,39 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return function($step = NULL, $params = []) { |
| 4 | - $options = ['max_height' => 1200, 'max_width' => 1200]; |
|
| 5 | - $types = [ |
|
| 6 | - [ |
|
| 7 | - 'dir' => '/static/mediafiles/images/', |
|
| 8 | - 'ext' => 'png', |
|
| 9 | - 'group' => 'image', |
|
| 10 | - 'allow_resize' => 1, |
|
| 11 | - 'options' => json_encode($options) |
|
| 12 | - ], |
|
| 13 | - [ |
|
| 14 | - 'dir' => '/static/mediafiles/images/', |
|
| 15 | - 'ext' => 'jpeg', |
|
| 16 | - 'group' => 'image', |
|
| 17 | - 'allow_resize' => 1, |
|
| 18 | - 'options' => json_encode($options) |
|
| 19 | - ], |
|
| 20 | - [ |
|
| 21 | - 'dir' => '/static/mediafiles/images/', |
|
| 22 | - 'ext' => 'jpg', |
|
| 23 | - 'group' => 'image', |
|
| 24 | - 'allow_resize' => 1, |
|
| 25 | - 'options' => json_encode($options) |
|
| 26 | - ], |
|
| 27 | - [ |
|
| 28 | - 'dir' => '/static/mediafiles/images/', |
|
| 29 | - 'ext' => 'gif', |
|
| 30 | - 'group' => 'image', |
|
| 31 | - 'allow_resize' => 1, |
|
| 32 | - 'options' => json_encode($options) |
|
| 33 | - ], |
|
| 34 | - ]; |
|
| 35 | - foreach ($types as $type) { |
|
| 4 | + $options = ['max_height' => 1200, 'max_width' => 1200]; |
|
| 5 | + $types = [ |
|
| 6 | + [ |
|
| 7 | + 'dir' => '/static/mediafiles/images/', |
|
| 8 | + 'ext' => 'png', |
|
| 9 | + 'group' => 'image', |
|
| 10 | + 'allow_resize' => 1, |
|
| 11 | + 'options' => json_encode($options) |
|
| 12 | + ], |
|
| 13 | + [ |
|
| 14 | + 'dir' => '/static/mediafiles/images/', |
|
| 15 | + 'ext' => 'jpeg', |
|
| 16 | + 'group' => 'image', |
|
| 17 | + 'allow_resize' => 1, |
|
| 18 | + 'options' => json_encode($options) |
|
| 19 | + ], |
|
| 20 | + [ |
|
| 21 | + 'dir' => '/static/mediafiles/images/', |
|
| 22 | + 'ext' => 'jpg', |
|
| 23 | + 'group' => 'image', |
|
| 24 | + 'allow_resize' => 1, |
|
| 25 | + 'options' => json_encode($options) |
|
| 26 | + ], |
|
| 27 | + [ |
|
| 28 | + 'dir' => '/static/mediafiles/images/', |
|
| 29 | + 'ext' => 'gif', |
|
| 30 | + 'group' => 'image', |
|
| 31 | + 'allow_resize' => 1, |
|
| 32 | + 'options' => json_encode($options) |
|
| 33 | + ], |
|
| 34 | + ]; |
|
| 35 | + foreach ($types as $type) { |
|
| 36 | 36 | $typeObject = new \Files\Type($type); |
| 37 | 37 | $typeObject->save(); |
| 38 | - } |
|
| 38 | + } |
|
| 39 | 39 | }; |
@@ -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 | } |
@@ -46,21 +46,21 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | $fileObject->name = $fileinfo['filename']; |
| 49 | - $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension']; |
|
| 50 | - if ($fileObject->id && file_exists($sitePath . $fileObject->path)) |
|
| 51 | - unlink($sitePath . $fileObject->path); |
|
| 49 | + $fileObject->path = $type->type_dir.date('Y-m-d').'/'.microtime(true).'.'.$fileinfo['extension']; |
|
| 50 | + if ($fileObject->id && file_exists($sitePath.$fileObject->path)) |
|
| 51 | + unlink($sitePath.$fileObject->path); |
|
| 52 | 52 | |
| 53 | - Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/'); |
|
| 53 | + Tools::createDir($sitePath.$type->type_dir.date('Y-m-d').'/'); |
|
| 54 | 54 | |
| 55 | - if (!move_uploaded_file($file['tmp_name'], $sitePath . $fileObject->path)) { |
|
| 55 | + if (!move_uploaded_file($file['tmp_name'], $sitePath.$fileObject->path)) { |
|
| 56 | 56 | return false; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | if ($type->allow_resize && $type->options && json_decode($type->options, true)) { |
| 60 | 60 | $typeOptions = json_decode($type->options, true); |
| 61 | - list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path); |
|
| 61 | + list($img_width, $img_height, $img_type, $img_tag) = getimagesize($sitePath.$fileObject->path); |
|
| 62 | 62 | if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) { |
| 63 | - Tools::resizeImage($sitePath . $fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']); |
|
| 63 | + Tools::resizeImage($sitePath.$fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -104,25 +104,25 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | $fileObject->name = $fileinfo['filename']; |
| 107 | - $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension']; |
|
| 108 | - if ($fileObject->id && file_exists($sitePath . $fileObject->path)) |
|
| 109 | - unlink($sitePath . $fileObject->path); |
|
| 107 | + $fileObject->path = $type->type_dir.date('Y-m-d').'/'.microtime(true).'.'.$fileinfo['extension']; |
|
| 108 | + if ($fileObject->id && file_exists($sitePath.$fileObject->path)) |
|
| 109 | + unlink($sitePath.$fileObject->path); |
|
| 110 | 110 | |
| 111 | - Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/'); |
|
| 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 | 115 | return 0; |
| 116 | 116 | } |
| 117 | - if (!file_put_contents($sitePath . $fileObject->path, $file)) { |
|
| 117 | + if (!file_put_contents($sitePath.$fileObject->path, $file)) { |
|
| 118 | 118 | return 0; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | if ($type->allow_resize && $type->options && json_decode($type->options, true)) { |
| 122 | 122 | $typeOptions = json_decode($type->options, true); |
| 123 | - list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path); |
|
| 123 | + list($img_width, $img_height, $img_type, $img_tag) = getimagesize($sitePath.$fileObject->path); |
|
| 124 | 124 | if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) { |
| 125 | - Tools::resizeImage($sitePath . $fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']); |
|
| 125 | + Tools::resizeImage($sitePath.$fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']); |
|
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | |
@@ -22,16 +22,19 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | $sitePath = App::$primary->path; |
| 24 | 24 | |
| 25 | - if (!is_uploaded_file($file['tmp_name'])) |
|
| 26 | - return 0; |
|
| 25 | + if (!is_uploaded_file($file['tmp_name'])) { |
|
| 26 | + return 0; |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | $fileinfo = pathinfo($file['name']); |
| 29 | - if (empty($fileinfo['extension'])) |
|
| 30 | - return 0; |
|
| 30 | + if (empty($fileinfo['extension'])) { |
|
| 31 | + return 0; |
|
| 32 | + } |
|
| 31 | 33 | |
| 32 | 34 | $type = Files\Type::get($fileinfo['extension'], 'ext'); |
| 33 | - if (!$type) |
|
| 34 | - return 0; |
|
| 35 | + if (!$type) { |
|
| 36 | + return 0; |
|
| 37 | + } |
|
| 35 | 38 | |
| 36 | 39 | if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) { |
| 37 | 40 | return 0; |
@@ -47,8 +50,9 @@ discard block |
||
| 47 | 50 | } |
| 48 | 51 | $fileObject->name = $fileinfo['filename']; |
| 49 | 52 | $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension']; |
| 50 | - if ($fileObject->id && file_exists($sitePath . $fileObject->path)) |
|
| 51 | - unlink($sitePath . $fileObject->path); |
|
| 53 | + if ($fileObject->id && file_exists($sitePath . $fileObject->path)) { |
|
| 54 | + unlink($sitePath . $fileObject->path); |
|
| 55 | + } |
|
| 52 | 56 | |
| 53 | 57 | Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/'); |
| 54 | 58 | |
@@ -84,12 +88,14 @@ discard block |
||
| 84 | 88 | $sitePath = App::$primary->path; |
| 85 | 89 | |
| 86 | 90 | $fileinfo = pathinfo($url); |
| 87 | - if (empty($fileinfo['extension'])) |
|
| 88 | - return 0; |
|
| 91 | + if (empty($fileinfo['extension'])) { |
|
| 92 | + return 0; |
|
| 93 | + } |
|
| 89 | 94 | |
| 90 | 95 | $type = Files\Type::get($fileinfo['extension'], 'ext'); |
| 91 | - if (!$type) |
|
| 92 | - return 0; |
|
| 96 | + if (!$type) { |
|
| 97 | + return 0; |
|
| 98 | + } |
|
| 93 | 99 | |
| 94 | 100 | if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) { |
| 95 | 101 | return 0; |
@@ -105,8 +111,9 @@ discard block |
||
| 105 | 111 | } |
| 106 | 112 | $fileObject->name = $fileinfo['filename']; |
| 107 | 113 | $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension']; |
| 108 | - if ($fileObject->id && file_exists($sitePath . $fileObject->path)) |
|
| 109 | - unlink($sitePath . $fileObject->path); |
|
| 114 | + if ($fileObject->id && file_exists($sitePath . $fileObject->path)) { |
|
| 115 | + unlink($sitePath . $fileObject->path); |
|
| 116 | + } |
|
| 110 | 117 | |
| 111 | 118 | Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/'); |
| 112 | 119 | |
@@ -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 |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (!$dataManager->checkAccess()) { |
| 3 | - echo 'you not have access to "' . $dataManager->modelName . '" manager with name: "' . $dataManager->managerName . '"'; |
|
| 3 | + echo 'you not have access to "'.$dataManager->modelName.'" manager with name: "'.$dataManager->managerName.'"'; |
|
| 4 | 4 | return false; |
| 5 | 5 | } |
| 6 | 6 | ?> |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | continue; |
| 47 | 47 | } |
| 48 | - if(++$i && !($i%2)){ |
|
| 48 | + if (++$i && !($i % 2)) { |
|
| 49 | 49 | echo '</div><div class="row">'; |
| 50 | 50 | } |
| 51 | 51 | echo '<div class="col-md-6">'; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | $options = [ |
| 74 | 74 | 'where' => !empty($filters['getRows']['where']) ? $filters['getRows']['where'] : '' |
| 75 | 75 | ]; |
| 76 | - if (isset($cols[$relations[$colInfo['colParams']['relation']]['model']::colPrefix() . 'name'])) { |
|
| 76 | + if (isset($cols[$relations[$colInfo['colParams']['relation']]['model']::colPrefix().'name'])) { |
|
| 77 | 77 | $options['order'] = 'name'; |
| 78 | 78 | } |
| 79 | 79 | $items = $relations[$colInfo['colParams']['relation']]['model']::getList($options); |
@@ -12,61 +12,61 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | class DataManager extends \Object { |
| 14 | 14 | |
| 15 | - public $modelName = ''; |
|
| 16 | - public $managerOptions = []; |
|
| 17 | - public $managerName = 'customManager'; |
|
| 18 | - public $name = 'Менеджер данных'; |
|
| 19 | - public $limit = 30; |
|
| 20 | - public $page = 1; |
|
| 21 | - public $table = null; |
|
| 22 | - public $joins = []; |
|
| 23 | - public $predraw = false; |
|
| 24 | - public $cols = []; |
|
| 25 | - public $managerId = ''; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Construct new data manager |
|
| 29 | - * |
|
| 30 | - * @param string|array $modelNameOrOptions |
|
| 31 | - * @param string $managerName |
|
| 32 | - * @throws Exception |
|
| 33 | - */ |
|
| 34 | - public function __construct($modelNameOrOptions, $managerName = 'manager') { |
|
| 15 | + public $modelName = ''; |
|
| 16 | + public $managerOptions = []; |
|
| 17 | + public $managerName = 'customManager'; |
|
| 18 | + public $name = 'Менеджер данных'; |
|
| 19 | + public $limit = 30; |
|
| 20 | + public $page = 1; |
|
| 21 | + public $table = null; |
|
| 22 | + public $joins = []; |
|
| 23 | + public $predraw = false; |
|
| 24 | + public $cols = []; |
|
| 25 | + public $managerId = ''; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Construct new data manager |
|
| 29 | + * |
|
| 30 | + * @param string|array $modelNameOrOptions |
|
| 31 | + * @param string $managerName |
|
| 32 | + * @throws Exception |
|
| 33 | + */ |
|
| 34 | + public function __construct($modelNameOrOptions, $managerName = 'manager') { |
|
| 35 | 35 | $this->managerName = $managerName; |
| 36 | 36 | |
| 37 | 37 | if (!is_array($modelNameOrOptions)) { |
| 38 | - if (!class_exists($modelNameOrOptions)) { |
|
| 38 | + if (!class_exists($modelNameOrOptions)) { |
|
| 39 | 39 | throw new \Exception("model {$modelNameOrOptions} not exists"); |
| 40 | - } |
|
| 41 | - $this->modelName = $modelNameOrOptions; |
|
| 42 | - $this->managerOptions = !empty($modelNameOrOptions::$dataManagers[$managerName]) ? $modelNameOrOptions::$dataManagers[$managerName] : []; |
|
| 43 | - if (isset($modelNameOrOptions::$objectName)) { |
|
| 40 | + } |
|
| 41 | + $this->modelName = $modelNameOrOptions; |
|
| 42 | + $this->managerOptions = !empty($modelNameOrOptions::$dataManagers[$managerName]) ? $modelNameOrOptions::$dataManagers[$managerName] : []; |
|
| 43 | + if (isset($modelNameOrOptions::$objectName)) { |
|
| 44 | 44 | $this->name = $modelNameOrOptions::$objectName; |
| 45 | - } else { |
|
| 45 | + } else { |
|
| 46 | 46 | $this->name = $modelNameOrOptions; |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | } else { |
| 49 | - $this->managerOptions = $modelNameOrOptions; |
|
| 49 | + $this->managerOptions = $modelNameOrOptions; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | if (!$this->managerOptions || !is_array($this->managerOptions)) { |
| 53 | - throw new \Exception('empty DataManager'); |
|
| 53 | + throw new \Exception('empty DataManager'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | if (!empty($this->managerOptions['name'])) { |
| 57 | - $this->name = $this->managerOptions['name']; |
|
| 57 | + $this->name = $this->managerOptions['name']; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $this->managerId = str_replace('\\', '_', 'dataManager_' . $this->modelName . '_' . $this->managerName . '_' . \Tools::randomString()); |
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Get buttons for manager |
|
| 65 | - * |
|
| 66 | - * @param string $params |
|
| 67 | - * @param object $model |
|
| 68 | - */ |
|
| 69 | - public function getButtons($params = [], $model = null) { |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Get buttons for manager |
|
| 65 | + * |
|
| 66 | + * @param string $params |
|
| 67 | + * @param object $model |
|
| 68 | + */ |
|
| 69 | + public function getButtons($params = [], $model = null) { |
|
| 70 | 70 | $modelName = $this->modelName; |
| 71 | 71 | |
| 72 | 72 | |
@@ -76,96 +76,96 @@ discard block |
||
| 76 | 76 | 'formName' => !empty($this->managerOptions['editForm']) ? $this->managerOptions['editForm'] : 'manager' |
| 77 | 77 | ]; |
| 78 | 78 | if ($model) { |
| 79 | - $formModelName = get_class($model); |
|
| 80 | - $relations = $formModelName::relations(); |
|
| 81 | - $type = !empty($relations[$params['relation']]['type']) ? $relations[$params['relation']]['type'] : 'to'; |
|
| 82 | - switch ($type) { |
|
| 79 | + $formModelName = get_class($model); |
|
| 80 | + $relations = $formModelName::relations(); |
|
| 81 | + $type = !empty($relations[$params['relation']]['type']) ? $relations[$params['relation']]['type'] : 'to'; |
|
| 82 | + switch ($type) { |
|
| 83 | 83 | case 'relModel': |
| 84 | 84 | $formParams['preset'] = [ |
| 85 | - $formModelName::index() => $model->pk() |
|
| 86 | - ]; |
|
| 87 | - break; |
|
| 85 | + $formModelName::index() => $model->pk() |
|
| 86 | + ]; |
|
| 87 | + break; |
|
| 88 | 88 | default: |
| 89 | 89 | $formParams['preset'] = [ |
| 90 | - $relations[$params['relation']]['col'] => $model->pk() |
|
| 91 | - ]; |
|
| 92 | - } |
|
| 90 | + $relations[$params['relation']]['col'] => $model->pk() |
|
| 91 | + ]; |
|
| 92 | + } |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $buttons = []; |
| 96 | 96 | if (!empty($this->managerOptions['sortMode'])) { |
| 97 | - $buttons[] = [ |
|
| 98 | - 'class' => 'modeBtn', |
|
| 99 | - 'data-mode' => 'sort', |
|
| 100 | - 'text' => 'Сортировать', |
|
| 101 | - ]; |
|
| 97 | + $buttons[] = [ |
|
| 98 | + 'class' => 'modeBtn', |
|
| 99 | + 'data-mode' => 'sort', |
|
| 100 | + 'text' => 'Сортировать', |
|
| 101 | + ]; |
|
| 102 | 102 | } |
| 103 | 103 | if (!empty($this->managerOptions['filters'])) { |
| 104 | - $buttons[] = [ |
|
| 105 | - 'text' => 'Фильтры', |
|
| 106 | - 'onclick' => ' var modal = $("#' . $this->managerId . '_filters"); |
|
| 104 | + $buttons[] = [ |
|
| 105 | + 'text' => 'Фильтры', |
|
| 106 | + 'onclick' => ' var modal = $("#' . $this->managerId . '_filters"); |
|
| 107 | 107 | modal.modal("show");', |
| 108 | - ]; |
|
| 108 | + ]; |
|
| 109 | 109 | } |
| 110 | 110 | if (!empty($modelName::$forms['simpleItem'])) { |
| 111 | - $formParams['formName'] = 'simpleItem'; |
|
| 112 | - $buttons[] = [ |
|
| 113 | - 'text' => '<i class = "glyphicon glyphicon-send"></i> Быстрое создание', |
|
| 114 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
| 115 | - ]; |
|
| 111 | + $formParams['formName'] = 'simpleItem'; |
|
| 112 | + $buttons[] = [ |
|
| 113 | + 'text' => '<i class = "glyphicon glyphicon-send"></i> Быстрое создание', |
|
| 114 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
| 115 | + ]; |
|
| 116 | 116 | } |
| 117 | 117 | $formParams['formName'] = !empty($this->managerOptions['editForm']) ? $this->managerOptions['editForm'] : 'manager'; |
| 118 | 118 | $name = 'Элемент'; |
| 119 | 119 | if ($modelName::$objectName) { |
| 120 | - $name = $modelName::$objectName; |
|
| 120 | + $name = $modelName::$objectName; |
|
| 121 | 121 | } |
| 122 | 122 | if (!empty($modelName::$forms[$formParams['formName']])) { |
| 123 | - $buttons[] = [ |
|
| 124 | - 'text' => 'Создать ' . $name, |
|
| 125 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
| 126 | - ]; |
|
| 123 | + $buttons[] = [ |
|
| 124 | + 'text' => 'Создать ' . $name, |
|
| 125 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
| 126 | + ]; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | return $buttons; |
| 130 | - } |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - function getActions($onlyGroupActions = false) { |
|
| 132 | + function getActions($onlyGroupActions = false) { |
|
| 133 | 133 | $actions = [ |
| 134 | 134 | 'Open' => ['className' => 'Open'], 'Edit' => ['className' => 'Edit'], 'Delete' => ['className' => 'Delete'] |
| 135 | 135 | ]; |
| 136 | 136 | if (isset($this->managerOptions['actions'])) { |
| 137 | - $actions = array_merge($actions, $this->managerOptions['actions']); |
|
| 137 | + $actions = array_merge($actions, $this->managerOptions['actions']); |
|
| 138 | 138 | } |
| 139 | 139 | $return = []; |
| 140 | 140 | foreach ($actions as $key => $action) { |
| 141 | - if ($action === false) { |
|
| 141 | + if ($action === false) { |
|
| 142 | 142 | continue; |
| 143 | - } |
|
| 144 | - if (is_array($action)) { |
|
| 143 | + } |
|
| 144 | + if (is_array($action)) { |
|
| 145 | 145 | if (!empty($action['access']['groups']) && !in_array(\Users\User::$cur->group_id, $action['access']['groups'])) { |
| 146 | - continue; |
|
| 146 | + continue; |
|
| 147 | 147 | } |
| 148 | 148 | $return[$key] = $action; |
| 149 | - } else { |
|
| 149 | + } else { |
|
| 150 | 150 | $key = $action; |
| 151 | 151 | $return[$key] = [ |
| 152 | 152 | 'className' => $action |
| 153 | 153 | ]; |
| 154 | - } |
|
| 155 | - $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\' . $return[$key]['className']) ? 'Ui\DataManager\Action\\' . $return[$key]['className'] : $return[$key]['className']; |
|
| 156 | - if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
|
| 154 | + } |
|
| 155 | + $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\' . $return[$key]['className']) ? 'Ui\DataManager\Action\\' . $return[$key]['className'] : $return[$key]['className']; |
|
| 156 | + if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
|
| 157 | 157 | unset($return[$key]); |
| 158 | - } |
|
| 158 | + } |
|
| 159 | 159 | } |
| 160 | 160 | return $return; |
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Get cols for manager |
|
| 165 | - * |
|
| 166 | - * @return string |
|
| 167 | - */ |
|
| 168 | - public function getCols() { |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Get cols for manager |
|
| 165 | + * |
|
| 166 | + * @return string |
|
| 167 | + */ |
|
| 168 | + public function getCols() { |
|
| 169 | 169 | $actions = $this->getActions(); |
| 170 | 170 | ob_start(); |
| 171 | 171 | ?> |
@@ -181,12 +181,12 @@ discard block |
||
| 181 | 181 | <li><a href ='' onclick='inji.Ui.dataManagers.get(this).rowSelection("inverse");return false;'>Инвертировать</a></li> |
| 182 | 182 | <li role="separator" class="divider"></li> |
| 183 | 183 | <?php |
| 184 | - foreach ($actions as $action => $actionParams) { |
|
| 184 | + foreach ($actions as $action => $actionParams) { |
|
| 185 | 185 | if (class_exists($actionParams['className']) && $actionParams['className']::$groupAction) { |
| 186 | - echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
| 186 | + echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
| 187 | + } |
|
| 187 | 188 | } |
| 188 | - } |
|
| 189 | - ?> |
|
| 189 | + ?> |
|
| 190 | 190 | </ul> |
| 191 | 191 | </div> |
| 192 | 192 | <?php |
@@ -199,299 +199,299 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $modelName = $this->modelName; |
| 201 | 201 | foreach ($this->managerOptions['cols'] as $key => $col) { |
| 202 | - if (is_array($col)) { |
|
| 202 | + if (is_array($col)) { |
|
| 203 | 203 | $colName = $key; |
| 204 | 204 | $colOptions = $col; |
| 205 | - } else { |
|
| 205 | + } else { |
|
| 206 | 206 | $colName = $col; |
| 207 | 207 | $colOptions = []; |
| 208 | - } |
|
| 209 | - $colInfo = []; |
|
| 210 | - if ($modelName) { |
|
| 208 | + } |
|
| 209 | + $colInfo = []; |
|
| 210 | + if ($modelName) { |
|
| 211 | 211 | $colInfo = $modelName::getColInfo($colName); |
| 212 | - } |
|
| 213 | - if (empty($colOptions['label']) && !empty($colInfo['label'])) { |
|
| 212 | + } |
|
| 213 | + if (empty($colOptions['label']) && !empty($colInfo['label'])) { |
|
| 214 | 214 | $colOptions['label'] = $colInfo['label']; |
| 215 | - } elseif (empty($colOptions['label'])) { |
|
| 215 | + } elseif (empty($colOptions['label'])) { |
|
| 216 | 216 | $colOptions['label'] = $colName; |
| 217 | - } |
|
| 218 | - $cols[$colName] = $colOptions; |
|
| 217 | + } |
|
| 218 | + $cols[$colName] = $colOptions; |
|
| 219 | 219 | } |
| 220 | 220 | return $cols; |
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Get rows for manager |
|
| 225 | - * |
|
| 226 | - * @param array $params |
|
| 227 | - * @param object $model |
|
| 228 | - * @return type |
|
| 229 | - */ |
|
| 230 | - public function getRows($params = [], $model = null) { |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Get rows for manager |
|
| 225 | + * |
|
| 226 | + * @param array $params |
|
| 227 | + * @param object $model |
|
| 228 | + * @return type |
|
| 229 | + */ |
|
| 230 | + public function getRows($params = [], $model = null) { |
|
| 231 | 231 | $modelName = $this->modelName; |
| 232 | 232 | if (!class_exists($modelName)) { |
| 233 | - return []; |
|
| 233 | + return []; |
|
| 234 | 234 | } |
| 235 | 235 | if (!$this->checkAccess()) { |
| 236 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 237 | - return []; |
|
| 236 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 237 | + return []; |
|
| 238 | 238 | } |
| 239 | 239 | $modelName = $this->modelName; |
| 240 | 240 | $queryParams = []; |
| 241 | 241 | if (empty($params['all'])) { |
| 242 | - if (!empty($params['limit'])) { |
|
| 242 | + if (!empty($params['limit'])) { |
|
| 243 | 243 | $this->limit = (int) $params['limit']; |
| 244 | - } |
|
| 245 | - if (!empty($params['page'])) { |
|
| 244 | + } |
|
| 245 | + if (!empty($params['page'])) { |
|
| 246 | 246 | $this->page = (int) $params['page']; |
| 247 | - } |
|
| 248 | - $queryParams['limit'] = $this->limit; |
|
| 249 | - $queryParams['start'] = $this->page * $this->limit - $this->limit; |
|
| 247 | + } |
|
| 248 | + $queryParams['limit'] = $this->limit; |
|
| 249 | + $queryParams['start'] = $this->page * $this->limit - $this->limit; |
|
| 250 | 250 | } |
| 251 | 251 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
| 252 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
| 252 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
| 253 | 253 | } |
| 254 | 254 | if (!empty($params['appType'])) { |
| 255 | - $queryParams['appType'] = $params['appType']; |
|
| 255 | + $queryParams['appType'] = $params['appType']; |
|
| 256 | 256 | } |
| 257 | 257 | if ($this->joins) { |
| 258 | - $queryParams['joins'] = $this->joins; |
|
| 258 | + $queryParams['joins'] = $this->joins; |
|
| 259 | 259 | } |
| 260 | 260 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
| 261 | - foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
| 261 | + foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
| 262 | 262 | if (!empty($colOptions['userCol'])) { |
| 263 | - if (strpos($colOptions['userCol'], ':')) { |
|
| 263 | + if (strpos($colOptions['userCol'], ':')) { |
|
| 264 | 264 | $rel = substr($colOptions['userCol'], 0, strpos($colOptions['userCol'], ':')); |
| 265 | 265 | $param = substr($colOptions['userCol'], strpos($colOptions['userCol'], ':') + 1); |
| 266 | 266 | $queryParams['where'][] = [$colName, \Users\User::$cur->$rel->$param]; |
| 267 | - } |
|
| 267 | + } |
|
| 268 | 268 | } elseif (isset($colOptions['value'])) { |
| 269 | - $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
| 269 | + $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
| 270 | + } |
|
| 270 | 271 | } |
| 271 | - } |
|
| 272 | 272 | } |
| 273 | 273 | if (!empty($this->managerOptions['filters'])) { |
| 274 | - foreach ($this->managerOptions['filters'] as $col) { |
|
| 274 | + foreach ($this->managerOptions['filters'] as $col) { |
|
| 275 | 275 | $colInfo = $modelName::getColInfo($col); |
| 276 | 276 | switch ($colInfo['colParams']['type']) { |
| 277 | - case 'select': |
|
| 277 | + case 'select': |
|
| 278 | 278 | if (empty($params['filters'][$col]['value'])) { |
| 279 | - continue; |
|
| 279 | + continue; |
|
| 280 | 280 | } |
| 281 | 281 | if (is_array($params['filters'][$col]['value'])) { |
| 282 | - foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
| 282 | + foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
| 283 | 283 | if ($value === '') { |
| 284 | - unset($params['filters'][$col]['value'][$key]); |
|
| 284 | + unset($params['filters'][$col]['value'][$key]); |
|
| 285 | + } |
|
| 285 | 286 | } |
| 286 | - } |
|
| 287 | 287 | } |
| 288 | 288 | if (!$params['filters'][$col]['value']) { |
| 289 | - continue; |
|
| 289 | + continue; |
|
| 290 | 290 | } |
| 291 | 291 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'], is_array($params['filters'][$col]['value']) ? 'IN' : '=']; |
| 292 | 292 | break; |
| 293 | - case 'bool': |
|
| 293 | + case 'bool': |
|
| 294 | 294 | |
| 295 | 295 | if (!isset($params['filters'][$col]['value']) || $params['filters'][$col]['value'] === '') { |
| 296 | - continue; |
|
| 296 | + continue; |
|
| 297 | 297 | } |
| 298 | 298 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
| 299 | 299 | break; |
| 300 | - case 'dateTime': |
|
| 300 | + case 'dateTime': |
|
| 301 | 301 | case 'date': |
| 302 | 302 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
| 303 | - continue; |
|
| 303 | + continue; |
|
| 304 | 304 | } |
| 305 | 305 | if (!empty($params['filters'][$col]['min'])) { |
| 306 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 306 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 307 | 307 | } |
| 308 | 308 | if (!empty($params['filters'][$col]['max'])) { |
| 309 | - if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
| 309 | + if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
| 310 | 310 | |
| 311 | 311 | $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
| 312 | - } else { |
|
| 312 | + } else { |
|
| 313 | 313 | $date = $params['filters'][$col]['max']; |
| 314 | - } |
|
| 315 | - $queryParams['where'][] = [$col, $date, '<=']; |
|
| 314 | + } |
|
| 315 | + $queryParams['where'][] = [$col, $date, '<=']; |
|
| 316 | 316 | } |
| 317 | 317 | break; |
| 318 | - case 'number': |
|
| 318 | + case 'number': |
|
| 319 | 319 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
| 320 | - continue; |
|
| 320 | + continue; |
|
| 321 | 321 | } |
| 322 | 322 | if (!empty($params['filters'][$col]['min'])) { |
| 323 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 323 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 324 | 324 | } |
| 325 | 325 | if (!empty($params['filters'][$col]['max'])) { |
| 326 | - $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
| 326 | + $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
| 327 | 327 | } |
| 328 | 328 | break; |
| 329 | - case 'email': |
|
| 329 | + case 'email': |
|
| 330 | 330 | case 'text': |
| 331 | 331 | case 'textarea': |
| 332 | 332 | case 'html': |
| 333 | 333 | if (empty($params['filters'][$col]['value'])) { |
| 334 | - continue; |
|
| 334 | + continue; |
|
| 335 | 335 | } |
| 336 | 336 | switch ($params['filters'][$col]['compareType']) { |
| 337 | - case 'contains': |
|
| 337 | + case 'contains': |
|
| 338 | 338 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
| 339 | 339 | break; |
| 340 | - case 'equals': |
|
| 340 | + case 'equals': |
|
| 341 | 341 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
| 342 | 342 | break; |
| 343 | - case 'starts_with': |
|
| 343 | + case 'starts_with': |
|
| 344 | 344 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
| 345 | 345 | break; |
| 346 | - case 'ends_with': |
|
| 346 | + case 'ends_with': |
|
| 347 | 347 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
| 348 | 348 | break; |
| 349 | 349 | } |
| 350 | 350 | break; |
| 351 | 351 | } |
| 352 | - } |
|
| 352 | + } |
|
| 353 | 353 | } |
| 354 | 354 | if (!empty($params['mode']) && $params['mode'] == 'sort') { |
| 355 | - $queryParams['order'] = ['weight', 'asc']; |
|
| 355 | + $queryParams['order'] = ['weight', 'asc']; |
|
| 356 | 356 | } elseif (!empty($params['sortered']) && !empty($this->managerOptions['sortable'])) { |
| 357 | - foreach ($params['sortered'] as $key => $sortType) { |
|
| 357 | + foreach ($params['sortered'] as $key => $sortType) { |
|
| 358 | 358 | $keys = array_keys($this->managerOptions['cols']); |
| 359 | 359 | $colName = ''; |
| 360 | 360 | if (isset($keys[$key])) { |
| 361 | - if (is_array($this->managerOptions['cols'][$keys[$key]])) { |
|
| 361 | + if (is_array($this->managerOptions['cols'][$keys[$key]])) { |
|
| 362 | 362 | $colName = $keys[$key]; |
| 363 | - } else { |
|
| 363 | + } else { |
|
| 364 | 364 | $colName = $this->managerOptions['cols'][$keys[$key]]; |
| 365 | - } |
|
| 365 | + } |
|
| 366 | 366 | } |
| 367 | 367 | if ($colName && in_array($colName, $this->managerOptions['sortable'])) { |
| 368 | - $sortType = in_array($sortType, ['desc', 'asc']) ? $sortType : 'desc'; |
|
| 369 | - $queryParams['order'][] = [$colName, $sortType]; |
|
| 368 | + $sortType = in_array($sortType, ['desc', 'asc']) ? $sortType : 'desc'; |
|
| 369 | + $queryParams['order'][] = [$colName, $sortType]; |
|
| 370 | + } |
|
| 370 | 371 | } |
| 371 | - } |
|
| 372 | 372 | } |
| 373 | 373 | if ($model && !empty($params['relation'])) { |
| 374 | - $relation = $model::getRelation($params['relation']); |
|
| 375 | - $items = $model->$params['relation']($queryParams); |
|
| 374 | + $relation = $model::getRelation($params['relation']); |
|
| 375 | + $items = $model->$params['relation']($queryParams); |
|
| 376 | 376 | } else { |
| 377 | - $relation = false; |
|
| 378 | - $items = $modelName::getList($queryParams); |
|
| 377 | + $relation = false; |
|
| 378 | + $items = $modelName::getList($queryParams); |
|
| 379 | 379 | } |
| 380 | 380 | $rows = []; |
| 381 | 381 | foreach ($items as $item) { |
| 382 | - if ($relation && !empty($relation['relModel'])) { |
|
| 382 | + if ($relation && !empty($relation['relModel'])) { |
|
| 383 | 383 | $item = $relation['relModel']::get([[$item->index(), $item->id], [$model->index(), $model->id]]); |
| 384 | - } |
|
| 385 | - $row = []; |
|
| 386 | - $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
| 387 | - $row[] = $item->pk(); |
|
| 388 | - foreach ($this->managerOptions['cols'] as $key => $colName) { |
|
| 384 | + } |
|
| 385 | + $row = []; |
|
| 386 | + $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
| 387 | + $row[] = $item->pk(); |
|
| 388 | + foreach ($this->managerOptions['cols'] as $key => $colName) { |
|
| 389 | 389 | if (!empty($params['download'])) { |
| 390 | - $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
|
| 390 | + $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
|
| 391 | 391 | } else { |
| 392 | - $row[] = DataManager::drawCol($item, is_array($colName) ? $key : $colName, $params, $this); |
|
| 392 | + $row[] = DataManager::drawCol($item, is_array($colName) ? $key : $colName, $params, $this); |
|
| 393 | + } |
|
| 393 | 394 | } |
| 394 | - } |
|
| 395 | - $row[] = $this->rowButtons($item, $params); |
|
| 396 | - $rows[] = $row; |
|
| 395 | + $row[] = $this->rowButtons($item, $params); |
|
| 396 | + $rows[] = $row; |
|
| 397 | 397 | } |
| 398 | 398 | return $rows; |
| 399 | - } |
|
| 399 | + } |
|
| 400 | 400 | |
| 401 | - public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
|
| 401 | + public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
|
| 402 | 402 | $modelName = get_class($item); |
| 403 | 403 | if (!class_exists($modelName)) { |
| 404 | - return false; |
|
| 404 | + return false; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | if (!$originalCol) { |
| 408 | - $originalCol = $colName; |
|
| 408 | + $originalCol = $colName; |
|
| 409 | 409 | } |
| 410 | 410 | if (!$originalItem) { |
| 411 | - $originalItem = $item; |
|
| 411 | + $originalItem = $item; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | $relations = $modelName::relations(); |
| 415 | 415 | if (strpos($colName, ':') !== false && !empty($relations[substr($colName, 0, strpos($colName, ':'))])) { |
| 416 | - $rel = substr($colName, 0, strpos($colName, ':')); |
|
| 417 | - $col = substr($colName, strpos($colName, ':') + 1); |
|
| 418 | - if ($item->$rel) { |
|
| 416 | + $rel = substr($colName, 0, strpos($colName, ':')); |
|
| 417 | + $col = substr($colName, strpos($colName, ':') + 1); |
|
| 418 | + if ($item->$rel) { |
|
| 419 | 419 | return DataManager::drawCol($item->$rel, $col, $params, $dataManager, $originalCol, $originalItem); |
| 420 | - } else { |
|
| 420 | + } else { |
|
| 421 | 421 | return 'Не указано'; |
| 422 | - } |
|
| 422 | + } |
|
| 423 | 423 | } |
| 424 | 424 | if (!empty($modelName::$cols[$colName]['relation'])) { |
| 425 | - $type = !empty($relations[$modelName::$cols[$colName]['relation']]['type']) ? $relations[$modelName::$cols[$colName]['relation']]['type'] : 'to'; |
|
| 426 | - switch ($type) { |
|
| 425 | + $type = !empty($relations[$modelName::$cols[$colName]['relation']]['type']) ? $relations[$modelName::$cols[$colName]['relation']]['type'] : 'to'; |
|
| 426 | + switch ($type) { |
|
| 427 | 427 | case 'relModel': |
| 428 | 428 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
| 429 | - $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
| 430 | - $count = $count ? $count : 'Нет'; |
|
| 431 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
| 429 | + $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
| 430 | + $count = $count ? $count : 'Нет'; |
|
| 431 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
| 432 | 432 | case 'many': |
| 433 | 433 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
| 434 | - $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
| 435 | - $count = $count ? $count : 'Нет'; |
|
| 436 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
| 434 | + $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
| 435 | + $count = $count ? $count : 'Нет'; |
|
| 436 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
| 437 | 437 | default : |
| 438 | 438 | if ($item->{$modelName::$cols[$colName]['relation']}) { |
| 439 | 439 | if (\App::$cur->name == 'admin') { |
| 440 | - $href = "<a href ='/admin/" . str_replace('\\', '/view/', $relations[$modelName::$cols[$colName]['relation']]['model']) . "/" . $item->{$modelName::$cols[$colName]['relation']}->pk() . "'>"; |
|
| 441 | - if (!empty($modelName::$cols[$colName]['showCol'])) { |
|
| 440 | + $href = "<a href ='/admin/" . str_replace('\\', '/view/', $relations[$modelName::$cols[$colName]['relation']]['model']) . "/" . $item->{$modelName::$cols[$colName]['relation']}->pk() . "'>"; |
|
| 441 | + if (!empty($modelName::$cols[$colName]['showCol'])) { |
|
| 442 | 442 | $href .= $item->{$modelName::$cols[$colName]['relation']}->{$modelName::$cols[$colName]['showCol']}; |
| 443 | - } else { |
|
| 443 | + } else { |
|
| 444 | 444 | |
| 445 | 445 | $href .= $item->{$modelName::$cols[$colName]['relation']}->name(); |
| 446 | - } |
|
| 447 | - $href .= '</a>'; |
|
| 448 | - return $href; |
|
| 446 | + } |
|
| 447 | + $href .= '</a>'; |
|
| 448 | + return $href; |
|
| 449 | 449 | } else { |
| 450 | - return $item->{$modelName::$cols[$colName]['relation']}->name(); |
|
| 450 | + return $item->{$modelName::$cols[$colName]['relation']}->name(); |
|
| 451 | 451 | } |
| 452 | - } else { |
|
| 452 | + } else { |
|
| 453 | 453 | return $item->$colName; |
| 454 | - } |
|
| 455 | - } |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | 456 | } else { |
| 457 | - if (!empty($modelName::$cols[$colName]['view']['type'])) { |
|
| 457 | + if (!empty($modelName::$cols[$colName]['view']['type'])) { |
|
| 458 | 458 | switch ($modelName::$cols[$colName]['view']['type']) { |
| 459 | - case 'widget': |
|
| 459 | + case 'widget': |
|
| 460 | 460 | ob_start(); |
| 461 | 461 | \App::$cur->view->widget($modelName::$cols[$colName]['view']['widget'], ['item' => $item, 'colName' => $colName, 'colParams' => $modelName::$cols[$colName]]); |
| 462 | 462 | $content = ob_get_contents(); |
| 463 | 463 | ob_end_clean(); |
| 464 | 464 | return $content; |
| 465 | - case 'moduleMethod': |
|
| 465 | + case 'moduleMethod': |
|
| 466 | 466 | return \App::$cur->{$modelName::$cols[$colName]['view']['module']}->{$modelName::$cols[$colName]['view']['method']}($item, $colName, $modelName::$cols[$colName]); |
| 467 | - case 'many': |
|
| 467 | + case 'many': |
|
| 468 | 468 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
| 469 | 469 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
| 470 | 470 | return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count} " . \Tools::getNumEnding($count, ['Элемент', 'Элемента', 'Элементов']) . "</a>"; |
| 471 | - default: |
|
| 471 | + default: |
|
| 472 | 472 | return $item->$colName; |
| 473 | 473 | } |
| 474 | - } elseif (!empty($modelName::$cols[$colName]['type'])) { |
|
| 474 | + } elseif (!empty($modelName::$cols[$colName]['type'])) { |
|
| 475 | 475 | if (\App::$cur->name == 'admin' && $originalCol == 'name' || ( $dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
| 476 | - $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
|
| 477 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
| 478 | - return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($originalItem)) . "/{$originalItem->id}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 476 | + $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
|
| 477 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
| 478 | + return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($originalItem)) . "/{$originalItem->id}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 479 | 479 | } elseif (\App::$cur->name == 'admin' && $colName == 'name') { |
| 480 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
| 481 | - return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($item)) . "/{$item->id}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 480 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
| 481 | + return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($item)) . "/{$item->id}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 482 | 482 | } else { |
| 483 | - return \Model::resloveTypeValue($item, $colName); |
|
| 483 | + return \Model::resloveTypeValue($item, $colName); |
|
| 484 | 484 | } |
| 485 | - } else { |
|
| 485 | + } else { |
|
| 486 | 486 | return $item->$colName; |
| 487 | - } |
|
| 487 | + } |
|
| 488 | + } |
|
| 488 | 489 | } |
| 489 | - } |
|
| 490 | 490 | |
| 491 | - public function rowButtons($item, $params) { |
|
| 491 | + public function rowButtons($item, $params) { |
|
| 492 | 492 | $modelName = $this->modelName; |
| 493 | 493 | if (!class_exists($modelName)) { |
| 494 | - return false; |
|
| 494 | + return false; |
|
| 495 | 495 | } |
| 496 | 496 | ob_start(); |
| 497 | 497 | $widgetName = !empty($this->managerOptions['rowButtonsWidget']) ? $this->managerOptions['rowButtonsWidget'] : 'Ui\DataManager/rowButtons'; |
@@ -503,129 +503,129 @@ discard block |
||
| 503 | 503 | $buttons = ob_get_contents(); |
| 504 | 504 | ob_end_clean(); |
| 505 | 505 | return $buttons; |
| 506 | - } |
|
| 506 | + } |
|
| 507 | 507 | |
| 508 | - public function getPages($params = [], $model = null) { |
|
| 508 | + public function getPages($params = [], $model = null) { |
|
| 509 | 509 | $modelName = $this->modelName; |
| 510 | 510 | if (!class_exists($modelName)) { |
| 511 | - return []; |
|
| 511 | + return []; |
|
| 512 | 512 | } |
| 513 | 513 | if (!$this->checkAccess()) { |
| 514 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 515 | - return []; |
|
| 514 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 515 | + return []; |
|
| 516 | 516 | } |
| 517 | 517 | if (!empty($params['limit'])) { |
| 518 | - $this->limit = (int) $params['limit']; |
|
| 518 | + $this->limit = (int) $params['limit']; |
|
| 519 | 519 | } |
| 520 | 520 | if (!empty($params['page'])) { |
| 521 | - $this->page = (int) $params['page']; |
|
| 521 | + $this->page = (int) $params['page']; |
|
| 522 | 522 | } |
| 523 | 523 | $queryParams = [ |
| 524 | 524 | 'count' => true |
| 525 | 525 | ]; |
| 526 | 526 | $modelName = $this->modelName; |
| 527 | 527 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
| 528 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
| 528 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
| 529 | 529 | } |
| 530 | 530 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
| 531 | - foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
| 531 | + foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
| 532 | 532 | if (!empty($colOptions['userCol'])) { |
| 533 | - if (strpos($colOptions['userCol'], ':')) { |
|
| 533 | + if (strpos($colOptions['userCol'], ':')) { |
|
| 534 | 534 | $rel = substr($colOptions['userCol'], 0, strpos($colOptions['userCol'], ':')); |
| 535 | 535 | $param = substr($colOptions['userCol'], strpos($colOptions['userCol'], ':') + 1); |
| 536 | 536 | $queryParams['where'][] = [$colName, \Users\User::$cur->$rel->$param]; |
| 537 | - } |
|
| 537 | + } |
|
| 538 | 538 | } elseif (isset($colOptions['value'])) { |
| 539 | - $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
| 539 | + $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
| 540 | + } |
|
| 540 | 541 | } |
| 541 | - } |
|
| 542 | 542 | } |
| 543 | 543 | $modelName = $this->modelName; |
| 544 | 544 | if (!empty($this->managerOptions['filters'])) { |
| 545 | - foreach ($this->managerOptions['filters'] as $col) { |
|
| 545 | + foreach ($this->managerOptions['filters'] as $col) { |
|
| 546 | 546 | $colInfo = $modelName::getColInfo($col); |
| 547 | 547 | switch ($colInfo['colParams']['type']) { |
| 548 | - case 'select': |
|
| 548 | + case 'select': |
|
| 549 | 549 | if (empty($params['filters'][$col]['value'])) { |
| 550 | - continue; |
|
| 550 | + continue; |
|
| 551 | 551 | } |
| 552 | 552 | if (is_array($params['filters'][$col]['value'])) { |
| 553 | - foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
| 553 | + foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
| 554 | 554 | if ($value === '') { |
| 555 | - unset($params['filters'][$col]['value'][$key]); |
|
| 555 | + unset($params['filters'][$col]['value'][$key]); |
|
| 556 | + } |
|
| 556 | 557 | } |
| 557 | - } |
|
| 558 | 558 | } |
| 559 | 559 | if (!$params['filters'][$col]['value']) { |
| 560 | - continue; |
|
| 560 | + continue; |
|
| 561 | 561 | } |
| 562 | 562 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'], is_array($params['filters'][$col]['value']) ? 'IN' : '=']; |
| 563 | 563 | break; |
| 564 | - case 'bool': |
|
| 564 | + case 'bool': |
|
| 565 | 565 | |
| 566 | 566 | if (empty($params['filters'][$col]['value'])) { |
| 567 | - continue; |
|
| 567 | + continue; |
|
| 568 | 568 | } |
| 569 | 569 | $queryParams['where'][] = [$col, '1']; |
| 570 | 570 | break; |
| 571 | - case 'dateTime': |
|
| 571 | + case 'dateTime': |
|
| 572 | 572 | case 'date': |
| 573 | 573 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
| 574 | - continue; |
|
| 574 | + continue; |
|
| 575 | 575 | } |
| 576 | 576 | if (!empty($params['filters'][$col]['min'])) { |
| 577 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 577 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 578 | 578 | } |
| 579 | 579 | if (!empty($params['filters'][$col]['max'])) { |
| 580 | - if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
| 580 | + if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
| 581 | 581 | |
| 582 | 582 | $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
| 583 | - } else { |
|
| 583 | + } else { |
|
| 584 | 584 | $date = $params['filters'][$col]['max']; |
| 585 | - } |
|
| 586 | - $queryParams['where'][] = [$col, $date, '<=']; |
|
| 585 | + } |
|
| 586 | + $queryParams['where'][] = [$col, $date, '<=']; |
|
| 587 | 587 | } |
| 588 | 588 | break; |
| 589 | - case 'number': |
|
| 589 | + case 'number': |
|
| 590 | 590 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
| 591 | - continue; |
|
| 591 | + continue; |
|
| 592 | 592 | } |
| 593 | 593 | if (!empty($params['filters'][$col]['min'])) { |
| 594 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 594 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
| 595 | 595 | } |
| 596 | 596 | if (!empty($params['filters'][$col]['max'])) { |
| 597 | - $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
| 597 | + $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
| 598 | 598 | } |
| 599 | 599 | break; |
| 600 | - case 'email': |
|
| 600 | + case 'email': |
|
| 601 | 601 | case 'text': |
| 602 | 602 | case 'textarea': |
| 603 | 603 | case 'html': |
| 604 | 604 | if (empty($params['filters'][$col]['value'])) { |
| 605 | - continue; |
|
| 605 | + continue; |
|
| 606 | 606 | } |
| 607 | 607 | switch ($params['filters'][$col]['compareType']) { |
| 608 | - case 'contains': |
|
| 608 | + case 'contains': |
|
| 609 | 609 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
| 610 | 610 | break; |
| 611 | - case 'equals': |
|
| 611 | + case 'equals': |
|
| 612 | 612 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
| 613 | 613 | break; |
| 614 | - case 'starts_with': |
|
| 614 | + case 'starts_with': |
|
| 615 | 615 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
| 616 | 616 | break; |
| 617 | - case 'ends_with': |
|
| 617 | + case 'ends_with': |
|
| 618 | 618 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
| 619 | 619 | break; |
| 620 | 620 | } |
| 621 | 621 | break; |
| 622 | 622 | } |
| 623 | - } |
|
| 623 | + } |
|
| 624 | 624 | } |
| 625 | 625 | if ($model && !empty($params['relation'])) { |
| 626 | - $count = $model->$params['relation']($queryParams); |
|
| 626 | + $count = $model->$params['relation']($queryParams); |
|
| 627 | 627 | } else { |
| 628 | - $count = $modelName::getCount($queryParams); |
|
| 628 | + $count = $modelName::getCount($queryParams); |
|
| 629 | 629 | } |
| 630 | 630 | $pages = new Pages([ |
| 631 | 631 | 'limit' => $this->limit, |
@@ -635,9 +635,9 @@ discard block |
||
| 635 | 635 | 'dataManager' => $this |
| 636 | 636 | ]); |
| 637 | 637 | return $pages; |
| 638 | - } |
|
| 638 | + } |
|
| 639 | 639 | |
| 640 | - public function preDraw($params = [], $model = null) { |
|
| 640 | + public function preDraw($params = [], $model = null) { |
|
| 641 | 641 | $this->predraw = true; |
| 642 | 642 | |
| 643 | 643 | $cols = $this->getCols(); |
@@ -645,16 +645,16 @@ discard block |
||
| 645 | 645 | $this->table = new Table(); |
| 646 | 646 | $tableCols = []; |
| 647 | 647 | foreach ($cols as $colName => $colOptions) { |
| 648 | - $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
|
| 648 | + $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
|
| 649 | 649 | } |
| 650 | 650 | $tableCols[] = ''; |
| 651 | 651 | $this->table->class .=' datamanagertable'; |
| 652 | 652 | $this->table->setCols($tableCols); |
| 653 | - } |
|
| 653 | + } |
|
| 654 | 654 | |
| 655 | - public function draw($params = [], $model = null) { |
|
| 655 | + public function draw($params = [], $model = null) { |
|
| 656 | 656 | if (!$this->predraw) { |
| 657 | - $this->preDraw($params, $model); |
|
| 657 | + $this->preDraw($params, $model); |
|
| 658 | 658 | } |
| 659 | 659 | \App::$cur->view->widget('Ui\DataManager/DataManager', [ |
| 660 | 660 | 'dataManager' => $this, |
@@ -662,58 +662,58 @@ discard block |
||
| 662 | 662 | 'table' => $this->table, |
| 663 | 663 | 'params' => $params |
| 664 | 664 | ]); |
| 665 | - } |
|
| 665 | + } |
|
| 666 | 666 | |
| 667 | - public function drawCategorys() { |
|
| 667 | + public function drawCategorys() { |
|
| 668 | 668 | if (!class_exists($this->modelName)) { |
| 669 | - return false; |
|
| 669 | + return false; |
|
| 670 | 670 | } |
| 671 | 671 | if (!$this->checkAccess()) { |
| 672 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 673 | - return []; |
|
| 672 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 673 | + return []; |
|
| 674 | 674 | } |
| 675 | 675 | $tree = new Tree(); |
| 676 | 676 | $tree->ul($this->managerOptions['categorys']['model'], 0, function($category) { |
| 677 | - $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
| 678 | - $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
|
| 679 | - return "<a href='#' onclick='inji.Ui.dataManagers.get(this).switchCategory(this);return false;' data-index='{$category->index()}' data-path ='{$path}' data-id='{$category->pk()}' data-model='{$this->managerOptions['categorys']['model']}'> {$category->name}</a> |
|
| 677 | + $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
| 678 | + $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
|
| 679 | + return "<a href='#' onclick='inji.Ui.dataManagers.get(this).switchCategory(this);return false;' data-index='{$category->index()}' data-path ='{$path}' data-id='{$category->pk()}' data-model='{$this->managerOptions['categorys']['model']}'> {$category->name}</a> |
|
| 680 | 680 | |
| 681 | 681 | <a href = '#' class ='glyphicon glyphicon-edit' onclick = 'inji.Ui.forms.popUp(\"{$cleanClassName}:{$category->pk()}\")'></a> |
| 682 | 682 | <a href = '#' class ='glyphicon glyphicon-remove' onclick = 'inji.Ui.dataManagers.get(this).delCategory({$category->pk()});return false;'></a>"; |
| 683 | 683 | }); |
| 684 | 684 | ?> |
| 685 | 685 | <?php |
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Draw error message |
|
| 690 | - * |
|
| 691 | - * @param string $errorText |
|
| 692 | - */ |
|
| 693 | - public function drawError($errorText) { |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Draw error message |
|
| 690 | + * |
|
| 691 | + * @param string $errorText |
|
| 692 | + */ |
|
| 693 | + public function drawError($errorText) { |
|
| 694 | 694 | echo $errorText; |
| 695 | - } |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Check access cur user to manager with name in param |
|
| 699 | - * |
|
| 700 | - * @return boolean |
|
| 701 | - */ |
|
| 702 | - public function checkAccess() { |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Check access cur user to manager with name in param |
|
| 699 | + * |
|
| 700 | + * @return boolean |
|
| 701 | + */ |
|
| 702 | + public function checkAccess() { |
|
| 703 | 703 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
| 704 | - return false; |
|
| 704 | + return false; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | if (!empty($this->managerOptions['options']['access']['apps']) && !in_array(\App::$cur->name, $this->managerOptions['options']['access']['apps'])) { |
| 708 | - return false; |
|
| 708 | + return false; |
|
| 709 | 709 | } |
| 710 | 710 | if (!empty($this->managerOptions['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->managerOptions['options']['access']['groups'])) { |
| 711 | - return true; |
|
| 711 | + return true; |
|
| 712 | 712 | } |
| 713 | 713 | if ($this->managerName == 'manager' && !\Users\User::$cur->isAdmin()) { |
| 714 | - return false; |
|
| 714 | + return false; |
|
| 715 | 715 | } |
| 716 | 716 | return true; |
| 717 | - } |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | 719 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $this->name = $this->managerOptions['name']; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $this->managerId = str_replace('\\', '_', 'dataManager_' . $this->modelName . '_' . $this->managerName . '_' . \Tools::randomString()); |
|
| 60 | + $this->managerId = str_replace('\\', '_', 'dataManager_'.$this->modelName.'_'.$this->managerName.'_'.\Tools::randomString()); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | if (!empty($this->managerOptions['filters'])) { |
| 104 | 104 | $buttons[] = [ |
| 105 | 105 | 'text' => 'Фильтры', |
| 106 | - 'onclick' => ' var modal = $("#' . $this->managerId . '_filters"); |
|
| 106 | + 'onclick' => ' var modal = $("#'.$this->managerId.'_filters"); |
|
| 107 | 107 | modal.modal("show");', |
| 108 | 108 | ]; |
| 109 | 109 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | $formParams['formName'] = 'simpleItem'; |
| 112 | 112 | $buttons[] = [ |
| 113 | 113 | 'text' => '<i class = "glyphicon glyphicon-send"></i> Быстрое создание', |
| 114 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
| 114 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("'.str_replace('\\', '\\\\', $modelName).'",'.json_encode($formParams).');', |
|
| 115 | 115 | ]; |
| 116 | 116 | } |
| 117 | 117 | $formParams['formName'] = !empty($this->managerOptions['editForm']) ? $this->managerOptions['editForm'] : 'manager'; |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | if (!empty($modelName::$forms[$formParams['formName']])) { |
| 123 | 123 | $buttons[] = [ |
| 124 | - 'text' => 'Создать ' . $name, |
|
| 125 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
| 124 | + 'text' => 'Создать '.$name, |
|
| 125 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("'.str_replace('\\', '\\\\', $modelName).'",'.json_encode($formParams).');', |
|
| 126 | 126 | ]; |
| 127 | 127 | } |
| 128 | 128 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | 'className' => $action |
| 153 | 153 | ]; |
| 154 | 154 | } |
| 155 | - $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\' . $return[$key]['className']) ? 'Ui\DataManager\Action\\' . $return[$key]['className'] : $return[$key]['className']; |
|
| 155 | + $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\'.$return[$key]['className']) ? 'Ui\DataManager\Action\\'.$return[$key]['className'] : $return[$key]['className']; |
|
| 156 | 156 | if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
| 157 | 157 | unset($return[$key]); |
| 158 | 158 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | <?php |
| 184 | 184 | foreach ($actions as $action => $actionParams) { |
| 185 | 185 | if (class_exists($actionParams['className']) && $actionParams['className']::$groupAction) { |
| 186 | - echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
| 186 | + echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"".str_replace('\\', '\\\\', $action)."\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | ?> |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | return []; |
| 234 | 234 | } |
| 235 | 235 | if (!$this->checkAccess()) { |
| 236 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 236 | + $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->managerName.'"'); |
|
| 237 | 237 | return []; |
| 238 | 238 | } |
| 239 | 239 | $modelName = $this->modelName; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $queryParams['start'] = $this->page * $this->limit - $this->limit; |
| 250 | 250 | } |
| 251 | 251 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
| 252 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
| 252 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'].'%', 'LIKE']; |
|
| 253 | 253 | } |
| 254 | 254 | if (!empty($params['appType'])) { |
| 255 | 255 | $queryParams['appType'] = $params['appType']; |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | if (!empty($params['filters'][$col]['max'])) { |
| 309 | 309 | if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
| 310 | 310 | |
| 311 | - $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
|
| 311 | + $date = $params['filters'][$col]['max'].' 23:59:59'; |
|
| 312 | 312 | } else { |
| 313 | 313 | $date = $params['filters'][$col]['max']; |
| 314 | 314 | } |
@@ -335,16 +335,16 @@ discard block |
||
| 335 | 335 | } |
| 336 | 336 | switch ($params['filters'][$col]['compareType']) { |
| 337 | 337 | case 'contains': |
| 338 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
| 338 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'].'%', 'LIKE']; |
|
| 339 | 339 | break; |
| 340 | 340 | case 'equals': |
| 341 | 341 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
| 342 | 342 | break; |
| 343 | 343 | case 'starts_with': |
| 344 | - $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
| 344 | + $queryParams['where'][] = [$col, $params['filters'][$col]['value'].'%', 'LIKE']; |
|
| 345 | 345 | break; |
| 346 | 346 | case 'ends_with': |
| 347 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
|
| 347 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'], 'LIKE']; |
|
| 348 | 348 | break; |
| 349 | 349 | } |
| 350 | 350 | break; |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | $item = $relation['relModel']::get([[$item->index(), $item->id], [$model->index(), $model->id]]); |
| 384 | 384 | } |
| 385 | 385 | $row = []; |
| 386 | - $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
| 386 | + $row[] = '<input type ="checkbox" name = "pk[]" value ='.$item->pk().'>'; |
|
| 387 | 387 | $row[] = $item->pk(); |
| 388 | 388 | foreach ($this->managerOptions['cols'] as $key => $colName) { |
| 389 | 389 | if (!empty($params['download'])) { |
@@ -428,16 +428,16 @@ discard block |
||
| 428 | 428 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
| 429 | 429 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
| 430 | 430 | $count = $count ? $count : 'Нет'; |
| 431 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
| 431 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"".str_replace('\\', '\\\\', $modelName).":".$item->pk()."\",".json_encode(array_merge($params, $managerParams)).")'>{$count}</a>"; |
|
| 432 | 432 | case 'many': |
| 433 | 433 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
| 434 | 434 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
| 435 | 435 | $count = $count ? $count : 'Нет'; |
| 436 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
| 436 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"".str_replace('\\', '\\\\', $modelName).":".$item->pk()."\",".json_encode(array_merge($params, $managerParams)).")'>{$count}</a>"; |
|
| 437 | 437 | default : |
| 438 | 438 | if ($item->{$modelName::$cols[$colName]['relation']}) { |
| 439 | 439 | if (\App::$cur->name == 'admin') { |
| 440 | - $href = "<a href ='/admin/" . str_replace('\\', '/view/', $relations[$modelName::$cols[$colName]['relation']]['model']) . "/" . $item->{$modelName::$cols[$colName]['relation']}->pk() . "'>"; |
|
| 440 | + $href = "<a href ='/admin/".str_replace('\\', '/view/', $relations[$modelName::$cols[$colName]['relation']]['model'])."/".$item->{$modelName::$cols[$colName]['relation']}->pk()."'>"; |
|
| 441 | 441 | if (!empty($modelName::$cols[$colName]['showCol'])) { |
| 442 | 442 | $href .= $item->{$modelName::$cols[$colName]['relation']}->{$modelName::$cols[$colName]['showCol']}; |
| 443 | 443 | } else { |
@@ -467,18 +467,18 @@ discard block |
||
| 467 | 467 | case 'many': |
| 468 | 468 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
| 469 | 469 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
| 470 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count} " . \Tools::getNumEnding($count, ['Элемент', 'Элемента', 'Элементов']) . "</a>"; |
|
| 470 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"".str_replace('\\', '\\\\', $modelName).":".$item->pk()."\",".json_encode(array_merge($params, $managerParams)).")'>{$count} ".\Tools::getNumEnding($count, ['Элемент', 'Элемента', 'Элементов'])."</a>"; |
|
| 471 | 471 | default: |
| 472 | 472 | return $item->$colName; |
| 473 | 473 | } |
| 474 | 474 | } elseif (!empty($modelName::$cols[$colName]['type'])) { |
| 475 | - if (\App::$cur->name == 'admin' && $originalCol == 'name' || ( $dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
|
| 475 | + if (\App::$cur->name == 'admin' && $originalCol == 'name' || ($dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
|
| 476 | 476 | $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
| 477 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
| 478 | - return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($originalItem)) . "/{$originalItem->id}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 477 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/'.str_replace('\\', '/', get_class($originalItem)); |
|
| 478 | + return "<a href ='/admin/".str_replace('\\', '/view/', get_class($originalItem))."/{$originalItem->id}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 479 | 479 | } elseif (\App::$cur->name == 'admin' && $colName == 'name') { |
| 480 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
| 481 | - return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($item)) . "/{$item->id}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 480 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/'.str_replace('\\', '/', get_class($originalItem)); |
|
| 481 | + return "<a href ='/admin/".str_replace('\\', '/view/', get_class($item))."/{$item->id}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
| 482 | 482 | } else { |
| 483 | 483 | return \Model::resloveTypeValue($item, $colName); |
| 484 | 484 | } |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | return []; |
| 512 | 512 | } |
| 513 | 513 | if (!$this->checkAccess()) { |
| 514 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 514 | + $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->managerName.'"'); |
|
| 515 | 515 | return []; |
| 516 | 516 | } |
| 517 | 517 | if (!empty($params['limit'])) { |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | ]; |
| 526 | 526 | $modelName = $this->modelName; |
| 527 | 527 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
| 528 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
| 528 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'].'%', 'LIKE']; |
|
| 529 | 529 | } |
| 530 | 530 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
| 531 | 531 | foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | if (!empty($params['filters'][$col]['max'])) { |
| 580 | 580 | if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
| 581 | 581 | |
| 582 | - $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
|
| 582 | + $date = $params['filters'][$col]['max'].' 23:59:59'; |
|
| 583 | 583 | } else { |
| 584 | 584 | $date = $params['filters'][$col]['max']; |
| 585 | 585 | } |
@@ -606,16 +606,16 @@ discard block |
||
| 606 | 606 | } |
| 607 | 607 | switch ($params['filters'][$col]['compareType']) { |
| 608 | 608 | case 'contains': |
| 609 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
| 609 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'].'%', 'LIKE']; |
|
| 610 | 610 | break; |
| 611 | 611 | case 'equals': |
| 612 | 612 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
| 613 | 613 | break; |
| 614 | 614 | case 'starts_with': |
| 615 | - $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
| 615 | + $queryParams['where'][] = [$col, $params['filters'][$col]['value'].'%', 'LIKE']; |
|
| 616 | 616 | break; |
| 617 | 617 | case 'ends_with': |
| 618 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
|
| 618 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'], 'LIKE']; |
|
| 619 | 619 | break; |
| 620 | 620 | } |
| 621 | 621 | break; |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
| 649 | 649 | } |
| 650 | 650 | $tableCols[] = ''; |
| 651 | - $this->table->class .=' datamanagertable'; |
|
| 651 | + $this->table->class .= ' datamanagertable'; |
|
| 652 | 652 | $this->table->setCols($tableCols); |
| 653 | 653 | } |
| 654 | 654 | |
@@ -669,12 +669,12 @@ discard block |
||
| 669 | 669 | return false; |
| 670 | 670 | } |
| 671 | 671 | if (!$this->checkAccess()) { |
| 672 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
| 672 | + $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->managerName.'"'); |
|
| 673 | 673 | return []; |
| 674 | 674 | } |
| 675 | 675 | $tree = new Tree(); |
| 676 | 676 | $tree->ul($this->managerOptions['categorys']['model'], 0, function($category) { |
| 677 | - $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
| 677 | + $path = $category->tree_path.($category->pk() ? $category->pk()."/" : ''); |
|
| 678 | 678 | $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
| 679 | 679 | return "<a href='#' onclick='inji.Ui.dataManagers.get(this).switchCategory(this);return false;' data-index='{$category->index()}' data-path ='{$path}' data-id='{$category->pk()}' data-model='{$this->managerOptions['categorys']['model']}'> {$category->name}</a> |
| 680 | 680 | |