UnknownSec Bypass
403
:
/
mnt
/
lmsestudio-instance-vol002
/
lms_cde040c36613
/
app
/
Services
/
Environment
/ [
drwxr-xr-x
]
Menu
Upload
Mass depes
Mass delete
Terminal
Info server
About
name :
DashboardServices.php
<?php namespace EstudioLMS\Services\Environment; use Carbon\Carbon; use EstudioLMS\Helpers\Admin\Financial; use EstudioLMS\Models\Environment\HiredCourse; use EstudioLMS\Models\Environment\Record; use EstudioLMS\Models\Financial\HireSubscription; use EstudioLMS\Models\Statistic\Login; use EstudioLMS\Repositories\Courses\Course\CourseRepository; use EstudioLMS\Repositories\Environment\HiredCourseRepository; use EstudioLMS\Repositories\Financial\HireSubscriptionInterface; use EstudioLMS\Repositories\Financial\HiringInterface; use EstudioLMS\Repositories\Student\CourseHistoryInterface; use EstudioLMS\Repositories\Ticket\TicketRepository; use Illuminate\Contracts\Auth\Guard; use EstudioLMS\Repositories\Auth\UserRepository; use Illuminate\Support\Collection; /** * Class DashboardServices * @package EstudioLMS\Services\Environment */ class DashboardServices { /** * @var CourseRepository */ private $courseRepository; /** * @var Guard */ private $auth; /** * @var TicketRepository */ private $ticketRepository; /** * @var HiredCourseRepository */ private $hiredCourseRepository; /** * @var HiringInterface */ private $hiring; /** * @var UserRepository */ private $user; /** * @var Login */ private $login; /** * @var Record */ private $record; /** * @var HiredCourse */ private $hiredCourse; /** * @var HireSubscription */ private $hireSubscription; /** * @var HireSubscriptionInterface */ private $subscription; /** * @var CourseHistoryInterface */ private $courseHistory; /** * @var StudentService */ private $studentService; /** * DashboardServices constructor. * @param Guard $auth * @param CourseRepository $courseRepository * @param TicketRepository $ticketRepository * @param HiredCourseRepository $hiredCourseRepository * @param HiringInterface $hiring * @param UserRepository $user * @param Login $login * @param Record $record * @param HiredCourse $hiredCourse * @param HireSubscription $hireSubscription * @param HireSubscriptionInterface $subscription * @param CourseHistoryInterface $courseHistory * @param StudentService $studentService */ public function __construct( Guard $auth, CourseRepository $courseRepository, TicketRepository $ticketRepository, HiredCourseRepository $hiredCourseRepository, HiringInterface $hiring, UserRepository $user, Login $login, Record $record, HiredCourse $hiredCourse, HireSubscription $hireSubscription, HireSubscriptionInterface $subscription, CourseHistoryInterface $courseHistory, StudentService $studentService ) { $this->auth = $auth; $this->courseRepository = $courseRepository; $this->ticketRepository = $ticketRepository; $this->hiredCourseRepository = $hiredCourseRepository; $this->hiring = $hiring; $this->user = $user; $this->login = $login; $this->record = $record; $this->hiredCourse = $hiredCourse; $this->hireSubscription = $hireSubscription; $this->subscription = $subscription; $this->courseHistory = $courseHistory; $this->studentService = $studentService; } /** * @return int */ public function coursesByTeacher() { return count($this->courseRepository->listRelatedCourses($this->auth->user()['id'])); } /** * @return int */ public function totalMonth() { $teacherId = $this->auth->user()['id']; $dateIni = new Carbon('first day of this month'); $dateEnd = new Carbon('last day of this month'); $salesData = $this->hiring->reportData( 0, $teacherId, $dateIni, $dateEnd ); $salesData = Financial::sumNetAmount($salesData); return $salesData; } /** * @return int */ public function totalOpenedTickets() { $tickets = $this->ticketRepository->with(['messages']) ->scopeQuery(function ($query) { return $query->whereHas('messages', function ($query) { if ($this->auth->user()['roles'][0]['name'] === 'teacher') { $query->where('ticket_messages.to_id', '=', $this->auth->user()['id']); } else { $query->where('ticket_messages.from_id', '=', $this->auth->user()['id']); } }); }) ->findWhere( [ ['ticket_status_id', '=', 1] ])->all(); return count($tickets); } /** * @return int */ public function totalAnsweredTickets() { $tickets = $this->ticketRepository->with(['messages']) ->scopeQuery(function ($query) { return $query->whereHas('messages', function ($query) { $query->where('ticket_messages.to_id', '=', $this->auth->user()['id']); }); }); if ($this->auth->user()['roles'][0]['name'] === 'teacher') { $tickets = $tickets->findWhere([['ticket_status_id', '=', 2]]); } else { $tickets = $tickets->findWhere([['ticket_status_id', '<>', 1]]); } return count($tickets->all()); } /** * @return int */ public function coursesInProgress() { return $this->courseHistory->coursesInProgress($this->auth->user()['id']); } /** * @return int */ public function coursesCompleted() { return $this->courseHistory->coursesCompleted($this->auth->user()['id']); } /** * @return int|mixed */ public function score() { $user = $this->user->with(['ranking'])->find($this->auth->user()['id']); $sum = 0; foreach ($user['ranking'] as $ranking) { $sum += $ranking['value']; } return $sum; } /** * @return false|string */ public function accessInLast12Months() { $tempArray = null; $now = date('Y-m'); $tempArray[0]['month'] = $now; $tempArray[0]['minutes'] = '0'; for ($x = 11; $x >= 1; $x--) { $ym = date('Y-m', strtotime($now . " -$x month")); $tempArray[$x]['month'] = $ym; $tempArray[$x]['minutes'] = '0'; } ksort($tempArray); $firstDate = Carbon::now()->subDays(365)->startOfDay(); $lastDate = Carbon::now()->startOfDay()->endOfDay(); $logins = $this->login ->where('user_id', '=', $this->auth->user()['id']) ->where('created_at', '>=', $firstDate) ->where('created_at', '<=', $lastDate) ->selectRaw('DATE_FORMAT(DATE(created_at), "%Y-%m") AS dm, SUM(elapsed_minutes) AS minutes') ->groupBy(\DB::raw('YEAR(created_at), MONTH(created_at)')) ->orderBy(\DB::raw('DATE(created_at)')) ->get(); foreach ($tempArray as $key => $value) { foreach ($logins as $login) { if ($value['month'] == $login->dm) { $tempArray[$key]['minutes'] = $login->minutes; } } } //krsort($tempArray); $resultMonths[] = ['Ano-Mes', 'Minutos']; $count = 1; foreach ($tempArray as $key => $reg) { $resultMonths[$count] = [$reg['month'], (int)$reg['minutes']]; $count++; } $resultMonths = json_encode($resultMonths); return $resultMonths; } /** * @return array|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Query\Builder[]|Record[] */ public function twoLastAccessedCourses() { $today = Carbon::now(); $courses = $this->record->with(['course']) ->where('user_id', '=', $this->auth->user()['id']) ->groupBy('course_id') ->orderBy('watched_at', 'DESC') ->limit(2) ->get(); foreach ($courses as $key => $course) { $check = null; $check = $this->hiredCourse ->where('user_id', '=', $this->auth->user()['id']) ->where('course_id', '=', $course->course_id) ->latest()->first(); if ($check) { if ($check->status == 4 && $today <= Carbon::parse($check->getOriginal('end'))) { $courses[$key]['is_subscription'] = false; $courses[$key]['end'] = $check->end; $courses[$key]['expired'] = false; $courses[$key]['subscription_id'] = null; } else { $courses[$key]['is_subscription'] = false; $courses[$key]['end'] = $check->end; $courses[$key]['expired'] = true; $courses[$key]['subscription_id'] = null; $this->courseOfSubscription($courses, $key, $course->course_id); } } else { $courses[$key]['is_subscription'] = true; $courses[$key]['end'] = null; $courses[$key]['expired'] = true; $courses[$key]['subscription_id'] = null; $this->courseOfSubscription($courses, $key, $course->course_id); } $check = null; } return $courses; } /** * @param $courses * @param $key * @param $courseId * @return void */ private function courseOfSubscription(&$courses, $key, $courseId) { $mySubscriptions = $this->subscription->hiredSubscriptions($this->auth->user()['id'], [1]); foreach ($mySubscriptions as $subscription) { if ($subscription->subscription->full_content) { $courses[$key]['is_subscription'] = true; $courses[$key]['end'] = null; $courses[$key]['expired'] = false; $courses[$key]['subscription_id'] = $subscription->subscription_id; break; } else { $find = \DB::table('course_subscription') ->where('subscription_id', '=', $subscription->subscription_id) ->where('course_id', '=', $courseId) ->first(); if ($find) { $courses[$key]['is_subscription'] = true; $courses[$key]['end'] = null; $courses[$key]['expired'] = false; $courses[$key]['subscription_id'] = $subscription->subscription_id; break; } } } } /** * @return void */ public function coursesStatus() { $userId = $this->auth->user()['id']; $selectCourses = new Collection(); $mySubscriptions = $this->subscription->hiredSubscriptions($userId, [1]); $subscriptionId = null; foreach ($mySubscriptions as $subscription) { if ($subscription->subscription->full_content) { $selectCourses = null; $selectCourses = $this->courseRepository->showCourseList(); $subscriptionId = $subscription->subscription_id; break; } else { $temp = $subscription->subscription->courses; $temp->subscription_id = $subscription->subscription_id; $selectCourses = $selectCourses->merge($temp); } } $showCourses = new Collection(); foreach ($selectCourses as $course) { $this->studentService->hasCompletedCourse($userId, $course->id); } $myCourses = $this->hiredCourseRepository->hiredCourses($userId); foreach ($myCourses as $myCourse) { $this->studentService->hasCompletedCourse($userId, $myCourse->course->id); } } }
Copyright © 2026 - UnknownSec