$this->assertNotNull($objectnew);
        unset($objectnew);
    }
    /**
	* Object construction with no required param 'toolid' and 'taskid'. It should throw a 'moodle_exception'???
	*/
    public function test_construction_fail_5()
    {
            $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:
                    }
示例#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;
 }
 /**
  * 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;
     }
 }