Webservice update data created
This commit is contained in:
parent
da14cf4623
commit
ae94d42fdf
9 changed files with 990 additions and 624 deletions
453
externallib.php
453
externallib.php
|
|
@ -21,138 +21,201 @@
|
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
require_once($CFG->libdir . "/externallib.php");
|
||||
require_once("classes/import.php");
|
||||
|
||||
class mod_timetable_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function search_parameters() {
|
||||
return new external_function_parameters(
|
||||
array('searchstring' => new external_value(PARAM_TEXT, 'The searchstring.', VALUE_DEFAULT, ''))
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function search_parameters() {
|
||||
return new external_function_parameters(
|
||||
array('searchstring' => new external_value(PARAM_TEXT, 'The searchstring.', VALUE_DEFAULT, ''))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns welcome message
|
||||
* @return search result message
|
||||
*/
|
||||
public static function search($searchstring = 'Hello world, ') {
|
||||
global $USER,$DB;
|
||||
/**
|
||||
* Returns welcome message
|
||||
* @return search result message
|
||||
*/
|
||||
public static function search($searchstring = 'Hello world, ') {
|
||||
global $USER,$DB;
|
||||
|
||||
//Parameter validation
|
||||
//REQUIRED
|
||||
$params = self::validate_parameters(self::search_parameters(),
|
||||
array('searchstring' => $searchstring));
|
||||
//Parameter validation
|
||||
//REQUIRED
|
||||
$params = self::validate_parameters(self::search_parameters(),
|
||||
array('searchstring' => $searchstring));
|
||||
|
||||
//Context validation
|
||||
//OPTIONAL but in most web service it should present
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
self::validate_context($context);
|
||||
//Context validation
|
||||
//OPTIONAL but in most web service it should present
|
||||
//$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
self::validate_context($context);
|
||||
|
||||
//Capability checking
|
||||
//OPTIONAL but in most web service it should present
|
||||
if (!has_capability('mod/timetable:search', $context)) {
|
||||
throw new moodle_exception('cannotperformsearch');
|
||||
}
|
||||
|
||||
|
||||
$results = array();
|
||||
//return $params['searchstring'] . $USER->firstname ;
|
||||
$classes = $DB->get_records_select('timetable_class', 'class like ? OR description like ? LIMIT 10', array ('%'.$params['searchstring'].'%', '%'.$params['searchstring'].'%'));
|
||||
foreach($classes as $class) {
|
||||
$result = array(
|
||||
'type' => 'class',
|
||||
'name' => $class->class,
|
||||
'description' => "Klassenplan: $class->description ($class->class)"
|
||||
);
|
||||
$results[] = $result;
|
||||
}
|
||||
$teachers = $DB->get_records_select('timetable_teacher', 'teacher like ? OR surname like ? LIMIT 10', array ('%'.$params['searchstring'].'%', '%'.$params['searchstring'].'%'));
|
||||
foreach($teachers as $teacher) {
|
||||
$result = array(
|
||||
'type' => 'teacher',
|
||||
'name' => $teacher->teacher,
|
||||
'description' => "Lehrerplan: $teacher->surname, $teacher->firstname ($teacher->teacher)"
|
||||
);
|
||||
$results[] = $result;
|
||||
}
|
||||
$rooms = $DB->get_records_select('timetable_room', 'description like ? limit 10', array ('%'.$params['searchstring'].'%'));
|
||||
foreach($rooms as $room) {
|
||||
$result = array(
|
||||
'type' => 'room',
|
||||
'name' => $room->room,
|
||||
'description' => "Raumplan: ".$room->description
|
||||
);
|
||||
$results[] = $result;
|
||||
}
|
||||
//echo var_dump($results);
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function search_returns() {
|
||||
//return new external_value(PARAM_TEXT, 'The search result');
|
||||
return new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'type' => new external_value(PARAM_TEXT, 'type of timetable: class, teacher, room'),
|
||||
'name' => new external_value(PARAM_TEXT, 'value of type'),
|
||||
'description' => new external_value(PARAM_TEXT, 'description')
|
||||
)
|
||||
)
|
||||
);
|
||||
//Capability checking
|
||||
//OPTIONAL but in most web service it should present
|
||||
if (!has_capability('mod/timetable:search', $context)) {
|
||||
throw new moodle_exception('cannotperformsearch');
|
||||
}
|
||||
|
||||
|
||||
$results = array();
|
||||
$classes = $DB->get_records_select('timetable_class', 'class like ? OR description like ? LIMIT 10', array ('%'.$params['searchstring'].'%', '%'.$params['searchstring'].'%'));
|
||||
foreach($classes as $class) {
|
||||
$result = array(
|
||||
'type' => 'class',
|
||||
'name' => $class->class,
|
||||
'description' => "Klassenplan: $class->description ($class->class)"
|
||||
);
|
||||
$results[] = $result;
|
||||
}
|
||||
$teachers = $DB->get_records_select('timetable_teacher', 'teacher like ? OR surname like ? LIMIT 10', array ('%'.$params['searchstring'].'%', '%'.$params['searchstring'].'%'));
|
||||
foreach($teachers as $teacher) {
|
||||
$result = array(
|
||||
'type' => 'teacher',
|
||||
'name' => $teacher->teacher,
|
||||
'description' => "Lehrerplan: $teacher->surname, $teacher->firstname ($teacher->teacher)"
|
||||
);
|
||||
$results[] = $result;
|
||||
}
|
||||
$rooms = $DB->get_records_select('timetable_room', 'description like ? limit 10', array ('%'.$params['searchstring'].'%'));
|
||||
foreach($rooms as $room) {
|
||||
$result = array(
|
||||
'type' => 'room',
|
||||
'name' => $room->room,
|
||||
'description' => "Raumplan: ".$room->description
|
||||
);
|
||||
$results[] = $result;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_parameters() {
|
||||
return new external_function_parameters(
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function search_returns() {
|
||||
//return new external_value(PARAM_TEXT, 'The search result');
|
||||
return new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'type' => new external_value(PARAM_TEXT, 'type of timetable: class, teacher, room'),
|
||||
'name' => new external_value(PARAM_TEXT, 'value of type'),
|
||||
'description' => new external_value(PARAM_TEXT, 'description')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function update_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'files' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'type' => new external_value(PARAM_TEXT, 'The type of timetable: class, teacher, room'),
|
||||
'name' => new external_value(PARAM_TEXT, 'value of type'),
|
||||
'week' => new external_value(PARAM_INT, 'The week of timetable')
|
||||
'name' => new external_value(PARAM_TEXT, 'name of file'),
|
||||
'content' => new external_value(PARAM_RAW, 'content of file')
|
||||
)
|
||||
);
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function update_returns() {
|
||||
return new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'name' => new external_value(PARAM_TEXT, 'name of file'),
|
||||
'result' => new external_value(PARAM_RAW, 'result message')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function update($files) {
|
||||
global $USER;
|
||||
//Context validation
|
||||
//OPTIONAL but in most web service it should present
|
||||
$context = context_user::instance($USER->id);
|
||||
self::validate_context($context);
|
||||
|
||||
//$contextmodule = context_module::instance($cm->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
|
||||
//Capability checking
|
||||
//OPTIONAL but in most web service it should present
|
||||
if (!has_capability('mod/timetable:update', $usercontext)) {
|
||||
throw new \moodle_exception('cannotupdatetimetable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns welcome message
|
||||
* @return get result message
|
||||
*/
|
||||
public static function get($type,$name,$week) {
|
||||
global $USER,$DB;
|
||||
$import_data = new \mod_timetable\import_data();
|
||||
return $import_data->update($files);
|
||||
}
|
||||
|
||||
//Parameter validation
|
||||
//REQUIRED
|
||||
|
||||
//echo "Hallo\n";
|
||||
$params = self::validate_parameters(self::get_parameters(),
|
||||
array('type' => $type, 'name'=> $name, 'week' => $week));
|
||||
|
||||
//Context validation
|
||||
//OPTIONAL but in most web service it should present
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
self::validate_context($context);
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'type' => new external_value(PARAM_TEXT, 'The type of timetable: class, teacher, room'),
|
||||
'name' => new external_value(PARAM_TEXT, 'value of type'),
|
||||
'week' => new external_value(PARAM_INT, 'The week of timetable')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
//$contextmodule = context_module::instance($cm->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
/**
|
||||
* Returns welcome message
|
||||
* @return get result message
|
||||
*/
|
||||
public static function get($type,$name,$week) {
|
||||
global $USER,$DB;
|
||||
|
||||
//Capability checking
|
||||
//OPTIONAL but in most web service it should present
|
||||
if (!has_capability('mod/timetable:view'.$params['type'], $usercontext)) {
|
||||
//if (!(($params['type'] == 'class') && has_capability('mod/timetable:viewownclass', $usercontext) && ($params['name'] == str_replace('_','/',$USER->department))))
|
||||
if (!(($params['type'] == 'class') && ($params['name'] == str_replace('_','/',$USER->department))))
|
||||
throw new \moodle_exception('cannotviewtimetable'.$params['type']);
|
||||
}
|
||||
//Parameter validation
|
||||
//REQUIRED
|
||||
$params = self::validate_parameters(self::get_parameters(),
|
||||
array('type' => $type, 'name'=> $name, 'week' => $week));
|
||||
|
||||
//Context validation
|
||||
//OPTIONAL but in most web service it should present
|
||||
//$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
self::validate_context($context);
|
||||
|
||||
//$contextmodule = context_module::instance($cm->id);
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
|
||||
//Capability checking
|
||||
//OPTIONAL but in most web service it should present
|
||||
if (!has_capability('mod/timetable:view'.$params['type'], $usercontext)) {
|
||||
//if (!(($params['type'] == 'class') && has_capability('mod/timetable:viewownclass', $usercontext) && ($params['name'] == str_replace('_','/',$USER->department))))
|
||||
if (!(($params['type'] == 'class') && ($params['name'] == str_replace('_','/',$USER->department))))
|
||||
throw new \moodle_exception('cannotviewtimetable'.$params['type']);
|
||||
}
|
||||
|
||||
/*
|
||||
if ($USER->department == "Lehrer" || $USER->department == "Lehrer_fvs") {
|
||||
|
|
@ -162,99 +225,99 @@ class mod_timetable_external extends external_api {
|
|||
} else {
|
||||
throw new \moodle_exeption('Forbidden');
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
//echo "Type: ".$params['type']."\n";
|
||||
//echo "Name: ".$params['name']."\n";
|
||||
//echo "Week: ".$params['week']."\n";
|
||||
if(!($params['week'])) {
|
||||
$today = new \DateTime();
|
||||
$params['week'] = $today->format("W");
|
||||
$dayofweek = $today->format('w');
|
||||
if (($dayofweek > 5 + get_config('timetable', 'saturday')) || ($dayofweek == 0)) {
|
||||
$params['week']++;
|
||||
}
|
||||
}
|
||||
|
||||
$ttable = new \mod_timetable\timetable($params['type'],$params['name']);
|
||||
$ttable->read_db($params['week']);
|
||||
//echo var_dump($ttable->prepare_output());
|
||||
return $ttable->prepare_output();
|
||||
//$renderable = new \mod_timetable\output\timetable($ttable);
|
||||
//return $renderable->export_for_template(new \mod_timetable\output\renderer($USER,array()));
|
||||
//echo "Type: ".$params['type']."\n";
|
||||
//echo "Name: ".$params['name']."\n";
|
||||
//echo "Week: ".$params['week']."\n";
|
||||
if(!($params['week'])) {
|
||||
$today = new \DateTime();
|
||||
$params['week'] = $today->format("W");
|
||||
$dayofweek = $today->format('w');
|
||||
if (($dayofweek > 5 + get_config('timetable', 'saturday')) || ($dayofweek == 0)) {
|
||||
$params['week']++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_returns() {
|
||||
$ttable = new \mod_timetable\timetable($params['type'],$params['name']);
|
||||
$ttable->read_db($params['week']);
|
||||
//echo var_dump($ttable->prepare_output());
|
||||
return $ttable->prepare_output();
|
||||
//$renderable = new \mod_timetable\output\timetable($ttable);
|
||||
//return $renderable->export_for_template(new \mod_timetable\output\renderer($USER,array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_returns() {
|
||||
|
||||
|
||||
return new external_single_structure(
|
||||
return new external_single_structure(
|
||||
array(
|
||||
'periods' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'periods' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
'number' => new external_value(PARAM_INT, 'number of period'),
|
||||
'starttime' => new external_value(PARAM_TEXT, 'starttime of period'),
|
||||
'endtime' => new external_value(PARAM_TEXT, 'endtime of period'),
|
||||
'days' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'substitutionold' => new external_value(PARAM_TEXT, 'substitution'),
|
||||
'lessons' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'number' => new external_value(PARAM_INT, 'number of period'),
|
||||
'starttime' => new external_value(PARAM_TEXT, 'starttime of period'),
|
||||
'endtime' => new external_value(PARAM_TEXT, 'endtime of period'),
|
||||
'days' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'substitutionold' => new external_value(PARAM_TEXT, 'substitution'),
|
||||
'lessons' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'class' => new external_value(PARAM_TEXT, 'name of class'),
|
||||
'teacher' => new external_value(PARAM_TEXT, 'name of teacher'),
|
||||
'room' => new external_value(PARAM_TEXT, 'name of room'),
|
||||
'subject' => new external_value(PARAM_TEXT, 'name of subject'),
|
||||
'classa' => new external_value(PARAM_TEXT, 'name of class'),
|
||||
'teachera'=> new external_value(PARAM_TEXT, 'name of teacher'),
|
||||
'rooma' => new external_value(PARAM_TEXT, 'name of room'),
|
||||
'subjecta' => new external_value(PARAM_TEXT, 'name of subject'),
|
||||
'classb' => new external_value(PARAM_TEXT, 'name of class'),
|
||||
'teacherb'=> new external_value(PARAM_TEXT, 'name of teacher'),
|
||||
'roomb' => new external_value(PARAM_TEXT, 'name of room'),
|
||||
'subjectb' => new external_value(PARAM_TEXT, 'name of subject'),
|
||||
'classchanged' => new external_value(PARAM_BOOL, 'name of class'),
|
||||
'teacherchanged' => new external_value(PARAM_BOOL, 'name of teacher'),
|
||||
'roomchanged' => new external_value(PARAM_BOOL, 'name of room'),
|
||||
'subjectchanged' => new external_value(PARAM_BOOL, 'name of subject'),
|
||||
'substitution'=> new external_value(PARAM_TEXT, 'lesson is substitution'),
|
||||
'cancel' => new external_value(PARAM_TEXT, 'lesson is canceled'),
|
||||
'cancel4me' => new external_value(PARAM_TEXT, 'lesson is canceled 4 me'),
|
||||
'event' => new external_value(PARAM_TEXT, 'lesson is event'),
|
||||
'status' => new external_value(PARAM_TEXT, 'status of lesson'),
|
||||
'flag' => new external_value(PARAM_TEXT, 'flag of lesson'),
|
||||
'text' => new external_value(PARAM_TEXT, 'description text'),
|
||||
'subtype' => new external_multiple_structure( new external_value(PARAM_INT, 'bitnumber'))
|
||||
//'subtype' => new external_multiple_structure( new external_value('number', PARAM_INT, 'bitnumber'))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
'class' => new external_value(PARAM_TEXT, 'name of class'),
|
||||
'teacher' => new external_value(PARAM_TEXT, 'name of teacher'),
|
||||
'room' => new external_value(PARAM_TEXT, 'name of room'),
|
||||
'subject' => new external_value(PARAM_TEXT, 'name of subject'),
|
||||
'classa' => new external_value(PARAM_TEXT, 'name of class'),
|
||||
'teachera'=> new external_value(PARAM_TEXT, 'name of teacher'),
|
||||
'rooma' => new external_value(PARAM_TEXT, 'name of room'),
|
||||
'subjecta' => new external_value(PARAM_TEXT, 'name of subject'),
|
||||
'classb' => new external_value(PARAM_TEXT, 'name of class'),
|
||||
'teacherb'=> new external_value(PARAM_TEXT, 'name of teacher'),
|
||||
'roomb' => new external_value(PARAM_TEXT, 'name of room'),
|
||||
'subjectb' => new external_value(PARAM_TEXT, 'name of subject'),
|
||||
'classchanged' => new external_value(PARAM_BOOL, 'name of class'),
|
||||
'teacherchanged' => new external_value(PARAM_BOOL, 'name of teacher'),
|
||||
'roomchanged' => new external_value(PARAM_BOOL, 'name of room'),
|
||||
'subjectchanged' => new external_value(PARAM_BOOL, 'name of subject'),
|
||||
'substitution'=> new external_value(PARAM_TEXT, 'lesson is substitution'),
|
||||
'cancel' => new external_value(PARAM_TEXT, 'lesson is canceled'),
|
||||
'cancel4me' => new external_value(PARAM_TEXT, 'lesson is canceled 4 me'),
|
||||
'event' => new external_value(PARAM_TEXT, 'lesson is event'),
|
||||
'status' => new external_value(PARAM_TEXT, 'status of lesson'),
|
||||
'flag' => new external_value(PARAM_TEXT, 'flag of lesson'),
|
||||
'text' => new external_value(PARAM_TEXT, 'description text'),
|
||||
'subtype' => new external_multiple_structure( new external_value(PARAM_INT, 'bitnumber'))
|
||||
//'subtype' => new external_multiple_structure( new external_value('number', PARAM_INT, 'bitnumber'))
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'type' => new external_value(PARAM_TEXT, 'The type of timetable: class, teacher, room'),
|
||||
'viewteacher' => new external_value(PARAM_TEXT, '1 if type of timetable teacher'),
|
||||
'viewclass' => new external_value(PARAM_TEXT, '1 if type of timetable class'),
|
||||
'viewroom' => new external_value(PARAM_TEXT, '1 if type of timetable room'),
|
||||
'name' => new external_value(PARAM_TEXT, 'value of type'),
|
||||
'date' => new external_value(PARAM_TEXT, 'date'),
|
||||
'description' => new external_value(PARAM_TEXT, 'description'),
|
||||
'saturday' => new external_value(PARAM_INT, 'if timetable includes saturday'),
|
||||
'week' => new external_value(PARAM_INT, 'The week of timetable'),
|
||||
'prevweek' => new external_value(PARAM_INT, 'The next week of timetable'),
|
||||
'nextweek' => new external_value(PARAM_INT, 'The prev week of timetable'),
|
||||
'id' => new external_value(PARAM_TEXT, 'The id of timetable')
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
)
|
||||
),
|
||||
'type' => new external_value(PARAM_TEXT, 'The type of timetable: class, teacher, room'),
|
||||
'viewteacher' => new external_value(PARAM_TEXT, '1 if type of timetable teacher'),
|
||||
'viewclass' => new external_value(PARAM_TEXT, '1 if type of timetable class'),
|
||||
'viewroom' => new external_value(PARAM_TEXT, '1 if type of timetable room'),
|
||||
'name' => new external_value(PARAM_TEXT, 'value of type'),
|
||||
'date' => new external_value(PARAM_TEXT, 'date'),
|
||||
'description' => new external_value(PARAM_TEXT, 'description'),
|
||||
'saturday' => new external_value(PARAM_INT, 'if timetable includes saturday'),
|
||||
'week' => new external_value(PARAM_INT, 'The week of timetable'),
|
||||
'prevweek' => new external_value(PARAM_INT, 'The next week of timetable'),
|
||||
'nextweek' => new external_value(PARAM_INT, 'The prev week of timetable'),
|
||||
'id' => new external_value(PARAM_TEXT, 'The id of timetable')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue