Bugfix in studyplan period creator

This commit is contained in:
PMKuipers 2023-08-16 23:15:48 +02:00
parent 9bd0f2002e
commit cae51717a9
5 changed files with 16 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1455,7 +1455,7 @@ export default {
if(modalresponse){ if(modalresponse){
call([{ call([{
methodname: 'local_treestudyplan_delete_studyplan', methodname: 'local_treestudyplan_delete_studyplan',
args: { 'id': studyplan.id, } args: { 'id': studyplan.id, force: true}
}])[0].done(function(response){ }])[0].done(function(response){
if(response.success == true){ if(response.success == true){
self.$root.$emit("studyplanRemoved",studyplan); self.$root.$emit("studyplanRemoved",studyplan);

View File

@ -195,7 +195,7 @@ class studyplan {
// TODO: Remove this when proper page management is implemented // TODO: Remove this when proper page management is implemented
if(!$bare){ if(!$bare){
$pageaddable = ['name','shortname','description',]; $pageaddable = ['name','shortname','description','periods','startdate','enddate'];
$pageinfo = ['studyplan_id' => $id]; $pageinfo = ['studyplan_id' => $id];
foreach($pageaddable as $f){ foreach($pageaddable as $f){
if(array_key_exists($f,$fields)){ if(array_key_exists($f,$fields)){
@ -217,7 +217,7 @@ class studyplan {
public function edit($fields){ public function edit($fields){
global $DB; global $DB;
$editable = ['name','shortname','description','idnumber','context_id','periods','startdate','enddate','aggregation','aggregation_config']; $editable = ['name','shortname','description','idnumber','context_id','aggregation','aggregation_config'];
$info = ['id' => $this->id,]; $info = ['id' => $this->id,];
foreach($editable as $f){ foreach($editable as $f){
if(array_key_exists($f,$fields)){ if(array_key_exists($f,$fields)){
@ -240,7 +240,7 @@ class studyplan {
if(count($this->pages()) == 1){ if(count($this->pages()) == 1){
// update the info to the page as well // update the info to the page as well
$page = $this->pages()[0]; $page = $this->pages()[0];
$pageeditable = ['name','shortname','description']; $pageeditable = ['name','shortname','description','periods','startdate','enddate'];
$pageinfo = []; $pageinfo = [];
foreach($pageeditable as $f){ foreach($pageeditable as $f){
if(array_key_exists($f,$fields)){ if(array_key_exists($f,$fields)){

View File

@ -145,6 +145,12 @@ class studyplanpage {
$info[$f] = $fields[$f]; $info[$f] = $fields[$f];
} }
} }
if(!isset($addable['periods'])){
$addable['periods'] = 4;
} else if($addable['periods'] < 1){
$addable['periods'] = 1;
}
$id = $DB->insert_record(self::TABLE, $info); $id = $DB->insert_record(self::TABLE, $info);
return self::findById($id); // make sure the new page is immediately cached return self::findById($id); // make sure the new page is immediately cached
} }
@ -158,6 +164,10 @@ class studyplanpage {
$info[$f] = $fields[$f]; $info[$f] = $fields[$f];
} }
} }
if(isset($info['periods']) && $info['periods'] < 1){
$info['periods'] = 1;
}
$DB->update_record(self::TABLE, $info); $DB->update_record(self::TABLE, $info);
//reload record after edit //reload record after edit
$this->r = $DB->get_record(self::TABLE,['id' => $this->id],"*",MUST_EXIST); $this->r = $DB->get_record(self::TABLE,['id' => $this->id],"*",MUST_EXIST);