From 92335883a12d1befe77d718323afee2c169ffbd1 Mon Sep 17 00:00:00 2001 From: Myriam Delaruelle <myriam.delaruelle@univ-lorraine.fr> Date: Tue, 24 May 2022 08:42:06 +0200 Subject: [PATCH] fetch linked activities in evaluation modal and create a link with the student name when possible --- competency_iena_competencies_2.php | 25 ++++++++++++++++++++----- js/dropdown.js | 3 ++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/competency_iena_competencies_2.php b/competency_iena_competencies_2.php index 0462696..fa46b9e 100644 --- a/competency_iena_competencies_2.php +++ b/competency_iena_competencies_2.php @@ -3,6 +3,7 @@ require_once('../../config.php'); require_once('entity/block_competency_iena_student.php'); +require_once('../../user/lib.php'); global $COURSE, $DB, $USER, $CFG; @@ -27,31 +28,45 @@ if (!has_capability('moodle/course:update', $context = context_course::instance( } } +//fetch the linked activities for a competency/student and create a link to the corresponding page when possible if(isset($_GET["action"]) && $_GET['action']=="get_links"){ $competencyid=$_GET["competencyid"]; $courseid=$_GET["courseid"]; + if(isset($_GET["studentid"])){ + $studentid=$_GET["studentid"]; + } + else{ + $studentid=$USER->id; + } + $cm_ids = \core_competency\api::list_course_modules_using_competency($competencyid, $courseid); $data=array(); if ( count($cm_ids) !== 0 ) { $modules=array(); $modinfo = get_fast_modinfo($courseid); - foreach ($cm_ids as $cm_id) { $module=new StdClass(); + //if the activity is an assignment or a quiz we'll try to redirect to the student submissions specifically + $is_assign = strpos($modinfo->cms[$cm_id]->url->out(), '/mod/assign') !== false; + $is_quiz= strpos($modinfo->cms[$cm_id]->url->out(), '/mod/quiz') !== false; $module->url = $modinfo->cms[$cm_id]->url->out(); + $user=$DB->get_record("user", array("id"=>$studentid)); + //for the moment we don't manage accents in names + if (has_capability('mod/assign:grade', $context = context_course::instance($courseid), $USER->id) && $is_assign) { + $module->url = $module->url . "&action=grading&tifirst=" . $user->firstname[0] . "&tilast=". $user->lastname[0]; + } + else if (has_capability('mod/quiz:grade', $context = context_course::instance($courseid), $USER->id) && $is_quiz) { + $module->url = $module->url . "&mode=responses&tifirst=" . $user->firstname[0] . "&tilast=". $user->lastname[0]; + } $module->link_icon=$CFG->wwwroot."/theme/image.php/boost/".$modinfo->cms[$cm_id]->modname."/1/icon"; $module->name=$modinfo->cms[$cm_id]->name; array_push($modules, $module); } $data["modules"]=$modules; $renderer = $PAGE->get_renderer('block_competency_iena'); - echo $renderer->get_linked_activities($data); - - //echo json_encode($html); return; - } echo "false"; return; diff --git a/js/dropdown.js b/js/dropdown.js index bb719d7..b08bbdb 100644 --- a/js/dropdown.js +++ b/js/dropdown.js @@ -179,10 +179,11 @@ }); function loadLinkedActivities(courseid, competencyid){ + user=document.getElementById('studentid_sel').value; $.ajax({ url: window.location.href, type: 'GET', - data: {competencyid:competencyid, courseid:courseid, action:"get_links"}, + data: {competencyid:competencyid, courseid:courseid, user:user, action:"get_links"}, success: function(html) { if(html=='false'){ html="<p><i>Il n'y a aucune activité liée</i></p>" -- GitLab