From 24fe99b72b423088369d4202e825b0f38d75b821 Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Sun, 23 Jul 2023 16:47:02 +0200 Subject: [PATCH] Fixed to backend --- classes/gradeinfo.php | 2 +- classes/studyplan.php | 50 ++++++++++++++++++++++++++++++++++++++++++- version.php | 2 +- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/classes/gradeinfo.php b/classes/gradeinfo.php index ff47cc3..9c663c3 100644 --- a/classes/gradeinfo.php +++ b/classes/gradeinfo.php @@ -195,7 +195,7 @@ class gradeinfo { "required" => $this->is_required(), ]; // Unfortunately, lazy loading of the completion data is off, since we need the data to show study item completion... - if($studyitem !== null && $this->is_selected() && has_capability('local/treestudyplan:viewuserreports',$studyitem->getStudyline()->studyplan()->context()) + if($studyitem !== null && $this->is_selected() && has_capability('local/treestudyplan:viewuserreports',$studyitem->studyline()->studyplan()->context()) && $this->gradingscanner->is_available()){ $model['grading'] = $this->gradingscanner->model(); } diff --git a/classes/studyplan.php b/classes/studyplan.php index 847bb06..4e0aaf2 100644 --- a/classes/studyplan.php +++ b/classes/studyplan.php @@ -178,7 +178,31 @@ class studyplan { } } $id = $DB->insert_record(self::TABLE, $info); - return self::findById($id); // make sure the new studyplan is immediately cached + $plan = self::findById($id); // make sure the new studyplan is immediately cached + + + // Start temporary skräpp code + // Add a single page and copy the names.This keeps the data sane until the upgrade to + // real page management is done + // TODO: Remove this when proper page management is implemented + $pageaddable = ['name','shortname','description','slots','startdate','enddate']; + $pageinfo = ['studyplan_id' => $id]; + foreach($pageaddable as $f){ + if(array_key_exists($f,$fields)){ + if($f == "name"){ + $pageinfo["fullname"] = $fields[$f]; + } else if ($f == "slots") { + $pageinfo["periods"] = $fields[$f]; + }else { + $pageinfo[$f] = $fields[$f]; + } + } + } + $page = studyplanpage::add($pageinfo); + $plan->page_cache = [$page]; + // End temporary skräpp code + + return $plan; } public function edit($fields){ @@ -199,6 +223,30 @@ class studyplan { $this->context(); // reload aggregator $this->aggregator = aggregator::createOrDefault($this->r->aggregation, $this->r->aggregation_config); + + // Start temporary skräpp code + // TODO: Until proper page editing is implemented, copy data from studyplan to it's first page + // This keeps the data sane until the upgrade is done. + if(count($this->pages()) == 1){ + // update the info to the page as well + $page = $this->pages()[0]; + $pageeditable = ['name','shortname','description','slots','startdate','enddate']; + $pageinfo = []; + foreach($pageeditable as $f){ + if(array_key_exists($f,$fields)){ + if($f == "name"){ + $pageinfo["fullname"] = $fields[$f]; + } else if ($f == "slots") { + $pageinfo["periods"] = $fields[$f]; + }else { + $pageinfo[$f] = $fields[$f]; + } + } + } + $page->edit($pageinfo); + } + // End temporary skräpp code + return $this; } diff --git a/version.php b/version.php index cc18b1c..dd6d6dc 100644 --- a/version.php +++ b/version.php @@ -1,6 +1,6 @@ component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494) -$plugin->version = 2023071900; // YYYYMMDDHH (year, month, day, iteration) +$plugin->version = 2023072300; // YYYYMMDDHH (year, month, day, iteration) $plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11) $plugin->dependencies = [