-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internal: Add course access tracking- BT#21694 #5508
Conversation
$access = $this->entityManager->getRepository(TrackECourseAccess::class) | ||
->createQueryBuilder('a') | ||
->where('a.user = :user AND a.cId = :courseId AND a.sessionId = :sessionId') | ||
->andWhere('a.loginCourseDate > :limitTime') | ||
->setParameters([ | ||
'user' => $user, | ||
'courseId' => $courseId, | ||
'sessionId' => $sessionId, | ||
'limitTime' => $limitTime, | ||
]) | ||
->orderBy('a.loginCourseDate', 'DESC') | ||
->setMaxResults(1) | ||
->getQuery() | ||
->getOneOrNullResult(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Es mejor pasar la query a un método de TrackECourseAccessRepository
$user = $this->tokenStorage->getToken()?->getUser(); | ||
if ($user instanceof User) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puedes usar el helper Chamilo\CoreBundle\ServiceHelper\UserHelper
en el constructor
$user = $this->tokenStorage->getToken()?->getUser(); | |
if ($user instanceof User) { | |
$user = $this->userHelper->getCurrent(); | |
if ($user) { |
if ($courseId > 0) { | ||
$user = $this->tokenStorage->getToken()?->getUser(); | ||
if ($user instanceof User) { | ||
$ip = $this->requestStack->getCurrentRequest()->getClientIp(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
La request puedes obtenerla desde el mismo envento
$ip = $this->requestStack->getCurrentRequest()->getClientIp(); | |
$ip = $event->getRequest()->getClientIp(); |
} | ||
|
||
public function __invoke(CourseAccess $event): void | ||
private function findExistingAccess(User $user, int $courseId, int $sessionId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Este método debería estar en TrackeECourseAccess
tags: | ||
- {name: kernel.event_listener, event: chamilo_course.course.access} | ||
tags: | ||
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 6 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El CidReqListener tiene la misma prioridad (de 6). Y en ambos hay una función que puede registrar un $access = new TrackECourseAccess();
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5508 +/- ##
============================================
+ Coverage 39.66% 39.81% +0.14%
- Complexity 10567 10593 +26
============================================
Files 840 841 +1
Lines 44173 44255 +82
============================================
+ Hits 17522 17619 +97
+ Misses 26651 26636 -15 ☔ View full report in Codecov by Sentry. |
An error occurred when fetching issues. View more on Code Climate. |
No description provided.