summaryrefslogtreecommitdiff
path: root/public/app/controllers/admin
diff options
context:
space:
mode:
Diffstat (limited to 'public/app/controllers/admin')
-rw-r--r--public/app/controllers/admin/Course_admin.php93
-rw-r--r--public/app/controllers/admin/Users_admin.php42
2 files changed, 135 insertions, 0 deletions
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 @@
+<?php
+
+namespace app\controllers\admin;
+
+use Registry;
+use Render;
+use app\models\cms\Course_model;
+
+class Course_admin {
+
+
+ /** breadcrumbs
+ * ---
+ * responds to ajax GET: /admin/api/categories
+ */
+ public static function breadcrumbs()
+ {
+ $tree = proxy( // cache-get categories
+ [\app\models\cms\Course_model::class, 'category_tree'],
+ [], CACHE_ROOT_TTL
+ );
+ $breadcrumbs = proxy( // cache-get breadcrumbs
+ [\app\models\cms\Course_model::class, 'breadcrumbs'],
+ [$tree], CACHE_ROOT_TTL
+ );
+ Render::json($breadcrumbs); // send as json
+ }
+
+ /** add course
+ * ---
+ * @param void (get data from POST)
+ */
+ public static function add_course()
+ {
+ // insert new category; id = new category id
+ $id = Registry::use('database')->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
diff --git a/public/app/controllers/admin/Users_admin.php b/public/app/controllers/admin/Users_admin.php
new file mode 100644
index 0000000..4e335c1
--- /dev/null
+++ b/public/app/controllers/admin/Users_admin.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace app\controllers\admin;
+
+use Registry;
+use Render;
+
+
+class Users_admin {
+
+ /** privileges
+ * ---
+ * get all privileges
+ *
+ * @param void
+ * @return privileges (array)
+ */
+ public static function privileges()
+ {
+ return Registry::use('database')->runQuery(
+ "SELECT * FROM privilege",[]
+ );
+ }
+
+ /** edit privileges
+ * ---
+ */
+ public static function edit_privileges()
+ {
+ // TODO: ...
+ }
+
+
+ /** update course
+ * ---
+ */
+ public static function update_course()
+ {
+ // TODO: ...
+ }
+
+} \ No newline at end of file