Skip to content

Commit

Permalink
fixes for grade table
Browse files Browse the repository at this point in the history
  • Loading branch information
Uwe-Kohnle committed Apr 2, 2024
1 parent ac1b6f7 commit a586401
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 126 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,13 +16,16 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Class ilObjLTIConsumerResult
* Class ilLTIConsumerGradeSynchronization
*
* @author Uwe Kohnle <[email protected]>
*
* @package Modules/LTIConsumer
*/

class ilLTIConsumerGradeSynchronization
{
public int $id;
Expand All @@ -36,18 +37,6 @@ class ilLTIConsumerGradeSynchronization
*/
public ?float $result = null;

/**
* Fill the properties with data from an array
* @param array assoc data
*/
// protected function fillData(array $data): void
// {
// $this->id = (int) $data['id'];
// $this->obj_id = (int) $data['obj_id'];
// $this->usr_id = (int) $data['usr_id'];
// $this->result = (float) $data['result'];
// }


public function getId(): int
{
Expand All @@ -69,22 +58,40 @@ public function getResult(): ?float
return $this->result;
}

/**
* @param $objId
* @return ilLTIConsumerResult[]
*/
public static function getGradesForObject(int $objId, ?int $usrID = null): array
public static function getGradesForObject(int $objId, ?int $usrID = null, ?string $activity_progress = null, ?string $grading_progress = null, ?ilDateTime $startDate = null, ?ilDateTime $endDate = null): array
{
global $DIC; /* @var \ILIAS\DI\Container $DIC */

$query = 'SELECT * FROM lti_consumer_grades'
. ' WHERE obj_id = ' . $DIC->database()->quote($objId, 'integer');

if ($usrID != null) {
$query .= ' AND usr_id = ' . $DIC->database()->quote($usrID, 'integer');
}

if ($activity_progress != null) {
$query .= ' AND activity_progress = ' . $DIC->database()->quote($activity_progress, 'text');
}

if ($grading_progress != null) {
$query .= ' AND grading_progress = ' . $DIC->database()->quote($grading_progress, 'text');
}

if ($startDate != null && $startDate->get(IL_CAL_DATETIME) != null) {
$query .= ' AND lti_timestamp >= ' . $DIC->database()->quote($startDate->get(IL_CAL_DATETIME), 'timestamp');
}

if ($endDate != null && $endDate->get(IL_CAL_DATETIME) != null) {
$query .= ' AND lti_timestamp <= ' . $DIC->database()->quote($endDate->get(IL_CAL_DATETIME), 'timestamp');
}

$query .= ' ORDER BY lti_timestamp DESC';

$res = $DIC->database()->query($query);

$results = [];

if ($row = $DIC->database()->fetchAssoc($res)) {
while ($row = $DIC->database()->fetchAssoc($res)) {
$results[] = $row;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Class ilLTIConsumerGradeSynchronizationFilter
*
Expand All @@ -38,23 +38,16 @@ class ilLTIConsumerGradeSynchronizationFilter

protected string $orderDirection = "";

protected ?ilCmiXapiUser $actor = null;
protected ?int $actor = null;

protected ?string $verb = null;
protected ?string $activity_progress = null;

protected ?ilCmiXapiDateTime $startDate = null;
protected ?string $grading_progress = null;

protected ?ilCmiXapiDateTime $endDate = null;
protected ?ilDateTime $startDate = null;

public function getActivityId(): string
{
return $this->activityId;
}
protected ?ilDateTime $endDate = null;

public function setActivityId(string $activityId): void
{
$this->activityId = $activityId;
}

public function getLimit(): int
{
Expand Down Expand Up @@ -96,42 +89,52 @@ public function setOrderDirection(string $orderDirection): void
$this->orderDirection = $orderDirection;
}

public function getActor(): ?\ilCmiXapiUser
public function getActor(): ?int
{
return $this->actor;
}

public function setActor(\ilCmiXapiUser $actor): void
public function setActor(int $actor): void
{
$this->actor = $actor;
}

public function getVerb(): ?string
public function getActivityProgress(): ?string
{
return $this->activity_progress;
}

public function setActivityProgress(string $activityProgress): void
{
$this->activity_progress = $activityProgress;
}

public function getGradingProgress(): ?string
{
return $this->verb;
return $this->grading_progress;
}

public function setVerb(string $verb): void
public function setGradingProgress(string $gradingProgress): void
{
$this->verb = $verb;
$this->grading_progress = $gradingProgress;
}

public function getStartDate(): ?\ilCmiXapiDateTime
public function getStartDate(): ?\ilDateTime
{
return $this->startDate;
}

public function setStartDate(\ilCmiXapiDateTime $startDate): void
public function setStartDate(\ilDateTime $startDate): void
{
$this->startDate = $startDate;
}

public function getEndDate(): ?\ilCmiXapiDateTime
public function getEndDate(): ?\ilDateTime
{
return $this->endDate;
}

public function setEndDate(\ilCmiXapiDateTime $endDate): void
public function setEndDate(\ilDateTime $endDate): void
{
$this->endDate = $endDate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Class ilLTIConsumerGradeSynchronizationGUI
*
Expand All @@ -28,14 +28,8 @@
*/
class ilLTIConsumerGradeSynchronizationGUI
{
/**
* @var ilObjLTIConsumer
*/
protected ilObjLTIConsumer $object;

/**
* @var ilLTIConsumerAccess
*/
protected ilLTIConsumerAccess $access;
private \ilGlobalTemplateInterface $main_tpl;
private \ILIAS\DI\Container $dic;
Expand Down Expand Up @@ -94,11 +88,10 @@ protected function showCmd(): void
try {
$statementsFilter = new ilLTIConsumerGradeSynchronizationFilter();

$statementsFilter->setActivityId($this->object->getProvider()->getContentItemUrl());

$this->initLimitingAndOrdering($statementsFilter, $table);
$this->initActorFilter($statementsFilter, $table);
$this->initVerbFilter($statementsFilter, $table);
$this->initActivityProgressFilter($statementsFilter, $table);
$this->initGradingProgressFilter($statementsFilter, $table);
$this->initPeriodFilter($statementsFilter, $table);
$this->initTableData($table, $statementsFilter);
} catch (Exception $e) {
Expand All @@ -113,7 +106,7 @@ protected function showCmd(): void

protected function initLimitingAndOrdering(ilLTIConsumerGradeSynchronizationFilter $filter, ilLTIConsumerGradeSynchronizationTableGUI $table): void
{
$table->determineOffsetAndOrder();
$table->determineOffsetAndOrder(true);

$filter->setLimit($table->getLimit());
$filter->setOffset($table->getOffset());
Expand All @@ -137,39 +130,46 @@ protected function initActorFilter(ilLTIConsumerGradeSynchronizationFilter $filt
$usrId = ilObjUser::getUserIdByLogin($actor);

if ($usrId) {
$filter->setActor(new ilCmiXapiUser($this->object->getId(), $usrId, $this->object->getProvider()->getPrivacyIdent()));
} else {
throw new ilCmiXapiInvalidStatementsFilterException(
"given actor ({$actor}) is not a valid actor for object ({$this->object->getId()})"
);
$filter->setActor($usrId);
}
}
} else {
$filter->setActor(new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId(), $this->object->getProvider()->getPrivacyIdent()));
$filter->setActor($DIC->user()->getId());
}
}

protected function initActivityProgressFilter(ilLTIConsumerGradeSynchronizationFilter $filter, ilLTIConsumerGradeSynchronizationTableGUI $table): void
{
$activityProgress = urldecode($table->getFilterItemByPostVar('activity_progress')->getValue());

$allowed = ['Initialized', 'Started', 'InProgress', 'Submitted', 'Completed'];

if (in_array($activityProgress, $allowed)) {
$filter->setActivityProgress($activityProgress);
}
}

protected function initVerbFilter(ilLTIConsumerGradeSynchronizationFilter $filter, ilLTIConsumerGradeSynchronizationTableGUI $table): void
protected function initGradingProgressFilter(ilLTIConsumerGradeSynchronizationFilter $filter, ilLTIConsumerGradeSynchronizationTableGUI $table): void
{
$verb = urldecode($table->getFilterItemByPostVar('verb')->getValue());
$gradingProgress = urldecode($table->getFilterItemByPostVar('grading_progress')->getValue());

$verbsallowed = ['completed', 'passed'];
$allowed = ['FullyGraded', 'Pending', 'PendingManual', 'Failed', 'NotReady'];

if (in_array($verb, $verbsallowed)) {
$filter->setVerb($verb);
if (in_array($gradingProgress, $allowed)) {
$filter->setGradingProgress($gradingProgress);
}
}

protected function initPeriodFilter(ilLTIConsumerGradeSynchronizationFilter $filter, ilLTIConsumerGradeSynchronizationTableGUI $table): void
{
$period = $table->getFilterItemByPostVar('period');

if ($period->getStartXapiDateTime()) {
$filter->setStartDate($period->getStartXapiDateTime());
if ($period->getStart()) {
$filter->setStartDate($period->getStart());
}

if ($period->getEndXapiDateTime()) {
$filter->setEndDate($period->getEndXapiDateTime());
if ($period->getEnd()) {
$filter->setEndDate($period->getEnd());
}
}

Expand Down Expand Up @@ -197,8 +197,37 @@ public function asyncUserAutocompleteCmd(): void

protected function initTableData(ilLTIConsumerGradeSynchronizationTableGUI $table, ilLTIConsumerGradeSynchronizationFilter $filter): void
{
$table->setData(ilLTIConsumerGradeSynchronization::getGradesForObject($this->object->getId()));
// $table->setMaxCount($statementsReport->getMaxCount());
$cUser = null;
if (!$this->access->hasOutcomesAccess()) {
$cUser = $this->dic->user()->getId();
} else {
$cUser = $filter->getActor();
}
$data = ilLTIConsumerGradeSynchronization::getGradesForObject(
$this->object->getId(),
$cUser,
$filter->getActivityProgress(),
$filter->getGradingProgress(),
$filter->getStartDate(),
$filter->getEndDate()
);

for ((int) $i = 0; $i < count($data); $i++) {
$usr = new ilObjUser((int) $data[$i]['usr_id']);
$data[$i]['actor'] = $usr->getFullname();
}
$sortNum = false;
if ($table->getOrderField() == 'score_given') {
$sortNum = true;
}

$data = ilArrayUtil::sortArray(
$data,
$table->getOrderField(),
$table->getOrderDirection(),
$sortNum
);
$table->setData($data);
}

protected function buildTableGUI(): ilLTIConsumerGradeSynchronizationTableGUI
Expand Down
Loading

0 comments on commit a586401

Please sign in to comment.