Beispiel #1
0
 /**
  * Processes the data sent by the form (grades and feedbacks).
  * Caller is responsible for all access control checks
  * @param array $data form submission (with magic quotes)
  * @return array empty array if success, array of warnings if something fails.
  */
 public function process_data($data)
 {
     global $CFG, $DB, $COURSE, $USER;
     //ESto es lo que acabo de añadir
     // Para guardar la actividad en la bd de evalcomix
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/webservice_evalcomix_client.php';
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_tasks.php';
     include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_tool.php';
     //para quitar notice
     $save_conf_act = 0;
     if (isset($data['cmid'])) {
         $activity = $data['cmid'];
         $module = evalcomix_tasks::get_type_task($activity);
         $save_conf_act = 1;
     }
     $timeavailableAE = 0;
     $timedueAE = 0;
     $idtoolAE = 0;
     $pon_AE = 0;
     $timeavailableEI = 0;
     $timedueEI = 0;
     $idtoolEI = 0;
     $pon_EI = 0;
     $idtoolEP = 0;
     $pon_EP = 0;
     if (isset($data['toolEP']) && $data['toolEP'] != 0) {
         $toolEP = evalcomix_tool::fetch(array('id' => $data['toolEP']));
         $idtoolEP = $toolEP->idtool;
         $pon_EP = $data['pon_EP'];
     }
     if (isset($data['toolAE']) && $data['toolAE'] != 0) {
         $timeavailableAE = mktime($data['hour_available_AE'], $data['minute_available_AE'], 0, $data['month_available_AE'], $data['day_available_AE'], $data['year_available_AE']);
         $timedueAE = mktime($data['hour_timedue_AE'], $data['minute_timedue_AE'], 0, $data['month_timedue_AE'], $data['day_timedue_AE'], $data['year_timedue_AE']);
         $toolAE = evalcomix_tool::fetch(array('id' => $data['toolAE']));
         $idtoolAE = $toolAE->idtool;
         $pon_AE = $data['pon_AE'];
     }
     if (isset($data['toolEI']) && $data['toolEI'] != 0) {
         $timeavailableEI = mktime($data['hour_available_EI'], $data['minute_available_EI'], 0, $data['month_available_EI'], $data['day_available_EI'], $data['year_available_EI']);
         $timedueEI = mktime($data['hour_timedue_EI'], $data['minute_timedue_EI'], 0, $data['month_timedue_EI'], $data['day_timedue_EI'], $data['year_timedue_EI']);
         $toolEI = evalcomix_tool::fetch(array('id' => $data['toolEI']));
         $idtoolEI = $toolEI->idtool;
         $pon_EI = $data['pon_EI'];
     }
     /*if($save_conf_act == 1){
     			$result = webservice_evalcomix_client::put_ws_savetask($COURSE->id, $module, $activity, $idtoolEP, $idtoolAE, $idtoolEI, $pon_EP, $pon_AE, $pon_EI, $timeavailableAE, $timedueAE, $timeavailableEI, $timedueEI, MOODLE_NAME);				
     		}*/
     //Hasta aquí---------------------
     if (isset($data['save']) && $data['save'] == get_string('save', 'block_evalcomix')) {
         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';
         $data_exists = false;
         $task_exists = false;
         $modality_delete = false;
         $taskid = null;
         if (isset($data['toolEP']) && $data['toolEP'] != '0' || isset($data['toolAE']) && $data['toolAE'] != '0' || isset($data['toolEI']) && $data['toolEI'] != '0') {
             $data_exists = true;
         }
         $task = new evalcomix_tasks('', $data['cmid'], $data['maxgrade'], '50', time());
         if ($taskid = $task->exist()) {
             $task_exists = true;
             $params = array('id' => $taskid);
             evalcomix_tasks::set_properties($task, $params);
             $task->update();
         } elseif ($data_exists == true) {
             $taskid = $task->insert();
         }
         if ($data['toolEP'] != 0) {
             $modeEP = new evalcomix_modes('', $taskid, $data['toolEP'], 'teacher', $data['pon_EP']);
             if ($modeid = $modeEP->exist()) {
                 $params = array('id' => $modeid);
                 evalcomix_modes::set_properties($modeEP, $params);
                 $modeEP->update();
             } else {
                 $modeid = $modeEP->insert();
             }
         } elseif ($task_exists == true) {
             $modeEP = new evalcomix_modes('', $taskid, '', 'teacher');
             if ($modeid = $modeEP->exist()) {
                 $modeEP->delete();
                 $modality_delete = true;
             }
         }
         if ($data['toolAE'] != 0) {
             $modeAE = new evalcomix_modes('', $taskid, $data['toolAE'], 'self', $data['pon_AE']);
             if ($modeid = $modeAE->exist()) {
                 $params = array('id' => $modeid);
                 evalcomix_modes::set_properties($modeAE, $params);
                 $modeAE->update();
                 $timeavailable = mktime($data['hour_available_AE'], $data['minute_available_AE'], 0, $data['month_available_AE'], $data['day_available_AE'], $data['year_available_AE']);
                 $timedue = mktime($data['hour_timedue_AE'], $data['minute_timedue_AE'], 0, $data['month_timedue_AE'], $data['day_timedue_AE'], $data['year_timedue_AE']);
                 $modeAE_time = new evalcomix_modes_time('', $modeid, $timeavailable, $timedue);
                 if ($modeAE_timeid = $modeAE_time->exist()) {
                     $params = array('id' => $modeAE_timeid);
                     evalcomix_modes::set_properties($modeAE_time, $params);
                     $modeAE_time->update();
                 }
             } else {
                 $modeid = $modeAE->insert();
                 $timeavailable = mktime($data['hour_available_AE'], $data['minute_available_AE'], 0, $data['month_available_AE'], $data['day_available_AE'], $data['year_available_AE']);
                 $timedue = mktime($data['hour_timedue_AE'], $data['minute_timedue_AE'], 0, $data['month_timedue_AE'], $data['day_timedue_AE'], $data['year_timedue_AE']);
                 $modeAE_time = new evalcomix_modes_time('', $modeid, $timeavailable, $timedue);
                 $modeAE_time->insert();
             }
         } elseif ($task_exists == true) {
             $modeAE = new evalcomix_modes('', $taskid, '', 'self');
             if ($modeid = $modeAE->exist()) {
                 $modeAE_time = new evalcomix_modes_time('', $modeid);
                 if ($modeAE_time->exist()) {
                     $modeAE_time->delete();
                 }
                 $modeAE->delete();
                 $modality_delete = true;
             }
         }
         if ($data['toolEI'] != 0) {
             $anonymous = 0;
             if (isset($data['anonymousEI']) && $data['anonymousEI'] == 'on') {
                 $anonymous = 1;
             }
             $alwaysvisible = 0;
             if (isset($data['alwaysvisibleEI']) && $data['alwaysvisibleEI']) {
                 $alwaysvisible = 1;
             }
             $whoassesses = 0;
             if (isset($data['whoassessesEI']) && $data['whoassessesEI']) {
                 $whoassesses = $data['whoassessesEI'];
             }
             $modeEI = new evalcomix_modes('', $taskid, $data['toolEI'], 'peer', $data['pon_EI']);
             if ($modeid = $modeEI->exist()) {
                 $params = array('id' => $modeid);
                 evalcomix_modes::set_properties($modeEI, $params);
                 $modeEI->update();
                 $timeavailable = mktime($data['hour_available_EI'], $data['minute_available_EI'], 0, $data['month_available_EI'], $data['day_available_EI'], $data['year_available_EI']);
                 $timedue = mktime($data['hour_timedue_EI'], $data['minute_timedue_EI'], 0, $data['month_timedue_EI'], $data['day_timedue_EI'], $data['year_timedue_EI']);
                 $modeEI_time = new evalcomix_modes_time('', $modeid, $timeavailable, $timedue);
                 if ($modeEI_timeid = $modeEI_time->exist()) {
                     $params = array('id' => $modeEI_timeid);
                     evalcomix_modes_time::set_properties($modeEI_time, $params);
                     $modeEI_time->update();
                 }
                 $modeEI_extra = new evalcomix_modes_extra('', $modeid, $anonymous, $alwaysvisible, $whoassesses);
                 $modeEI_extraObject = $DB->get_record('block_evalcomix_modes_extra', array('modeid' => $modeid));
                 $modeEI_extraid = $modeEI_extraObject->id;
                 $params = array('id' => $modeEI_extraid, 'anonymous' => $anonymous, 'visible' => $alwaysvisible, 'whoassesses' => $whoassesses);
                 evalcomix_modes_extra::set_properties($modeEI_extra, $params);
                 $modeEI_extra->update();
             } else {
                 $modeid = $modeEI->insert();
                 $timeavailable = mktime($data['hour_available_EI'], $data['minute_available_EI'], 0, $data['month_available_EI'], $data['day_available_EI'], $data['year_available_EI']);
                 $timedue = mktime($data['hour_timedue_EI'], $data['minute_timedue_EI'], 0, $data['month_timedue_EI'], $data['day_timedue_EI'], $data['year_timedue_EI']);
                 $modeEI_time = new evalcomix_modes_time('', $modeid, $timeavailable, $timedue);
                 $modeEI_time->insert();
                 $modeEI_extra = new evalcomix_modes_extra('', $modeid, $anonymous, $alwaysvisible, $whoassesses);
                 $modeEI_extra->insert();
             }
         } elseif ($task_exists == true) {
             $modeEI = new evalcomix_modes('', $taskid, '', 'peer');
             if ($modeid = $modeEI->exist()) {
                 $modeEI_extra = new evalcomix_modes_extra('', $modeid);
                 if ($modeEI_extra->exist()) {
                     $modeEI_extra->delete();
                 }
                 $modeEI_time = new evalcomix_modes_time('', $modeid);
                 if ($modeEI_time->exist()) {
                     $modeEI_time->delete();
                 }
                 $modeEI->delete();
                 $modality_delete = true;
             }
         }
         if ($task_exists == true && $data_exists == true) {
             include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_grades.php';
             if ($grades = evalcomix_grades::fetch_all(array('courseid' => $this->courseid, 'cmid' => $task->instanceid))) {
                 foreach ($grades as $grade) {
                     $user = $grade->userid;
                     $params = array('cmid' => $task->instanceid, 'userid' => $user, 'courseid' => $this->courseid);
                     $finalgrade = evalcomix_grades::get_finalgrade_user_task($params);
                     if ($finalgrade !== null) {
                         $grade->finalgrade = $finalgrade;
                         $grade->update();
                     }
                 }
             }
         }
         /*elseif($data_exists != true){
         			include_once($CFG->dirroot .'/blocks/evalcomix/classes/evalcomix_grades.php');
         		
         			if($grades = evalcomix_grades::fetch_all(array('courseid' => $this->courseid, 'cmid' => $task->instanceid))){
         				foreach($grades as $grade){
         					$grade->finalgrade = -3;
         					$grade->update();						
         				}
         			}
         		}*/
         //Recalculamos en cualquier caso las notas
         include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_grades.php';
         if ($grades = evalcomix_grades::fetch_all(array('courseid' => $this->courseid, 'cmid' => $task->instanceid))) {
             foreach ($grades as $grade) {
                 $user = $grade->userid;
                 $params = array('cmid' => $task->instanceid, 'userid' => $user, 'courseid' => $this->courseid);
                 $finalgrade = evalcomix_grades::get_finalgrade_user_task($params);
                 if ($finalgrade !== null) {
                     $grade->finalgrade = $finalgrade;
                     $grade->update();
                 }
             }
         }
     } elseif (isset($data['cancel']) && $data['cancel'] == 'cancel') {
     }
     // Comprobar si hay datos de alguna evaluación realizada con evalcomix para guardarla en la base de datos de Moodle
     // Se hace aquí ya que ese método se procesa cada vez que se recarga la página
     if (isset($data['stu']) && $data['stu'] != 0 && $data['cma'] != 0) {
         $activity = $data['cma'];
         $module = evalcomix_tasks::get_type_task($activity);
         //$mode = $this->get_type_evaluation($data['stu']);
         $mode = grade_report_evalcomix::get_type_evaluation($data['stu'], $this->courseid);
         /*echo $COURSE->id . '<br>';
         		echo $module . '<br>';
         		echo $activity . '<br>';
         		echo $data['stu'] . '<br>';
         		echo $USER->id . '<br>';
         		echo $mode . '<br>';
         		echo MOODLE_NAME . '<br>';*/
         $task = new evalcomix_tasks('', $data['cma']);
         if ($taskid = $task->exist()) {
             $tool = get_evalcomix_modality_tool($this->courseid, $taskid, $mode);
             $evalcomix_assessment = webservice_evalcomix_client::get_ws_singlegrade($tool->idtool, $this->courseid, $module, $activity, $data['stu'], $USER->id, $mode, MOODLE_NAME);
         }
         //if $evalcomix_assessment->grade == -1  means that the grade is empty
         if ($evalcomix_assessment != null) {
             //Checks if the assessment exists in the table mdl_blocks_evalcomix_assessments
             $params = array('taskid' => $evalcomix_assessment->taskid, 'assessorid' => $evalcomix_assessment->assessorid, 'studentid' => $evalcomix_assessment->studentid);
             $evx_assessment_object = evalcomix_assessments::fetch($params);
             //print_r($evx_assessment_object);
             //echo $evalcomix_assessment->grade;
             //					if ($evx_assessment_object != null) {
             if ($evx_assessment_object != false) {
                 if ($evalcomix_assessment->grade != -1) {
                     //If the grade is not null
                     $evx_assessment_object->grade = $evalcomix_assessment->grade;
                     $evx_assessment_object->update();
                 } else {
                     //If the grade is null
                     $evx_assessment_object->delete();
                 }
             } elseif ($evalcomix_assessment->grade != -1) {
                 //if it does not exist and the grade is not null inserts it
                 $evalcomix_assessment->insert();
             }
         }
         //Save the finalgrade
         include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_grades.php';
         $params = array('cmid' => $data['cma'], 'userid' => $data['stu'], 'courseid' => $this->courseid);
         $finalgrade = evalcomix_grades::get_finalgrade_user_task($params);
         if ($finalgrade !== null) {
             if ($gradeObject = evalcomix_grades::fetch($params)) {
                 $gradeObject->finalgrade = $finalgrade;
                 $gradeObject->update();
             } else {
                 $params['finalgrade'] = $finalgrade;
                 $gradeObject = new evalcomix_grades($params);
                 $gradeObject->insert();
             }
         } else {
             if ($gradeObject = evalcomix_grades::fetch($params)) {
                 $gradeObject->delete();
             }
         }
     }
 }
 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);
 }