Skip to content

Commit

Permalink
v.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
bluecraank committed Apr 19, 2024
1 parent 6169962 commit ad451af
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
8 changes: 1 addition & 7 deletions app/Console/Commands/PresentationProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ public function handle()

$presentation = Presentation::where('id', $id)->firstOrFail();

$type = $this->argument('type');

if ($type == 'pdf') {
$this->processPdf($presentation);
} else if ($type == 'video') {
// Deprecated
}
$this->processPdf($presentation);
}

public function processPdf($presentation)
Expand Down
15 changes: 6 additions & 9 deletions app/Http/Controllers/PresentationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function index()
{
$presentations = Presentation::all()->sortBy('name');

// Sort by inUse
$presentations = $presentations->sortBy(function ($presentation) {
return !$presentation->in_use();
});

$groups = Group::all()->sortBy('name');
$devices = Device::all()->sortBy('name');

Expand All @@ -28,15 +33,7 @@ public function index()

// Loop through groups and devices and see which presentations are unused
foreach($presentations as $presentation) {
$devices = $presentation->devices->count();
$groups = $presentation->groups->count();
$schedules = $presentation->schedules->count();

if($devices == 0 && $groups == 0 && $schedules == 0) {
$countUnused++;
} else {
$countUsed++;
}
$presentation->in_use() ? $countUsed++ : $countUnused++;
}

return view('presentations.index', compact('presentations', 'countUsed', 'countUnused'));
Expand Down
36 changes: 19 additions & 17 deletions app/Http/Controllers/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\Schedule;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;

class ScheduleController extends Controller
{
Expand Down Expand Up @@ -160,34 +161,37 @@ public function destroy(string $id)
static function checkForExpiredSchedules() {
$currentTimestamp = now();

$expiredSchedules = Schedule::where('end_time', '<', $currentTimestamp)->get();

// dd($expiredSchedules);
$expiredSchedules = Schedule::where('end_time', '<', $currentTimestamp)->where('delete_presentation', 1)->get();

foreach($expiredSchedules as $schedule) {
if($schedule->delete_presentation == 1) {
$presentation = $schedule->presentation;

if($presentation) {
if($presentation->devices()->count() == 0 && $presentation->groups()->count() == 0) {
Log::create([
'ip_address' => "127.0.0.1",
'username' => 'System',
'action' => __('log.presentation_deleted_because_schedule', ['name' => $presentation->name, 'schedule' => $schedule->name,]),
]);
try {
$presentation->slides()->delete();

File::delete(storage_path('app/public/presentations/' . $presentation->id . '/' . $presentation->id) . '.pdf');
File::deleteDirectory(storage_path('app/public/presentations/' . $presentation->id . '/'));

$presentation->delete();
$oldName = $presentation->name;

$presentation->delete();

Log::create([
'ip_address' => "127.0.0.1",
'username' => 'System',
'action' => __('log.presentation_deleted_because_schedule', ['name' => $oldName, 'schedule' => $schedule->name,]),
]);
} catch (\Exception $e) {

}
} else {
Log::create([
'ip_address' => "127.0.0.1",
'username' => 'System',
'action' => __('log.presentation_not_deleted_because_schedule', ['name' => $presentation->name, 'schedule' => $schedule->name,]),
]);

$schedule->delete_presentation = false;
$schedule->save();

return false;
}
}

Expand All @@ -196,8 +200,6 @@ static function checkForExpiredSchedules() {
$schedule->save();

return true;
}

}

return false;
Expand Down
7 changes: 7 additions & 0 deletions app/Models/Presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ protected static function booted(): void
'total_slides'
];

protected $appends = ['in_use'];

public function devices()
{
return $this->hasMany(Device::class);
Expand Down Expand Up @@ -65,4 +67,9 @@ public function getSchedules()

return $schedules;
}

public function in_use()
{
return $this->devices->count() > 0 || $this->groups->count() > 0 || $this->getSchedules()->count() > 0;
}
}
15 changes: 8 additions & 7 deletions resources/views/presentations/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ class="img-thumbnail" style="max-height: 100px;">
<td>{{ $presentation->slides->count() }}</td>
<td>{{ $presentation->slides->first()?->created_at?->format('d.m.Y H:i') ?? 'N/A' }}</td>
<td>

@php $list = []; @endphp
@if ($presentation->devices->count() > 0)
{{ $presentation->devices->count() }}
{{ trans_choice('Device|Devices', $presentation->devices->count()) }},
@php $list[] = $presentation->devices->count() . " " . trans_choice('Device|Devices', $presentation->devices->count()); @endphp
@endif

@if ($presentation->groups->count() > 0)
{{ $presentation->groups->count() }}
{{ trans_choice('Group|Groups', $presentation->groups->count()) }},
@php $list[] = $presentation->groups->count() . " " . trans_choice('Group|Groups', $presentation->groups->count()); @endphp
@endif

@if ($presentation->getSchedules()->count() > 0)
{{ $presentation->getSchedules()->count() }}
{{ trans_choice('Schedule|Schedules', $presentation->getSchedules()->count()) }},
@php $list[] = $presentation->getSchedules()->count() . " " . trans_choice('Schedule|Schedules', $presentation->getSchedules()->count()); @endphp
@endif

@if (count($list) > 0)
{{ implode(', ', $list) }}
@endif
</td>
<td>{{ $presentation->author }}</td>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/schedules/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function validate() {
<label for="start_date" class="form-label">{{ __('Start date') }}<span
class="text-danger">*</span></label>
<input required type="datetime-local" class="form-control" name="start_date" id="start_date"
value="{{ now()->format('Y-m-d H:i') }}">
value="{{ now()->format('Y-m-d H:00') }}">
</div>
</div>

Expand All @@ -81,7 +81,7 @@ class="text-danger">*</span></label>
<label for="end_date" class="form-label">{{ __('End date') }}<span
class="text-danger">*</span></label>
<input required type="datetime-local" class="form-control" name="end_date" id="end_date"
value="{{ now()->addHours(1)->format('Y-m-d H:i') }}">
value="{{ now()->addHours(1)->format('Y-m-d H:00') }}">
</div>
</div>
</div>
Expand Down

0 comments on commit ad451af

Please sign in to comment.