jeremykenedy /
laravel-soundboard
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Services; |
||
| 4 | |||
| 5 | use App\Models\Setting; |
||
| 6 | use App\Models\Theme; |
||
| 7 | |||
| 8 | class ThemeServices |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Return the theme. |
||
| 12 | * |
||
| 13 | * @param string $text |
||
| 14 | * |
||
| 15 | * @return string |
||
| 16 | */ |
||
| 17 | public static function getTheTheme() |
||
| 18 | { |
||
| 19 | $self = new self(); |
||
| 20 | $theme = Theme::find($self->getTheThemeId()); |
||
| 21 | |||
| 22 | return $theme; |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Check for random theme. |
||
| 27 | * |
||
| 28 | * @param object $theme The theme |
||
| 29 | * |
||
| 30 | * @return object |
||
| 31 | */ |
||
| 32 | public static function checkForRandomTheme($theme) |
||
| 33 | { |
||
| 34 | if ($theme->name != 'Random') { |
||
| 35 | return $theme; |
||
| 36 | } |
||
| 37 | |||
| 38 | return self::getRandomTheme($theme); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get random theme. |
||
| 43 | * |
||
| 44 | * @param object $theme The theme |
||
| 45 | * |
||
| 46 | * @return object |
||
| 47 | */ |
||
| 48 | public static function getRandomTheme($theme) |
||
| 49 | { |
||
| 50 | $themes = collect(Theme::all()->pluck('id'))->toArray(); |
||
| 51 | $themes = array_filter($themes, function ($v) use ($theme) { |
||
| 52 | return $v != $theme->id; |
||
| 53 | }); |
||
| 54 | |||
| 55 | return Theme::find(array_rand($themes)); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Returns the the theme identifier. |
||
| 60 | * |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | public function getTheThemeId() |
||
| 64 | { |
||
| 65 | return Setting::themeId()->pluck('value')->first(); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Gets a theme. |
||
| 70 | * |
||
| 71 | * @param int$id |
||
| 72 | * |
||
| 73 | * @return colletion. |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 74 | */ |
||
| 75 | public static function getTheme($id) |
||
| 76 | { |
||
| 77 | return Theme::findOrFail($id); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Gets all themes. |
||
| 82 | * |
||
| 83 | * @return collection |
||
|
0 ignored issues
–
show
The type
App\Services\collection was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 84 | */ |
||
| 85 | public static function getAllThemes() |
||
| 86 | { |
||
| 87 | return Theme::orderBy('name', 'asc')->get(); |
||
|
0 ignored issues
–
show
|
|||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Stores a new theme. |
||
| 92 | * |
||
| 93 | * @param $validatedRequest The validated request |
||
| 94 | * |
||
| 95 | * @return collection |
||
| 96 | */ |
||
| 97 | public static function storeNewTheme($validatedRequest) |
||
| 98 | { |
||
| 99 | $taggableBase = [ |
||
| 100 | 'taggable_id' => 0, |
||
| 101 | 'taggable_type' => 'theme', |
||
| 102 | ]; |
||
| 103 | |||
| 104 | $theme = Theme::create(array_merge($validatedRequest, $taggableBase)); |
||
| 105 | $theme->taggable_id = $theme->id; |
||
| 106 | $theme->save(); |
||
| 107 | |||
| 108 | return $theme; |
||
|
0 ignored issues
–
show
|
|||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Update the default theme in the settings. |
||
| 113 | * |
||
| 114 | * @param int $themeId The theme identifier |
||
| 115 | * |
||
| 116 | * @return collection |
||
| 117 | */ |
||
| 118 | public static function updateDefaultThemeSetting($themeId) |
||
| 119 | { |
||
| 120 | $theTheme = Setting::where('key', '=', 'theme_id')->first(); |
||
| 121 | $theTheme->value = $themeId; |
||
| 122 | $theTheme->save(); |
||
| 123 | |||
| 124 | return $theTheme; |
||
|
0 ignored issues
–
show
|
|||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Delete a blgo theme. |
||
| 129 | * |
||
| 130 | * @param int $themeId |
||
| 131 | * |
||
| 132 | * @return collection |
||
| 133 | */ |
||
| 134 | public static function deleteTheme($themeId) |
||
| 135 | { |
||
| 136 | $theme = Theme::findOrFail($themeId); |
||
| 137 | $theme->delete(); |
||
| 138 | |||
| 139 | return $theme; |
||
|
0 ignored issues
–
show
|
|||
| 140 | } |
||
| 141 | } |
||
| 142 |