Ejemplo n.º 1
0
 require_capability('block/evalcomix:assessed', $context, $studentid);
 $lms = MOODLE_NAME;
 $module = evalcomix_tasks::get_type_task($cmid);
 //echo "$courseid - $module - $cmid - $studentid, - $assessor - $mode - $lms ";
 $user = $DB->get_record('user', array('id' => $studentid));
 if ($user) {
     $modinfo = get_fast_modinfo($courseid);
     $mods = $modinfo->get_cms();
     $mod = $mods[$cmid];
     $title = fullname($user) . get_string('studentwork2', 'block_evalcomix') . $mod->name;
 }
 $url_instrument = '';
 if ($perspective == 'assess') {
     $mode = grade_report_evalcomix::get_type_evaluation($studentid, $courseid);
     if ($task = evalcomix_tasks::fetch(array('instanceid' => $cmid))) {
         if (!($modefetch = evalcomix_modes::fetch(array('taskid' => $task->id, 'modality' => $mode)))) {
             print_error('EvalCOMIX: No permissions');
         }
     } else {
         print_error('EvalCOMIX: The activity is not configured with EvalCOMIX');
     }
     $assessor = $USER->id;
     $url_instrument = webservice_evalcomix_client::get_ws_assessment_form($toolid, $lang . '_utf8', $courseid, $module, $cmid, $studentid, $assessor, $mode, $lms, 'assess', $title);
 } elseif ($perspective == 'view') {
     $assessorid = required_param('as', PARAM_INT);
     if ($assessorid == $studentid) {
         $mode = 'self';
     } else {
         //if (has_capability('block/evalcomix:edit',$context, $assessorid)){
         if (has_capability('moodle/grade:viewhidden', $context, $assessorid)) {
             $mode = 'teacher';
                     foreach ($assessments as $assessment) {
                         //If it is a self assessment
                         if ($assessment->studentid == $assessment->assessorid && $selfweight) {
                             $selfgrade = $assessment->grade;
                         } elseif (has_capability('moodle/grade:viewhidden', $coursecontext, $assessment->assessorid) && $teacherweight) {
                             $teachergrade += $assessment->grade;
                             $numteachers++;
                         } else {
                             //If it is a peer assessment
                             //Only gets grades when the assessment period in the task is finished
                             if ($modeEI = evalcomix_modes::fetch(array('taskid' => $assessment->taskid, 'modality' => 'peer'))) {
                                 $modeEItime = evalcomix_modes_time::fetch(array('modeid' => $modeEI->id));
                                 if ($modeEItime && $now > $modeEItime->timedue) {
                                     $peergrade += $assessment->grade;
                                     $numpeers++;
                                 }
                             }
                         }
                     }
                     //Calculates peergrade
                     if ($numpeers > 0) {
                         $peergrade = round($peergrade / $numpeers, 2);
                     }
                     //Calculates teachergrade
                     if ($numteachers > 0) {
                         $teachergrade = round($teachergrade / $numteachers, 2);
                     }
                     //Calcultes the total grade
                     //if($teachergrade != 0 || $selfgrade != 0 || $peergrade != 0){
                     if ($numteachers > 0 || $numpeers > 0 || $selfgrade != -1) {
                         if ($selfgrade == -1) {
                             $selfgrade = 0;
                         }
                         $totalgrade = $selfgrade * ($selfweight / 100) + $teachergrade * ($teacherweight / 100) + $peergrade * ($peerweight / 100);
                         //Add grade to array final grades
                         //$finalgrades[$task->id][$user->id] = $totalgrade;
                         $finalgrades[$task->instanceid][$user->id] = $totalgrade;
                     } else {
                         //There is peer assessments but assessment period hasn't finished
                         $finalgrades[$task->instanceid][$user->id] = -1;
                     }
                 }
             }
         }
     }
     return $finalgrades;
 }
 /**
  * Finds and returns all evalcomix_assessments instances.
  * @static abstract
  * @param array $params
Ejemplo n.º 3
0
 /**
  * @return array of course tools by [taskid][modality]
  */
 function load_tools()
 {
     $result = array();
     if ($evalcomix = evalcomix::fetch(array('courseid' => $this->courseid))) {
         if ($tools = evalcomix_tool::fetch_all(array('evxid' => $evalcomix->id))) {
             foreach ($tools as $tool) {
                 if ($modes = evalcomix_modes::fetch_all(array('toolid' => $tool->id))) {
                     foreach ($modes as $mode) {
                         $taskid = $mode->taskid;
                         $modality = $mode->modality;
                         $result[$taskid][$modality] = $tool;
                     }
                 }
             }
         }
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Calculates finalgrade for a student in a activity
  * @param int $params[cmid] course module id
  * @param int $params[userid] student id
  * @return the finalgrade or -1 if there is only peer-assessment but assessment period hasn't finished or -2 if there is not any assessment
  */
 public static function get_finalgrade_user_task($params)
 {
     if (!isset($params['cmid']) || !isset($params['userid']) || !isset($params['courseid'])) {
         return null;
     }
     $cmid = $params['cmid'];
     $userid = $params['userid'];
     $courseid = $params['courseid'];
     //$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
     $coursecontext = context_course::instance($courseid);
     $now = time();
     global $CFG, $DB;
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_tasks.php';
     if (!($task = evalcomix_tasks::fetch(array('instanceid' => $cmid)))) {
         return null;
     }
     $result = null;
     $teacherweight = -1;
     $selfweight = -1;
     $peerweight = -1;
     $params_modes = array('taskid' => $task->id);
     $modes = evalcomix_modes::fetch_all($params_modes);
     if ($modes) {
         //Obtains activity´s weights
         foreach ($modes as $mode) {
             switch ($mode->modality) {
                 case 'teacher':
                     $teacherweight = $mode->weighing;
                     break;
                 case 'self':
                     $selfweight = $mode->weighing;
                     break;
                 case 'peer':
                     $peerweight = $mode->weighing;
                     break;
                 default:
             }
         }
         //echo $task->id . ': teacherweight-' . $teacherweight . ' selfweight-' .$selfweight . ' peerweight-' .$peerweight.'<br/>';
         $params2 = array('taskid' => $task->id, 'studentid' => $userid);
         $assessments = evalcomix_assessments::fetch_all($params2);
         $inperiod = false;
         if ($assessments) {
             //$selfgrade = 0;
             $selfgrade = -1;
             $teachergrade = 0;
             $numteachers = 0;
             $peergrade = 0;
             $numpeers = 0;
             $grade = 0;
             foreach ($assessments as $assessment) {
                 //If it is a self assessment
                 if ($assessment->studentid == $assessment->assessorid && $selfweight != -1) {
                     $selfgrade = $assessment->grade;
                 } elseif (has_capability('moodle/grade:viewhidden', $coursecontext, $assessment->assessorid)) {
                     if ($teacherweight != -1) {
                         $teachergrade += $assessment->grade;
                         $numteachers++;
                     }
                 } elseif ($assessment->studentid != $assessment->assessorid) {
                     //If it is a peer assessment
                     //Only gets grades when the assessment period in the task is finished
                     if ($modeEI = evalcomix_modes::fetch(array('taskid' => $assessment->taskid, 'modality' => 'peer'))) {
                         $modeEItime = evalcomix_modes_time::fetch(array('modeid' => $modeEI->id));
                         if ($modeEItime && $now > $modeEItime->timedue) {
                             $peergrade += $assessment->grade;
                             $numpeers++;
                         } elseif ($now >= $modeEItime->timeavailable && $now <= $modeEItime->timedue) {
                             $inperiod = true;
                         }
                     }
                 }
             }
             //Calculates peergrade
             if ($numpeers > 0) {
                 $peergrade = round($peergrade / $numpeers, 2);
             }
             //Calculates teachergrade
             if ($numteachers > 0) {
                 $teachergrade = round($teachergrade / $numteachers, 2);
             }
             //Calcultes the total grade
             //if($teachergrade != 0 || $selfgrade != 0 || $peergrade != 0){
             if ($numteachers > 0 || $numpeers > 0 || $selfgrade != -1) {
                 if ($selfgrade == -1) {
                     $selfgrade = 0;
                 }
                 $result = $selfgrade * ($selfweight / 100) + $teachergrade * ($teacherweight / 100) + $peergrade * ($peerweight / 100);
             } elseif ($inperiod == true) {
                 //There is peer assessments but assessment period hasn't finished
                 $result = -1;
             } else {
                 $result = -2;
             }
             return $result;
         } else {
             return null;
         }
     } else {
         return -3;
     }
 }
Ejemplo n.º 5
0
}
$selfassessment = null;
$teacherassessments = array();
$peerassessments = array();
$totalpeergrade = 0;
$num_peer_grades = 0;
$totalteachergrade = 0;
$num_teacher_grades = 0;
// Get Weighings
$modality = evalcomix_modes::fetch(array('taskid' => $itemid, 'modality' => 'teacher'));
if ($modality != null) {
    $weighingteacher = $modality->weighing;
} else {
    $weighingteacher = null;
}
$modality = evalcomix_modes::fetch(array('taskid' => $itemid, 'modality' => 'self'));
if ($modality != null) {
    $weighingself = $modality->weighing;
} else {
    $weighingself = null;
}
$modality = evalcomix_modes::fetch(array('taskid' => $itemid, 'modality' => 'peer'));
if ($modality != null) {
    $weighingpeer = $modality->weighing;
} else {
    $weighingpeer = null;
}
if ($assessments) {
    foreach ($assessments as $assessment) {
        //if(has_capability('block/evalcomix:edit',$context, $assessment->assessorid)){
        if (has_capability('moodle/grade:viewhidden', $context, $assessment->assessorid)) {
    }
    /**
	* Fetch an object with no unique params. Return false
	*/
    public function test_fetch_fail()
    {
        $this->expectException('moodle_exception');
        $params = array('modality' => 'peer');
        $result = evalcomix_modes::fetch($params);
        unset($params, $result);
    }
 public function after_restore()
 {
     global $DB, $COURSE, $CFG;
     include_once $CFG->dirroot . '/blocks/evalcomix/configeval.php';
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_tasks.php';
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_modes.php';
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_modes_time.php';
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_modes_extra.php';
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_assessments.php';
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/webservice_evalcomix_client.php';
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_grades.php';
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_allowedusers.php';
     $settings = $this->task->get_info()->root_settings;
     //$this->oldcontextid; busco en tabla mdl_context->instanceid es el courseid; con el courseid obtengo todos los cms antiguos y nuevos y voy copiando uno a uno
     //$this->basepath   = $CFG->dataroot . '/temp/backup/' . $controller->get_tempdir();
     //$blockid = $this->get_old_blockid();
     //$xml = simplexml_load_file($this->get_basepath() . '/course/blocks/evalcomix_'. $blockid .'/evalcomix.xml');
     $fullpath = $this->task->get_taskbasepath();
     // We MUST have one fullpath here, else, error
     if (empty($fullpath)) {
         throw new restore_step_exception('restore_structure_step_undefined_fullpath');
     }
     // Append the filename to the fullpath
     $fullpath = rtrim($fullpath, '/') . '/' . $this->filename;
     // And it MUST exist
     if (!file_exists($fullpath)) {
         // Shouldn't happen ever, but...
         throw new restore_step_exception('missing_moodle_backup_xml_file', $fullpath);
     }
     $xml = simplexml_load_file($fullpath);
     //echo $this->task->get_taskbasepath() . '/course/blocks/evalcomix_'. $blockid .'/evalcomix.xml';
     $evxid_old = (int) $xml->evalcomix['id'];
     $viewmode_old = (string) $xml->evalcomix->viewmode;
     if (isset($xml->evalcomix->environment->courseid)) {
         $courseid_old = $xml->evalcomix->environment->courseid;
     }
     if (isset($xml->evalcomix->environment->moodlename)) {
         $moodlename_old = $xml->evalcomix->environment->moodlename;
     }
     include_once $CFG->dirroot . '/blocks/evalcomix/configeval.php';
     //include_once($CFG->dirroot . '/backup/lib.php');
     //$courseid_new = $this->plan->get_courseid();
     $courseid_new = $this->get_courseid();
     $moodlename_new = MOODLE_NAME;
     $block_evalcomix = $DB->get_record('block_evalcomix', array('courseid' => $courseid_new));
     //$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid_new);
     $coursecontext = context_course::instance($courseid_new);
     $tasksid = '';
     if (isset($xml->evalcomix->tasks[0])) {
         $assessmentids = array();
         foreach ($xml->evalcomix->tasks[0] as $task) {
             $task_id_old = (int) $task['id'];
             $task_instanceid_old = (int) $task->instanceid;
             $task_maxgrade_old = (string) $task->maxgrade;
             $task_weighing_old = (string) $task->weighing;
             $cm = $DB->get_record('block_evalcomix', array('courseid' => $courseid_new));
             $cm_mapping = $this->get_mapping('course_module', $task_instanceid_old);
             $newcmid = $cm_mapping->newitemid;
             $visibletask = '1';
             if (isset($task->visible)) {
                 $visibletask = (string) $task->visible;
             }
             if (!($task_fetch = evalcomix_tasks::fetch(array('instanceid' => $newcmid)))) {
                 $task_object = new evalcomix_tasks('', $newcmid, $task_maxgrade_old, $task_weighing_old, '', $visibletask);
                 $newtaskid = $task_object->insert();
                 $tasksid .= $task_instanceid_old . '-' . $newcmid . ',';
                 foreach ($task->modes[0] as $mode) {
                     $mode_id_old = (int) $mode['id'];
                     $mode_toolid_old = (string) $mode->toolid;
                     $mode_modality_old = (string) $mode->modality;
                     $mode_weighing_old = (string) $mode->weighing;
                     $tool_mapping = $this->get_mapping('evalcomix_tool', $mode_toolid_old);
                     if (!empty($tool_mapping) && ($newtoolid = $tool_mapping->newitemid)) {
                         if (!($mode_object = evalcomix_modes::fetch(array('taskid' => $newtaskid, 'toolid' => $newtoolid, 'modality' => $mode_modality_old)))) {
                             $mode_object = new evalcomix_modes('', $newtaskid, $newtoolid, $mode_modality_old, $mode_weighing_old);
                             $newmodeid = $mode_object->insert();
                             if (isset($mode->mode_time['id'])) {
                                 $mode_time_id_old = (string) $mode->mode_time['id'];
                                 $mode_time_timeavailable_old = (string) $mode->mode_time->timeavailable;
                                 $mode_time_timedue_old = (string) $mode->mode_time->timedue;
                                 if (!evalcomix_modes_time::fetch(array('modeid' => $newmodeid))) {
                                     $mode_time_object = new evalcomix_modes_time('', $newmodeid, $mode_time_timeavailable_old, $mode_time_timedue_old);
                                     $mode_time_object->insert();
                                 }
                             }
                             if (isset($mode->mode_extra)) {
                                 $mode_extra_id_old = (string) $mode->mode_extra['id'];
                                 $mode_extra_timeavailable_old = (string) $mode->mode_extra->anonymous;
                                 $mode_extra_visible = $mode->mode_extra->visible;
                                 $mode_extra_whoassesses = $mode->mode_extra->whoassesses;
                                 if (!($mode_extra_object = evalcomix_modes_extra::fetch(array('modeid' => $newmodeid)))) {
                                     $mode_extra_object = new evalcomix_modes_extra('', $newmodeid, $mode_extra_timeavailable_old, $mode_extra_visible, $mode_extra_whoassesses);
                                     $mode_extra_object->insert();
                                 }
                             }
                         }
                     }
                 }
             }
             if ($settings['users'] == 1) {
                 foreach ($task->assessments[0] as $assessment) {
                     $assessment_id_old = (string) $assessment['id'];
                     $assessment_assessorid_old = (string) $assessment->assessorid;
                     $assessment_studentid_old = (string) $assessment->studentid;
                     $assessment_grade_old = (string) $assessment->grade;
                     $assessor_user = $this->get_mapping('user', $assessment_assessorid_old);
                     $student_user = $this->get_mapping('user', $assessment_studentid_old);
                     if (!isset($assessor_user->newitemid) || !isset($student_user->newitemid)) {
                         continue;
                     }
                     if (!($assessment_object = evalcomix_assessments::fetch(array('taskid' => $newtaskid, 'assessorid' => $assessor_user->newitemid, 'studentid' => $student_user->newitemid)))) {
                         $assessment_object = new evalcomix_assessments('', $newtaskid, $assessor_user->newitemid, $student_user->newitemid, $assessment_grade_old);
                         $assessment_object->insert();
                     }
                     //$modulename = get_module_type ($courseid_new, $newcmid);
                     $modulename = evalcomix_tasks::get_type_task($newcmid);
                     $mode = '';
                     if ($student_user->newitemid == $assessor_user->newitemid) {
                         $mode = 'self';
                     } elseif (has_capability('moodle/grade:viewhidden', $coursecontext, $assessor_user->newitemid)) {
                         $mode = 'teacher';
                     } else {
                         $mode = 'peer';
                     }
                     //$courseid_old, $modulename, $task_instanceid_old, $assessment_studentid_old, $assessment_assessorid_old, $mode, $moodlename_old
                     $str = $courseid_old . '_' . $modulename . '_' . $task_instanceid_old . '_' . $assessment_studentid_old . '_' . $assessment_assessorid_old . '_' . $mode . '_' . $moodlename_old;
                     $assessmentid_old = md5($str);
                     $str = $courseid_new . '_' . $modulename . '_' . $newcmid . '_' . $student_user->newitemid . '_' . $assessor_user->newitemid . '_' . $mode . '_' . $moodlename_new;
                     //echo $str . ' -- ';
                     $assessmentid_new = md5($str);
                     $object = new stdClass();
                     $object->oldid = $assessmentid_old;
                     $object->newid = $assessmentid_new;
                     $assessmentids[] = $object;
                 }
             }
         }
     }
     if ($tasksid != '') {
         $tasksid = substr($tasksid, 0, -1);
     }
     if ($settings['users'] == 1) {
         if (isset($xml->evalcomix->grades[0])) {
             foreach ($xml->evalcomix->grades[0] as $grade) {
                 $cm_mapping = $this->get_mapping('course_module', $grade->cmid);
                 $newcmid = $cm_mapping->newitemid;
                 $student = $this->get_mapping('user', (int) $grade->userid);
                 if (!isset($student->newitemid)) {
                     continue;
                 }
                 $params = array('finalgrade' => (double) $grade->finalgrade, 'courseid' => $courseid_new, 'cmid' => $newcmid, 'userid' => $student->newitemid);
                 if (!($grade_object = evalcomix_grades::fetch(array('courseid' => $courseid_new, 'cmid' => $newcmid, 'userid' => $student->newitemid)))) {
                     $grade_object = new evalcomix_grades($params);
                     $newgradeid = $grade_object->insert();
                 }
             }
         }
         if (isset($xml->evalcomix->allowedusers[0])) {
             foreach ($xml->evalcomix->allowedusers[0] as $users) {
                 $cm_mapping = $this->get_mapping('course_module', $users->cmid);
                 $newcmid = $cm_mapping->newitemid;
                 $assessor = $this->get_mapping('user', (int) $users->assessorid);
                 $student = $this->get_mapping('user', (int) $users->studentid);
                 if (!isset($student->newitemid) || !isset($assessor->newitemid)) {
                     continue;
                 }
                 $params = array('assessorid' => (int) $assessor->newitemid, 'studentid' => $student->newitemid, 'cmid' => $newcmid);
                 if (!($allowedusers_object = evalcomix_allowedusers::fetch($params))) {
                     $allowedusers_object = new evalcomix_allowedusers($params);
                     $newid = $allowedusers_object->insert();
                 }
             }
         }
     }
     if (isset($xml->evalcomix->tools[0])) {
         $hashtools = array();
         foreach ($xml->evalcomix->tools[0] as $tool) {
             if ((string) $tool->type == 'tmp') {
                 continue;
             }
             $idtoolold = (string) $tool->idtool;
             $tool_mapping = $this->get_mapping('evalcomix_tool', (string) $tool['id']);
             $toolnew = evalcomix_tool::fetch(array('id' => $tool_mapping->newitemid));
             $idtoolnew = $toolnew->idtool;
             $object = new stdClass();
             $object->oldid = $idtoolold;
             $object->newid = $idtoolnew;
             $hashtools[] = $object;
         }
     }
     if (isset($hashtools) && isset($assessmentids)) {
         $result = webservice_evalcomix_client::duplicate_course($assessmentids, $hashtools);
     }
     //$newtools = webservice_evalcomix_client::get_ws_list_tool($courseid_new, $moodlename_new);
 }