Skip to content
Snippets Groups Projects
Commit d183cde1 authored by catch's avatar catch Committed by Marcin Grabias
Browse files

Issue #3465106: Add a way to reset training progress by learning path

parent 29a634b5
Branches
No related tags found
1 merge request!14Allow resetting all non-passed LP statuses.
......@@ -1197,16 +1197,37 @@ class TrainingManager {
*
* @todo Remove when no longer needed.
*/
public function resetTraining($user_id, $group_id) {
public function resetTraining($group_id, $user_id = NULL) {
$lp_status_storage = $this->getStorage('user_lp_status');
$module_status_storage = $this->getStorage('user_module_status');
$answer_storage = $this->getStorage('opigno_answer');
$lp_status_ids = $lp_status_storage->getQuery()
$lp_status_query = $lp_status_storage->getQuery();
$lp_status_query
->accessCheck(FALSE)
->condition('gid', $group_id)
->condition('uid', $user_id)
->execute();
->condition('gid', $group_id);
if ($user_id !== NULL) {
$lp_status_query->condition('uid', $user_id);
}
$lp_status_ids = $lp_status_query->execute();
// If user ID is not provided and some learning path statuses are
// completed - only clear current module and current activity values
// if students wanted to revisit the training.
if ($user_id === NULL) {
foreach ($lp_status_storage->loadMultiple($lp_status_ids) as $lp_status) {
if (
$lp_status->getStatus() === LPStatus::STATUS_PROGRESS ||
$lp_status->getStatus() === LPStatus::STATUS_NEEDS_EVALUATION
) {
continue;
}
dump($lp_status->id());
$lp_status->set('current_module_status', NULL);
$lp_status->save();
unset($lp_status_ids[$lp_status->id()]);
}
}
$module_status_ids = [];
if (\count($lp_status_ids) !== 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment