@@ -621,14 +621,12 @@ discard block |
||
| 621 | 621 | $conditions = $this->constructConditions($value, $model); |
| 622 | 622 | $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
| 623 | 623 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 624 | - } |
|
| 625 | - else if ($key == 'or') |
|
| 624 | + } else if ($key == 'or') |
|
| 626 | 625 | { |
| 627 | 626 | $conditions = $this->constructConditions($value, $model); |
| 628 | 627 | $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
| 629 | 628 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 630 | - } |
|
| 631 | - else |
|
| 629 | + } else |
|
| 632 | 630 | { |
| 633 | 631 | if (is_array($value)) |
| 634 | 632 | { |
@@ -653,29 +651,24 @@ discard block |
||
| 653 | 651 | |
| 654 | 652 | $conditionString .= $key.' <= ? {op} '; |
| 655 | 653 | $conditionValues[] = $value2; |
| 656 | - } |
|
| 657 | - elseif (strtolower($operator) == 'in') |
|
| 654 | + } elseif (strtolower($operator) == 'in') |
|
| 658 | 655 | { |
| 659 | 656 | $conditionValues = array_merge($conditionValues, $value); |
| 660 | 657 | $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
| 661 | 658 | $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
| 662 | - } |
|
| 663 | - elseif (strtolower($operator) == 'null') |
|
| 659 | + } elseif (strtolower($operator) == 'null') |
|
| 664 | 660 | { |
| 665 | 661 | $conditionString .= $key.' is null {op} '; |
| 666 | - } |
|
| 667 | - elseif (strtolower($operator) == 'not null') |
|
| 662 | + } elseif (strtolower($operator) == 'not null') |
|
| 668 | 663 | { |
| 669 | 664 | $conditionString .= $key.' is not null {op} '; |
| 670 | - } |
|
| 671 | - elseif (strtolower($operator) == 'has') |
|
| 665 | + } elseif (strtolower($operator) == 'has') |
|
| 672 | 666 | { |
| 673 | 667 | $sql = $model->withTrashed()->has($key)->toSql(); |
| 674 | 668 | $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
| 675 | 669 | $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
| 676 | 670 | $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
| 677 | - } |
|
| 678 | - else |
|
| 671 | + } else |
|
| 679 | 672 | { |
| 680 | 673 | $conditionString .= $key.' '.$operator.' ? {op} '; |
| 681 | 674 | $conditionValues[] = $value; |
@@ -227,10 +227,8 @@ |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model))) |
| 230 | - {} |
|
| 231 | - elseif ( ! $isPasswordClient && $user->tokenCan($this->model.'-'.$permission)) |
|
| 232 | - {} |
|
| 233 | - else |
|
| 230 | + {} elseif ( ! $isPasswordClient && $user->tokenCan($this->model.'-'.$permission)) |
|
| 231 | + {} else |
|
| 234 | 232 | { |
| 235 | 233 | |
| 236 | 234 | \ErrorHandler::noPermissions(); |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | return $next($request); |
| 44 | 44 | }); |
| 45 | 45 | |
| 46 | - $this->setSessions(); |
|
| 47 | - $this->checkPermission($route); |
|
| 48 | - $this->setRelations($route); |
|
| 46 | + $this->setSessions(); |
|
| 47 | + $this->checkPermission($route); |
|
| 48 | + $this->setRelations($route); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $user = \Auth::user(); |
| 222 | 222 | $permission = $permission !== 'index' ? $permission : 'list'; |
| 223 | 223 | $isPasswordClient = $user->token()->client->password_client; |
| 224 | - $this->updateLocaleAndTimezone($user); |
|
| 224 | + $this->updateLocaleAndTimezone($user); |
|
| 225 | 225 | |
| 226 | 226 | if ($user->blocked) |
| 227 | 227 | { |
@@ -287,32 +287,32 @@ discard block |
||
| 287 | 287 | $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - /** |
|
| 291 | - * Update the logged in user locale and time zone. |
|
| 292 | - * |
|
| 293 | - * @param object $user |
|
| 294 | - * @return void |
|
| 295 | - */ |
|
| 296 | - private function updateLocaleAndTimezone($user) |
|
| 297 | - { |
|
| 298 | - $update = false; |
|
| 299 | - $locale = \Session::get('locale'); |
|
| 300 | - $timezone = \Session::get('time-zone'); |
|
| 301 | - if ($locale && $locale !== 'all' && $locale !== $user->locale) |
|
| 302 | - { |
|
| 303 | - $user->locale = $locale; |
|
| 304 | - $update = true; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - if ($timezone && $timezone !== $user->timezone) |
|
| 308 | - { |
|
| 309 | - $user->timezone = $timezone; |
|
| 310 | - $update = true; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - if ($update) |
|
| 314 | - { |
|
| 315 | - $user->save(); |
|
| 316 | - } |
|
| 317 | - } |
|
| 290 | + /** |
|
| 291 | + * Update the logged in user locale and time zone. |
|
| 292 | + * |
|
| 293 | + * @param object $user |
|
| 294 | + * @return void |
|
| 295 | + */ |
|
| 296 | + private function updateLocaleAndTimezone($user) |
|
| 297 | + { |
|
| 298 | + $update = false; |
|
| 299 | + $locale = \Session::get('locale'); |
|
| 300 | + $timezone = \Session::get('time-zone'); |
|
| 301 | + if ($locale && $locale !== 'all' && $locale !== $user->locale) |
|
| 302 | + { |
|
| 303 | + $user->locale = $locale; |
|
| 304 | + $update = true; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + if ($timezone && $timezone !== $user->timezone) |
|
| 308 | + { |
|
| 309 | + $user->timezone = $timezone; |
|
| 310 | + $update = true; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + if ($update) |
|
| 314 | + { |
|
| 315 | + $user->save(); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | 318 | } |
@@ -174,14 +174,12 @@ |
||
| 174 | 174 | if (strpos($rule, 'unique')) |
| 175 | 175 | { |
| 176 | 176 | $rule = substr($rule, 0, strpos($rule, 'unique') + 6); |
| 177 | - } |
|
| 178 | - elseif (strpos($rule, 'exists')) |
|
| 177 | + } elseif (strpos($rule, 'exists')) |
|
| 179 | 178 | { |
| 180 | 179 | $rule = substr($rule, 0, strpos($rule, 'exists') - 1); |
| 181 | 180 | } |
| 182 | 181 | } |
| 183 | - } |
|
| 184 | - else |
|
| 182 | + } else |
|
| 185 | 183 | { |
| 186 | 184 | $route['body'] = 'conditions'; |
| 187 | 185 | } |
@@ -39,8 +39,7 @@ |
||
| 39 | 39 | if ( ! $report) |
| 40 | 40 | { |
| 41 | 41 | \ErrorHandler::notFound('report'); |
| 42 | - } |
|
| 43 | - else if ( ! $skipPermission && ! \Core::users()->can($report->view_name, 'reports')) |
|
| 42 | + } else if ( ! $skipPermission && ! \Core::users()->can($report->view_name, 'reports')) |
|
| 44 | 43 | { |
| 45 | 44 | \ErrorHandler::noPermissions(); |
| 46 | 45 | } |
@@ -13,26 +13,26 @@ discard block |
||
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | 15 | Schema::create('users', function(Blueprint $table) { |
| 16 | - $table->increments('id'); |
|
| 17 | - $table->string('profile_picture', 150)->nullable(); |
|
| 18 | - $table->string('name', 100)->nullable(); |
|
| 19 | - $table->string('email')->unique(); |
|
| 20 | - $table->string('password', 60)->nullable(); |
|
| 21 | - $table->boolean('blocked')->default(0); |
|
| 22 | - $table->boolean('confirmed')->default(0); |
|
| 23 | - $table->string('confirmation_code')->nullable(); |
|
| 24 | - $table->string('locale', 2)->default('en'); |
|
| 25 | - $table->string('timezone', 50)->default('Africa/Cairo'); |
|
| 26 | - $table->softDeletes(); |
|
| 27 | - $table->rememberToken(); |
|
| 28 | - $table->timestamps(); |
|
| 29 | - }); |
|
| 16 | + $table->increments('id'); |
|
| 17 | + $table->string('profile_picture', 150)->nullable(); |
|
| 18 | + $table->string('name', 100)->nullable(); |
|
| 19 | + $table->string('email')->unique(); |
|
| 20 | + $table->string('password', 60)->nullable(); |
|
| 21 | + $table->boolean('blocked')->default(0); |
|
| 22 | + $table->boolean('confirmed')->default(0); |
|
| 23 | + $table->string('confirmation_code')->nullable(); |
|
| 24 | + $table->string('locale', 2)->default('en'); |
|
| 25 | + $table->string('timezone', 50)->default('Africa/Cairo'); |
|
| 26 | + $table->softDeletes(); |
|
| 27 | + $table->rememberToken(); |
|
| 28 | + $table->timestamps(); |
|
| 29 | + }); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Create Default users. |
| 33 | 33 | */ |
| 34 | 34 | \DB::table('users')->insertGetId( |
| 35 | - [ |
|
| 35 | + [ |
|
| 36 | 36 | 'name' => 'Admin', |
| 37 | 37 | 'email' => '[email protected]', |
| 38 | 38 | 'password' => bcrypt('123456'), |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | 'created_at' => \DB::raw('NOW()'), |
| 41 | 41 | 'updated_at' => \DB::raw('NOW()') |
| 42 | 42 | ] |
| 43 | - ); |
|
| 43 | + ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -7,10 +7,10 @@ |
||
| 7 | 7 | |
| 8 | 8 | public function saving($model) |
| 9 | 9 | { |
| 10 | - if ($model->isDirty('profile_picture')) |
|
| 11 | - { |
|
| 12 | - \Media::deleteImage($model->getOriginal('profile_picture')); |
|
| 13 | - } |
|
| 10 | + if ($model->isDirty('profile_picture')) |
|
| 11 | + { |
|
| 12 | + \Media::deleteImage($model->getOriginal('profile_picture')); |
|
| 13 | + } |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function saved($model) |
@@ -2,63 +2,63 @@ |
||
| 2 | 2 | |
| 3 | 3 | class Media |
| 4 | 4 | { |
| 5 | - /** |
|
| 6 | - * Upload the given image. |
|
| 7 | - * |
|
| 8 | - * @param object $image |
|
| 9 | - * @param string $dir |
|
| 10 | - * @return string |
|
| 11 | - */ |
|
| 12 | - public function uploadImage($image, $dir) |
|
| 13 | - { |
|
| 14 | - $image = \Image::make($image); |
|
| 15 | - return $this->saveImage($image, $dir); |
|
| 16 | - } |
|
| 5 | + /** |
|
| 6 | + * Upload the given image. |
|
| 7 | + * |
|
| 8 | + * @param object $image |
|
| 9 | + * @param string $dir |
|
| 10 | + * @return string |
|
| 11 | + */ |
|
| 12 | + public function uploadImage($image, $dir) |
|
| 13 | + { |
|
| 14 | + $image = \Image::make($image); |
|
| 15 | + return $this->saveImage($image, $dir); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Upload the given image. |
|
| 20 | - * |
|
| 21 | - * @param object $image |
|
| 22 | - * @param string $dir |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public function uploadImageBas64($image, $dir) |
|
| 26 | - { |
|
| 27 | - if ( ! strlen($image)) |
|
| 28 | - { |
|
| 29 | - return null; |
|
| 30 | - } |
|
| 18 | + /** |
|
| 19 | + * Upload the given image. |
|
| 20 | + * |
|
| 21 | + * @param object $image |
|
| 22 | + * @param string $dir |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public function uploadImageBas64($image, $dir) |
|
| 26 | + { |
|
| 27 | + if ( ! strlen($image)) |
|
| 28 | + { |
|
| 29 | + return null; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $base = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image)); |
|
| 33 | - $image = \Image::make($base); |
|
| 32 | + $base = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image)); |
|
| 33 | + $image = \Image::make($base); |
|
| 34 | 34 | |
| 35 | - return $this->saveImage($image, $dir); |
|
| 36 | - } |
|
| 35 | + return $this->saveImage($image, $dir); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Delete the given image. |
|
| 40 | - * |
|
| 41 | - * @param object $path |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function deleteImage($path) |
|
| 45 | - { |
|
| 46 | - \Storage::delete($path); |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * Delete the given image. |
|
| 40 | + * |
|
| 41 | + * @param object $path |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function deleteImage($path) |
|
| 45 | + { |
|
| 46 | + \Storage::delete($path); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Save the given image. |
|
| 51 | - * |
|
| 52 | - * @param object $image |
|
| 53 | - * @param string $dir |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - protected function saveImage($image, $dir) |
|
| 57 | - { |
|
| 58 | - $imageName = 'image'.uniqid().time().'.jpg'; |
|
| 59 | - $path = 'public'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$imageName; |
|
| 60 | - \Storage::put($path, $image->stream()); |
|
| 49 | + /** |
|
| 50 | + * Save the given image. |
|
| 51 | + * |
|
| 52 | + * @param object $image |
|
| 53 | + * @param string $dir |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + protected function saveImage($image, $dir) |
|
| 57 | + { |
|
| 58 | + $imageName = 'image'.uniqid().time().'.jpg'; |
|
| 59 | + $path = 'public'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$imageName; |
|
| 60 | + \Storage::put($path, $image->stream()); |
|
| 61 | 61 | |
| 62 | - return $path; |
|
| 63 | - } |
|
| 62 | + return $path; |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -104,11 +104,11 @@ |
||
| 104 | 104 | abort($error['status'], $error['message']); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - public function invalidConfirmationCode() |
|
| 108 | - { |
|
| 109 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidConfirmationCode')]; |
|
| 110 | - abort($error['status'], $error['message']); |
|
| 111 | - } |
|
| 107 | + public function invalidConfirmationCode() |
|
| 108 | + { |
|
| 109 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidConfirmationCode')]; |
|
| 110 | + abort($error['status'], $error['message']); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | 113 | public function notFound($text) |
| 114 | 114 | { |
@@ -12,5 +12,5 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | Broadcast::channel('users.{id}', function ($user, $id) { |
| 15 | - return (int) $user->id === (int) $id; |
|
| 15 | + return (int) $user->id === (int) $id; |
|
| 16 | 16 | }); |