From 423505cdf54c52947482509329c2a1c8ece97c39 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Wed, 19 Apr 2023 05:22:22 +0300 Subject: admin back-office environment: lessons management --- public/app/controllers/admin/Course_admin.php | 93 +++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 public/app/controllers/admin/Course_admin.php (limited to 'public/app/controllers/admin/Course_admin.php') diff --git a/public/app/controllers/admin/Course_admin.php b/public/app/controllers/admin/Course_admin.php new file mode 100644 index 0000000..0e34e00 --- /dev/null +++ b/public/app/controllers/admin/Course_admin.php @@ -0,0 +1,93 @@ +query( + "INSERT INTO course (parent_id, label) VALUES (:parent, :label)", + [ + ':parent' => Registry::get('REQUEST')->POST['parent_id'], + ':label' => Registry::get('REQUEST')->POST['label'] + ] + )->lastInsertID(); + + $cache = self::update_courses_cache(); // update category caches + return $cache['breadcrumbs']; // return + } + + + /** update course + * --- + * @param void (get data from POST) + */ + public static function update_course() + { + Registry::use('database')->query( + "UPDATE course SET parent_id = :parent, label = :label + WHERE id = :id", + [ + ':id' => Registry::get('REQUEST')->POST['id'], + ':parent' => Registry::get('REQUEST')->POST['parent_id'], + ':label' => Registry::get('REQUEST')->POST['label'] + ] + ); + $cache = self::update_courses_cache(); + return $cache['breadcrumbs']; + } + + + /** update courses cache + * --- -- -- - - - + * Shall run if anything changes to courses + * + * @param void + * @return (array): the two course caches + */ + public static function update_courses_cache() + { + $tree = proxy( // cache-get categories + [\app\models\cms\Course_model::class, 'category_tree'], + [], CACHE_ROOT_TTL, PROXY_IGNORE_CACHE + ); + $breadcrumbs = proxy( // cache-get breadcrumbs + [\app\models\cms\Course_model::class, 'breadcrumbs'], + [$tree], CACHE_ROOT_TTL, PROXY_IGNORE_CACHE + ); + + return [ + 'tree' => $tree, + 'breadcrumbs' => $breadcrumbs + ]; + } + +} \ No newline at end of file -- cgit v1.2.3