diff --git a/plugin/xapi/lang/english.php b/plugin/xapi/lang/english.php index 621f07d6bc..d9810cc29b 100644 --- a/plugin/xapi/lang/english.php +++ b/plugin/xapi/lang/english.php @@ -45,3 +45,4 @@ $strings['Terminated'] = 'Terminated'; $strings['Completed'] = 'Completed'; $strings['Answered'] = 'Answered'; $strings['Viewed'] = 'Viewed'; +$strings['ActivityAddedToLPCannotBeAccessed'] = 'This activity has been included in a learning path, so it cannot be accessed by students directly from here.'; diff --git a/plugin/xapi/lang/french.php b/plugin/xapi/lang/french.php index be031075b3..a745ee81ed 100644 --- a/plugin/xapi/lang/french.php +++ b/plugin/xapi/lang/french.php @@ -40,3 +40,4 @@ $strings['LrsConfiguration'] = 'Configuration LRS'; $strings['Verb'] = 'Verbe'; $strings['Actor'] = 'Acteur'; $strings['ToolTinCan'] = 'Activités'; +$strings['ActivityAddedToLPCannotBeAccessed'] = 'Cet activité fait partie d\'un parcours d\'apprentissage, il n\'est donc pas accessible par les étudiants depuis cette page'; diff --git a/plugin/xapi/lang/spanish.php b/plugin/xapi/lang/spanish.php index 3a63889e7d..ea26bc6456 100644 --- a/plugin/xapi/lang/spanish.php +++ b/plugin/xapi/lang/spanish.php @@ -45,3 +45,4 @@ $strings['Terminated'] = 'Terminó'; $strings['Completed'] = 'Completó'; $strings['Answered'] = 'Respondió'; $strings['Viewed'] = 'Visualizó'; +$strings['ActivityAddedToLPCannotBeAccessed'] = 'Esta actividad ha sido incluida en una secuencia de aprendizaje, por lo cual no podrá ser accesible directamente por los estudiantes desde aquí.'; diff --git a/plugin/xapi/src/Entity/Repository/ToolLaunchRepository.php b/plugin/xapi/src/Entity/Repository/ToolLaunchRepository.php index e2dfec20d1..92370320a0 100644 --- a/plugin/xapi/src/Entity/Repository/ToolLaunchRepository.php +++ b/plugin/xapi/src/Entity/Repository/ToolLaunchRepository.php @@ -6,7 +6,13 @@ namespace Chamilo\PluginBundle\Entity\XApi\Repository; use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Session; +use Chamilo\CourseBundle\Entity\CLp; +use Chamilo\CourseBundle\Entity\CLpItem; +use Chamilo\PluginBundle\Entity\XApi\ToolLaunch; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\NonUniqueResultException; +use Doctrine\ORM\NoResultException; +use Doctrine\ORM\Query\Expr\Join; /** * Class ToolLaunchRepository. @@ -34,7 +40,7 @@ class ToolLaunchRepository extends EntityRepository return $this->findBy($criteria, $orderBy, $limit, $start); } - public function countByCourseAndSession(Course $course, Session $session = null): int + public function countByCourseAndSession(Course $course, Session $session = null, $filteredForStudent = false): int { $qb = $this->createQueryBuilder('tl'); $qb->select($qb->expr()->count('tl')) @@ -48,6 +54,28 @@ class ToolLaunchRepository extends EntityRepository $qb->andWhere($qb->expr()->isNull('tl.session')); } - return (int) $qb->getQuery()->getSingleScalarResult(); + if ($filteredForStudent) { + $qb->leftJoin(CLpItem::class, 'lpi', Join::WITH, 'tl.id = lpi.path') + ->andWhere($qb->expr()->isNull('lpi.path')); + } + + $query = $qb->getQuery(); + + return (int) $query->getSingleScalarResult(); + } + + public function wasAddedInLp(ToolLaunch $toolLaunch): int + { + $qb = $this->getEntityManager()->createQueryBuilder(); + + return (int) $qb->select($qb->expr()->count('lp')) + ->from(CLp::class, 'lp') + ->innerJoin(CLpItem::class, 'lpi', Join::WITH, 'lp.id = lpi.lpId') + ->where('lpi.itemType = :type') + ->andWhere('lpi.path = :tool_id') + ->setParameter('type', TOOL_XAPI) + ->setParameter('tool_id', $toolLaunch->getId()) + ->getQuery() + ->getSingleScalarResult(); } } diff --git a/plugin/xapi/start.php b/plugin/xapi/start.php index a7c7fb18ff..5776f05e1e 100644 --- a/plugin/xapi/start.php +++ b/plugin/xapi/start.php @@ -14,6 +14,7 @@ $plugin = XApiPlugin::create(); $isAllowedToEdit = api_is_allowed_to_edit(); $em = Database::getManager(); +$toolLaunchRepo = $em->getRepository(ToolLaunch::class); $course = api_get_course_entity(); $session = api_get_session_entity(); @@ -23,24 +24,30 @@ $cidReq = api_get_cidreq(); $table = new SortableTable( 'tbl_xapi', - function () use ($em, $course, $session) { + function () use ($em, $course, $session, $isAllowedToEdit) { return $em->getRepository(ToolLaunch::class) - ->countByCourseAndSession($course, $session); + ->countByCourseAndSession($course, $session, !$isAllowedToEdit); }, - function ($start, $limit, $orderBy, $orderDir) use ($em, $course, $session, $isAllowedToEdit) { - $tools = $em->getRepository(ToolLaunch::class) - ->findByCourseAndSession($course, $session, ['title' => $orderDir], $limit, $start); + function ($start, $limit, $orderBy, $orderDir) use ($toolLaunchRepo, $course, $session, $isAllowedToEdit) { + $tools = $toolLaunchRepo->findByCourseAndSession($course, $session, ['title' => $orderDir], $limit, $start); $data = []; /** @var ToolLaunch $toolLaunch */ foreach ($tools as $toolLaunch) { + $wasAddedInLp = $toolLaunchRepo->wasAddedInLp($toolLaunch); + + if ($wasAddedInLp && !$isAllowedToEdit) { + continue; + } + $datum = []; $datum[] = [ $toolLaunch->getId(), $toolLaunch->getTitle(), $toolLaunch->getDescription(), $toolLaunch->getActivityType(), + $wasAddedInLp, ]; if ($isAllowedToEdit) { @@ -57,8 +64,8 @@ $table = new SortableTable( $table->set_header(0, $plugin->get_lang('ActivityTitle'), true); $table->set_column_filter( 0, - function (array $toolInfo) use ($cidReq, $session, $userInfo) { - list($id, $title, $description, $activityType) = $toolInfo; + function (array $toolInfo) use ($cidReq, $session, $userInfo, $plugin, $toolLaunchRepo) { + list($id, $title, $description, $activityType, $wasAddedInLp) = $toolInfo; $sessionStar = api_get_session_image( $session ? $session->getId() : 0, @@ -75,6 +82,13 @@ $table->set_column_filter( $data .= PHP_EOL.Display::tag('small', $description, ['class' => 'text-muted']); } + if ($wasAddedInLp) { + $data .= Display::div( + $plugin->get_lang('ActivityAddedToLPCannotBeAccessed'), + ['class' => 'lp_content_type_label'] + ); + } + return $data; } );