$this->taskid = 0;
        }
        //Por si queremos crear una instancia vacía (para usar evalcomix_object::fetch_all_helper es necesario)
        if (is_numeric($assessorid) && !is_float($assessorid) && $assessorid > '0') {
            //if($assessorid != '0'){
            $assessor = $DB->get_record('user', array('id' => $assessorid), '*', MUST_EXIST);
            $this->assessorid = $assessor->id;
        } else {
            $this->assessorid = 0;
        }
        //Por si queremos crear una instancia vacía (para usar evalcomix_object::fetch_all_helper es necesario)
        if (is_numeric($studentid) && !is_float($studentid) && $studentid > '0') {
            //if($studentid != '0'){
            $student = $DB->get_record('user', array('id' => $studentid), '*', MUST_EXIST);
            $this->studentid = $student->id;
        } else {
            $this->studentid = 0;
        }
    }
    /**
     * Updates this object in the Database, based on its object variables. ID must be set.
     * @param string $source from where was the object updated (mod/forum, manual, etc.)
     * @return boolean success
     */
    public function update()
    {
        global $DB;
        if (empty($this->id)) {
            debugging('Can not update assessment object, no id!');
            return false;
        }
        $this->timemodified = time();
        $data = $this->get_record_data();
        $DB->update_record($this->table, $data);
        $this->notify_changed(false);
        return true;
    }
    /**
     * Updates this object in the Database, based on its object variables. ID must be set.
     * @param string $source from where was the object updated (mod/forum, manual, etc.)
     * @return boolean success
     */
    /*public function delete(){
		global $DB;
        if (empty($this->id)) {
            debugging('Can not delete assessment object, no id!');
            return false;
        }
				
        //$data = $this->get_record_data();
		
        $DB->delete_records($this->table, array('id' => $this->id));
        $this->notify_changed(false);
        return true;
	}*/
    /**
     * Calculate evalcomix final grade.
     * @static abstract
     * @param array $users
	 * @param int $courseid
     * @return array $finalgrades with two dimensions [$taskinstance][$userid] that contains the finalgrades.
     */
    public static function get_final_grade($courseid, $users)
    {
        global $CFG, $COURSE;
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_tasks.php';
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix.php';
        //$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
        $coursecontext = context_course::instance($courseid);
        $finalgrades = array();
        $tasks = evalcomix_tasks::get_tasks_by_courseid($courseid);
        $now = time();
        foreach ($tasks as $task) {
            $teacherweight = 0;
            $selfweight = 0;
            $peerweight = 0;
            $params = array('taskid' => $task->id);
            $modes = evalcomix_modes::fetch_all($params);
            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:
                    }
예제 #2
0
 /**
  * Return a modes_time object
  * @param $taskid
  * @param $modality
  * @return object evalcomix_modes_time
  */
 public function get_modestime($taskid, $modality)
 {
     if ($mode = evalcomix_modes::fetch(array('taskid' => $taskid, 'modality' => $modality))) {
         if ($mode_time = evalcomix_modes_time::fetch(array('modeid' => $mode->id))) {
             return $mode_time;
         }
     }
     return false;
 }
 /**
  * Exists
  */
 public function test_exist_ok()
 {
     $objectnew = new evalcomix_modes_time('1', '2', '1327755000', '1329569400');
     $id = $objectnew->exist();
     $this->assertTrue($id);
     unset($objectnew, $id);
 }
예제 #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;
     }
 }
예제 #5
0
if ($popup) {
    $PAGE->set_pagelayout('popup');
}
$PAGE->set_title(get_string('ratingsforitem', 'block_evalcomix'));
echo $OUTPUT->header();
include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_assessments.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/webservice_evalcomix_client.php';
include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_grades.php';
include_once $CFG->dirroot . '/blocks/evalcomix/javascript/popup.php';
global $DB, $USER;
//GETTING DATAS----------------------------------------------------------------------------------------
require_capability('block/evalcomix:view', $context, $userid);
$user = $DB->get_record('user', array('id' => $userid), '*');
if (!($task = evalcomix_tasks::fetch(array('id' => $itemid)))) {
    print_error('Wrong parameters');
}
if ($modeEI = evalcomix_modes::fetch(array('taskid' => $task->id, 'modality' => 'peer'))) {
    $modeEItime = evalcomix_modes_time::fetch(array('modeid' => $modeEI->id));
    $modesExtra = evalcomix_modes_extra::fetch(array('modeid' => $modeEI->id));
} else {
    $modeEItime = '';
}
$cm = $DB->get_record('course_modules', array('id' => $task->instanceid), '*');
$module = $DB->get_record('modules', array('id' => $cm->module), '*');
$maxgrade = $task->maxgrade;
$data_activity = $DB->get_record($module->name, array('id' => $cm->instance));
// If a teacher has done click on Delete button
 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);
 }