diff --git a/main/inc/lib/statistics.lib.php b/main/inc/lib/statistics.lib.php index 97a8f533a7..8f09b1388a 100644 --- a/main/inc/lib/statistics.lib.php +++ b/main/inc/lib/statistics.lib.php @@ -1463,6 +1463,7 @@ class Statistics $table->setHeaderContents(0, 1, get_lang('ToolLp')); $table->setHeaderContents(0, 2, get_lang('LastName')); $table->setHeaderContents(0, 3, get_lang('FirstName')); + $table->setHeaderContents(0, 4, get_lang('FirstAccess')); $i = 1; foreach ($result as $item) { if (!empty($item['learnpaths'])) { @@ -1474,6 +1475,7 @@ class Statistics $table->setCellContents($i, 1, $lpName); $table->setCellContents($i, 2, $user['lastname']); $table->setCellContents($i, 3, $user['firstname']); + $table->setCellContents($i, 4, $user['first_access']); $i++; } } diff --git a/plugin/lti_provider/LtiProviderPlugin.php b/plugin/lti_provider/LtiProviderPlugin.php index e01423580a..d9b46f9ef4 100644 --- a/plugin/lti_provider/LtiProviderPlugin.php +++ b/plugin/lti_provider/LtiProviderPlugin.php @@ -192,6 +192,46 @@ class LtiProviderPlugin extends Plugin 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) { $dql = "SELECT @@ -212,7 +252,8 @@ class LtiProviderPlugin extends Plugin $issuer = $issuerValue['issuer']; $dqlLp = "SELECT a.toolId, - a.userId + a.userId, + a.courseCode FROM ChamiloPluginBundle:LtiProvider\Result a WHERE @@ -226,9 +267,11 @@ class LtiProviderPlugin extends Plugin $lps = []; foreach ($lpValues as $lp) { $uinfo = api_get_user_info($lp['userId']); + $firstAccess = self::getUserFirstAccessOnToolLp($lp['courseCode'], $lp['toolId'], $lp['userId']); $lps[$lp['toolId']]['users'][$lp['userId']] = [ 'firstname' => $uinfo['firstname'], 'lastname' => $uinfo['lastname'], + 'first_access' => $firstAccess, ]; } $result[] = [