/** * Builds and returns the headers of the table * @return string HTML */ public function get_headers() { global $USER, $DB; if (!($course = $DB->get_record('course', array('id' => $this->courseid)))) { print_error('nocourseid'); } $total = ''; //To print Lastname / Firstname $arrows = $this->get_sort_arrows(); $header = '<tr style="border:1px solid #146C84;"> <th colspan="2">' . $arrows['studentname'] . '</th>'; //print_r($this->gtree->levels[1]); $levels = $this->gtree->get_levels(); foreach ($levels as $row) { foreach ($row as $element) { if ($element['object']->hidden == 1 && !$this->canviewhidden) { continue; } if (isset($element['object']->itemnumber) && $element['object']->itemnumber == 0 && $element['object']->itemtype != 'manual') { // Checks if it is an activity if ($element['type'] == 'item') { if ($cm = get_coursemodule_from_instance($element['object']->itemmodule, $element['object']->iteminstance, $this->courseid)) { $cmid = $cm->id; if (!($task = evalcomix_tasks::fetch(array('instanceid' => $cmid)))) { $task = new evalcomix_tasks('', $cmid, 100, 50, time(), '1'); $task->insert(); } elseif ($task->visible == 0) { continue; } $this->activities_configured[$cmid] = $this->configured_activity($cmid); if (!$this->canviewhidden && !$this->activities_configured[$cmid]) { continue; } if (property_exists($cm, 'availability')) { $grey = false; $hide = false; global $USER; $this->modinfo = new course_modinfo($course, $USER->id); $instances = $this->modinfo->get_instances_of($element['object']->itemmodule); if (!empty($instances[$element['object']->iteminstance])) { $cm_info = $instances[$element['object']->iteminstance]; if (!$cm_info->uservisible) { // If there is 'availableinfo' text then it is only greyed // out and not entirely hidden. if (!$cm_info->availableinfo) { $hide = true; } $grey = true; } } } if (!$this->canviewhidden) { if (!empty($hide) || !empty($grey)) { continue; } $gm = true; if (property_exists($cm, 'groupmembersonly') && !$cm->groupmembersonly) { $gm = false; } if ($gm) { $groupingid = $cm->groupingid; $intersect1 = array(); $groups = $this->get_groupids($USER->id); if (isset($this->coursegroupings[$groupingid]) && is_array($groups)) { $grouping_groups = $this->coursegroupings[$groupingid]; $intersect1 = array_intersect($groups, $grouping_groups); } if ($cm->groupingid && empty($intersect1)) { continue; } /*elseif(!$cm->groupingid && $groups == -1){ continue; }*/ } } if ($cm->visible == 0 && !$this->canviewhidden) { //if($cm->visible == 0){ continue; } } $header .= '<th style="width:10em;border:1px solid #146C84;">' . $this->print_header_element($element, true); $header .= '</th>'; } // Checks if it is the total grade of the course if ($element['type'] == 'courseitem') { $total = '<th style="border:1px solid #146C84;"> ' . $this->print_header_element($element, true) . '</th>'; } } } } $header .= $total . '</tr>'; return $header; }
/** * Update more than one param */ public function test_more_than_one_param_update_ok() { $objectnew = new evalcomix_tasks('', '20', '100', 'AAA'); $objectnew->insert(); $params = array('maxgrade' => '80', 'weighing' => '70'); evalcomix_tasks::set_properties($objectnew, $params); $id = $objectnew->update(); $this->assertTrue($id); $objectnew->delete(); unset($objectnew, $id); }
<center> <div>' . get_string('settings_description', 'block_evalcomix') . '</div><br> <table class="gradestable flexible boxaligncenter generaltable"> <tr><th>' . get_string('activities', 'block_evalcomix') . '</th><th>' . get_string('edition', 'block_evalcomix') . '</th></tr> '; $activities = array(); $tasks = array(); foreach ($levels as $row) { foreach ($row as $element) { if (isset($element['object']->itemnumber) && $element['object']->itemnumber == 0 && $element['object']->itemtype != 'manual') { if ($element['type'] == 'item') { if ($cm = get_coursemodule_from_instance($element['object']->itemmodule, $element['object']->iteminstance, $courseid)) { $cmid = $cm->id; if (!($task = evalcomix_tasks::fetch(array('instanceid' => $cmid)))) { $task = new evalcomix_tasks('', $cmid, 100, 50, time(), '1'); $task->insert(); } $taskid = $task->id; $tasks[$taskid] = $task; $name = $element['object']->get_name(); $dots = ''; if (strlen($name) > 50) { $dots = '... '; } $taskname = substr($element['object']->get_name(), 0, 50) . $dots; $activities[$taskid] = $taskname; $icontask[$taskid] = $report_evalcomix->gtree->get_element_icon($element, false); } } } }
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); }