XAPI: Add repository for ToolLaunch entity - refs BT#18403

pull/3826/head
Angel Fernando Quiroz Campos 5 years ago
parent 1d6fd65269
commit f4e78c2015
  1. 53
      plugin/xapi/src/Entity/Repository/ToolLaunchRepository.php
  2. 2
      plugin/xapi/src/Entity/ToolLaunch.php
  3. 19
      plugin/xapi/start.php

@ -0,0 +1,53 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\Entity\XApi\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Doctrine\ORM\EntityRepository;
/**
* Class ToolLaunchRepository.
*
* @package Chamilo\PluginBundle\Entity\XApi\Repository
*/
class ToolLaunchRepository extends EntityRepository
{
public function findByCourseAndSession(
Course $course,
Session $session = null,
array $orderBy = [],
int $limit = null,
int $start = null
): array {
$criteria = [
'course' => $course,
'session' => null,
];
if ($session) {
$criteria['session'] = $session;
}
return $this->findBy($criteria, $orderBy, $limit, $start);
}
public function countByCourseAndSession(Course $course, Session $session = null): int
{
$qb = $this->createQueryBuilder('tl');
$qb->select($qb->expr()->count('tl'))
->where($qb->expr()->eq('tl.course', ':course'))
->setParameter('course', $course);
if ($session) {
$qb->andWhere($qb->expr()->eq('tl.session', ':session'))
->setParameter('session', $session);
} else {
$qb->andWhere($qb->expr()->isNull('tl.session'));
}
return (int) $qb->getQuery()->getSingleScalarResult();
}
}

@ -15,7 +15,7 @@ use Doctrine\ORM\Mapping as ORM;
* @package Chamilo\PluginBundle\Entity\XApi * @package Chamilo\PluginBundle\Entity\XApi
* *
* @ORM\Table(name="xapi_tool_launch") * @ORM\Table(name="xapi_tool_launch")
* @ORM\Entity() * @ORM\Entity(repositoryClass="Chamilo\PluginBundle\Entity\XApi\Repository\ToolLaunchRepository")
*/ */
class ToolLaunch class ToolLaunch
{ {

@ -22,20 +22,13 @@ $cidReq = api_get_cidreq();
$table = new SortableTable( $table = new SortableTable(
'tbl_xapi', 'tbl_xapi',
function () use ($em, $course) { function () use ($em, $course, $session) {
return $em return $em->getRepository(ToolLaunch::class)
->createQuery('SELECT COUNT(tl) FROM ChamiloPluginBundle:XApi\ToolLaunch tl WHERE tl.course = :course') ->countByCourseAndSession($course, $session);
->setParameter('course', $course)
->getSingleScalarResult();
}, },
function ($start, $limit, $orderBy, $orderDir) use ($em, $course, $isAllowedToEdit) { function ($start, $limit, $orderBy, $orderDir) use ($em, $course, $session, $isAllowedToEdit) {
$tools = $em->getRepository('ChamiloPluginBundle:XApi\ToolLaunch') $tools = $em->getRepository(ToolLaunch::class)
->findBy( ->findByCourseAndSession($course, $session, ['title' => $orderDir], $limit, $start);
['course' => $course],
['title' => $orderDir],
$limit,
$start
);
$data = []; $data = [];

Loading…
Cancel
Save