Plugins - Improve report lti provider with learnpaths - refs BT#20103

pull/4401/head
Christian 3 years ago
parent 873a81bc64
commit 26efca0022
  1. 2
      main/inc/lib/statistics.lib.php
  2. 45
      plugin/lti_provider/LtiProviderPlugin.php

@ -1463,6 +1463,7 @@ class Statistics
$table->setHeaderContents(0, 1, get_lang('ToolLp')); $table->setHeaderContents(0, 1, get_lang('ToolLp'));
$table->setHeaderContents(0, 2, get_lang('LastName')); $table->setHeaderContents(0, 2, get_lang('LastName'));
$table->setHeaderContents(0, 3, get_lang('FirstName')); $table->setHeaderContents(0, 3, get_lang('FirstName'));
$table->setHeaderContents(0, 4, get_lang('FirstAccess'));
$i = 1; $i = 1;
foreach ($result as $item) { foreach ($result as $item) {
if (!empty($item['learnpaths'])) { if (!empty($item['learnpaths'])) {
@ -1474,6 +1475,7 @@ class Statistics
$table->setCellContents($i, 1, $lpName); $table->setCellContents($i, 1, $lpName);
$table->setCellContents($i, 2, $user['lastname']); $table->setCellContents($i, 2, $user['lastname']);
$table->setCellContents($i, 3, $user['firstname']); $table->setCellContents($i, 3, $user['firstname']);
$table->setCellContents($i, 4, $user['first_access']);
$i++; $i++;
} }
} }

@ -192,6 +192,46 @@ class LtiProviderPlugin extends Plugin
return $publicKey; return $publicKey;
} }
/**
* Get the first access date of a user in a tool.
*
* @param $courseCode
* @param $toolId
* @param $userId
*
* @return string
*/
public function getUserFirstAccessOnToolLp($courseCode, $toolId, $userId)
{
$dql = "SELECT
a.startDate
FROM ChamiloPluginBundle:LtiProvider\Result a
WHERE
a.courseCode = '$courseCode' AND
a.toolName = 'lp' AND
a.toolId = $toolId AND
a.userId = $userId
ORDER BY a.startDate";
$qb = Database::getManager()->createQuery($dql);
$result = $qb->getArrayResult();
$firstDate = '';
if (isset($result[0])) {
$startDate = $result[0]['startDate'];
$firstDate = $startDate->format('Y-m-d H:i');
}
return $firstDate;
}
/**
* Get the results of users in tools lti.
*
* @param $startDate
* @param $endDate
*
* @return array
*/
public function getToolLearnPathResult($startDate, $endDate) public function getToolLearnPathResult($startDate, $endDate)
{ {
$dql = "SELECT $dql = "SELECT
@ -212,7 +252,8 @@ class LtiProviderPlugin extends Plugin
$issuer = $issuerValue['issuer']; $issuer = $issuerValue['issuer'];
$dqlLp = "SELECT $dqlLp = "SELECT
a.toolId, a.toolId,
a.userId a.userId,
a.courseCode
FROM FROM
ChamiloPluginBundle:LtiProvider\Result a ChamiloPluginBundle:LtiProvider\Result a
WHERE WHERE
@ -226,9 +267,11 @@ class LtiProviderPlugin extends Plugin
$lps = []; $lps = [];
foreach ($lpValues as $lp) { foreach ($lpValues as $lp) {
$uinfo = api_get_user_info($lp['userId']); $uinfo = api_get_user_info($lp['userId']);
$firstAccess = self::getUserFirstAccessOnToolLp($lp['courseCode'], $lp['toolId'], $lp['userId']);
$lps[$lp['toolId']]['users'][$lp['userId']] = [ $lps[$lp['toolId']]['users'][$lp['userId']] = [
'firstname' => $uinfo['firstname'], 'firstname' => $uinfo['firstname'],
'lastname' => $uinfo['lastname'], 'lastname' => $uinfo['lastname'],
'first_access' => $firstAccess,
]; ];
} }
$result[] = [ $result[] = [

Loading…
Cancel
Save