Beispiel #1
0
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_grades.php';
        $toolids = array();
        foreach ($tasks as $task) {
            if ($assessments = evalcomix_assessments::fetch_all(array('taskid' => $task->id))) {
                foreach ($assessments as $assessment) {
                    $activity = $task->instanceid;
                    $module = evalcomix_tasks::get_type_task($activity);
                    $mode = grade_report_evalcomix::get_type_evaluation($assessment->studentid, $courseid, $assessment->assessorid);
                    $str = $courseid . '_' . $module . '_' . $activity . '_' . $assessment->studentid . '_' . $assessment->assessorid . '_' . $mode . '_' . MOODLE_NAME;
                    $assessmentid = md5($str);
                    if (isset($newgrades[$assessmentid])) {
                        $grade = $newgrades[$assessmentid]->grade;
                        $toolids[] = $newgrades[$assessmentid]->toolid;
                        $assessment->grade = $grade;
                        $assessment->update();
                        if ($evalcomix_grade = evalcomix_grades::fetch(array('courseid' => $courseid, 'cmid' => $task->instanceid, 'userid' => $assessment->studentid))) {
                            $params = array('cmid' => $task->instanceid, 'userid' => $assessment->studentid, 'courseid' => $courseid);
                            $finalgrade = evalcomix_grades::get_finalgrade_user_task($params);
                            if ($finalgrade !== null) {
                                $evalcomix_grade->finalgrade = $finalgrade;
                                $evalcomix_grade->update();
                            }
                        }
                    }
                }
            }
        }
        webservice_evalcomix_client::set_assessments_modified(array('toolids' => $toolids));
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Beispiel #2
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();
             }
         }
     }
 }
Beispiel #3
0
/**
 * @param int $oldversion
 */
function xmldb_block_evalcomix_upgrade($oldversion = 201111802)
{
    global $DB;
    $dbman = $DB->get_manager();
    $result = true;
    /// Add a new column newcol to the mdl_question_myqtype
    if ($oldversion < 2012013005) {
        // Define table block_evalcomix to be created
        $table = new xmldb_table('block_evalcomix');
        // Adding fields to table block_evalcomix
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('viewmode', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'evx');
        $table->add_field('sendgradebook', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '0');
        // Adding keys to table block_evalcomix
        $table->add_key('id', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_evalcomix
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // evalcomix savepoint reached
        upgrade_block_savepoint(true, 2012013005, 'evalcomix');
    }
    if ($oldversion < 2012013004) {
        // Define table block_evalcomix_tasks to be created
        $table = new xmldb_table('block_evalcomix_tasks');
        // Adding fields to table block_evalcomix_tasks
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, '0');
        $table->add_field('weighing', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        // Adding keys to table block_evalcomix_tasks
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_evalcomix_tasks
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // evalcomix savepoint reached
        upgrade_block_savepoint(true, 2012013004, 'evalcomix');
    }
    if ($oldversion < 2012013004) {
        // Define table block_evalcomix_modes to be created
        $table = new xmldb_table('block_evalcomix_modes');
        // Adding fields to table block_evalcomix_modes
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('taskid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('toolid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('modality', XMLDB_TYPE_CHAR, '7', null, XMLDB_NOTNULL, null, 'teacher');
        $table->add_field('weighing', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        // Adding keys to table block_evalcomix_modes
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_evalcomix_modes
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // evalcomix savepoint reached
        upgrade_block_savepoint(true, 2012013004, 'evalcomix');
    }
    if ($oldversion < 2012013004) {
        // Define table block_evalcomix_modes_time to be created
        $table = new xmldb_table('block_evalcomix_modes_time');
        // Adding fields to table block_evalcomix_modes_time
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('modeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
        $table->add_field('timeavailable', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
        $table->add_field('timedue', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0');
        // Adding keys to table block_evalcomix_modes_time
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_evalcomix_modes_time
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // evalcomix savepoint reached
        upgrade_block_savepoint(true, 2012013004, 'evalcomix');
    }
    //if ($oldversion < 2013110600) {
    if ($oldversion < 2012013004) {
        // Define table block_evalcomix_modes_extra to be created.
        $table = new xmldb_table('block_evalcomix_modes_extra');
        // Adding fields to table block_evalcomix_modes_extra.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('anonymous', XMLDB_TYPE_INTEGER, '1', null, null, null, '0');
        $table->add_field('modeid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
        // Adding keys to table block_evalcomix_modes_extra.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_evalcomix_modes_extra.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Evalcomix savepoint reached.
        //upgrade_block_savepoint(true, 2013110600, 'evalcomix');
        upgrade_block_savepoint(true, 2012013004, 'evalcomix');
    } else {
    }
    //if ($oldversion < 2013090502) {
    if ($oldversion < 2012013004) {
        // Define table block_evalcomix_tools to be created
        $table = new xmldb_table('block_evalcomix_tools');
        // Adding fields to table block_evalcomix_tools
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('evxid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
        $table->add_field('title', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
        $table->add_field('type', XMLDB_TYPE_CHAR, '12', null, XMLDB_NOTNULL, null, 'scale');
        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
        $table->add_field('idtool', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, '0');
        // Adding keys to table block_evalcomix_tools
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_evalcomix_tools
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // evalcomix savepoint reached
        //upgrade_block_savepoint(true, 2013090502, 'evalcomix');
        upgrade_block_savepoint(true, 2012013004, 'evalcomix');
    }
    if ($oldversion < 2013102505) {
        // Define table block_evalcomix_grades to be created.
        $table = new xmldb_table('block_evalcomix_grades');
        // Adding fields to table block_evalcomix_grades.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('cmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('finalgrade', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
        $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        // Adding keys to table block_evalcomix_grades.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_evalcomix_grades.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Evalcomix savepoint reached.
        upgrade_block_savepoint(true, 2013102505, 'evalcomix');
        global $CFG;
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_grades.php';
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_tasks.php';
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_assessments.php';
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_modes_extra.php';
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_modes_time.php';
        if ($tasks = evalcomix_tasks::fetch_all(array())) {
            foreach ($tasks as $task) {
                echo '<br><br><br>Procesando task: ' . $task->id . '<br>';
                echo 'Finalgrades asociados: <br>';
                if ($cm = $DB->get_record('course_modules', array('id' => $task->instanceid))) {
                    $courseid = $cm->course;
                    if ($assessments = evalcomix_assessments::fetch_all(array('taskid' => $task->id))) {
                        foreach ($assessments as $assessment) {
                            $params = array();
                            //cmid -- userid -- courseid
                            $params['cmid'] = $task->instanceid;
                            $params['userid'] = $assessment->studentid;
                            $params['courseid'] = $courseid;
                            $finalgrade = evalcomix_grades::get_finalgrade_user_task($params);
                            echo "finalgrade: {$finalgrade} <br>";
                            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();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($oldversion < 2013111801) {
        // Define table block_evalcomix_allowedusers to be created.
        $table = new xmldb_table('block_evalcomix_allowedusers');
        // Adding fields to table block_evalcomix_allowedusers.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('cmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('assessorid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('studentid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        // Adding keys to table block_evalcomix_allowedusers.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
        // Conditionally launch create table for block_evalcomix_allowedusers.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }
        // Evalcomix savepoint reached.
        upgrade_block_savepoint(true, 2013111801, 'evalcomix');
    }
    if ($oldversion < 2013111801) {
        // Define field whoassesses to be added to block_evalcomix_modes_extra.
        $table = new xmldb_table('block_evalcomix_modes_extra');
        $field1 = new xmldb_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
        if (!$dbman->field_exists($table, $field1)) {
            $dbman->add_field($table, $field1);
        }
        $field2 = new xmldb_field('whoassesses', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'visible');
        // Conditionally launch add field whoassesses.
        if (!$dbman->field_exists($table, $field2)) {
            $dbman->add_field($table, $field2);
        }
        // Evalcomix savepoint reached.
        upgrade_block_savepoint(true, 2013111802, 'evalcomix');
    }
    if ($oldversion < 2013121700) {
        // Define field visible to be added to block_evalcomix_tasks.
        $table = new xmldb_table('block_evalcomix_tasks');
        $field = new xmldb_field('visible', XMLDB_TYPE_INTEGER, '1', null, null, null, '1', 'timemodified');
        // Conditionally launch add field visible.
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        // Evalcomix savepoint reached.
        upgrade_block_savepoint(true, 2013121700, 'evalcomix');
    }
    if ($oldversion < 2014040716) {
        // Define field idtool to be added to block_evalcomix_tools.
        $table = new xmldb_table('block_evalcomix_tools');
        $field = new xmldb_field('idtool', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, '0', 'timemodified');
        // Conditionally launch add field idtool.
        if ($dbman->field_exists($table, $field)) {
            $dbman->change_field_type($table, $field);
        }
        // Evalcomix savepoint reached.
        upgrade_block_savepoint(true, 2014040716, 'evalcomix');
    }
    return $result;
}
Beispiel #4
0
$maxgrade = $task->maxgrade;
$data_activity = $DB->get_record($module->name, array('id' => $cm->instance));
// If a teacher has done click on Delete button
//if($assid && has_capability('block/evalcomix:edit', $context)){
if ($assid && has_capability('moodle/block:edit', $context)) {
    $assessdelete = evalcomix_assessments::fetch(array('id' => $assid));
    if ($assessdelete) {
        $stringmode = 'peer';
        if ($assessdelete->assessorid == $assessdelete->studentid) {
            $stringmode = 'self';
        }
        $response = webservice_evalcomix_client::delete_ws_assessment($course->id, $module->name, $task->instanceid, $user->id, $assessdelete->assessorid, $stringmode, MOODLE_NAME);
        $assessdelete->delete();
        $params = array('cmid' => $task->instanceid, 'userid' => $user->id, 'courseid' => $course->id);
        $finalgrade = evalcomix_grades::get_finalgrade_user_task($params);
        if ($finalgrade !== null) {
            if ($gradeObject = evalcomix_grades::fetch($params)) {
                $gradeObject->finalgrade = $finalgrade;
                $gradeObject->update();
            }
        } else {
            if ($gradeObject = evalcomix_grades::fetch($params)) {
                $gradeObject->delete();
            }
        }
    }
}
if (!($assessments = evalcomix_assessments::fetch_all(array('studentid' => $user->id, 'taskid' => $itemid)))) {
    //	print_error('Wrong parameters');
}
$selfassessment = null;
 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);
 }