xAPI: Display message when activity is added to LP - refs BT#18403

pull/3826/head
Angel Fernando Quiroz Campos 5 years ago
parent 1c4ce33b38
commit b893078214
  1. 1
      plugin/xapi/lang/english.php
  2. 1
      plugin/xapi/lang/french.php
  3. 1
      plugin/xapi/lang/spanish.php
  4. 32
      plugin/xapi/src/Entity/Repository/ToolLaunchRepository.php
  5. 28
      plugin/xapi/start.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.';

@ -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';

@ -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í.';

@ -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();
}
}

@ -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;
}
);

Loading…
Cancel
Save