$PAGE->set_title('EvalCOMIX');
echo $OUTPUT->header();
$context = context_course::instance($courseid);
$report_evalcomix = new grade_report_evalcomix($courseid, null, $context);
$users = $report_evalcomix->load_users(false);
$activity = get_activity_data($cm);
echo '<div style="font-weight:bold; font-size:16px">' . $activity->name . '</div>';
echo '<div style="font-weight:bold; font-size:14px;color:#00f">' . fullname($users[$assessorid]) . '</div>';
if (isset($add) && isset($potentialuser) && is_array($potentialuser)) {
    foreach ($potentialuser as $puser) {
        $params = array('cmid' => $cm->id, 'assessorid' => $assessorid, 'studentid' => $puser);
        if (!($alloweduser = evalcomix_allowedusers::fetch($params))) {
            $alloweduser = new evalcomix_allowedusers($params);
            $alloweduser->insert();
        }
    }
}
if (isset($remove) && isset($allowed) && is_array($allowed)) {
    foreach ($allowed as $auser) {
        $params = array('cmid' => $cm->id, 'assessorid' => $assessorid, 'studentid' => $auser);
        if ($alloweduser = evalcomix_allowedusers::fetch($params)) {
            $alloweduser->delete();
        }
    }
}
echo '
	<script type="text/javascript" src="../ajax.js"></script>
	<script type="text/javascript">window.opener.onunload=function(){close();};</script>
	<form id="assignform" method="post" action="assigning_users_form.php?id=' . $courseid . '&a=' . $cm->id . '&assessorid=' . $assessorid . '"><div>
		<input type="hidden" name="sesskey" value="' . sesskey() . '" />
		<div style="text-align:center">
Esempio n. 2
0
 $cm = $DB->get_record('course_modules', array('id' => $cmid));
 $groupmode = $cm->groupmode;
 $groupmembersonly = 0;
 if (isset($cm->groupmembersonly)) {
     $groupmembersonly = $cm->groupmembersonly;
 }
 $groupingid = $cm->groupingid;
 $same_grouping = false;
 $same_group = $report_evalcomix->same_group($assessorid, $userid);
 if ($groupingid != 0) {
     $same_grouping = $report_evalcomix->same_grouping_by_users($assessorid, $userid, $cm);
 }
 $gid_loginuser = $report_evalcomix->get_groupids($assessorid);
 $gid_user = $report_evalcomix->get_groupids($userid);
 $condition = false;
 if ($evalcomixallowedusers = evalcomix_allowedusers::fetch(array('cmid' => $cmid, 'assessorid' => $assessorid, 'studentid' => $userid))) {
     $condition = true;
 }
 //echo $this->activities['name'][$i] . ': ' . $groupmode . ' - gid_loginuser: '******' - gid_user: '******'<br/>';
 //If (there are not Separated groups) OR
 //   (there are Separated groups AND
 //($user is member of the same group that login $USER OR they are in the same grouping in that activity))
 //if(($groupmode != 1) || ($groupmode == 1 &&
 //				($gid_loginuser == $gid_user || $report_evalcomix->same_grouping($gid_loginuser, $gid_user, $cmid)))){
 if (!$groupmembersonly && ($same_grouping && ($groupmode != 1 || $same_group) || !$groupingid && ($groupmode != 1 || $same_group)) || $groupmembersonly && (!$groupingid && ($groupmode != 1 || $same_group) || $same_grouping && ($groupmode != 1 || $same_group)) || $condition == true) {
     $mode_time = $report_evalcomix->get_modestime($task->id, $mode);
     if ($mode_time != false) {
         $now = getdate();
         $now_timestamp = mktime($now["hours"], $now["seconds"], $now["minutes"], $now["mon"], $now["mday"], $now["year"]);
         $available = $mode_time->timeavailable;
         $due = $mode_time->timedue;
 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);
 }