예제 #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();
             }
         }
     }
 }
 /**
  * Exists
  */
 public function test_exist_ok()
 {
     $objectnew = new evalcomix_tasks('11', '40', '100.00000', '50');
     $id = $objectnew->exist();
     $this->assertTrue($id);
     unset($objectnew, $id);
 }