From 65d07ba64d45c77d2db16272710ec5702b34d641 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Tue, 25 Apr 2023 03:40:09 +0300 Subject: front-end: putting everything together --- public/app/controllers/cms/Course.php | 116 +++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 2 deletions(-) (limited to 'public/app/controllers/cms') diff --git a/public/app/controllers/cms/Course.php b/public/app/controllers/cms/Course.php index b671a5f..7e53d3a 100644 --- a/public/app/controllers/cms/Course.php +++ b/public/app/controllers/cms/Course.php @@ -6,9 +6,45 @@ use Registry; use Render; use app\controllers\Auth; use app\models\cms\Course_model; +use app\extends\Cache_service; class Course { + + /** PERMITION + * ------------------------------------------------------------------------- + */ + + + /** is admin or permited + * + * shortcut method for checking access authorization + * + * returns true if user belogns to the admin group + * or has the specified permition/privilege + * + * @param $privilege_id (int) + * + * NOTE: + * unlike the other authorization methods ... + * $privilege_id is NOT an array but a single privilege id + * + * @return true|false + */ + private static function is_admin_or_permited( $privilege_id) + { + return ( + Auth::in_admin_group() + || Auth::has_Permition([ $privilege_id ]) + ); + } + + + + /** FILES + * ------------------------------------------------------------------------- + */ + /** serve file by file_path * (request is valid only for admin users) * @@ -17,8 +53,10 @@ class Course { */ public static function serve_file($file_path) { - // check privileges - if (Auth::is_admin()) { // TODO: -OR- has prvivilege + $file = self::get_file_attributes($file_path); + + // if user is authorized + if (is_admin_or_permited($file['privilege_id'])) { $media_type = Registry::get('REQUEST')->GET['type']; // get media-type $real_path = MEDIA_STORAGE_ROOT . $file_path; // construct real path @@ -33,4 +71,78 @@ class Course { } } + + /** get_file_attributes + * + * returns attributes of a file + * (medias are proxied for speed optimization) + * + * @param $path (string) : file path + * @return $file attributes --or-- false + */ + private static function get_file_attributes($path) + { + $medias = Cache_service::files_attributes(); + + foreach($medias as $key => $medi) { + if ($medi['path'] == $path) { + return $medi; + } + } + + return false; + } + + + + /** COURSES + * ------------------------------------------------------------------------- + */ + + + public static function course($id) + { + $cache = Cache_service::courses_struct(); + $tree = $cache['tree']; + $breadcrumbs = $cache['breadcrumbs']; + $lessons = Course_model::lessons_of_course(intval($id)); + $id = intval($id); + + // print_r($breadcrumbs); die(); + + // find parent_ids of current category (to open the menu tree) + $course_path = []; + foreach($breadcrumbs[$id]['parents'] as $key => $parent) { + $course_path[] = intval($parent['id']); + } + $course_path[] = intval($id); + + Render::view('templates/course', [ + 'id' => $id, + 'title' => $breadcrumbs[ $id ]['rec']['label'], + 'categories' => $tree, + 'breadcrumbs' => $breadcrumbs, + 'lessons' => $lessons, + 'course_path' => $course_path + ]); + } + + + + + + + /** LESSONS + * ------------------------------------------------------------------------ + */ + + + + + + + + + + } \ No newline at end of file -- cgit v1.2.3