UnknownSec Bypass
403
:
/
mnt
/
lmsestudio-instance-vol002
/
cursosconsultec
/
app
/
Helpers
/ [
drwxr-xr-x
]
Menu
Upload
Mass depes
Mass delete
Terminal
Info server
About
name :
GetDataRecords.php
<?php namespace EstudioLMS\Helpers; use Carbon\Carbon; use EstudioLMS\Models\Courses\Resources\UtfComment; use EstudioLMS\Repositories\Auth\UserRepository; use EstudioLMS\Repositories\Courses\Course\CourseRepository; use EstudioLMS\Repositories\Courses\Course\CourseResourceRepository; use EstudioLMS\Repositories\Courses\Course\ModuleRepository; use EstudioLMS\Repositories\Courses\Resources\AttachmentLessonInterface; use EstudioLMS\Repositories\Courses\Resources\AudioLessonInterface; use EstudioLMS\Repositories\Courses\Resources\CodeLessonInterface; use EstudioLMS\Repositories\Courses\Resources\HotPotatoesLessonInterface; use EstudioLMS\Repositories\Courses\Resources\Html5LessonInterface; use EstudioLMS\Repositories\Courses\Resources\LinkLessonInterface; use EstudioLMS\Repositories\Courses\Resources\PdfLessonInterface; use EstudioLMS\Repositories\Courses\Resources\Questions\MultipleChoiceAnswerInterface; use EstudioLMS\Repositories\Courses\Resources\Questions\MultipleChoiceInterface; use EstudioLMS\Repositories\Courses\Resources\QuizInterface; use EstudioLMS\Repositories\Courses\Resources\QuizQuestionInterface; use EstudioLMS\Repositories\Courses\Resources\ResourceTypeInterface; use EstudioLMS\Repositories\Courses\Resources\SeparatorInterface; use EstudioLMS\Repositories\Courses\Resources\SlideShareLessonInterface; use EstudioLMS\Repositories\Courses\Resources\TaskLessonInterface; use EstudioLMS\Repositories\Courses\Resources\TextLessonInterface; use EstudioLMS\Repositories\Courses\Resources\UtfCommentInterface; use EstudioLMS\Repositories\Courses\Resources\UtfLessonInterface; use EstudioLMS\Repositories\Courses\Resources\VideoLessonInterface; use EstudioLMS\Repositories\Courses\Resources\VimeoLiveLessonInterface; use EstudioLMS\Repositories\Courses\Resources\YoutubeLiveLessonInterface; use EstudioLMS\Repositories\Courses\Resources\VideoUploadLessonInterface; use EstudioLMS\Repositories\Courses\Resources\ZoomMeetingLessonInterface; use EstudioLMS\Repositories\Environment\RecordRepository; /** * Class GetDataRecords * @package EstudioLMS\Helpers */ class GetDataRecords { /** * @var CourseRepository */ private $courseRepository; /** * @var ModuleRepository */ private $moduleRepository; /** * @var CourseResourceRepository */ private $courseResourceRepository; /** * @var QuizInterface */ private $quizRepository; /** * @var ResourceTypeInterface */ private $resourceTypeRepository; /** * @var VideoLessonInterface */ private $videoLessonRepository; /** * @var CodeLessonInterface */ private $codeLessonRepository; /** * @var TextLessonInterface */ private $textLessonRepository; /** * @var AttachmentLessonInterface */ private $attachmentLessonRepository; /** * @var LinkLessonInterface */ private $linkLessonRepository; /** * @var HotPotatoesLessonInterface */ private $hotPotatoesLessonRepository; /** * @var SlideShareLessonInterface */ private $slideShareLessonRepository; /** * @var RecordRepository */ private $recordRepository; /** * @var QuizQuestionInterface */ private $quizQuestionRepository; /** * @var MultipleChoiceInterface */ private $multipleChoiceRepository; /** * @var MultipleChoiceAnswerInterface */ private $multipleChoiceAnswerRepository; /** * @var UserRepository */ private $userRepository; /** * @var YoutubeLiveLessonInterface */ private $youtubeLiveLessonRepository; /** * @var VimeoLiveLessonInterface */ private $vimeoLiveLessonRepository; /** * @var VideoUploadLessonInterface */ private $videoUploadLessonRepository; /** * @var ZoomMeetingLessonInterface */ private $zoomMeetingLessonRepository; /** * @var SeparatorInterface */ private $separator; /** * @var UtfLessonInterface */ private $utfLessonRepository; /** * @var UtfCommentInterface */ private $utfCommentRepository; /** * @var TaskLessonInterface */ private $taskLessonRepository; /** * @var PdfLessonInterface */ private $pdfLessonRepository; /** * @var AudioLessonInterface */ private $audioLessonRepository; /** * @var Html5LessonInterface */ private $html5LessonRepository; /** * GetDataRecords constructor. * @param CourseRepository $courseRepository * @param ModuleRepository $moduleRepository * @param CourseResourceRepository $courseResourceRepository * @param QuizInterface $quizRepository * @param ResourceTypeInterface $resourceTypeRepository * @param VideoLessonInterface $videoLessonRepository * @param CodeLessonInterface $codeLessonRepository * @param TextLessonInterface $textLessonRepository * @param AttachmentLessonInterface $attachmentLessonRepository * @param LinkLessonInterface $linkLessonRepository * @param HotPotatoesLessonInterface $hotPotatoesLessonRepository * @param SlideShareLessonInterface $slideShareLessonRepository * @param RecordRepository $recordRepository * @param QuizQuestionInterface $quizQuestionRepository * @param MultipleChoiceInterface $multipleChoiceRepository * @param MultipleChoiceAnswerInterface $multipleChoiceAnswerRepository * @param UserRepository $userRepository * @param YoutubeLiveLessonInterface $youtubeLiveLessonRepository * @param VimeoLiveLessonInterface $vimeoLiveLessonRepository * @param VideoUploadLessonInterface $videoUploadLessonRepository * @param ZoomMeetingLessonInterface $zoomMeetingLessonRepository * @param SeparatorInterface $separator * @param UtfLessonInterface $utfLessonRepository * @param UtfCommentInterface $utfCommentRepository * @param TaskLessonInterface $taskLessonRepository * @param PdfLessonInterface $pdfLessonRepository * @param AudioLessonInterface $audioLessonRepository * @param Html5LessonInterface $html5LessonRepository */ public function __construct( CourseRepository $courseRepository, ModuleRepository $moduleRepository, CourseResourceRepository $courseResourceRepository, QuizInterface $quizRepository, ResourceTypeInterface $resourceTypeRepository, VideoLessonInterface $videoLessonRepository, CodeLessonInterface $codeLessonRepository, TextLessonInterface $textLessonRepository, AttachmentLessonInterface $attachmentLessonRepository, LinkLessonInterface $linkLessonRepository, HotPotatoesLessonInterface $hotPotatoesLessonRepository, SlideShareLessonInterface $slideShareLessonRepository, RecordRepository $recordRepository, QuizQuestionInterface $quizQuestionRepository, MultipleChoiceInterface $multipleChoiceRepository, MultipleChoiceAnswerInterface $multipleChoiceAnswerRepository, UserRepository $userRepository, YoutubeLiveLessonInterface $youtubeLiveLessonRepository, VimeoLiveLessonInterface $vimeoLiveLessonRepository, VideoUploadLessonInterface $videoUploadLessonRepository, ZoomMeetingLessonInterface $zoomMeetingLessonRepository, SeparatorInterface $separator, UtfLessonInterface $utfLessonRepository, UtfCommentInterface $utfCommentRepository, TaskLessonInterface $taskLessonRepository, PdfLessonInterface $pdfLessonRepository, AudioLessonInterface $audioLessonRepository, Html5LessonInterface $html5LessonRepository ) { $this->courseRepository = $courseRepository; $this->moduleRepository = $moduleRepository; $this->courseResourceRepository = $courseResourceRepository; $this->quizRepository = $quizRepository; $this->resourceTypeRepository = $resourceTypeRepository; $this->videoLessonRepository = $videoLessonRepository; $this->codeLessonRepository = $codeLessonRepository; $this->textLessonRepository = $textLessonRepository; $this->attachmentLessonRepository = $attachmentLessonRepository; $this->linkLessonRepository = $linkLessonRepository; $this->hotPotatoesLessonRepository = $hotPotatoesLessonRepository; $this->slideShareLessonRepository = $slideShareLessonRepository; $this->recordRepository = $recordRepository; $this->quizQuestionRepository = $quizQuestionRepository; $this->multipleChoiceRepository = $multipleChoiceRepository; $this->multipleChoiceAnswerRepository = $multipleChoiceAnswerRepository; $this->userRepository = $userRepository; $this->youtubeLiveLessonRepository = $youtubeLiveLessonRepository; $this->vimeoLiveLessonRepository = $vimeoLiveLessonRepository; $this->videoUploadLessonRepository = $videoUploadLessonRepository; $this->zoomMeetingLessonRepository = $zoomMeetingLessonRepository; $this->separator = $separator; $this->utfLessonRepository = $utfLessonRepository; $this->utfCommentRepository = $utfCommentRepository; $this->taskLessonRepository = $taskLessonRepository; $this->pdfLessonRepository = $pdfLessonRepository; $this->audioLessonRepository = $audioLessonRepository; $this->html5LessonRepository = $html5LessonRepository; } /** * @param $resourceTypeId * @param int $resourceId * @param bool $withTrashed * @return mixed */ public function getResourceByResourceId($resourceTypeId, $resourceId = 0, $withTrashed = false) { switch ($resourceTypeId) { case 1 : return $withTrashed ? $this->separator->withTrashed()->find($resourceId) : $this->separator->find($resourceId); case 2 : if ($resourceId == 0) { return $withTrashed ? $this->videoLessonRepository->withTrashed()->all() : $this->videoLessonRepository->all(); } return $withTrashed ? $this->videoLessonRepository->withTrashed()->find($resourceId) : $this->videoLessonRepository->find($resourceId); case 3 : if ($resourceId == 0) { return $withTrashed ? $this->codeLessonRepository->withTrashed()->all() : $this->codeLessonRepository->all(); } return $withTrashed ? $this->codeLessonRepository->withTrashed()->find($resourceId) : $this->codeLessonRepository->find($resourceId); case 4 : if ($resourceId == 0) { return $withTrashed ? $this->textLessonRepository->withTrashed()->all() : $this->textLessonRepository->all(); } return $withTrashed ? $this->textLessonRepository->withTrashed()->find($resourceId) : $this->textLessonRepository->find($resourceId); case 5 : if ($resourceId == 0) { return $withTrashed ? $this->attachmentLessonRepository->withTrashed()->all() : $this->attachmentLessonRepository->all(); } return $withTrashed ? $this->attachmentLessonRepository->withTrashed()->find($resourceId) : $this->attachmentLessonRepository->find($resourceId); case 6 : if ($resourceId == 0) { return $withTrashed ? $this->linkLessonRepository->withTrashed()->all() : $this->linkLessonRepository->all(); } return $withTrashed ? $this->linkLessonRepository->withTrashed()->find($resourceId) : $this->linkLessonRepository->find($resourceId); case 7 : if ($resourceId == 0) { return $withTrashed ? $this->hotPotatoesLessonRepository->withTrashed()->all() : $this->hotPotatoesLessonRepository->all(); } return $withTrashed ? $this->hotPotatoesLessonRepository->withTrashed()->find($resourceId) : $this->hotPotatoesLessonRepository->find($resourceId); case 8 : if ($resourceId == 0) { return $withTrashed ? $this->slideShareLessonRepository->withTrashed()->all() : $this->slideShareLessonRepository->all(); } return $withTrashed ? $this->slideShareLessonRepository->withTrashed()->find($resourceId) : $this->slideShareLessonRepository->find($resourceId); case 9 : if ($resourceId == 0) { return $withTrashed ? $this->quizRepository->withTrashed()->all() : $this->quizRepository->all(); } return $withTrashed ? $this->quizRepository->withTrashed()->find($resourceId) : $this->quizRepository->find($resourceId); case 10 : if ($resourceId == 0) { return $withTrashed ? $this->youtubeLiveLessonRepository->withTrashed()->all() : $this->youtubeLiveLessonRepository->all(); } return $withTrashed ? $this->youtubeLiveLessonRepository->withTrashed()->find($resourceId) : $this->youtubeLiveLessonRepository->find($resourceId); case 11 : if ($resourceId == 0) { return $withTrashed ? $this->vimeoLiveLessonRepository->withTrashed()->all() : $this->vimeoLiveLessonRepository->all(); } return $withTrashed ? $this->vimeoLiveLessonRepository->withTrashed()->find($resourceId) : $this->vimeoLiveLessonRepository->find($resourceId); case 12 : if ($resourceId == 0) { return $withTrashed ? $this->videoUploadLessonRepository->withTrashed()->all() : $this->videoUploadLessonRepository->all(); } return $withTrashed ? $this->videoUploadLessonRepository->withTrashed()->find($resourceId) : $this->videoUploadLessonRepository->find($resourceId); case 13 : if ($resourceId == 0) { return $withTrashed ? $this->zoomMeetingLessonRepository->withTrashed()->all() : $this->zoomMeetingLessonRepository->all(); } return $withTrashed ? $this->zoomMeetingLessonRepository->withTrashed()->find($resourceId) : $this->zoomMeetingLessonRepository->find($resourceId); case 14 : if ($resourceId == 0) { return $withTrashed ? $this->utfLessonRepository->withTrashed()->all() : $this->utfLessonRepository->all(); } return $withTrashed ? $this->utfLessonRepository->withTrashed()->find($resourceId) : $this->utfLessonRepository->find($resourceId); case 15: if ($resourceId == 0) { return $withTrashed ? $this->taskLessonRepository->withTrashed()->all() : $this->taskLessonRepository->all(); } return $withTrashed ? $this->taskLessonRepository->withTrashed()->find($resourceId) : $this->taskLessonRepository->find($resourceId); case 16: if ($resourceId == 0) { return $withTrashed ? $this->pdfLessonRepository->withTrashed()->all() : $this->pdfLessonRepository->all(); } return $withTrashed ? $this->pdfLessonRepository->withTrashed()->find($resourceId) : $this->pdfLessonRepository->find($resourceId); case 17: if ($resourceId == 0) { return $withTrashed ? $this->audioLessonRepository->withTrashed()->all() : $this->audioLessonRepository->all(); } return $withTrashed ? $this->audioLessonRepository->withTrashed()->find($resourceId) : $this->audioLessonRepository->find($resourceId); case 18: if ($resourceId == 0) { return $withTrashed ? $this->html5LessonRepository->withTrashed()->all() : $this->html5LessonRepository->all(); } return $withTrashed ? $this->html5LessonRepository->withTrashed()->find($resourceId) : $this->html5LessonRepository->find($resourceId); default: return false; } } /** * @param $resourceTypeId * @param $resourceSlug * @return null */ public function getResourceByResourceSlug($resourceTypeId, $resourceSlug) { $resource = null; switch ($resourceTypeId) { case 2 : $resource = $this->videoLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 3 : $resource = $this->codeLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 4 : $resource = $this->textLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 5 : $resource = $this->attachmentLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 6 : $resource = $this->linkLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 7 : $resource = $this->hotPotatoesLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 8 : $resource = $this->slideShareLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 9 : $resource = $this->quizRepository->findByField('slug', $resourceSlug)->first(); break; case 10 : $resource = $this->youtubeLiveLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 11 : $resource = $this->vimeoLiveLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 12 : $resource = $this->videoUploadLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 13 : $resource = $this->zoomMeetingLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 14 : $resource = $this->utfLessonRepository->with(['comment.user.roles', 'comment.replicas.user.roles', 'comment.replicas.replicas.user.roles'])->findByField('slug', $resourceSlug)->first(); break; case 15 : $resource = $this->taskLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 16 : $resource = $this->pdfLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 17 : $resource = $this->audioLessonRepository->findByField('slug', $resourceSlug)->first(); break; case 18 : $resource = $this->html5LessonRepository->findByField('slug', $resourceSlug)->first(); break; } return $resource; } /** * @param $questionId * @return mixed */ public function getQuestionWithAnswersById($questionId) { return $this->multipleChoiceRepository->with(['tags', 'answers'])->find($questionId); } /** * @param $resourceTypeId * @return mixed */ public function getResourceTypeById($resourceTypeId) { return $this->resourceTypeRepository->find($resourceTypeId); } /** * @param $resourceTypeSlug * @return mixed */ public function getResourceTypeBySlug($resourceTypeSlug) { return $this->resourceTypeRepository->findByField('slug', $resourceTypeSlug)->first(); } /** * @param $courseId * @return mixed */ public function getCourseById($courseId) { return $this->courseRepository->withTrashed()->find($courseId); } /** * @param $moduleId * @param bool $available * @return mixed */ public function getModuleById($moduleId, $available = false) { if ($available) { return $this->moduleRepository->moduleAvailable($moduleId)->first(); } else { return $this->moduleRepository->withTrashed()->find($moduleId); } } /** * @param $courseSlug * @param bool $first * @return mixed */ public function getCourseBySlug($courseSlug, $first = true) { return $this->courseRepository->getCourseBySlug($courseSlug, $first); } /** * @param $moduleSlug * @param $courseId * @param bool $first * @return mixed */ public function getModuleBySlug($moduleSlug, $courseId, $first = true) { if ($first) { return $this->moduleRepository->findWhere([ ['slug', '=', $moduleSlug], ['course_id', '=', $courseId] ])->first(); } return $this->moduleRepository->findWhere([ ['slug', '=', $moduleSlug], ['course_id', '=', $courseId] ]); } /** * @param $course * @param $module * @param $resource * @return array|string */ public function previousResource($course, $module, $resource) { $allResources = $this->courseResourceRepository->allLessonsThatCanBeRenderedByCourse($course['id']); $currentResource = $allResources->where('module_id', $module['id']) ->where('resource_id', $resource['id']) ->where('resource_type_id', $resource['resource_type_id']) ->keys()->first(); if ($currentResource == 0) { return ''; } $previous = $allResources[$currentResource - 1]; $resource = $this->getResourceByResourceId($previous['resource_type_id'], $previous['resource_id']); $prevModule = $this->getModuleById($previous['module_id']); $resourceType = $this->getResourceTypeById($previous['resource_type_id']); $previousResource = [ 'course_slug' => $course['slug'], 'module_slug' => $prevModule['slug'], 'resource_slug' => $resource['slug'], 'resource_type_slug' => $resourceType['slug'], 'enabled' => true, 'route' => $resourceType['route'] ]; return $previousResource; } /** * @param $userId * @param $course * @param $module * @param $resource * @return array|string */ public function nextResource($userId, $course, $module, $resource) { $allResources = $this->courseResourceRepository->allLessonsThatCanBeRenderedByCourse($course['id']); $lastResource = count($allResources) - 1; $currentResource = $allResources->where('module_id', $module['id']) ->where('resource_id', $resource['id']) ->where('resource_type_id', $resource['resource_type_id']) ->keys()->first(); if ($currentResource == $lastResource) { return ''; } $current = $allResources[$currentResource]; //Define se o próximo recurso está liberado para acesso ou não $can = $this->canAccessNextResource($current, $userId); $next = $allResources[$currentResource + 1]; $nextModule = $this->getModuleById($next['module_id'], true); $resource = $this->getResourceByResourceId($next['resource_type_id'], $next['resource_id']); $resourceType = $this->getResourceTypeById($next['resource_type_id']); $nextResource = [ 'course_slug' => $course['slug'], 'module_slug' => $nextModule['slug'], 'resource_slug' => $resource['slug'], 'resource_type_slug' => $resourceType['slug'], 'enabled' => $can, 'route' => $resourceType['route'] ]; return $nextResource; } /** * @param $courseId * @param $moduleId * @param $quizId * @return mixed */ public function getQuizAllQuestions($courseId, $moduleId, $quizId) { return $this->quizQuestionRepository->orderBy('position') ->findWhere( [ ['course_id', '=', $courseId], ['module_id', '=', $moduleId], ['quiz_id', '=', $quizId], ['status_id', '=', 1] ] ); } /** * @param $courseId * @param $moduleId * @param $quizId * @return mixed */ public function getQuizAllAvailableQuestions($courseId, $moduleId, $quizId) { return $this->quizQuestionRepository->orderBy('position') ->findWhere( [ ['course_id', '=', $courseId], ['module_id', '=', $moduleId], ['quiz_id', '=', $quizId], ['status_id', '=', 1] ] ); } /** * @param $courseId * @param $moduleId * @param $quizId * @param $hash * @return mixed */ public function getQuestionByHash($courseId, $moduleId, $quizId, $hash) { return $this->quizQuestionRepository->orderBy('position') ->findWhere( [ ['course_id', '=', $courseId], ['module_id', '=', $moduleId], ['quiz_id', '=', $quizId], ['hash', '=', $hash] ] )->first(); } /** * @param $resource * @param $userId * @return bool */ private function canAccessNextResource($resource, $userId) { $check = $this->recordRepository ->findWhere([ ['user_id', '=', $userId], ['course_id', '=', $resource['course_id']], ['module_id', '=', $resource['module_id']], ['resource_id', '=', $resource['resource_id']], ['resource_type_id', '=', $resource['resource_type_id']] ])->all(); if ($check) { return true; } return false; } /** * @param $userId * @return mixed */ public function getUserProfile($userId) { /* * Verificar par usar apenas no course ratings */ return $this->userRepository->withTrashed()->find($userId); } /** * @param $userId * @param $courseId * @return mixed */ public function getLastRecordedLesson($userId, $courseId) { return $this->recordRepository->getLastWatchedLesson($userId, $courseId); } /** * @param $userId * @param $utfLessonId * @return bool */ public function checkIfUtfHasAnswered($userId, $utfLessonId) { $answer = $this->utfCommentRepository->findWhere( [ ['user_id', '=', $userId], ['utf_lesson_id', '=', $utfLessonId] ] )->first(); return (bool)count($answer); } /** * @param $comments * @return array */ public function countUtfReplyAndRejoinder($comments) { Carbon::setLocale('pt'); $countReply = 0; $countRejoinder = 0; $totals = null; $lastInteraction = null; foreach ($comments as $answer) { $lastInteraction = null; $countReply = 0; $countRejoinder = 0; $lastInteraction = Carbon::parse($answer->updated_at); foreach ($answer->replicas as $reply) { $countReply += 1; if (is_null($lastInteraction)) { $lastInteraction = Carbon::parse($reply->updated_at); } else { if (Carbon::parse($reply->updated_at) > $lastInteraction) { $lastInteraction = Carbon::parse($reply->updated_at); } } foreach ($reply->replicas as $rejoinder) { $countRejoinder += 1; if (Carbon::parse($rejoinder->updated_at) > $lastInteraction) { $lastInteraction = Carbon::parse($rejoinder->updated_at); } } } $totals[$answer->id]['reply'] = $countReply; $totals[$answer->id]['rejoinder'] = $countRejoinder; $totals[$answer->id]['last_interact'] = $lastInteraction->diffForHumans(); } return $totals; } }
Copyright © 2026 - UnknownSec