Skip to content

Commit

Permalink
Обновление
Browse files Browse the repository at this point in the history
  • Loading branch information
Sashagm committed Jun 29, 2023
1 parent 7d989cf commit f7efac3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 51 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ if (Themes){ require __DIR__ ."/". Themes .".php"; }

'check' => [

'active' => true, // разрешить проверку или false пропускать
'active' => true, // True Разрешить проверку или false Пропускать проверку

'save_colum' => 'id', // поле для группы/роли или прав
'save_value' => 1, // какое значение необходимо получить
'save_colum' => 'id', // Поле для группы/роли или прав
'save_value' => 1, // Какое значение необходимо получить

],

Expand Down
4 changes: 1 addition & 3 deletions src/Http/Controllers/ThemesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public function getThemes()

public function addThemes(Request $request)
{
$this->checkAccess();

$this->create($request);

return back()
Expand All @@ -56,7 +54,7 @@ public function addThemes(Request $request)

public function deleteThemes(Request $request, $id)
{
$this->checkAccess();

if ($id == 1) {
return back()
->with('success', "Тему с ид: $id нельзя удалить так как она резервная и системная!");
Expand Down
9 changes: 6 additions & 3 deletions src/Models/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,24 @@ class Themes extends Model

public static function getActiveThemeTitle()
{
$theme = self::where('active', 1)->first();
$theme = self::where('active', 1)
->first();

return $theme->title ?? null;
}

public static function getActiveThemeDescription()
{
$theme = self::where('active', 1)->first();
$theme = self::where('active', 1)
->first();

return $theme->description ?? null;
}

public static function getThemeInfo()
{
$theme = self::where('active', 1)->first();
$theme = self::where('active', 1)
->first();

return [
'title' => $theme->title ?? null,
Expand Down
68 changes: 26 additions & 42 deletions src/Traits/ThemesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,30 @@ trait ThemesTrait
private function save($id)
{
$info = Themes::findOrFail($id);

if (!$info) {
throw new Exception('Тема не найдена');
}

DB::beginTransaction();

try {
DB::table('themes')->update(['active' => 0]);
DB::table('themes')->where('id', $id)->update(['active' => 1]);

DB::table('themes')
->update(['active' => 0]);
DB::table('themes')
->where('id', $id)
->update(['active' => 1]);

$data = "<?php\r\n";
$data.= "
$data .= "
if(!defined('Themes')) {
define('Themes', '$info->title');
} \r\n";
$new_file=fopen( __DIR__ . '/../../../../../config/themes.php',"w");

$new_file = fopen(__DIR__ . '/../../../../../config/themes.php', "w");
fwrite($new_file, $data);
fclose($new_file);

DB::commit();
} catch (\Exception $e) {
DB::rollback();
Expand All @@ -47,18 +50,18 @@ private function save($id)

private function clear()
{
Artisan::call('cache:clear');
Artisan::call('config:cache');
Artisan::call('view:clear');
Artisan::call('route:clear');
Artisan::call('cache:clear');
Artisan::call('config:cache');
Artisan::call('view:clear');
Artisan::call('route:clear');
}



private function getCurrent()
{
$info = Themes::where('title', Themes)
->get();
->get();

if (!$info) {
throw new Exception('Тема не найдена');
Expand All @@ -77,35 +80,16 @@ private function getCurrent()



private function checkAccess() {
switch(false) {
case true:
$user = Auth::user();
if (!$user){
abort(403); // отправляем ошибку 403 Forbidden
}
if($user->id === 1) { // проверяем роль пользователя
return true;
} else {
abort(403); // отправляем ошибку 403 Forbidden
}
case false:
return true;
}
}

private function create(Request $request)
{

Themes::query()->create([
'title' => $request->title,
'description' => $request->desc,
'author' => $request->author,
'version' => $request->ver,
'active' => 0,
]);

Themes::query()
->create([
'title' => $request->title,
'description' => $request->desc,
'author' => $request->author,
'version' => $request->ver,
'active' => 0,
]);
}


}

0 comments on commit f7efac3

Please sign in to comment.