include_once $CFG->dirroot . '/blocks/evalcomix/configeval.php';
include_once $CFG->dirroot . '/lib/filelib.php';
/**
	API for EvalCOMIX webservices
*/
class webservice_evalcomix_client
{
    /**
	* @param string $lms name of instance of Moodle
	* @param $courseid
	* @param $language as 'es_es_utf8'
	* @param $extra parameters to add to URI
	* @return int new ID Tool
	*/
    public static function get_ws_createtool($id = null, $lms = 'Moodle24', $courseid, $language = 'es_es_utf8', $type = 'new')
    {
        defined('EVALCOMIX3') || print_error('EvalCOMIX is not configured');
        global $CFG;
        $serverurl_aux = EVALCOMIX3;
        if (!$id && $type == 'new') {
            //$id = 240912 * (time() + time());
            $id = webservice_evalcomix_client::generate_token();
        }
        $get = 'identifier=' . $id . '&lang=' . $language . '&type=' . $type;
        $serverurl = $serverurl_aux . '?' . $get;
        if (webservice_evalcomix_client::check_url($serverurl)) {
            include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_tool.php';
            include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix.php';
            $environment = evalcomix::fetch(array('courseid' => $courseid));
 /**
  * Existing object insert in a DB 
  */
 public function test_insert_fail_2()
 {
     $objectnew = new evalcomix_tool('120', '1', 'titulo de la escala2', 'scale');
     $id = $objectnew->insert();
     $this->assertFalse($id);
     unset($objectnew);
 }
    /**
	* Non-existing object insert in a DB 
	*/
    public function testInsertOk()
    {
        $objectnew = new evalcomix_tool('', '1', 'titulo de la escala2', 'scale');
        $id = $objectnew->insert();
        $this->AssertEquals($id, $objectnew->id);
    /**
	* Update object in the DB
	*/
    public function testUpdateOK()
    {
        $objectnew = new evalcomix_tool('', '1', 'titulo de la escala2', 'list');
        $id = $objectnew->insert();
        $id = $objectnew->update();
        $this->assertTrue($id);
<?php

include_once '../../../config.php';
include_once '../classes/evalcomix_tool.php';
$params = array('title' => 'hola');
$object = new evalcomix_tool('27', '1', 'titulo de la escala2', 'scale');
$id = $object->insert();
echo $id;
/*
	evalcomix_tool::set_properties($object, $params);
	print_r($object);
	if($object->update())
		echo "actualizado";
	else
		echo "no actualizado";
	*/
/*
	//$result = evalcomix_tool::fetch_all($params);
	//print_r($result);
	*/
if ($object->delete()) {
    echo "borrado";
} else {
    echo "no borrado";
}
Exemplo n.º 6
0
/**
 * Update database tools with Web Services tools
 * @param int $evxid primary key of evalcomix table
 * @param mixed $webtools tools of Web Service
 */
function update_tool_list($evxid, $webtools)
{
    global $CFG;
    include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_tool.php';
    foreach ($webtools as $tool) {
        if (!($toolupdate = evalcomix_tool::fetch(array('evxid' => $evxid, 'idtool' => $tool->idtool)))) {
            $newtool = new evalcomix_tool('', $evxid, $tool->title, $tool->type, (string) $tool->idtool);
            $newtool->insert();
        } else {
            evalcomix_tool::set_properties($toolupdate, array('title' => $tool->title));
            $toolupdate->update();
        }
    }
    //Si hay instrumentos duplicados de una restauración de eliminan y se configuran las actividades correctamente
    if ($oldtools_restored = evalcomix_tool::fetch_all(array('evxid' => $evxid, 'timemodified' => '-1'))) {
        global $COURSE, $DB;
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_tasks.php';
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_modes.php';
        $activities = $DB->get_records('course_modules', array('course' => $COURSE->id));
        //Bucle recorriendo las actividades del curso y llamando a webservice_evalcomix_client::get_instrument($courseid, $module, $activity, $lms)
        //De ahí sacar el idtool de evalcomix y actualizar la tabla modes en moodle
        foreach ($activities as $activity) {
            if ($task = evalcomix_tasks::fetch(array('instanceid' => $activity->id))) {
                $module = evalcomix_tasks::get_type_task($task->instanceid);
                $xml = webservice_evalcomix_client::get_instrument($COURSE->id, $module, $task->instanceid, MOODLE_NAME);
                //echo $COURSE->id . ' - ' .$module . ' - ' . $task->instanceid . ' - ' . MOODLE_NAME . '<br>';//
                //print_r($xml->evaluacion);
                //echo '<br>';
                if (isset($xml->evaluacion->teacher) && $xml->evaluacion->teacher != null) {
                    $tool = evalcomix_tool::fetch(array('evxid' => $evxid, 'idtool' => $xml->evaluacion->teacher));
                    $modes = evalcomix_modes::fetch(array('taskid' => $task->id, 'modality' => 'teacher'));
                    //Actualizamos el toolid de modes al toolid correcto
                    evalcomix_modes::set_properties($modes, array('toolid' => $tool->id));
                    $modes->update();
                }
                if (isset($xml->evaluacion->self) && $xml->evaluacion->self != null) {
                    $tool = evalcomix_tool::fetch(array('evxid' => $evxid, 'idtool' => $xml->evaluacion->self));
                    $modes = evalcomix_modes::fetch(array('taskid' => $task->id, 'modality' => 'self'));
                    //Actualizamos el toolid de modes al toolid correcto
                    evalcomix_modes::set_properties($modes, array('toolid' => $tool->id));
                    $modes->update();
                }
                if (isset($xml->evaluacion->peer) && $xml->evaluacion->peer != null) {
                    $tool = evalcomix_tool::fetch(array('evxid' => $evxid, 'idtool' => $xml->evaluacion->peer));
                    $modes = evalcomix_modes::fetch(array('taskid' => $task->id, 'modality' => 'peer'));
                    //Actualizamos el toolid de modes al toolid correcto
                    evalcomix_modes::set_properties($modes, array('toolid' => $tool->id));
                    $modes->update();
                }
            }
        }
        //Delete old restored tools
        foreach ($oldtools_restored as $tool) {
            $tool->delete();
        }
        //$DB->get_record('block_evalcomix_tasks', array('instanceid' => $activity->id))
        /*print_r($old_new_instruments);
        		print_r($oldtools_restored);*/
        //$xml_olds = array();
        /*foreach($oldtools_restored as $tool){				
        			//Almacenamos los instrumentos antiguos antes de eliminarlos
        			//$xml_olds[] = webservice_evalcomix_client::get_ws_tool_assessed('', '', '', '', '', '', '', (string)$tool->idtool);
        			//$tool->delete(); DESCOMENTAR
        		}*/
        /*$newtools =  evalcomix_tool::fetch_all(array('evxid' => $evxid));
        		evalcomix_modes::fetch_all(array('toolid' => ));
        		foreach($xml_olds as $xml_old_tool){
        			foreach($newtools as $newtool){
        				$new_xml = webservice_evalcomix_client::get_ws_tool_assessed('', '', '', '', '', '', '', $newtool->idtool);
        				if ($xml_old_tool === $new_xml){
        					
        					//$mode = evalcomix_modes::fetch(array('taskid' => $xml_old_tool->taskid, 'toolid' => $xml_old_tool->idtool));
        					
        				}
        			}			
        		}*/
    }
}
        $objectnew = new evalcomix_tool();
        $this->assertTrue(method_exists($objectnew, 'fetch'));
        $grades = evalcomix::fetch(array('id' => $this->evalcomix_tools[0]->id));
        $this->assertEqual($this->evalcomix[0]->id, $objectnew->id);
    }
    /**
	* Non-existing object insert in a DB 
	*/