Webservice update data created
This commit is contained in:
parent
da14cf4623
commit
ae94d42fdf
9 changed files with 990 additions and 624 deletions
340
classes/import.php
Executable file
340
classes/import.php
Executable file
|
@ -0,0 +1,340 @@
|
|||
<?php
|
||||
|
||||
namespace mod_timetable;
|
||||
|
||||
/**
|
||||
* An example of a scheduled task.
|
||||
*/
|
||||
class import_data {
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the task's name as shown in admin screens.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
||||
public function get_name() {
|
||||
return get_string('import_data', 'mod_timetable');
|
||||
}
|
||||
|
||||
private function update_lesson($content) {
|
||||
global $DB,$CFG;
|
||||
$filehash = get_config('timetable', 'filehash_lesson');
|
||||
$hash = md5($content);
|
||||
if ($hash == $filehash) return('Data not changed');
|
||||
$result ="";
|
||||
try {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$result .= "before delete\n";
|
||||
$DB->delete_records_select("timetable_lesson", "id>0");
|
||||
$result .= "after delete\n";
|
||||
foreach (preg_split('/$\R?^/m',$content) as $buffer) {
|
||||
//echo $buffer;
|
||||
$result .= "+";
|
||||
$buffer = utf8_encode(rtrim($buffer));
|
||||
$data = explode("\t", $buffer);
|
||||
if (count($data) != 10) throw new \Exception('Wrong size of elements ');
|
||||
$dataobject = (object)array('teacher' => $data[0],
|
||||
'day' => $data[1],
|
||||
'period' => $data[2],
|
||||
'subject' => $data[3],
|
||||
'room' => $data[4],
|
||||
'lessonid'=> $data[5],
|
||||
'flag' => $data[6],
|
||||
'class' => $data[7],
|
||||
'week' => $data[8],
|
||||
'unknown' => $data[9]);
|
||||
|
||||
$DB->insert_record("timetable_lesson", $dataobject);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
set_config('filehash_lesson', $hash, 'timetable');
|
||||
} catch(Exception $e) {
|
||||
$transaction->rollback($e);
|
||||
}
|
||||
return ($result);
|
||||
}
|
||||
|
||||
|
||||
private function update_substitution($content) {
|
||||
global $DB,$CFG;
|
||||
$filehash = get_config('timetable', 'filehash_substitution');
|
||||
$hash = md5($content);
|
||||
if ($hash == $filehash) return('Data not changed');
|
||||
$result ="";
|
||||
try {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$result .= "before delete\n";
|
||||
$DB->delete_records_select("timetable_substitution", "id>0");
|
||||
$result .= "after delete\n";
|
||||
foreach (preg_split('/$\R?^/m',$content) as $buffer) {
|
||||
$data = str_getcsv($buffer, ',');
|
||||
$dataobject = (object)array(
|
||||
'id' => $data[0],
|
||||
'date' => $data[1],
|
||||
'period' => $data[2],
|
||||
'absence' => $data[3],
|
||||
'lesson' => $data[4],
|
||||
'teachera' => $data[5],
|
||||
'teacherb' => $data[6],
|
||||
'subjecta' => utf8_encode($data[7]),
|
||||
'statistica' => $data[8],
|
||||
'subjectb' => utf8_encode($data[9]),
|
||||
'statisticb' => $data[10],
|
||||
'rooma' => $data[11],
|
||||
'roomb' => $data[12],
|
||||
'statisticflag' => $data[13],
|
||||
'classa' => utf8_encode($data[14]),
|
||||
'reason' => utf8_encode($data[15]),
|
||||
'text' => utf8_encode($data[16]),
|
||||
'type' => $data[17],
|
||||
'classb' => utf8_encode($data[18]),
|
||||
'substitutiontype' => $data[19],
|
||||
'changetime' => $data[20],
|
||||
'unknown' => $data[21]);
|
||||
//echo var_dump($dataobject);
|
||||
foreach (get_object_vars($dataobject) as $key => $value) {
|
||||
if ($value=='') unset($dataobject->{$key});
|
||||
}
|
||||
$DB->insert_record_raw("timetable_substitution", $dataobject,false, false, true);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
set_config('filehash_substitution', $hash, 'timetable');
|
||||
} catch(Exception $e) {
|
||||
$transaction->rollback($e);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function update_teacher($content) {
|
||||
global $DB,$CFG;
|
||||
$filehash = get_config('timetable', 'filehash_teacher');
|
||||
$hash = md5($content);
|
||||
if ($hash == $filehash) return('Data not changed');
|
||||
$result = "";
|
||||
try {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$result .= "before delete\n";
|
||||
$DB->delete_records_select("timetable_teacher", "id>0");
|
||||
$result .= "after delete\n";
|
||||
foreach (preg_split('/$\R?^/m',$content) as $buffer) {
|
||||
$buffer = utf8_encode(rtrim($buffer));
|
||||
$data = explode("\t", $buffer);
|
||||
if (!(array_key_exists(3,$data))) {
|
||||
$data[3] = '';
|
||||
} else {
|
||||
$result .= "firstname exists: $data[3]\n";
|
||||
}
|
||||
//if (count($data) < 3) throw new Exception('Wrong size of elements');
|
||||
$dataobject = (object)array('teacher' => $data[0],
|
||||
'surname' => $data[1],
|
||||
'firstname' => $data[3]);
|
||||
|
||||
$DB->insert_record("timetable_teacher", $dataobject);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
set_config('filehash_teacher', $hash, 'timetable');
|
||||
} catch(Exception $e) {
|
||||
$transaction->rollback($e);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function update_room($content) {
|
||||
global $DB,$CFG;
|
||||
$filehash = get_config('timetable', 'filehash_room');
|
||||
$hash = md5($content);
|
||||
if ($hash == $filehash) return('Data not changed');
|
||||
$result = "";
|
||||
try {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$result .= "before delete\n";
|
||||
$DB->delete_records_select("timetable_room", "id>0");
|
||||
$result .= "after delete\n";
|
||||
foreach (preg_split('/$\R?^/m',$content) as $buffer) {
|
||||
$buffer = utf8_encode(rtrim($buffer));
|
||||
$data = explode("\t", $buffer);
|
||||
if (count($data) < 2) throw new \Exception('Wrong size of elements');
|
||||
$dataobject = (object)array('room' => $data[0],
|
||||
'description' => $data[1]);
|
||||
|
||||
$DB->insert_record("timetable_room", $dataobject);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
set_config('filehash_room', $hash, 'timetable');
|
||||
} catch(Exception $e) {
|
||||
$transaction->rollback($e);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function update_class($content) {
|
||||
global $DB,$CFG;
|
||||
$filehash = get_config('timetable', 'filehash_class');
|
||||
$hash = md5($content);
|
||||
if ($hash == $filehash) return('Data not changed');
|
||||
$result = "";
|
||||
try {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$result .= "before delete\n";
|
||||
$DB->delete_records_select("timetable_class", "id>0");
|
||||
$result .= "after delete\n";
|
||||
foreach (preg_split('/$\R?^/m',$content) as $buffer) {
|
||||
$buffer = utf8_encode(rtrim($buffer));
|
||||
$data = explode("\t", $buffer);
|
||||
if (!(array_key_exists(1,$data))) $data[1] = $data[0];
|
||||
if (count($data) < 2) throw new \Exception('Wrong size of elements');
|
||||
$dataobject = (object)array('class' => $data[0],
|
||||
'description' => $data[1]);
|
||||
|
||||
$DB->insert_record("timetable_class", $dataobject);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
set_config('filehash_class', $hash, 'timetable');
|
||||
} catch(Exception $e) {
|
||||
$transaction->rollback($e);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function update_absence($content) {
|
||||
global $DB,$CFG;
|
||||
$filehash = get_config('timetable', 'filehash_abs');
|
||||
$hash = md5($content);
|
||||
if ($hash == $filehash) return('Data not changed');
|
||||
$result = "";
|
||||
try {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$result .= "before delete\n";
|
||||
$DB->delete_records_select("timetable_absence", "id>0");
|
||||
$result .= "after delete\n";
|
||||
foreach (preg_split('/$\R?^/m',$content) as $buffer) {
|
||||
$data = str_getcsv($buffer, ',');
|
||||
$dataobject = (object)array('id' => $data[0],
|
||||
'type' => $data[1],
|
||||
'name' => utf8_encode($data[2]),
|
||||
'startdate' => $data[3],
|
||||
'enddate' => $data[4],
|
||||
'startperiod' => $data[5],
|
||||
'endperiod' => $data[6],
|
||||
'reason' => utf8_encode($data[7]),
|
||||
'text' => utf8_encode($data[8]));
|
||||
foreach (get_object_vars($dataobject) as $key => $value) {
|
||||
if ($value=='') unset($dataobject->{$key});
|
||||
}
|
||||
$DB->insert_record("timetable_absence", $dataobject);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
set_config('filehash_abs', $hash, 'timetable');
|
||||
} catch(Exception $e) {
|
||||
$transaction->rollback($e);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function update_absence_reason($content) {
|
||||
global $DB,$CFG;
|
||||
$filehash = get_config('timetable', 'filehash_absreas');
|
||||
$hash = md5($content);
|
||||
if ($hash == $filehash) return('Data not changed');
|
||||
$result = "";
|
||||
try {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$result .= "before delete\n";
|
||||
$DB->delete_records_select("timetable_absence_reason", "id>0");
|
||||
$result .= "after delete\n";
|
||||
foreach (preg_split('/$\R?^/m',$content) as $buffer) {
|
||||
$data = str_getcsv($buffer, ',');
|
||||
$dataobject = (object)array('reason' => utf8_encode($data[0]),
|
||||
'description' => utf8_encode($data[1]),
|
||||
'flag' => $data[2],
|
||||
'statistic' => $data[3]);
|
||||
foreach (get_object_vars($dataobject) as $key => $value) {
|
||||
if ($value=='') unset($dataobject->{$key});
|
||||
}
|
||||
$DB->insert_record("timetable_absence_reason", $dataobject);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
set_config('filehash_absreas', $hash, 'timetable');
|
||||
} catch(Exception $e) {
|
||||
$transaction->rollback($e);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function update_time($content) {
|
||||
global $DB,$CFG;
|
||||
$filehash = get_config('timetable', 'filehash_times');
|
||||
$hash = md5($content);
|
||||
if ($hash == $filehash) return('Data not changed');
|
||||
$result = "";
|
||||
try {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$result .= "before delete\n";
|
||||
$DB->delete_records_select("timetable_time", "id>0");
|
||||
$result .= "after delete\n";
|
||||
foreach (preg_split('/$\R?^/m',$content) as $buffer) {
|
||||
$buffer = utf8_encode(rtrim($buffer));
|
||||
$data = explode("\t", $buffer);
|
||||
$dataobject = (object)array('day' => $data[0],
|
||||
'period' => $data[1],
|
||||
'maxperiod' => $data[2],
|
||||
'starttime' => $data[3],
|
||||
'endtime' => $data[4]);
|
||||
$DB->insert_record("timetable_time", $dataobject);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
set_config('filehash_times', $hash, 'timetable');
|
||||
} catch(Exception $e) {
|
||||
$transaction->rollback($e);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the task.
|
||||
*/
|
||||
public function update($files) {
|
||||
global $DB,$CFG;
|
||||
$results = array();
|
||||
foreach ($files as $file) {
|
||||
$content = base64_decode($file['content']);
|
||||
$result = array();
|
||||
$result['name'] = $file['name'];
|
||||
switch ($file['name']) {
|
||||
case 'lesson':
|
||||
$result['result'] = $this->update_lesson($content);
|
||||
break;
|
||||
case 'substitution':
|
||||
$result['result'] = $this->update_substitution($content);
|
||||
break;
|
||||
case 'teacher':
|
||||
$result['result'] = $this->update_teacher($content);
|
||||
break;
|
||||
case 'class':
|
||||
$result['result'] = $this->update_class($content);
|
||||
break;
|
||||
case 'room':
|
||||
$result['result'] = $this->update_room($content);
|
||||
break;
|
||||
case 'time':
|
||||
$result['result'] = $this->update_time($content);
|
||||
break;
|
||||
case 'absence':
|
||||
$result['result'] = $this->update_absence($content);
|
||||
break;
|
||||
case 'absence_reason':
|
||||
$result['result'] = $this->update_absence_reason($content);
|
||||
break;
|
||||
default:
|
||||
$result['result'] = "no handler";
|
||||
}
|
||||
$results[] = $result;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
|
@ -37,6 +37,7 @@ class lesson {
|
|||
$this->room = $lesson->room;
|
||||
$this->period = $lesson->period;
|
||||
$this->day = $lesson->day;
|
||||
$this->type = $lesson->type;
|
||||
$this->text = "";
|
||||
$this->substitution = "";
|
||||
$this->teachera = "";
|
||||
|
@ -52,7 +53,7 @@ class lesson {
|
|||
$this->classchanged = false;
|
||||
$this->roomchanged = false;
|
||||
$this->reason = "";
|
||||
$this->type = 0;
|
||||
$this->subtype = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,12 +71,12 @@ class lesson {
|
|||
$this->subjecta = $substitution->subjecta;
|
||||
$this->classa = $substitution->classa;
|
||||
$this->rooma = $substitution->rooma;
|
||||
$this->teacherchanged = ($this->teacher != $this->teachera) ? true : false;
|
||||
$this->subjectchanged = ($this->subject != $this->subjecta) ? true : false;
|
||||
$this->classchanged = (!preg_match("/(^|~)".preg_quote($this->class,"/")."($|~)/" , $this->classa )) ? true : false;
|
||||
$this->roomchanged = (!preg_match("/(^|~)".preg_quote($this->room,"/")."($|~)/" , $this->rooma )) ? true : false;
|
||||
$this->teacherchanged = ($this->teacher != $this->teachera && $this->teachera) ? true : false;
|
||||
$this->subjectchanged = ($this->subject != $this->subjecta && $this->subjecta) ? true : false;
|
||||
$this->classchanged = (!preg_match("/(^|~)".preg_quote($this->class,"/")."($|~)/" , $this->classa ) && $this->classa) ? true : false;
|
||||
$this->roomchanged = (!preg_match("/(^|~)".preg_quote($this->room,"/")."($|~)/" , $this->rooma ) && $this->rooma) ? true : false;
|
||||
if ($substitution->text) $this->text .= $substitution->text;
|
||||
$this->type = $substitution->type;
|
||||
$this->subtype = $substitution->type;
|
||||
$this->substitution = "1";
|
||||
return 1;
|
||||
} elseif (//$this->lessonid == $substitution->lesson &&
|
||||
|
@ -94,7 +95,7 @@ class lesson {
|
|||
$this->roomchanged = (!preg_match("/(^|~)".preg_quote($this->room,"/")."($|~)/" , $this->roomb )) ? true : false;
|
||||
if ($substitution->text) $this->text .= $substitution->text;
|
||||
// TODO Entfall, falls teacherb!=teacher bzw. class not in classb bzw. roomb!=room TODO
|
||||
$this->type = $substitution->type;
|
||||
$this->subtype = $substitution->type;
|
||||
$this->substitution = "1";
|
||||
return 1;
|
||||
} else {
|
||||
|
@ -128,6 +129,9 @@ class lesson {
|
|||
//$this->teacher == $lesson->teacher &&
|
||||
$this->subject == $lesson->subject &&
|
||||
$this->room == $lesson->room &&
|
||||
$this->type == $lesson->type &&
|
||||
$this->subtype == $lesson->subtype &&
|
||||
//$this->teacherchanged == $lesson->teacherchanged &&
|
||||
$this->text == $lesson->text) {
|
||||
if ($this->class != $lesson->class) {
|
||||
$class1parts = explode("/", $this->class);
|
||||
|
|
|
@ -29,7 +29,8 @@ function lesson_in_lessons($obj, $array) {
|
|||
$obj->teacher == $array[$n]->teacher &&
|
||||
$obj->subject == $array[$n]->subject &&
|
||||
$obj->class == $array[$n]->class &&
|
||||
$obj->room == $array[$n]->room) return true;
|
||||
$obj->room == $array[$n]->room &&
|
||||
$obj->type == $array[$n]->type) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -120,20 +121,23 @@ class timetable {
|
|||
$sql = "$this->type = '$this->name' AND NOT lessonid=0 AND (mid(week, $this->week, 1) = '1')";
|
||||
$result = $DB->get_records_select('timetable_lesson',$sql);
|
||||
foreach ($result as $lesson) {
|
||||
$lesson->type = "normal";
|
||||
if (!lesson_in_lessons($lesson, $this->lessons[$lesson->day][$lesson->period]))
|
||||
$this->lessons[$lesson->day][$lesson->period][] = new lesson($lesson);
|
||||
}
|
||||
$sql = "$this->type = '$this->name' AND lessonid=0 AND (mid(week, $this->week, 1) = '1')";
|
||||
$result = $DB->get_records_select('timetable_lesson',$sql);
|
||||
foreach ($result as $lesson) {
|
||||
if (!lesson_in_lessons($lesson, $this->lessons_event[$lesson->day][$lesson->period]))
|
||||
$this->lessons_event[$lesson->day][$lesson->period][] = new lesson($lesson);
|
||||
$lesson->type = "event";
|
||||
if (!lesson_in_lessons($lesson, $this->lessons[$lesson->day][$lesson->period]))
|
||||
$this->lessons[$lesson->day][$lesson->period][] = new lesson($lesson);
|
||||
}
|
||||
$sql = "$this->type = '$this->name' and (mid(week, $this->week, 1) = 'x')";
|
||||
$result = $DB->get_records_select('timetable_lesson',$sql);
|
||||
foreach ($result as $lesson) {
|
||||
if (!lesson_in_lessons($lesson, $this->lessons_canceled[$lesson->day][$lesson->period]))
|
||||
$this->lessons_canceled[$lesson->day][$lesson->period][] = new lesson($lesson);
|
||||
$lesson->type = "canceled";
|
||||
if (!lesson_in_lessons($lesson, $this->lessons[$lesson->day][$lesson->period]))
|
||||
$this->lessons[$lesson->day][$lesson->period][] = new lesson($lesson);
|
||||
}
|
||||
|
||||
$day = new \DateTime($this->monday->format('Y-m-d\TH:i:sP'));
|
||||
|
@ -144,12 +148,6 @@ class timetable {
|
|||
foreach ($this->lessons[$i+1][$substitution->period] as $lesson) {
|
||||
$lesson->process_substitution($substitution);
|
||||
}
|
||||
foreach ($this->lessons_canceled[$i+1][$substitution->period] as $lesson) {
|
||||
$lesson->process_substitution($substitution);
|
||||
}
|
||||
foreach ($this->lessons_event[$i+1][$substitution->period] as $lesson) {
|
||||
$lesson->process_substitution($substitution);
|
||||
}
|
||||
}
|
||||
|
||||
$types = array('teacher'=>'L', 'class'=>'K', 'room'=>'R');
|
||||
|
@ -157,8 +155,8 @@ class timetable {
|
|||
$result = $DB->get_records_select('timetable_absence',$sql);
|
||||
foreach ($result as $absence) {
|
||||
for ($j=$absence->startperiod; $j<=$absence->endperiod; $j++) {
|
||||
foreach ($this->lessons_event[$i+1][$j] as $lesson) {
|
||||
$lesson->process_absence($absence);
|
||||
foreach ($this->lessons[$i+1][$j] as $lesson) {
|
||||
if ($lesson->type == 'event') $lesson->process_absence($absence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +166,7 @@ class timetable {
|
|||
|
||||
for ($i=0; $i<$this->numdayweek; $i++) {
|
||||
foreach($this->lessons[$i+1] as &$lessons) $lessons = collapse_lessons($lessons);
|
||||
foreach($this->lessons_canceled[$i+1] as &$lessons) $lessons = collapse_lessons($lessons);
|
||||
// not to be done for events???
|
||||
}
|
||||
|
||||
if ($this->type == 'teacher') {
|
||||
|
@ -191,10 +189,6 @@ class timetable {
|
|||
for ($i=0; $i<$this->numdayweek; $i++) {
|
||||
foreach($this->lessons[$i+1] as $period => $lessons)
|
||||
if ($period > $maxperiod && count($lessons)) $maxperiod = $period;
|
||||
foreach($this->lessons_canceled[$i+1] as $period => $lessons)
|
||||
if ($period > $maxperiod && count($lessons)) $maxperiod = $period;
|
||||
foreach($this->lessons_event[$i+1] as $period => $lessons)
|
||||
if ($period > $maxperiod && count($lessons)) $maxperiod = $period;
|
||||
}
|
||||
return $maxperiod;
|
||||
}
|
||||
|
@ -226,40 +220,6 @@ class timetable {
|
|||
$days[$day] = array();
|
||||
$days[$day]['substitutionold'] = "";
|
||||
$days[$day]['lessons'] = array();
|
||||
foreach ($this->lessons_event[$day+1][$period+1] as $lesson) {
|
||||
$mylesson = array();
|
||||
$mylesson['class'] = $lesson->class;
|
||||
$mylesson['teacher'] = $lesson->teacher;
|
||||
$mylesson['room'] = $lesson->room;
|
||||
$mylesson['subject'] = $lesson->subject;
|
||||
$mylesson['classa'] = $lesson->classa;
|
||||
$mylesson['teachera'] = $lesson->teachera;
|
||||
$mylesson['rooma'] = $lesson->rooma;
|
||||
$mylesson['subjecta'] = $lesson->subjecta;
|
||||
$mylesson['classb'] = property_exists($lesson,'classb') ? $lesson->classb : null;
|
||||
$mylesson['teacherb'] = property_exists($lesson,'teacherb') ? $lesson->teacherb : null;
|
||||
$mylesson['roomb'] = property_exists($lesson,'roomb') ? $lesson->roomb : null;
|
||||
$mylesson['subjectb'] = property_exists($lesson,'subjectb') ? $lesson->subjectb : null;
|
||||
$mylesson['subjectchanged'] = $lesson->subjectchanged;
|
||||
$mylesson['teacherchanged'] = $lesson->teacherchanged;
|
||||
$mylesson['classchanged'] = $lesson->classchanged;
|
||||
$mylesson['roomchanged'] = $lesson->roomchanged;
|
||||
$mylesson['substitution'] = $lesson->substitution;
|
||||
$mylesson['cancel'] = "";
|
||||
$mylesson['cancel4me'] = "";
|
||||
$mylesson['event'] = $lesson->reason ? $lesson->reason : "Event";
|
||||
$mylesson['status'] = "1";
|
||||
$mylesson['flag'] = "1";
|
||||
$mylesson['text'] = $lesson->text;
|
||||
$mylesson['subtype'] = Array();
|
||||
if ($lesson->type) {
|
||||
for ($i=0; $i<32; $i++) {
|
||||
if ($lesson->type & (1<<$i)) $mylesson['subtype'][] = $i+1;
|
||||
}
|
||||
}
|
||||
$days[$day]['substitutionold'] .= $lesson->text;
|
||||
$days[$day]['lessons'][] = $mylesson;
|
||||
}
|
||||
foreach ($this->lessons[$day+1][$period+1] as $lesson) {
|
||||
$mylesson = array();
|
||||
$mylesson['class'] = $lesson->class;
|
||||
|
@ -286,52 +246,25 @@ class timetable {
|
|||
$mylesson['flag'] = "";
|
||||
$mylesson['text'] = $lesson->text;
|
||||
$mylesson['subtype'] = Array();
|
||||
if ($lesson->type) {
|
||||
if ($lesson->subtype) {
|
||||
for ($i=0; $i<32; $i++) {
|
||||
if ($lesson->type & (1<<$i)) $mylesson['subtype'][] = $i+1;
|
||||
if ($lesson->subtype & (1<<$i)) $mylesson['subtype'][] = $i+1;
|
||||
}
|
||||
}
|
||||
$days[$day]['substitutionold'] .= $lesson->text;
|
||||
$days[$day]['lessons'][] = $mylesson;
|
||||
}
|
||||
foreach ($this->lessons_canceled[$day+1][$period+1] as $lesson) {
|
||||
$mylesson = array();
|
||||
$mylesson['class'] = $lesson->class;
|
||||
$mylesson['teacher'] = $lesson->teacher;
|
||||
$mylesson['room'] = $lesson->room;
|
||||
$mylesson['subject'] = $lesson->subject;
|
||||
$mylesson['classa'] = $lesson->classa;
|
||||
$mylesson['teachera'] = $lesson->teachera;
|
||||
$mylesson['rooma'] = $lesson->rooma;
|
||||
$mylesson['subjecta'] = $lesson->subjecta;
|
||||
$mylesson['classb'] = property_exists($lesson,'classb') ? $lesson->classb : null;
|
||||
$mylesson['teacherb'] = property_exists($lesson,'teacherb') ? $lesson->teacherb : null;
|
||||
$mylesson['roomb'] = property_exists($lesson,'roomb') ? $lesson->roomb : null;
|
||||
$mylesson['subjectb'] = property_exists($lesson,'subjectb') ? $lesson->subjectb : null;
|
||||
$mylesson['substitution'] = $lesson->substitution;
|
||||
if ($lesson->type == 'event') {
|
||||
$mylesson['event'] = $lesson->reason ? $lesson->reason : "Event";
|
||||
$mylesson['status'] = "1";
|
||||
$mylesson['flag'] = "1";
|
||||
} elseif ($lesson->type == 'canceled') {
|
||||
$mylesson['cancel'] = "1";
|
||||
$mylesson['cancel4me'] = "";
|
||||
if (($lesson->teacherchanged && $this->type == 'teacher') ||
|
||||
($lesson->classchanged && $this->type == 'class') ||
|
||||
($lesson->roomchanged && $this->type == 'room')) $mylesson['cancel4me'] = "cancel4me";
|
||||
$mylesson['subjectchanged'] = $lesson->subjectchanged;
|
||||
$mylesson['teacherchanged'] = $lesson->teacherchanged;
|
||||
$mylesson['classchanged'] = $lesson->classchanged;
|
||||
$mylesson['roomchanged'] = $lesson->roomchanged;
|
||||
#if ((property_exists($lesson,'teacherb') && $this->type == 'teacher') ||
|
||||
# (property_exists($lesson,'classb') && $this->type == 'class') ||
|
||||
# (property_exists($lesson,'roomb') && $this->type == 'room')) $mylesson['cancel4me'] = "cancel4me";
|
||||
$mylesson['event'] = "";
|
||||
$mylesson['status'] = "1";
|
||||
$mylesson['flag'] = "1"; // status und flag werden vertauscht (im Template bzw. extern-lib.php
|
||||
$mylesson['text'] = $lesson->text;
|
||||
$mylesson['subtype'] = Array();
|
||||
if ($lesson->type) {
|
||||
for ($i=0; $i<32; $i++) {
|
||||
if ($lesson->type & (1<<$i)) $mylesson['subtype'][] = $i+1;
|
||||
}
|
||||
}
|
||||
$days[$day]['substitutionold'] .= $lesson->text;
|
||||
$days[$day]['lessons'][] = $mylesson;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,16 @@ defined('MOODLE_INTERNAL') || die();
|
|||
|
||||
$capabilities = array(
|
||||
|
||||
'mod/timetable:update' => array(
|
||||
'riskbitmask' => RISK_XSS,
|
||||
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_USER,
|
||||
'archetypes' => array(
|
||||
'manager' => CAP_ALLOW
|
||||
),
|
||||
),
|
||||
|
||||
'mod/timetable:addinstance' => array(
|
||||
'riskbitmask' => RISK_XSS,
|
||||
|
||||
|
|
|
@ -40,6 +40,15 @@ $functions = array(
|
|||
'type' => 'read',
|
||||
'ajax' => true,
|
||||
'capabilities' => array(), // capabilities required by the function.
|
||||
),
|
||||
'mod_timetable_update' => array(
|
||||
'classname' => 'mod_timetable_external',
|
||||
'methodname' => 'update',
|
||||
'classpath' => 'mod/timetable/externallib.php',
|
||||
'description' => 'update timetable data',
|
||||
'type' => 'write',
|
||||
'ajax' => false,
|
||||
'capabilities' => array(), // capabilities required by the function.
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
* @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 {
|
||||
|
||||
|
@ -48,7 +49,8 @@ class mod_timetable_external extends external_api {
|
|||
|
||||
//Context validation
|
||||
//OPTIONAL but in most web service it should present
|
||||
$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
//$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
self::validate_context($context);
|
||||
|
||||
//Capability checking
|
||||
|
@ -59,7 +61,6 @@ class mod_timetable_external extends external_api {
|
|||
|
||||
|
||||
$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(
|
||||
|
@ -87,7 +88,6 @@ class mod_timetable_external extends external_api {
|
|||
);
|
||||
$results[] = $result;
|
||||
}
|
||||
//echo var_dump($results);
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,70 @@ class mod_timetable_external extends external_api {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'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');
|
||||
}
|
||||
|
||||
$import_data = new \mod_timetable\import_data();
|
||||
return $import_data->update($files);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* @return external_function_parameters
|
||||
|
@ -133,14 +197,13 @@ class mod_timetable_external extends external_api {
|
|||
|
||||
//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);
|
||||
//$context = get_context_instance(CONTEXT_USER, $USER->id);
|
||||
$context = context_user::instance($USER->id);
|
||||
self::validate_context($context);
|
||||
|
||||
//$contextmodule = context_module::instance($cm->id);
|
||||
|
|
|
@ -28,6 +28,13 @@ defined('MOODLE_INTERNAL') || die();
|
|||
$string['pluginname'] = 'Timetable';
|
||||
$string['modulename'] = 'Timetable';
|
||||
$string['modulenameplural'] = 'Timetables';
|
||||
$string['timetable:addinstance'] = 'add timetable';
|
||||
$string['timetable:search'] = 'perform timetable search';
|
||||
$string['timetable:viewclass'] = 'view class timetable';
|
||||
$string['timetable:viewownclass'] = 'view own class timetable';
|
||||
$string['timetable:viewroom'] = 'view room timetable';
|
||||
$string['timetable:viewteacher'] = 'view teacher timetable';
|
||||
$string['timetable:update'] = 'update timetable data';
|
||||
$string['timetablename'] = 'Timetable';
|
||||
$string['timetablename_help'] = 'Timetable help';
|
||||
$string['timetablefieldset'] = 'Settings';
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'mod_timetable';
|
||||
$plugin->release = '0.1.0';
|
||||
$plugin->version = 2020112102;
|
||||
$plugin->release = '0.2.0';
|
||||
$plugin->version = 2020120401;
|
||||
$plugin->requires = 2020061500;
|
||||
$plugin->maturity = MATURITY_ALPHA;
|
||||
|
|
Loading…
Add table
Reference in a new issue