@@ -100,4 +100,4 @@ |
||
| 100 | 100 | |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - ?> |
|
| 103 | + ?> |
|
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | function __construct($file_manageable_model, $filetype) |
| 14 | 14 | { |
| 15 | - if(!is_subclass_of($file_manageable_model, '\HexMakina\ORM\TightModel')) |
|
| 15 | + if (!is_subclass_of($file_manageable_model, '\HexMakina\ORM\TightModel')) |
|
| 16 | 16 | throw new \Exception("__construct($file_manageable_model) // only Model items are manageable"); |
| 17 | 17 | |
| 18 | 18 | $this->pmi = $file_manageable_model; |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public function download($url) |
| 33 | 33 | { |
| 34 | 34 | $filename = $this->build_filename(); |
| 35 | - $filename .= '.' . pathinfo($url, PATHINFO_EXTENSION); |
|
| 35 | + $filename .= '.'.pathinfo($url, PATHINFO_EXTENSION); |
|
| 36 | 36 | |
| 37 | 37 | $filepath = $this->build_path_to_file($filename); |
| 38 | 38 | |
@@ -58,10 +58,10 @@ discard block |
||
| 58 | 58 | return $this->pmi->get_id().'/'; |
| 59 | 59 | |
| 60 | 60 | $pmi_model_type = get_class($this->pmi)::model_type(); |
| 61 | - if(!isset($this->pmi) || is_null($this->get_type())) |
|
| 61 | + if (!isset($this->pmi) || is_null($this->get_type())) |
|
| 62 | 62 | throw new \Exception(__FUNCTION__." // undefined manageable item or picture type"); |
| 63 | 63 | |
| 64 | - if(!isset($settings[$pmi_model_type][$this->get_type()]['import_directory'])) |
|
| 64 | + if (!isset($settings[$pmi_model_type][$this->get_type()]['import_directory'])) |
|
| 65 | 65 | throw new \Exception(__FUNCTION__." // undefined configuration for '".($pmi_model_type)."'>'".$this->get_type()."'>'import_directory'"); |
| 66 | 66 | |
| 67 | 67 | // global $settings; |
@@ -12,8 +12,9 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | function __construct($file_manageable_model, $filetype) |
| 14 | 14 | { |
| 15 | - if(!is_subclass_of($file_manageable_model, '\HexMakina\ORM\TightModel')) |
|
| 16 | - throw new \Exception("__construct($file_manageable_model) // only Model items are manageable"); |
|
| 15 | + if(!is_subclass_of($file_manageable_model, '\HexMakina\ORM\TightModel')) { |
|
| 16 | + throw new \Exception("__construct($file_manageable_model) // only Model items are manageable"); |
|
| 17 | + } |
|
| 17 | 18 | |
| 18 | 19 | $this->pmi = $file_manageable_model; |
| 19 | 20 | $this->picture_type = $filetype; |
@@ -58,11 +59,13 @@ discard block |
||
| 58 | 59 | return $this->pmi->get_id().'/'; |
| 59 | 60 | |
| 60 | 61 | $pmi_model_type = get_class($this->pmi)::model_type(); |
| 61 | - if(!isset($this->pmi) || is_null($this->get_type())) |
|
| 62 | - throw new \Exception(__FUNCTION__." // undefined manageable item or picture type"); |
|
| 62 | + if(!isset($this->pmi) || is_null($this->get_type())) { |
|
| 63 | + throw new \Exception(__FUNCTION__." // undefined manageable item or picture type"); |
|
| 64 | + } |
|
| 63 | 65 | |
| 64 | - if(!isset($settings[$pmi_model_type][$this->get_type()]['import_directory'])) |
|
| 65 | - throw new \Exception(__FUNCTION__." // undefined configuration for '".($pmi_model_type)."'>'".$this->get_type()."'>'import_directory'"); |
|
| 66 | + if(!isset($settings[$pmi_model_type][$this->get_type()]['import_directory'])) { |
|
| 67 | + throw new \Exception(__FUNCTION__." // undefined configuration for '".($pmi_model_type)."'>'".$this->get_type()."'>'import_directory'"); |
|
| 68 | + } |
|
| 66 | 69 | |
| 67 | 70 | // global $settings; |
| 68 | 71 | // return $settings[$pmi_model_type][$this->get_type()]['import_directory'].$this->pmi->get_id().'/'; |
@@ -15,4 +15,4 @@ |
||
| 15 | 15 | } |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - ?> |
|
| 18 | + ?> |
|
@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | $picture_directory = $this->build_path_to_directory(); |
| 31 | 31 | $thumbnail_directory = $picture_directory; |
| 32 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 33 | - throw new PictureManagerException("directory '$picture_directory' does not exist"); |
|
| 32 | + if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 33 | + throw new PictureManagerException("directory '$picture_directory' does not exist"); |
|
| 34 | 34 | |
| 35 | 35 | $filenames = self::preg_scandir($picture_directory, self::FILENAME_REGEX); |
| 36 | 36 | |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
| 88 | 88 | $filepath = $this->locate_file($filepath); |
| 89 | 89 | |
| 90 | - if(file_exists($filepath)) |
|
| 90 | + if(file_exists($filepath)) |
|
| 91 | 91 | throw new PictureManagerException($this->get_type()." new path '$filepath' already exists"); |
| 92 | 92 | |
| 93 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 94 | - throw new PictureManagerException(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 93 | + if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 94 | + throw new PictureManagerException(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 95 | 95 | |
| 96 | 96 | $this->make_thumbnail($filepath); |
| 97 | 97 | } |
@@ -107,64 +107,64 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | public function make_thumbnail($filepath) |
| 110 | - { |
|
| 110 | + { |
|
| 111 | 111 | global $settings; |
| 112 | 112 | |
| 113 | - $cover_iri = null; |
|
| 114 | - |
|
| 115 | - $mime_type = mime_content_type($filepath); |
|
| 116 | - switch($mime_type) |
|
| 117 | - { |
|
| 118 | - case 'image/jpeg': |
|
| 119 | - case 'image/pjpeg': |
|
| 120 | - $cover_iri = imagecreatefromjpeg($filepath); |
|
| 121 | - break; |
|
| 113 | + $cover_iri = null; |
|
| 122 | 114 | |
| 123 | - case 'image/png': |
|
| 124 | - $cover_iri = imagecreatefrompng($filepath); |
|
| 125 | - break; |
|
| 126 | - |
|
| 127 | - case 'image/gif': |
|
| 128 | - $cover_iri = imagecreatefromgif($filepath); |
|
| 129 | - break; |
|
| 130 | - } |
|
| 115 | + $mime_type = mime_content_type($filepath); |
|
| 116 | + switch($mime_type) |
|
| 117 | + { |
|
| 118 | + case 'image/jpeg': |
|
| 119 | + case 'image/pjpeg': |
|
| 120 | + $cover_iri = imagecreatefromjpeg($filepath); |
|
| 121 | + break; |
|
| 122 | + |
|
| 123 | + case 'image/png': |
|
| 124 | + $cover_iri = imagecreatefrompng($filepath); |
|
| 125 | + break; |
|
| 126 | + |
|
| 127 | + case 'image/gif': |
|
| 128 | + $cover_iri = imagecreatefromgif($filepath); |
|
| 129 | + break; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - if(!is_null($cover_iri)) |
|
| 133 | - { |
|
| 134 | - $width = imagesx( $cover_iri ); |
|
| 135 | - $height = imagesy( $cover_iri ); |
|
| 132 | + if(!is_null($cover_iri)) |
|
| 133 | + { |
|
| 134 | + $width = imagesx( $cover_iri ); |
|
| 135 | + $height = imagesy( $cover_iri ); |
|
| 136 | 136 | |
| 137 | - // calculate thumbnail size |
|
| 137 | + // calculate thumbnail size |
|
| 138 | 138 | |
| 139 | - $new_width = $settings[get_class($this->pmi)::model_type()][$this->get_type()]['thumbnail']['width']; |
|
| 140 | - $new_height = floor( $height * ( $new_width / $width ) ); |
|
| 139 | + $new_width = $settings[get_class($this->pmi)::model_type()][$this->get_type()]['thumbnail']['width']; |
|
| 140 | + $new_height = floor( $height * ( $new_width / $width ) ); |
|
| 141 | 141 | |
| 142 | - // create a new temporary image |
|
| 143 | - $thumb_iri = imagecreatetruecolor($new_width, $new_height); |
|
| 142 | + // create a new temporary image |
|
| 143 | + $thumb_iri = imagecreatetruecolor($new_width, $new_height); |
|
| 144 | 144 | |
| 145 | - // copy and resize old image into new image |
|
| 146 | - imagecopyresized( $thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|
| 145 | + // copy and resize old image into new image |
|
| 146 | + imagecopyresized( $thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|
| 147 | 147 | |
| 148 | - // save thumbnail into a file |
|
| 148 | + // save thumbnail into a file |
|
| 149 | 149 | imagejpeg($thumb_iri, $this->locate_thumbnail(pathinfo($filepath, PATHINFO_BASENAME))); |
| 150 | - } |
|
| 151 | - } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | 153 | public function remove_all() |
| 154 | 154 | { |
| 155 | 155 | $filenames = $this->filenames(); |
| 156 | 156 | |
| 157 | 157 | foreach($filenames as $filename) |
| 158 | - $this->remove($filename); |
|
| 158 | + $this->remove($filename); |
|
| 159 | 159 | |
| 160 | 160 | $directory = $this->build_path_to_directory(); |
| 161 | - if(file_exists($directory) === true) |
|
| 161 | + if(file_exists($directory) === true) |
|
| 162 | 162 | { |
| 163 | 163 | if(is_dir($directory) === false) |
| 164 | 164 | throw new PictureManagerException($this->get_type()."' directory '$directory' is not a directory"); |
| 165 | 165 | |
| 166 | - if(rmdir($directory) === false) |
|
| 167 | - throw new PictureManagerException("rmdir($directory) failed like a bitch"); |
|
| 166 | + if(rmdir($directory) === false) |
|
| 167 | + throw new PictureManagerException("rmdir($directory) failed like a bitch"); |
|
| 168 | 168 | } |
| 169 | 169 | else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
| 170 | 170 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | foreach($pathes as $what => $path) |
| 182 | 182 | { |
| 183 | 183 | $error = null; |
| 184 | - if(!file_exists($path)) |
|
| 184 | + if(!file_exists($path)) |
|
| 185 | 185 | $error = 'file does not exist'; |
| 186 | 186 | elseif(unlink($path)===false) |
| 187 | 187 | $error = 'unlink() failed'; |
@@ -235,16 +235,16 @@ discard block |
||
| 235 | 235 | global $settings; |
| 236 | 236 | $pi_manager = new PictureManager($item, $picture_type); |
| 237 | 237 | |
| 238 | - $pictures = $pi_manager->filenames(); |
|
| 238 | + $pictures = $pi_manager->filenames(); |
|
| 239 | 239 | |
| 240 | 240 | $item_model_type = get_class($item)::model_type(); |
| 241 | 241 | if(count($pictures)===0) |
| 242 | 242 | return hopper::file_uri($settings[$item_model_type][$picture_type]['generic_picture']); |
| 243 | 243 | |
| 244 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 245 | - $filename = $pictures[array_rand($pictures, 1)]; |
|
| 246 | - else |
|
| 247 | - $filename = array_shift($pictures); |
|
| 244 | + if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 245 | + $filename = $pictures[array_rand($pictures, 1)]; |
|
| 246 | + else |
|
| 247 | + $filename = array_shift($pictures); |
|
| 248 | 248 | |
| 249 | 249 | return hopper::file_uri( $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename)); |
| 250 | 250 | } |
@@ -25,11 +25,11 @@ discard block |
||
| 25 | 25 | // const MOVIE_POSTER = 'poster'; |
| 26 | 26 | // const MOVIE_SNAPSHOT = 'snapshot'; |
| 27 | 27 | |
| 28 | - public function filenames($replace_by_thumbs_if_exists=false) |
|
| 28 | + public function filenames($replace_by_thumbs_if_exists = false) |
|
| 29 | 29 | { |
| 30 | 30 | $picture_directory = $this->build_path_to_directory(); |
| 31 | 31 | $thumbnail_directory = $picture_directory; |
| 32 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 32 | + if (!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 33 | 33 | throw new PictureManagerException("directory '$picture_directory' does not exist"); |
| 34 | 34 | |
| 35 | 35 | $filenames = self::preg_scandir($picture_directory, self::FILENAME_REGEX); |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | return $filenames; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function filepathes($replace_by_thumbs_if_exists=false) |
|
| 41 | + public function filepathes($replace_by_thumbs_if_exists = false) |
|
| 42 | 42 | { |
| 43 | 43 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 44 | 44 | $filepathes = []; |
| 45 | - foreach($filenames as $filename) |
|
| 45 | + foreach ($filenames as $filename) |
|
| 46 | 46 | $filepathes[] = $this->locate_thumbnail($filename); |
| 47 | 47 | |
| 48 | 48 | return $filepathes; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function file_uris($replace_by_thumbs_if_exists=false) |
|
| 51 | + public function file_uris($replace_by_thumbs_if_exists = false) |
|
| 52 | 52 | { |
| 53 | 53 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 54 | 54 | $uris = []; |
| 55 | - foreach($filenames as $filename) |
|
| 55 | + foreach ($filenames as $filename) |
|
| 56 | 56 | $uris[] = hopper::file_uri($this->locate_file($filename)); ; |
| 57 | 57 | |
| 58 | 58 | return $uris; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | 'image/gif' => 'imagecreatefromgif', |
| 68 | 68 | ); |
| 69 | 69 | $mime = mime_content_type($filepath); |
| 70 | - if(array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
| 70 | + if (array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
| 71 | 71 | return true; |
| 72 | 72 | return $mime; |
| 73 | 73 | } |
@@ -75,22 +75,22 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function upload() |
| 77 | 77 | { |
| 78 | - if(!array_key_exists($this->get_type(), $_FILES)) |
|
| 78 | + if (!array_key_exists($this->get_type(), $_FILES)) |
|
| 79 | 79 | throw new PictureManagerException($this->get_type()." not found in _FILES"); |
| 80 | 80 | |
| 81 | - if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
| 81 | + if (!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
| 82 | 82 | throw new PictureManagerException('uploaded file has no size'); |
| 83 | 83 | |
| 84 | - if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
| 84 | + if (($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
| 85 | 85 | throw new PictureManagerException('data sent is not an image but a '.$file_type.''); |
| 86 | 86 | |
| 87 | - $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
|
| 87 | + $filepath = $this->build_filename().'.'.self::file_ext($_FILES[$this->get_type()]['name']); |
|
| 88 | 88 | $filepath = $this->locate_file($filepath); |
| 89 | 89 | |
| 90 | - if(file_exists($filepath)) |
|
| 90 | + if (file_exists($filepath)) |
|
| 91 | 91 | throw new PictureManagerException($this->get_type()." new path '$filepath' already exists"); |
| 92 | 92 | |
| 93 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 93 | + if (copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 94 | 94 | throw new PictureManagerException(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
| 95 | 95 | |
| 96 | 96 | $this->make_thumbnail($filepath); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | public function download($url) |
| 100 | 100 | { |
| 101 | - $filepath = $this->build_filename() . '.' . self::file_ext($url); |
|
| 101 | + $filepath = $this->build_filename().'.'.self::file_ext($url); |
|
| 102 | 102 | $filepath = $this->locate_file($filepath); |
| 103 | 103 | |
| 104 | 104 | \qivive\Curlyb::fetch($url, $filepath); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $cover_iri = null; |
| 114 | 114 | |
| 115 | 115 | $mime_type = mime_content_type($filepath); |
| 116 | - switch($mime_type) |
|
| 116 | + switch ($mime_type) |
|
| 117 | 117 | { |
| 118 | 118 | case 'image/jpeg': |
| 119 | 119 | case 'image/pjpeg': |
@@ -129,21 +129,21 @@ discard block |
||
| 129 | 129 | break; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if(!is_null($cover_iri)) |
|
| 132 | + if (!is_null($cover_iri)) |
|
| 133 | 133 | { |
| 134 | - $width = imagesx( $cover_iri ); |
|
| 135 | - $height = imagesy( $cover_iri ); |
|
| 134 | + $width = imagesx($cover_iri); |
|
| 135 | + $height = imagesy($cover_iri); |
|
| 136 | 136 | |
| 137 | 137 | // calculate thumbnail size |
| 138 | 138 | |
| 139 | 139 | $new_width = $settings[get_class($this->pmi)::model_type()][$this->get_type()]['thumbnail']['width']; |
| 140 | - $new_height = floor( $height * ( $new_width / $width ) ); |
|
| 140 | + $new_height = floor($height * ($new_width / $width)); |
|
| 141 | 141 | |
| 142 | 142 | // create a new temporary image |
| 143 | 143 | $thumb_iri = imagecreatetruecolor($new_width, $new_height); |
| 144 | 144 | |
| 145 | 145 | // copy and resize old image into new image |
| 146 | - imagecopyresized( $thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); |
|
| 146 | + imagecopyresized($thumb_iri, $cover_iri, 0, 0, 0, 0, $new_width, $new_height, $width, $height); |
|
| 147 | 147 | |
| 148 | 148 | // save thumbnail into a file |
| 149 | 149 | imagejpeg($thumb_iri, $this->locate_thumbnail(pathinfo($filepath, PATHINFO_BASENAME))); |
@@ -154,16 +154,16 @@ discard block |
||
| 154 | 154 | { |
| 155 | 155 | $filenames = $this->filenames(); |
| 156 | 156 | |
| 157 | - foreach($filenames as $filename) |
|
| 157 | + foreach ($filenames as $filename) |
|
| 158 | 158 | $this->remove($filename); |
| 159 | 159 | |
| 160 | 160 | $directory = $this->build_path_to_directory(); |
| 161 | - if(file_exists($directory) === true) |
|
| 161 | + if (file_exists($directory) === true) |
|
| 162 | 162 | { |
| 163 | - if(is_dir($directory) === false) |
|
| 163 | + if (is_dir($directory) === false) |
|
| 164 | 164 | throw new PictureManagerException($this->get_type()."' directory '$directory' is not a directory"); |
| 165 | 165 | |
| 166 | - if(rmdir($directory) === false) |
|
| 166 | + if (rmdir($directory) === false) |
|
| 167 | 167 | throw new PictureManagerException("rmdir($directory) failed like a bitch"); |
| 168 | 168 | } |
| 169 | 169 | else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
@@ -174,27 +174,27 @@ discard block |
||
| 174 | 174 | // removing a picture, and maybe a thumbnail? build the $pathes array accordingly |
| 175 | 175 | $pathes = []; |
| 176 | 176 | $pathes[$this->get_type()] = $this->locate_file($picture_filename); |
| 177 | - $pathes[$this->get_type() . ' thumbnail'] = $this->locate_thumbnail($picture_filename); |
|
| 177 | + $pathes[$this->get_type().' thumbnail'] = $this->locate_thumbnail($picture_filename); |
|
| 178 | 178 | |
| 179 | 179 | $deleted = []; |
| 180 | 180 | $still_walking = []; |
| 181 | - foreach($pathes as $what => $path) |
|
| 181 | + foreach ($pathes as $what => $path) |
|
| 182 | 182 | { |
| 183 | 183 | $error = null; |
| 184 | - if(!file_exists($path)) |
|
| 184 | + if (!file_exists($path)) |
|
| 185 | 185 | $error = 'file does not exist'; |
| 186 | - elseif(unlink($path)===false) |
|
| 186 | + elseif (unlink($path) === false) |
|
| 187 | 187 | $error = 'unlink() failed'; |
| 188 | 188 | |
| 189 | - if(is_null($error)) |
|
| 190 | - $deleted[]= $what; |
|
| 189 | + if (is_null($error)) |
|
| 190 | + $deleted[] = $what; |
|
| 191 | 191 | else |
| 192 | 192 | { |
| 193 | 193 | trigger_error(__FUNCTION__." '$picture_filename' ($what @ $path) impossible because ", E_USER_NOTICE); |
| 194 | - $still_walking[]=$what; |
|
| 194 | + $still_walking[] = $what; |
|
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | - return count($still_walking)===0; |
|
| 197 | + return count($still_walking) === 0; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | public function locate_thumbnail($filename) |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | return $settings['thumbnail']['file_prefix'].''.pathinfo($picture_basename, PATHINFO_FILENAME).'.jpg'; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - public static function file_info($absolute_path_to_picture, $what=null) |
|
| 211 | + public static function file_info($absolute_path_to_picture, $what = null) |
|
| 212 | 212 | { |
| 213 | - $ret = parent::file_info($absolute_path_to_picture, $what=null); |
|
| 213 | + $ret = parent::file_info($absolute_path_to_picture, $what = null); |
|
| 214 | 214 | |
| 215 | - if(is_array($ret)) |
|
| 215 | + if (is_array($ret)) |
|
| 216 | 216 | { |
| 217 | 217 | $t = getimagesize($absolute_path_to_picture); |
| 218 | 218 | $ret['width'] = $t[0]; |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
| 233 | - public static function uri_for($item, $picture_type, $thumbnail=true) |
|
| 233 | + public static function uri_for($item, $picture_type, $thumbnail = true) |
|
| 234 | 234 | { |
| 235 | 235 | global $settings; |
| 236 | 236 | $pi_manager = new PictureManager($item, $picture_type); |
@@ -238,24 +238,24 @@ discard block |
||
| 238 | 238 | $pictures = $pi_manager->filenames(); |
| 239 | 239 | |
| 240 | 240 | $item_model_type = get_class($item)::model_type(); |
| 241 | - if(count($pictures)===0) |
|
| 241 | + if (count($pictures) === 0) |
|
| 242 | 242 | return hopper::file_uri($settings[$item_model_type][$picture_type]['generic_picture']); |
| 243 | 243 | |
| 244 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 244 | + if ($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 245 | 245 | $filename = $pictures[array_rand($pictures, 1)]; |
| 246 | 246 | else |
| 247 | 247 | $filename = array_shift($pictures); |
| 248 | 248 | |
| 249 | - return hopper::file_uri( $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename)); |
|
| 249 | + return hopper::file_uri($thumbnail === true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename)); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | public function last_index() |
| 253 | 253 | { |
| 254 | 254 | $last_index = 0; |
| 255 | - if(count($filenames = $this->filenames()) > 0) |
|
| 255 | + if (count($filenames = $this->filenames()) > 0) |
|
| 256 | 256 | { |
| 257 | 257 | $last_filename = array_pop($filenames); // last cover name FIXME sort should be done here, check cost if sort already done |
| 258 | - if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
| 258 | + if (preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
| 259 | 259 | throw new PictureManagerException("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
| 260 | 260 | |
| 261 | 261 | $last_index = $last_index[1]; |
@@ -269,9 +269,9 @@ discard block |
||
| 269 | 269 | return sprintf('%s%s.jpg', $settings['thumbnail']['file_prefix'], pathinfo($picture_basename, PATHINFO_FILENAME)); |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - public function build_filename($index=null) |
|
| 272 | + public function build_filename($index = null) |
|
| 273 | 273 | { |
| 274 | - if(is_null($index)) |
|
| 274 | + if (is_null($index)) |
|
| 275 | 275 | $index = $this->last_index()+1; |
| 276 | 276 | |
| 277 | 277 | return $this->pmi->id.'_'.sprintf("%'.09d", $index); // prepend bean id |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | $new_thumbname_path = $this->locate_file($this->build_thumb_filename($new_filename_path)); //move current to zero |
| 291 | 291 | $this->rename($selected_thumbname_path, $new_thumbname_path); |
| 292 | 292 | |
| 293 | - for($i=$filename_index-1; $i>=0; --$i) |
|
| 293 | + for ($i = $filename_index-1; $i >= 0; --$i) |
|
| 294 | 294 | { |
| 295 | 295 | $move_this = $this->locate_file($files[$i]); |
| 296 | 296 | $to_that = $this->locate_file($files[$i+1]); |
@@ -29,8 +29,9 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | $picture_directory = $this->build_path_to_directory(); |
| 31 | 31 | $thumbnail_directory = $picture_directory; |
| 32 | - if(!file_exists($picture_directory) && mkdir($picture_directory) === false) |
|
| 33 | - throw new PictureManagerException("directory '$picture_directory' does not exist"); |
|
| 32 | + if(!file_exists($picture_directory) && mkdir($picture_directory) === false) { |
|
| 33 | + throw new PictureManagerException("directory '$picture_directory' does not exist"); |
|
| 34 | + } |
|
| 34 | 35 | |
| 35 | 36 | $filenames = self::preg_scandir($picture_directory, self::FILENAME_REGEX); |
| 36 | 37 | |
@@ -42,8 +43,9 @@ discard block |
||
| 42 | 43 | { |
| 43 | 44 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 44 | 45 | $filepathes = []; |
| 45 | - foreach($filenames as $filename) |
|
| 46 | - $filepathes[] = $this->locate_thumbnail($filename); |
|
| 46 | + foreach($filenames as $filename) { |
|
| 47 | + $filepathes[] = $this->locate_thumbnail($filename); |
|
| 48 | + } |
|
| 47 | 49 | |
| 48 | 50 | return $filepathes; |
| 49 | 51 | } |
@@ -52,8 +54,10 @@ discard block |
||
| 52 | 54 | { |
| 53 | 55 | $filenames = $this->filenames($replace_by_thumbs_if_exists); |
| 54 | 56 | $uris = []; |
| 55 | - foreach($filenames as $filename) |
|
| 56 | - $uris[] = hopper::file_uri($this->locate_file($filename)); ; |
|
| 57 | + foreach($filenames as $filename) { |
|
| 58 | + $uris[] = hopper::file_uri($this->locate_file($filename)); |
|
| 59 | + } |
|
| 60 | + ; |
|
| 57 | 61 | |
| 58 | 62 | return $uris; |
| 59 | 63 | } |
@@ -67,31 +71,37 @@ discard block |
||
| 67 | 71 | 'image/gif' => 'imagecreatefromgif', |
| 68 | 72 | ); |
| 69 | 73 | $mime = mime_content_type($filepath); |
| 70 | - if(array_key_exists($mime, $picture_mime_to_gd_create_function)) |
|
| 71 | - return true; |
|
| 74 | + if(array_key_exists($mime, $picture_mime_to_gd_create_function)) { |
|
| 75 | + return true; |
|
| 76 | + } |
|
| 72 | 77 | return $mime; |
| 73 | 78 | } |
| 74 | 79 | |
| 75 | 80 | |
| 76 | 81 | public function upload() |
| 77 | 82 | { |
| 78 | - if(!array_key_exists($this->get_type(), $_FILES)) |
|
| 79 | - throw new PictureManagerException($this->get_type()." not found in _FILES"); |
|
| 83 | + if(!array_key_exists($this->get_type(), $_FILES)) { |
|
| 84 | + throw new PictureManagerException($this->get_type()." not found in _FILES"); |
|
| 85 | + } |
|
| 80 | 86 | |
| 81 | - if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) |
|
| 82 | - throw new PictureManagerException('uploaded file has no size'); |
|
| 87 | + if(!array_key_exists('size', $_FILES[$this->get_type()]) || $_FILES[$this->get_type()]['size'] == 0) { |
|
| 88 | + throw new PictureManagerException('uploaded file has no size'); |
|
| 89 | + } |
|
| 83 | 90 | |
| 84 | - if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) |
|
| 85 | - throw new PictureManagerException('data sent is not an image but a '.$file_type.''); |
|
| 91 | + if(($file_type = self::is_picture_file($_FILES[$this->get_type()]['tmp_name'])) !== true) { |
|
| 92 | + throw new PictureManagerException('data sent is not an image but a '.$file_type.''); |
|
| 93 | + } |
|
| 86 | 94 | |
| 87 | 95 | $filepath = $this->build_filename() . '.' . self::file_ext($_FILES[$this->get_type()]['name']); |
| 88 | 96 | $filepath = $this->locate_file($filepath); |
| 89 | 97 | |
| 90 | - if(file_exists($filepath)) |
|
| 91 | - throw new PictureManagerException($this->get_type()." new path '$filepath' already exists"); |
|
| 98 | + if(file_exists($filepath)) { |
|
| 99 | + throw new PictureManagerException($this->get_type()." new path '$filepath' already exists"); |
|
| 100 | + } |
|
| 92 | 101 | |
| 93 | - if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) |
|
| 94 | - throw new PictureManagerException(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 102 | + if(copy($_FILES[$this->get_type()]['tmp_name'], $filepath) === false) { |
|
| 103 | + throw new PictureManagerException(" cant copy ".$_FILES[$this->get_type()]['name']." to ($filepath)"); |
|
| 104 | + } |
|
| 95 | 105 | |
| 96 | 106 | $this->make_thumbnail($filepath); |
| 97 | 107 | } |
@@ -154,19 +164,23 @@ discard block |
||
| 154 | 164 | { |
| 155 | 165 | $filenames = $this->filenames(); |
| 156 | 166 | |
| 157 | - foreach($filenames as $filename) |
|
| 158 | - $this->remove($filename); |
|
| 167 | + foreach($filenames as $filename) { |
|
| 168 | + $this->remove($filename); |
|
| 169 | + } |
|
| 159 | 170 | |
| 160 | 171 | $directory = $this->build_path_to_directory(); |
| 161 | 172 | if(file_exists($directory) === true) |
| 162 | 173 | { |
| 163 | - if(is_dir($directory) === false) |
|
| 164 | - throw new PictureManagerException($this->get_type()."' directory '$directory' is not a directory"); |
|
| 174 | + if(is_dir($directory) === false) { |
|
| 175 | + throw new PictureManagerException($this->get_type()."' directory '$directory' is not a directory"); |
|
| 176 | + } |
|
| 165 | 177 | |
| 166 | - if(rmdir($directory) === false) |
|
| 167 | - throw new PictureManagerException("rmdir($directory) failed like a bitch"); |
|
| 178 | + if(rmdir($directory) === false) { |
|
| 179 | + throw new PictureManagerException("rmdir($directory) failed like a bitch"); |
|
| 180 | + } |
|
| 181 | + } else { |
|
| 182 | + trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
|
| 168 | 183 | } |
| 169 | - else trigger_error($this->get_type()." $directory doesn't exist", E_USER_WARNING); |
|
| 170 | 184 | } |
| 171 | 185 | |
| 172 | 186 | public function remove($picture_filename) |
@@ -181,14 +195,15 @@ discard block |
||
| 181 | 195 | foreach($pathes as $what => $path) |
| 182 | 196 | { |
| 183 | 197 | $error = null; |
| 184 | - if(!file_exists($path)) |
|
| 185 | - $error = 'file does not exist'; |
|
| 186 | - elseif(unlink($path)===false) |
|
| 187 | - $error = 'unlink() failed'; |
|
| 188 | - |
|
| 189 | - if(is_null($error)) |
|
| 190 | - $deleted[]= $what; |
|
| 191 | - else |
|
| 198 | + if(!file_exists($path)) { |
|
| 199 | + $error = 'file does not exist'; |
|
| 200 | + } elseif(unlink($path)===false) { |
|
| 201 | + $error = 'unlink() failed'; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if(is_null($error)) { |
|
| 205 | + $deleted[]= $what; |
|
| 206 | + } else |
|
| 192 | 207 | { |
| 193 | 208 | trigger_error(__FUNCTION__." '$picture_filename' ($what @ $path) impossible because ", E_USER_NOTICE); |
| 194 | 209 | $still_walking[]=$what; |
@@ -238,13 +253,15 @@ discard block |
||
| 238 | 253 | $pictures = $pi_manager->filenames(); |
| 239 | 254 | |
| 240 | 255 | $item_model_type = get_class($item)::model_type(); |
| 241 | - if(count($pictures)===0) |
|
| 242 | - return hopper::file_uri($settings[$item_model_type][$picture_type]['generic_picture']); |
|
| 256 | + if(count($pictures)===0) { |
|
| 257 | + return hopper::file_uri($settings[$item_model_type][$picture_type]['generic_picture']); |
|
| 258 | + } |
|
| 243 | 259 | |
| 244 | - if($settings[$item_model_type][$picture_type]['cycle_on_load']) |
|
| 245 | - $filename = $pictures[array_rand($pictures, 1)]; |
|
| 246 | - else |
|
| 247 | - $filename = array_shift($pictures); |
|
| 260 | + if($settings[$item_model_type][$picture_type]['cycle_on_load']) { |
|
| 261 | + $filename = $pictures[array_rand($pictures, 1)]; |
|
| 262 | + } else { |
|
| 263 | + $filename = array_shift($pictures); |
|
| 264 | + } |
|
| 248 | 265 | |
| 249 | 266 | return hopper::file_uri( $thumbnail===true ? $pi_manager->locate_thumbnail($filename) : $pi_manager->locate_file($filename)); |
| 250 | 267 | } |
@@ -255,8 +272,9 @@ discard block |
||
| 255 | 272 | if(count($filenames = $this->filenames()) > 0) |
| 256 | 273 | { |
| 257 | 274 | $last_filename = array_pop($filenames); // last cover name FIXME sort should be done here, check cost if sort already done |
| 258 | - if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) |
|
| 259 | - throw new PictureManagerException("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
|
| 275 | + if(preg_match('/[0-9]+\_([0-9]+)\.[a-z]+/', $last_filename, $last_index) !== 1) { |
|
| 276 | + throw new PictureManagerException("FAILED_COMPUTING_NEW_INDEX_USING_REGEX"); |
|
| 277 | + } |
|
| 260 | 278 | |
| 261 | 279 | $last_index = $last_index[1]; |
| 262 | 280 | } |
@@ -271,8 +289,9 @@ discard block |
||
| 271 | 289 | |
| 272 | 290 | public function build_filename($index=null) |
| 273 | 291 | { |
| 274 | - if(is_null($index)) |
|
| 275 | - $index = $this->last_index()+1; |
|
| 292 | + if(is_null($index)) { |
|
| 293 | + $index = $this->last_index()+1; |
|
| 294 | + } |
|
| 276 | 295 | |
| 277 | 296 | return $this->pmi->id.'_'.sprintf("%'.09d", $index); // prepend bean id |
| 278 | 297 | } |
@@ -52,11 +52,11 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | // ----------------------------------------------------------- Static handlers for error, use set_error_handler('\HexMakina\kadro\Logger\LogLaddy::error_handler') |
| 54 | 54 | public static function error_handler($level, $message, $file = '', $line = 0) |
| 55 | - { |
|
| 55 | + { |
|
| 56 | 56 | $loglevel = self::map_error_level_to_log_level($level); |
| 57 | 57 | |
| 58 | 58 | (new LogLaddy())->$loglevel($message, ['file' => $file, 'line' => $line, 'trace' => debug_backtrace()]); |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | // ----------------------------------------------------------- Static handlers for throwables, use set_exception_handler('\HexMakina\kadro\Logger\LogLaddy::exception_handler'); |
| 62 | 62 | public static function exception_handler($throwable) |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | elseif(preg_match('/(oper|user|query_by)/', $o)) $q->aw_eq('query_by', $v); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - try{$q->run();} |
|
| 238 | - catch(CruditesException $e){vdt($e);return false;} |
|
| 237 | + try{$q->run();} |
|
| 238 | + catch(CruditesException $e){vdt($e);return false;} |
|
| 239 | 239 | |
| 240 | 240 | $res = $q->ret_num(); // ret num to list() |
| 241 | 241 | // ddt($res); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * const NOTICE = 'notice'; // Normal but significant events. |
| 266 | 266 | * const INFO = 'info'; // Interesting events. User logs in, SQL logs. |
| 267 | 267 | * const DEBUG = 'debug'; // Detailed debug information. |
| 268 | - */ |
|
| 268 | + */ |
|
| 269 | 269 | private static function map_error_level_to_log_level($level) : string |
| 270 | 270 | { |
| 271 | 271 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | namespace HexMakina\kadro\Logger; |
| 13 | 13 | |
| 14 | -use \HexMakina\Crudites\{Crudites,CruditesException,Table}; |
|
| 14 | +use \HexMakina\Crudites\{Crudites, CruditesException, Table}; |
|
| 15 | 15 | use \HexMakina\Crudites\TableInterface; |
| 16 | 16 | |
| 17 | 17 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | $context['class'] = get_class($throwable); |
| 69 | 69 | $context['trace'] = $throwable->getTrace(); |
| 70 | 70 | |
| 71 | - if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') |
|
| 71 | + if (is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') |
|
| 72 | 72 | (new LogLaddy())->alert(self::INTERNAL_ERROR, $context); |
| 73 | - elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
| 73 | + elseif (is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
| 74 | 74 | (new LogLaddy())->notice(self::USER_EXCEPTION, $context); |
| 75 | 75 | else |
| 76 | 76 | { |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | public function system_halted($level) |
| 83 | 83 | { |
| 84 | 84 | |
| 85 | - switch($level) |
|
| 85 | + switch ($level) |
|
| 86 | 86 | { |
| 87 | 87 | case LogLevel::ERROR: |
| 88 | 88 | case LogLevel::CRITICAL: |
@@ -101,19 +101,19 @@ discard block |
||
| 101 | 101 | $display_error = null; |
| 102 | 102 | |
| 103 | 103 | // --- Handles Throwables (exception_handler()) |
| 104 | - if($message==self::INTERNAL_ERROR || $message== self::USER_EXCEPTION) |
|
| 104 | + if ($message == self::INTERNAL_ERROR || $message == self::USER_EXCEPTION) |
|
| 105 | 105 | { |
| 106 | 106 | $this->has_halting_messages = true; |
| 107 | 107 | $display_error = \HexMakina\Debugger\Debugger::format_throwable_message($context['class'], $context['code'], $context['file'], $context['line'], $context['text']); |
| 108 | 108 | error_log($display_error); |
| 109 | - $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
| 109 | + $display_error .= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
| 110 | 110 | self::HTTP_500($display_error); |
| 111 | 111 | } |
| 112 | - elseif($this->system_halted($level)) // analyses error level |
|
| 112 | + elseif ($this->system_halted($level)) // analyses error level |
|
| 113 | 113 | { |
| 114 | 114 | $display_error = sprintf(PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', $level, \HexMakina\Debugger\Debugger::format_file($context['file']), $context['line'], $message); |
| 115 | 115 | error_log($display_error); |
| 116 | - $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
| 116 | + $display_error .= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
|
| 117 | 117 | self::HTTP_500($display_error); |
| 118 | 118 | } |
| 119 | 119 | else |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | // ----------------------------------------------------------- User messages:add one |
| 166 | 166 | public function report_to_user($level, $message, $context = []) |
| 167 | 167 | { |
| 168 | - if(!isset($_SESSION[self::REPORTING_USER])) |
|
| 168 | + if (!isset($_SESSION[self::REPORTING_USER])) |
|
| 169 | 169 | $_SESSION[self::REPORTING_USER] = []; |
| 170 | 170 | |
| 171 | - if(!isset($_SESSION[self::REPORTING_USER][$level])) |
|
| 171 | + if (!isset($_SESSION[self::REPORTING_USER][$level])) |
|
| 172 | 172 | $_SESSION[self::REPORTING_USER][$level] = []; |
| 173 | 173 | |
| 174 | 174 | $_SESSION[self::REPORTING_USER][$level][] = [$message, $context]; |
@@ -203,16 +203,16 @@ discard block |
||
| 203 | 203 | // } |
| 204 | 204 | |
| 205 | 205 | // ----------------------------------------------------------- CRUD Tracking:get for many models |
| 206 | - public function changes($options=[]) |
|
| 206 | + public function changes($options = []) |
|
| 207 | 207 | { |
| 208 | 208 | |
| 209 | - if(!isset($options['limit']) || empty($options['limit'])) |
|
| 209 | + if (!isset($options['limit']) || empty($options['limit'])) |
|
| 210 | 210 | $limit = 1000; |
| 211 | 211 | else $limit = intval($options['limit']); |
| 212 | 212 | |
| 213 | 213 | // TODO SELECT field order can't change without adapting the result parsing code (foreach $res) |
| 214 | 214 | $table = Crudites::inspect(self::LOG_TABLE_NAME); |
| 215 | - $select_fields = ['SUBSTR(query_on, 1, 10) AS working_day', 'query_table', 'query_id', 'GROUP_CONCAT(DISTINCT query_type, "-", query_by) as action_by']; |
|
| 215 | + $select_fields = ['SUBSTR(query_on, 1, 10) AS working_day', 'query_table', 'query_id', 'GROUP_CONCAT(DISTINCT query_type, "-", query_by) as action_by']; |
|
| 216 | 216 | $q = $table->select($select_fields); |
| 217 | 217 | $q->order_by(['', 'working_day', 'DESC']); |
| 218 | 218 | $q->order_by([self::LOG_TABLE_NAME, 'query_table', 'DESC']); |
@@ -224,30 +224,30 @@ discard block |
||
| 224 | 224 | $q->having("action_by NOT LIKE '%D%'"); |
| 225 | 225 | $q->limit($limit); |
| 226 | 226 | |
| 227 | - foreach($options as $o => $v) |
|
| 227 | + foreach ($options as $o => $v) |
|
| 228 | 228 | { |
| 229 | - if(preg_match('/id/', $o)) $q->aw_eq('query_id', $v); |
|
| 230 | - elseif(preg_match('/tables/', $o)) $q->aw_string_in('query_table', is_array($v) ? $v : [$v]); |
|
| 231 | - elseif(preg_match('/table/', $o)) $q->aw_eq('query_table', $v); |
|
| 232 | - elseif(preg_match('/(type|action)/', $o)) $q->aw_string_in('query_type', is_array($v) ? $v : [$v]); |
|
| 233 | - elseif(preg_match('/(date|query_on)/', $o)) $q->aw_like('query_on', "$v%"); |
|
| 234 | - elseif(preg_match('/(oper|user|query_by)/', $o)) $q->aw_eq('query_by', $v); |
|
| 229 | + if (preg_match('/id/', $o)) $q->aw_eq('query_id', $v); |
|
| 230 | + elseif (preg_match('/tables/', $o)) $q->aw_string_in('query_table', is_array($v) ? $v : [$v]); |
|
| 231 | + elseif (preg_match('/table/', $o)) $q->aw_eq('query_table', $v); |
|
| 232 | + elseif (preg_match('/(type|action)/', $o)) $q->aw_string_in('query_type', is_array($v) ? $v : [$v]); |
|
| 233 | + elseif (preg_match('/(date|query_on)/', $o)) $q->aw_like('query_on', "$v%"); |
|
| 234 | + elseif (preg_match('/(oper|user|query_by)/', $o)) $q->aw_eq('query_by', $v); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - try{$q->run();} |
|
| 238 | - catch(CruditesException $e){vdt($e);return false;} |
|
| 237 | + try {$q->run(); } |
|
| 238 | + catch (CruditesException $e) {vdt($e); return false; } |
|
| 239 | 239 | |
| 240 | 240 | $res = $q->ret_num(); // ret num to list() |
| 241 | 241 | // ddt($res); |
| 242 | 242 | $ret = []; |
| 243 | 243 | |
| 244 | - foreach($res as $r) |
|
| 244 | + foreach ($res as $r) |
|
| 245 | 245 | { |
| 246 | 246 | list($working_day, $class, $instance_id, $logs) = $r; |
| 247 | 247 | |
| 248 | - if(!isset($ret[$working_day])) |
|
| 248 | + if (!isset($ret[$working_day])) |
|
| 249 | 249 | $ret[$working_day] = []; |
| 250 | - if(!isset($ret[$working_day][$class])) |
|
| 250 | + if (!isset($ret[$working_day][$class])) |
|
| 251 | 251 | $ret[$working_day][$class] = []; |
| 252 | 252 | |
| 253 | 253 | $ret[$working_day][$class][$instance_id] = $logs; |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | private static function map_error_level_to_log_level($level) : string |
| 270 | 270 | { |
| 271 | 271 | |
| 272 | - switch($level) // http://php.net/manual/en/errorfunc.constants.php |
|
| 272 | + switch ($level) // http://php.net/manual/en/errorfunc.constants.php |
|
| 273 | 273 | { |
| 274 | 274 | case E_ERROR: // ('E_ERROR', "Fatal run-time errors. Execution of the script is halted"); |
| 275 | 275 | case 1: |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | $context['class'] = get_class($throwable); |
| 69 | 69 | $context['trace'] = $throwable->getTrace(); |
| 70 | 70 | |
| 71 | - if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') |
|
| 72 | - (new LogLaddy())->alert(self::INTERNAL_ERROR, $context); |
|
| 73 | - elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') |
|
| 74 | - (new LogLaddy())->notice(self::USER_EXCEPTION, $context); |
|
| 75 | - else |
|
| 71 | + if(is_subclass_of($throwable, 'Error') || get_class($throwable) === 'Error') { |
|
| 72 | + (new LogLaddy())->alert(self::INTERNAL_ERROR, $context); |
|
| 73 | + } elseif(is_subclass_of($throwable, 'Exception') || get_class($throwable) === 'Exception') { |
|
| 74 | + (new LogLaddy())->notice(self::USER_EXCEPTION, $context); |
|
| 75 | + } else |
|
| 76 | 76 | { |
| 77 | 77 | die('This Throwable is not an Error or an Exception. This is unfortunate.'); |
| 78 | 78 | } |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | error_log($display_error); |
| 109 | 109 | $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
| 110 | 110 | self::HTTP_500($display_error); |
| 111 | - } |
|
| 112 | - elseif($this->system_halted($level)) // analyses error level |
|
| 111 | + } elseif($this->system_halted($level)) { |
|
| 112 | + // analyses error level |
|
| 113 | 113 | { |
| 114 | 114 | $display_error = sprintf(PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', $level, \HexMakina\Debugger\Debugger::format_file($context['file']), $context['line'], $message); |
| 115 | + } |
|
| 115 | 116 | error_log($display_error); |
| 116 | 117 | $display_error.= \HexMakina\Debugger\Debugger::format_trace($context['trace'], false); |
| 117 | 118 | self::HTTP_500($display_error); |
| 118 | - } |
|
| 119 | - else |
|
| 119 | + } else |
|
| 120 | 120 | {// --- Handles user messages, through SESSION storage |
| 121 | 121 | $this->report_to_user($level, $message, $context); |
| 122 | 122 | } |
@@ -165,11 +165,13 @@ discard block |
||
| 165 | 165 | // ----------------------------------------------------------- User messages:add one |
| 166 | 166 | public function report_to_user($level, $message, $context = []) |
| 167 | 167 | { |
| 168 | - if(!isset($_SESSION[self::REPORTING_USER])) |
|
| 169 | - $_SESSION[self::REPORTING_USER] = []; |
|
| 168 | + if(!isset($_SESSION[self::REPORTING_USER])) { |
|
| 169 | + $_SESSION[self::REPORTING_USER] = []; |
|
| 170 | + } |
|
| 170 | 171 | |
| 171 | - if(!isset($_SESSION[self::REPORTING_USER][$level])) |
|
| 172 | - $_SESSION[self::REPORTING_USER][$level] = []; |
|
| 172 | + if(!isset($_SESSION[self::REPORTING_USER][$level])) { |
|
| 173 | + $_SESSION[self::REPORTING_USER][$level] = []; |
|
| 174 | + } |
|
| 173 | 175 | |
| 174 | 176 | $_SESSION[self::REPORTING_USER][$level][] = [$message, $context]; |
| 175 | 177 | } |
@@ -206,9 +208,11 @@ discard block |
||
| 206 | 208 | public function changes($options=[]) |
| 207 | 209 | { |
| 208 | 210 | |
| 209 | - if(!isset($options['limit']) || empty($options['limit'])) |
|
| 210 | - $limit = 1000; |
|
| 211 | - else $limit = intval($options['limit']); |
|
| 211 | + if(!isset($options['limit']) || empty($options['limit'])) { |
|
| 212 | + $limit = 1000; |
|
| 213 | + } else { |
|
| 214 | + $limit = intval($options['limit']); |
|
| 215 | + } |
|
| 212 | 216 | |
| 213 | 217 | // TODO SELECT field order can't change without adapting the result parsing code (foreach $res) |
| 214 | 218 | $table = Crudites::inspect(self::LOG_TABLE_NAME); |
@@ -226,16 +230,22 @@ discard block |
||
| 226 | 230 | |
| 227 | 231 | foreach($options as $o => $v) |
| 228 | 232 | { |
| 229 | - if(preg_match('/id/', $o)) $q->aw_eq('query_id', $v); |
|
| 230 | - elseif(preg_match('/tables/', $o)) $q->aw_string_in('query_table', is_array($v) ? $v : [$v]); |
|
| 231 | - elseif(preg_match('/table/', $o)) $q->aw_eq('query_table', $v); |
|
| 232 | - elseif(preg_match('/(type|action)/', $o)) $q->aw_string_in('query_type', is_array($v) ? $v : [$v]); |
|
| 233 | - elseif(preg_match('/(date|query_on)/', $o)) $q->aw_like('query_on', "$v%"); |
|
| 234 | - elseif(preg_match('/(oper|user|query_by)/', $o)) $q->aw_eq('query_by', $v); |
|
| 233 | + if(preg_match('/id/', $o)) { |
|
| 234 | + $q->aw_eq('query_id', $v); |
|
| 235 | + } elseif(preg_match('/tables/', $o)) { |
|
| 236 | + $q->aw_string_in('query_table', is_array($v) ? $v : [$v]); |
|
| 237 | + } elseif(preg_match('/table/', $o)) { |
|
| 238 | + $q->aw_eq('query_table', $v); |
|
| 239 | + } elseif(preg_match('/(type|action)/', $o)) { |
|
| 240 | + $q->aw_string_in('query_type', is_array($v) ? $v : [$v]); |
|
| 241 | + } elseif(preg_match('/(date|query_on)/', $o)) { |
|
| 242 | + $q->aw_like('query_on', "$v%"); |
|
| 243 | + } elseif(preg_match('/(oper|user|query_by)/', $o)) { |
|
| 244 | + $q->aw_eq('query_by', $v); |
|
| 245 | + } |
|
| 235 | 246 | } |
| 236 | 247 | |
| 237 | - try{$q->run();} |
|
| 238 | - catch(CruditesException $e){vdt($e);return false;} |
|
| 248 | + try{$q->run();} catch(CruditesException $e){vdt($e);return false;} |
|
| 239 | 249 | |
| 240 | 250 | $res = $q->ret_num(); // ret num to list() |
| 241 | 251 | // ddt($res); |
@@ -245,10 +255,12 @@ discard block |
||
| 245 | 255 | { |
| 246 | 256 | list($working_day, $class, $instance_id, $logs) = $r; |
| 247 | 257 | |
| 248 | - if(!isset($ret[$working_day])) |
|
| 249 | - $ret[$working_day] = []; |
|
| 250 | - if(!isset($ret[$working_day][$class])) |
|
| 251 | - $ret[$working_day][$class] = []; |
|
| 258 | + if(!isset($ret[$working_day])) { |
|
| 259 | + $ret[$working_day] = []; |
|
| 260 | + } |
|
| 261 | + if(!isset($ret[$working_day][$class])) { |
|
| 262 | + $ret[$working_day][$class] = []; |
|
| 263 | + } |
|
| 252 | 264 | |
| 253 | 265 | $ret[$working_day][$class][$instance_id] = $logs; |
| 254 | 266 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | // $options : https://www.php.net/manual/fr/session.configuration.php |
| 12 | 12 | public function __construct($options) |
| 13 | 13 | { |
| 14 | - if(isset($options['session_name'])) |
|
| 14 | + if (isset($options['session_name'])) |
|
| 15 | 15 | { |
| 16 | 16 | session_name($options['session_name']); |
| 17 | 17 | unset($options['session_name']); |
@@ -32,28 +32,28 @@ discard block |
||
| 32 | 32 | return isset($_SESSION[$this->index_filter][$filter_name]) && strlen(''.$_SESSION[$this->index_filter][$filter_name]) > 0; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function filters($filter_name=null, $value=null) |
|
| 35 | + public function filters($filter_name = null, $value = null) |
|
| 36 | 36 | { |
| 37 | - if(is_null($filter_name)) |
|
| 37 | + if (is_null($filter_name)) |
|
| 38 | 38 | return $_SESSION[$this->index_filter]; |
| 39 | 39 | |
| 40 | - if(!is_null($value)) |
|
| 40 | + if (!is_null($value)) |
|
| 41 | 41 | $_SESSION[$this->index_filter][$filter_name] = $value; |
| 42 | 42 | |
| 43 | 43 | return $_SESSION[$this->index_filter][$filter_name] ?? null; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public function reset_filters($filter_name=null) |
|
| 46 | + public function reset_filters($filter_name = null) |
|
| 47 | 47 | { |
| 48 | - if(is_null($filter_name)) |
|
| 49 | - $_SESSION[$this->index_filter]=[]; |
|
| 48 | + if (is_null($filter_name)) |
|
| 49 | + $_SESSION[$this->index_filter] = []; |
|
| 50 | 50 | else |
| 51 | 51 | unset($_SESSION[$this->index_filter][$filter_name]); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | public function operator_id($setter = null) |
| 55 | 55 | { |
| 56 | - if(!is_null($setter)) |
|
| 56 | + if (!is_null($setter)) |
|
| 57 | 57 | $_SESSION[$this->index_operator] = ['id' => $setter, 'set_on' => time()]; |
| 58 | 58 | |
| 59 | 59 | return $_SESSION[$this->index_operator]['id'] ?? null; |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | public function destroy() : bool |
| 69 | 69 | { |
| 70 | 70 | |
| 71 | - if(ini_get("session.use_cookies")) |
|
| 71 | + if (ini_get("session.use_cookies")) |
|
| 72 | 72 | { |
| 73 | 73 | $params = session_get_cookie_params(); |
| 74 | - setcookie(session_name(), '', time() - 42000, |
|
| 74 | + setcookie(session_name(), '', time()-42000, |
|
| 75 | 75 | $params["path"], $params["domain"], |
| 76 | 76 | $params["secure"], $params["httponly"] |
| 77 | 77 | ); |
@@ -34,27 +34,31 @@ |
||
| 34 | 34 | |
| 35 | 35 | public function filters($filter_name=null, $value=null) |
| 36 | 36 | { |
| 37 | - if(is_null($filter_name)) |
|
| 38 | - return $_SESSION[$this->index_filter]; |
|
| 37 | + if(is_null($filter_name)) { |
|
| 38 | + return $_SESSION[$this->index_filter]; |
|
| 39 | + } |
|
| 39 | 40 | |
| 40 | - if(!is_null($value)) |
|
| 41 | - $_SESSION[$this->index_filter][$filter_name] = $value; |
|
| 41 | + if(!is_null($value)) { |
|
| 42 | + $_SESSION[$this->index_filter][$filter_name] = $value; |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | return $_SESSION[$this->index_filter][$filter_name] ?? null; |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | 48 | public function reset_filters($filter_name=null) |
| 47 | 49 | { |
| 48 | - if(is_null($filter_name)) |
|
| 49 | - $_SESSION[$this->index_filter]=[]; |
|
| 50 | - else |
|
| 51 | - unset($_SESSION[$this->index_filter][$filter_name]); |
|
| 50 | + if(is_null($filter_name)) { |
|
| 51 | + $_SESSION[$this->index_filter]=[]; |
|
| 52 | + } else { |
|
| 53 | + unset($_SESSION[$this->index_filter][$filter_name]); |
|
| 54 | + } |
|
| 52 | 55 | } |
| 53 | 56 | |
| 54 | 57 | public function operator_id($setter = null) |
| 55 | 58 | { |
| 56 | - if(!is_null($setter)) |
|
| 57 | - $_SESSION[$this->index_operator] = ['id' => $setter, 'set_on' => time()]; |
|
| 59 | + if(!is_null($setter)) { |
|
| 60 | + $_SESSION[$this->index_operator] = ['id' => $setter, 'set_on' => time()]; |
|
| 61 | + } |
|
| 58 | 62 | |
| 59 | 63 | return $_SESSION[$this->index_operator]['id'] ?? null; |
| 60 | 64 | } |
@@ -9,9 +9,9 @@ |
||
| 9 | 9 | const TABLE_ALIAS = 'acl'; |
| 10 | 10 | |
| 11 | 11 | public function traceable() : bool |
| 12 | - { |
|
| 13 | - return false; |
|
| 14 | - } |
|
| 12 | + { |
|
| 13 | + return false; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | 16 | public static function match(OperatorInterface $op, $permission_name) |
| 17 | 17 | { |
@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | return in_array($permission_name, self::permissions_names_for($op)); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public static function query_retrieve($filters=[], $options=[]) : BaseQuery |
|
| 21 | + public static function query_retrieve($filters = [], $options = []) : BaseQuery |
|
| 22 | 22 | { |
| 23 | 23 | $options['eager'] = false; |
| 24 | - $ret = parent::query_retrieve($filters,$options); |
|
| 24 | + $ret = parent::query_retrieve($filters, $options); |
|
| 25 | 25 | $eager_params = []; |
| 26 | - $eager_params[Permission::table_name()]=Permission::table_alias(); |
|
| 27 | - $eager_params[Operator::table_name()]=Operator::table_alias(); |
|
| 28 | - $eager_params[ACL::table_name()]=ACL::table_alias(); |
|
| 26 | + $eager_params[Permission::table_name()] = Permission::table_alias(); |
|
| 27 | + $eager_params[Operator::table_name()] = Operator::table_alias(); |
|
| 28 | + $eager_params[ACL::table_name()] = ACL::table_alias(); |
|
| 29 | 29 | |
| 30 | 30 | $ret->eager($eager_params); |
| 31 | 31 | |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | $res = self::any(['operator_id'=>$op->get_id()]); |
| 38 | 38 | |
| 39 | 39 | $permission_ids = []; |
| 40 | - foreach($res as $r) |
|
| 41 | - $permission_ids[]=$r->get('permission_id'); |
|
| 40 | + foreach ($res as $r) |
|
| 41 | + $permission_ids[] = $r->get('permission_id'); |
|
| 42 | 42 | |
| 43 | 43 | $ret = Permission::filter(['ids'=>$permission_ids]); |
| 44 | 44 | return $ret; |
@@ -47,10 +47,10 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | $operator_with_perms = get_class($op)::exists($op->operator_id()); |
| 49 | 49 | // $operator_with_perms = get_class($op)::retrieve($operator_with_perms); |
| 50 | - if(is_null($operator_with_perms)) |
|
| 50 | + if (is_null($operator_with_perms)) |
|
| 51 | 51 | return []; |
| 52 | 52 | |
| 53 | - return explode(',',$operator_with_perms->get('permission_names')); |
|
| 53 | + return explode(',', $operator_with_perms->get('permission_names')); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public static function allow_in(OperatorInterface $op, Permission $p) |
@@ -37,8 +37,9 @@ discard block |
||
| 37 | 37 | $res = self::any(['operator_id'=>$op->get_id()]); |
| 38 | 38 | |
| 39 | 39 | $permission_ids = []; |
| 40 | - foreach($res as $r) |
|
| 41 | - $permission_ids[]=$r->get('permission_id'); |
|
| 40 | + foreach($res as $r) { |
|
| 41 | + $permission_ids[]=$r->get('permission_id'); |
|
| 42 | + } |
|
| 42 | 43 | |
| 43 | 44 | $ret = Permission::filter(['ids'=>$permission_ids]); |
| 44 | 45 | return $ret; |
@@ -47,8 +48,9 @@ discard block |
||
| 47 | 48 | { |
| 48 | 49 | $operator_with_perms = get_class($op)::exists($op->operator_id()); |
| 49 | 50 | // $operator_with_perms = get_class($op)::retrieve($operator_with_perms); |
| 50 | - if(is_null($operator_with_perms)) |
|
| 51 | - return []; |
|
| 51 | + if(is_null($operator_with_perms)) { |
|
| 52 | + return []; |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | return explode(',',$operator_with_perms->get('permission_names')); |
| 54 | 56 | } |
@@ -13,12 +13,12 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | use Permissionability; |
| 15 | 15 | |
| 16 | - public function __toString() |
|
| 16 | + public function __toString() |
|
| 17 | 17 | {
|
| 18 | 18 | return $this->get('username');
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - public function is_active() : bool |
|
| 21 | + public function is_active() : bool |
|
| 22 | 22 | {
|
| 23 | 23 | return !empty($this->get('active'));
|
| 24 | 24 | } |
@@ -39,14 +39,14 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function password_change($string) |
| 42 | - {
|
|
| 43 | - $this->password = password_hash($string, PASSWORD_DEFAULT); |
|
| 44 | - } |
|
| 42 | + {
|
|
| 43 | + $this->password = password_hash($string, PASSWORD_DEFAULT); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function password_verify($string) : bool |
|
| 47 | - {
|
|
| 48 | - return password_verify($string, $this->password()); |
|
| 49 | - } |
|
| 46 | + public function password_verify($string) : bool |
|
| 47 | + {
|
|
| 48 | + return password_verify($string, $this->password()); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | public function name() |
| 52 | 52 | {
|
@@ -62,39 +62,39 @@ discard block |
||
| 62 | 62 | return $this->get('phone');
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public function language_code() |
|
| 65 | + public function language_code() |
|
| 66 | 66 | {
|
| 67 | 67 | return $this->get('language_code');
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public static function query_retrieve($filters=[], $options=[]) : BaseQuery |
|
| 71 | - {
|
|
| 72 | - $Query = static::table()->select(); |
|
| 73 | - if(isset($options['eager']) && $options['eager'] === true) |
|
| 74 | - {
|
|
| 70 | + public static function query_retrieve($filters=[], $options=[]) : BaseQuery |
|
| 71 | + {
|
|
| 72 | + $Query = static::table()->select(); |
|
| 73 | + if(isset($options['eager']) && $options['eager'] === true) |
|
| 74 | + {
|
|
| 75 | 75 | $Query->group_by('id');
|
| 76 | 76 | |
| 77 | 77 | $Query->auto_join([ACL::table(), 'acl'], null, 'LEFT OUTER'); |
| 78 | 78 | $Query->auto_join([Permission::table(), 'kadro_permission'], null, 'LEFT OUTER'); |
| 79 | - $Query->select_also(["GROUP_CONCAT(DISTINCT kadro_permission.id) as permission_ids", "GROUP_CONCAT(DISTINCT kadro_permission.name) as permission_names"]); |
|
| 80 | - } |
|
| 79 | + $Query->select_also(["GROUP_CONCAT(DISTINCT kadro_permission.id) as permission_ids", "GROUP_CONCAT(DISTINCT kadro_permission.name) as permission_names"]); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if(isset($filters['model']) && !empty($filters['model'])) |
|
| 83 | - {
|
|
| 84 | - $model = $filters['model']; |
|
| 85 | - $Query->join([static::otm('t'), static::otm('a')],[[static::otm('a'),static::otm('k'), 't_from','id']], 'INNER');
|
|
| 86 | - $Query->aw_fields_eq(['model_id' => $filters['model']->get_id(), 'model_type' => get_class($filters['model'])::model_type()], static::otm('a'));
|
|
| 87 | - } |
|
| 82 | + if(isset($filters['model']) && !empty($filters['model'])) |
|
| 83 | + {
|
|
| 84 | + $model = $filters['model']; |
|
| 85 | + $Query->join([static::otm('t'), static::otm('a')],[[static::otm('a'),static::otm('k'), 't_from','id']], 'INNER');
|
|
| 86 | + $Query->aw_fields_eq(['model_id' => $filters['model']->get_id(), 'model_type' => get_class($filters['model'])::model_type()], static::otm('a'));
|
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | $Query->order_by([$Query->table_label(), 'name', 'ASC']); |
| 90 | 90 | |
| 91 | 91 | |
| 92 | - return $Query; |
|
| 93 | - } |
|
| 92 | + return $Query; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - public function immortal() : bool |
|
| 96 | - {
|
|
| 97 | - return true; // never delete a user, always deactivate |
|
| 98 | - } |
|
| 95 | + public function immortal() : bool |
|
| 96 | + {
|
|
| 97 | + return true; // never delete a user, always deactivate |
|
| 98 | + } |
|
| 99 | 99 | } |
| 100 | 100 | ?> |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | return $this->get('language_code');
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public static function query_retrieve($filters=[], $options=[]) : BaseQuery |
|
| 70 | + public static function query_retrieve($filters = [], $options = []) : BaseQuery |
|
| 71 | 71 | {
|
| 72 | 72 | $Query = static::table()->select(); |
| 73 | - if(isset($options['eager']) && $options['eager'] === true) |
|
| 73 | + if (isset($options['eager']) && $options['eager'] === true) |
|
| 74 | 74 | {
|
| 75 | 75 | $Query->group_by('id');
|
| 76 | 76 | |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | $Query->select_also(["GROUP_CONCAT(DISTINCT kadro_permission.id) as permission_ids", "GROUP_CONCAT(DISTINCT kadro_permission.name) as permission_names"]); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if(isset($filters['model']) && !empty($filters['model'])) |
|
| 82 | + if (isset($filters['model']) && !empty($filters['model'])) |
|
| 83 | 83 | {
|
| 84 | 84 | $model = $filters['model']; |
| 85 | - $Query->join([static::otm('t'), static::otm('a')],[[static::otm('a'),static::otm('k'), 't_from','id']], 'INNER');
|
|
| 85 | + $Query->join([static::otm('t'), static::otm('a')], [[static::otm('a'), static::otm('k'), 't_from', 'id']], 'INNER');
|
|
| 86 | 86 | $Query->aw_fields_eq(['model_id' => $filters['model']->get_id(), 'model_type' => get_class($filters['model'])::model_type()], static::otm('a'));
|
| 87 | 87 | } |
| 88 | 88 | |
@@ -8,17 +8,17 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | public function permission_names() |
| 10 | 10 | { |
| 11 | - if(property_exists($this, 'permission_names')) |
|
| 11 | + if (property_exists($this, 'permission_names')) |
|
| 12 | 12 | { |
| 13 | 13 | return explode(',', $this->permission_names); |
| 14 | 14 | } |
| 15 | - elseif(property_exists($this, 'permission_ids')) |
|
| 15 | + elseif (property_exists($this, 'permission_ids')) |
|
| 16 | 16 | { |
| 17 | 17 | $ids = explode(',', $this->permission_ids); |
| 18 | 18 | $ret = []; |
| 19 | 19 | $permissions = Permission::get_many_by_AIPK($ids); |
| 20 | - foreach($permissions as $id => $p) |
|
| 21 | - $ret[]="$p"; |
|
| 20 | + foreach ($permissions as $id => $p) |
|
| 21 | + $ret[] = "$p"; |
|
| 22 | 22 | return $ret; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -31,16 +31,16 @@ discard block |
||
| 31 | 31 | public function permissions() |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - if(!is_null($this->permissions)) |
|
| 34 | + if (!is_null($this->permissions)) |
|
| 35 | 35 | return $this->permissions; |
| 36 | 36 | $permission_unique_keys = null; |
| 37 | - if(property_exists($this, 'permission_names')) |
|
| 37 | + if (property_exists($this, 'permission_names')) |
|
| 38 | 38 | { |
| 39 | 39 | $permission_unique_keys = explode(',', $this->permission_names); |
| 40 | 40 | // vd(Permission::table()->select()); |
| 41 | 41 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_string_in('name', $permission_unique_keys)); |
| 42 | 42 | } |
| 43 | - elseif(property_exists($this, 'permission_ids')) |
|
| 43 | + elseif (property_exists($this, 'permission_ids')) |
|
| 44 | 44 | { |
| 45 | 45 | $permission_unique_keys = explode(',', $this->permission_ids); |
| 46 | 46 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_numeric_in('id', $permission_unique_keys)); |
@@ -56,40 +56,40 @@ discard block |
||
| 56 | 56 | public function has_permission($p) : bool |
| 57 | 57 | { |
| 58 | 58 | // new instances or inactive operators, none shall pass |
| 59 | - if($this->is_new() === true || $this->is_active() === false) |
|
| 59 | + if ($this->is_new() === true || $this->is_active() === false) |
|
| 60 | 60 | return false; |
| 61 | 61 | |
| 62 | 62 | $permission_name = $permission_id = null; |
| 63 | - if(is_subclass_of($p, '\HexMakina\kadro\Auth\Permission')) |
|
| 63 | + if (is_subclass_of($p, '\HexMakina\kadro\Auth\Permission')) |
|
| 64 | 64 | { |
| 65 | 65 | $permission_name = $p->get('name'); |
| 66 | 66 | $permission_id = $p->get_id(); |
| 67 | 67 | } |
| 68 | - elseif(preg_match('/[0-9]+/', $p)) |
|
| 68 | + elseif (preg_match('/[0-9]+/', $p)) |
|
| 69 | 69 | $permission_id = $p; |
| 70 | 70 | else |
| 71 | 71 | $permission_name = $p; |
| 72 | 72 | |
| 73 | 73 | |
| 74 | - if(!is_null($this->get('permission_names')) && !is_null($permission_name)) |
|
| 74 | + if (!is_null($this->get('permission_names')) && !is_null($permission_name)) |
|
| 75 | 75 | { |
| 76 | 76 | return strpos($this->get('permission_names'), $permission_name) !== false; |
| 77 | 77 | } |
| 78 | - elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
| 78 | + elseif (!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
| 79 | 79 | { |
| 80 | 80 | return strpos($this->get('permission_ids'), $permission_id) !== false; |
| 81 | 81 | } |
| 82 | - elseif(!is_null($permission_name)) |
|
| 82 | + elseif (!is_null($permission_name)) |
|
| 83 | 83 | { |
| 84 | - if(method_exists($this, $permission_name) && $this->$permission_name() == true) |
|
| 84 | + if (method_exists($this, $permission_name) && $this->$permission_name() == true) |
|
| 85 | 85 | { |
| 86 | 86 | return true; |
| 87 | 87 | } |
| 88 | - elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
| 88 | + elseif (property_exists($this, $permission_name) && $this->$permission_name == true) |
|
| 89 | 89 | { |
| 90 | 90 | return true; |
| 91 | 91 | } |
| 92 | - elseif(ACL::match($this, $permission_name) === true) |
|
| 92 | + elseif (ACL::match($this, $permission_name) === true) |
|
| 93 | 93 | { |
| 94 | 94 | return true; |
| 95 | 95 | } |
@@ -11,18 +11,16 @@ discard block |
||
| 11 | 11 | if(property_exists($this, 'permission_names')) |
| 12 | 12 | { |
| 13 | 13 | return explode(',', $this->permission_names); |
| 14 | - } |
|
| 15 | - elseif(property_exists($this, 'permission_ids')) |
|
| 14 | + } elseif(property_exists($this, 'permission_ids')) |
|
| 16 | 15 | { |
| 17 | 16 | $ids = explode(',', $this->permission_ids); |
| 18 | 17 | $ret = []; |
| 19 | 18 | $permissions = Permission::get_many_by_AIPK($ids); |
| 20 | - foreach($permissions as $id => $p) |
|
| 21 | - $ret[]="$p"; |
|
| 19 | + foreach($permissions as $id => $p) { |
|
| 20 | + $ret[]="$p"; |
|
| 21 | + } |
|
| 22 | 22 | return $ret; |
| 23 | - } |
|
| 24 | - |
|
| 25 | - else |
|
| 23 | + } else |
|
| 26 | 24 | { |
| 27 | 25 | return ACL::permissions_names_for($this); |
| 28 | 26 | } |
@@ -31,21 +29,20 @@ discard block |
||
| 31 | 29 | public function permissions() |
| 32 | 30 | { |
| 33 | 31 | |
| 34 | - if(!is_null($this->permissions)) |
|
| 35 | - return $this->permissions; |
|
| 32 | + if(!is_null($this->permissions)) { |
|
| 33 | + return $this->permissions; |
|
| 34 | + } |
|
| 36 | 35 | $permission_unique_keys = null; |
| 37 | 36 | if(property_exists($this, 'permission_names')) |
| 38 | 37 | { |
| 39 | 38 | $permission_unique_keys = explode(',', $this->permission_names); |
| 40 | 39 | // vd(Permission::table()->select()); |
| 41 | 40 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_string_in('name', $permission_unique_keys)); |
| 42 | - } |
|
| 43 | - elseif(property_exists($this, 'permission_ids')) |
|
| 41 | + } elseif(property_exists($this, 'permission_ids')) |
|
| 44 | 42 | { |
| 45 | 43 | $permission_unique_keys = explode(',', $this->permission_ids); |
| 46 | 44 | $this->permissions = Permission::retrieve(Permission::table()->select()->aw_numeric_in('id', $permission_unique_keys)); |
| 47 | - } |
|
| 48 | - else |
|
| 45 | + } else |
|
| 49 | 46 | { |
| 50 | 47 | $this->permissions = ACL::permissions_for($this); |
| 51 | 48 | } |
@@ -56,40 +53,37 @@ discard block |
||
| 56 | 53 | public function has_permission($p) : bool |
| 57 | 54 | { |
| 58 | 55 | // new instances or inactive operators, none shall pass |
| 59 | - if($this->is_new() === true || $this->is_active() === false) |
|
| 60 | - return false; |
|
| 56 | + if($this->is_new() === true || $this->is_active() === false) { |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 61 | 59 | |
| 62 | 60 | $permission_name = $permission_id = null; |
| 63 | 61 | if(is_subclass_of($p, '\HexMakina\kadro\Auth\Permission')) |
| 64 | 62 | { |
| 65 | 63 | $permission_name = $p->get('name'); |
| 66 | 64 | $permission_id = $p->get_id(); |
| 65 | + } elseif(preg_match('/[0-9]+/', $p)) { |
|
| 66 | + $permission_id = $p; |
|
| 67 | + } else { |
|
| 68 | + $permission_name = $p; |
|
| 67 | 69 | } |
| 68 | - elseif(preg_match('/[0-9]+/', $p)) |
|
| 69 | - $permission_id = $p; |
|
| 70 | - else |
|
| 71 | - $permission_name = $p; |
|
| 72 | 70 | |
| 73 | 71 | |
| 74 | 72 | if(!is_null($this->get('permission_names')) && !is_null($permission_name)) |
| 75 | 73 | { |
| 76 | 74 | return strpos($this->get('permission_names'), $permission_name) !== false; |
| 77 | - } |
|
| 78 | - elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
| 75 | + } elseif(!is_null($this->get('permission_ids')) && !is_null($permission_id)) |
|
| 79 | 76 | { |
| 80 | 77 | return strpos($this->get('permission_ids'), $permission_id) !== false; |
| 81 | - } |
|
| 82 | - elseif(!is_null($permission_name)) |
|
| 78 | + } elseif(!is_null($permission_name)) |
|
| 83 | 79 | { |
| 84 | 80 | if(method_exists($this, $permission_name) && $this->$permission_name() == true) |
| 85 | 81 | { |
| 86 | 82 | return true; |
| 87 | - } |
|
| 88 | - elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
| 83 | + } elseif(property_exists($this, $permission_name) && $this->$permission_name == true) |
|
| 89 | 84 | { |
| 90 | 85 | return true; |
| 91 | - } |
|
| 92 | - elseif(ACL::match($this, $permission_name) === true) |
|
| 86 | + } elseif(ACL::match($this, $permission_name) === true) |
|
| 93 | 87 | { |
| 94 | 88 | return true; |
| 95 | 89 | } |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public static function enhance_query_retrieve($Query, $filters, $options) |
| 47 | 47 | { |
| 48 | - $joined_alias = $Query->auto_join([ACL::table(),'ACL'], null, 'LEFT OUTER'); |
|
| 49 | - $joined_alias = $Query->auto_join([Permission::table(), 'permission'], null, 'LEFT OUTER'); |
|
| 48 | + $joined_alias = $Query->auto_join([ACL::table(),'ACL'], null, 'LEFT OUTER'); |
|
| 49 | + $joined_alias = $Query->auto_join([Permission::table(), 'permission'], null, 'LEFT OUTER'); |
|
| 50 | 50 | |
| 51 | 51 | $permission_ids_and_names = []; |
| 52 | 52 | $permission_ids_and_names []= sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'id', $joined_alias.'_ids'); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | return $Query; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function is_active() : bool |
|
| 70 | + public function is_active() : bool |
|
| 71 | 71 | { |
| 72 | 72 | return is_null($this->operator()) ? false : $this->operator()->is_active(); |
| 73 | 73 | } |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | return is_null($this->operator()) ? null : $this->operator()->operator_id(); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function username() |
|
| 80 | + public function username() |
|
| 81 | 81 | { |
| 82 | 82 | return is_null($this->operator()) ? null : $this->operator()->username(); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - public function password() |
|
| 85 | + public function password() |
|
| 86 | 86 | { |
| 87 | 87 | return is_null($this->operator()) ? null : $this->operator()->password(); |
| 88 | 88 | } |
@@ -97,22 +97,22 @@ discard block |
||
| 97 | 97 | return $this->operator()->password_verify($string); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - public function name() |
|
| 100 | + public function name() |
|
| 101 | 101 | { |
| 102 | 102 | return is_null($this->operator()) ? null : $this->operator()->name(); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - public function email() |
|
| 105 | + public function email() |
|
| 106 | 106 | { |
| 107 | 107 | return is_null($this->operator()) ? null : $this->operator()->email(); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public function phone() |
|
| 110 | + public function phone() |
|
| 111 | 111 | { |
| 112 | 112 | return is_null($this->operator()) ? null : $this->operator()->phone(); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - public function language_code() |
|
| 115 | + public function language_code() |
|
| 116 | 116 | { |
| 117 | 117 | return is_null($this->operator()) ? null : $this->operator()->language_code(); |
| 118 | 118 | } |
@@ -17,19 +17,19 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function load_operator($id = null) |
| 19 | 19 | { |
| 20 | - if(!is_null($operator_id = $id ?? $this->get('operator_id'))) // extraction failed but we have an fk |
|
| 20 | + if (!is_null($operator_id = $id ?? $this->get('operator_id'))) // extraction failed but we have an fk |
|
| 21 | 21 | $this->operator = Operator::exists($operator_id); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function operator() : ?OperatorInterface |
| 25 | 25 | { |
| 26 | - if(is_null($this->operator)) |
|
| 26 | + if (is_null($this->operator)) |
|
| 27 | 27 | { |
| 28 | 28 | $extract_attempt = $this->extract(new Operator(), true); |
| 29 | - if(!is_null($extract_attempt)) |
|
| 29 | + if (!is_null($extract_attempt)) |
|
| 30 | 30 | { |
| 31 | - foreach(['permission_names', 'permission_ids'] as $permission_marker) |
|
| 32 | - if(property_exists($this, $permission_marker)) |
|
| 31 | + foreach (['permission_names', 'permission_ids'] as $permission_marker) |
|
| 32 | + if (property_exists($this, $permission_marker)) |
|
| 33 | 33 | $extract_attempt->set($permission_marker, $this->$permission_marker); |
| 34 | 34 | |
| 35 | 35 | $this->operator = $extract_attempt; |
@@ -45,23 +45,23 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | public static function enhance_query_retrieve($Query, $filters, $options) |
| 47 | 47 | { |
| 48 | - $joined_alias = $Query->auto_join([ACL::table(),'ACL'], null, 'LEFT OUTER'); |
|
| 48 | + $joined_alias = $Query->auto_join([ACL::table(), 'ACL'], null, 'LEFT OUTER'); |
|
| 49 | 49 | $joined_alias = $Query->auto_join([Permission::table(), 'permission'], null, 'LEFT OUTER'); |
| 50 | 50 | |
| 51 | 51 | $permission_ids_and_names = []; |
| 52 | - $permission_ids_and_names []= sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'id', $joined_alias.'_ids'); |
|
| 53 | - $permission_ids_and_names []= sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'name', $joined_alias.'_names'); |
|
| 52 | + $permission_ids_and_names [] = sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'id', $joined_alias.'_ids'); |
|
| 53 | + $permission_ids_and_names [] = sprintf('GROUP_CONCAT(DISTINCT %s.%s) as %s', $joined_alias, 'name', $joined_alias.'_names'); |
|
| 54 | 54 | $Query->select_also($permission_ids_and_names); |
| 55 | 55 | |
| 56 | 56 | $Query->select_also(['operator.name as operator_name', 'operator.active as operator_active']); |
| 57 | 57 | |
| 58 | - if(isset($filters['username'])) |
|
| 58 | + if (isset($filters['username'])) |
|
| 59 | 59 | $Query->aw_eq('username', $filters['username'], 'operator'); |
| 60 | 60 | |
| 61 | - if(isset($filters['email'])) |
|
| 61 | + if (isset($filters['email'])) |
|
| 62 | 62 | $Query->aw_eq('email', $filters['email'], 'operator'); |
| 63 | 63 | |
| 64 | - if(isset($filters['active'])) |
|
| 64 | + if (isset($filters['active'])) |
|
| 65 | 65 | $Query->aw_eq('active', $filters['active'], 'operator'); |
| 66 | 66 | |
| 67 | 67 | return $Query; |
@@ -17,8 +17,10 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function load_operator($id = null) |
| 19 | 19 | { |
| 20 | - if(!is_null($operator_id = $id ?? $this->get('operator_id'))) // extraction failed but we have an fk |
|
| 20 | + if(!is_null($operator_id = $id ?? $this->get('operator_id'))) { |
|
| 21 | + // extraction failed but we have an fk |
|
| 21 | 22 | $this->operator = Operator::exists($operator_id); |
| 23 | + } |
|
| 22 | 24 | } |
| 23 | 25 | |
| 24 | 26 | public function operator() : ?OperatorInterface |
@@ -28,9 +30,10 @@ discard block |
||
| 28 | 30 | $extract_attempt = $this->extract(new Operator(), true); |
| 29 | 31 | if(!is_null($extract_attempt)) |
| 30 | 32 | { |
| 31 | - foreach(['permission_names', 'permission_ids'] as $permission_marker) |
|
| 32 | - if(property_exists($this, $permission_marker)) |
|
| 33 | + foreach(['permission_names', 'permission_ids'] as $permission_marker) { |
|
| 34 | + if(property_exists($this, $permission_marker)) |
|
| 33 | 35 | $extract_attempt->set($permission_marker, $this->$permission_marker); |
| 36 | + } |
|
| 34 | 37 | |
| 35 | 38 | $this->operator = $extract_attempt; |
| 36 | 39 | } |
@@ -55,14 +58,17 @@ discard block |
||
| 55 | 58 | |
| 56 | 59 | $Query->select_also(['operator.name as operator_name', 'operator.active as operator_active']); |
| 57 | 60 | |
| 58 | - if(isset($filters['username'])) |
|
| 59 | - $Query->aw_eq('username', $filters['username'], 'operator'); |
|
| 61 | + if(isset($filters['username'])) { |
|
| 62 | + $Query->aw_eq('username', $filters['username'], 'operator'); |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | - if(isset($filters['email'])) |
|
| 62 | - $Query->aw_eq('email', $filters['email'], 'operator'); |
|
| 65 | + if(isset($filters['email'])) { |
|
| 66 | + $Query->aw_eq('email', $filters['email'], 'operator'); |
|
| 67 | + } |
|
| 63 | 68 | |
| 64 | - if(isset($filters['active'])) |
|
| 65 | - $Query->aw_eq('active', $filters['active'], 'operator'); |
|
| 69 | + if(isset($filters['active'])) { |
|
| 70 | + $Query->aw_eq('active', $filters['active'], 'operator'); |
|
| 71 | + } |
|
| 66 | 72 | |
| 67 | 73 | return $Query; |
| 68 | 74 | } |