diff options
Diffstat (limited to 'public/app/controllers')
| -rw-r--r-- | public/app/controllers/.gitkeep | 0 | ||||
| -rw-r--r-- | public/app/controllers/Auth.php | 28 | ||||
| -rw-r--r-- | public/app/controllers/admin/Course_admin.php | 12 | ||||
| -rw-r--r-- | public/app/controllers/cli/CliContoller.php | 48 | ||||
| -rw-r--r-- | public/app/controllers/cms/Course.php | 86 |
5 files changed, 115 insertions, 59 deletions
diff --git a/public/app/controllers/.gitkeep b/public/app/controllers/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/public/app/controllers/.gitkeep diff --git a/public/app/controllers/Auth.php b/public/app/controllers/Auth.php index 0570a5e..8af7513 100644 --- a/public/app/controllers/Auth.php +++ b/public/app/controllers/Auth.php @@ -180,7 +180,11 @@ class Auth { } - + /** is_connected + * checks if the user is connected + * + * @return true|false + */ public static function is_connected() { $manager = new Classroom_manager(); @@ -193,13 +197,17 @@ class Auth { return $user; } else { - echo 'user is not connected'; + // user is not connected; return false; } } - + /** logout + * + * performs a secure logout; + * regenerates session; deletes cookies; + */ public static function logout() { $userManager = new Classroom_manager(); @@ -232,7 +240,7 @@ class Auth { return true; // permision 0 is always granted } - if ($user = $this->is_connected() === flase) { // if not connected + if ($user = self::is_connected() === false) { // if not connected return false; // then no other permition is granted } @@ -340,6 +348,18 @@ class Auth { } + /** hasValidRole + * like allowRoles() but dowes not stop execution + * + * @return true|false + */ + public static function hasValidRole($allowed) + { + $manager = new Classroom_manager(); + return ($manager->isGranted($allowed)); + } + + public static function in_admin_group() { $manager = new Classroom_manager(); diff --git a/public/app/controllers/admin/Course_admin.php b/public/app/controllers/admin/Course_admin.php index c2e06f2..72ddc79 100644 --- a/public/app/controllers/admin/Course_admin.php +++ b/public/app/controllers/admin/Course_admin.php @@ -213,8 +213,10 @@ class Course_admin { ] ); - // update media's privileges - self::update_medias_privileges($post['media'], $post['privilege_id']); + if (isset($post['media'])) { + // update media's privileges + self::update_medias_privileges($post['media'], $post['privilege_id']); + } // remove all old lesson's links to media files Registry::use('database')->runQuery( @@ -222,8 +224,10 @@ class Course_admin { [ ':lesson' => $post['id'] ] ); - // update lesson's media files - self::create_medias_for_lesson($post['media'], $post['id'], $post['privilege_id']); + if (isset($post['media'])) { + // update lesson's media files + self::create_medias_for_lesson($post['media'], $post['id'], $post['privilege_id']); + } return true; } diff --git a/public/app/controllers/cli/CliContoller.php b/public/app/controllers/cli/CliContoller.php index 310e2ae..4549b50 100644 --- a/public/app/controllers/cli/CliContoller.php +++ b/public/app/controllers/cli/CliContoller.php @@ -4,9 +4,11 @@ namespace app\controllers\cli; /** CliContoller * - * Re-generate cashes of commonly used entities - * like: product categories and trendy products - * (proxy calls make use of PROXY_IGNORE_CACHE) + * A typical cli constoller; this one is used to + * re-generate cashes of commonly used entities + * with expensive queries like (ex:) categories; + * + * Proxy calls make use of PROXY_IGNORE_CACHE * * CliController calls Model methods who create * cashed data with the exact same arguments as @@ -14,8 +16,8 @@ namespace app\controllers\cli; * the Model::method(arguments) triplete creates * the same keys as via the web interface. * - * NOTE: Only Cli interface is allowed - * [if (php_sapi_name() != 'cli') return false;] + * NOTE: Only Cli interface is allowed¨ + * `if (php_sapi_name() != 'cli') return false;` * * The Cli-interfaced script can run manualy or * (most usual scenario) scheduled via a cron job @@ -37,12 +39,12 @@ class CliContoller if (php_sapi_name() != 'cli') return false; # PROXY call: - # MARKET \ ProductCategories_model::tree(): + # CMS \ Course_model::courses_struct(): # + Refresh Cache # -------------------------------------- echo textColor("Creating category_products tree Cache ... ", \NORMAL); $reply = proxy( - [\app\models\market\ProductCategories_model::class, 'tree'], + [\app\models\cms\Course_model::class, 'courses_struct'], [], \CACHE_ROOT_TTL, \PROXY_IGNORE_CACHE ); @@ -50,36 +52,4 @@ class CliContoller } - - public static function getProductCategories() - { - return \Registry::use('database')->runQuery( - "SELECT * FROM product_categories", - [] - ); - } - - - - /** (re-) cacheCategoryByUrl( url ) - * regenerate cache of a category_product - * by category's friendly url - * @param $url (string): the category's friendly url - */ - public static function cacheCategoryByUrl(string $url) - { - // Only Cli interface is allowed - if (php_sapi_name() != 'cli') return false; - - # PROXY call: - # MARKET \ ProductCategories_model::tree(): - # + Refresh Cache - # -------------------------------------- - $reply = proxy( - [\app\models\market\ProductCategories_model::class, 'categoryFromUrl'], - [ $url ], \CACHE_CATEGORY_TTL, - \PROXY_IGNORE_CACHE - ); - echo ($reply == false) ? textColor("Failed\n", \FAIL) : textColor("Done!\n", \SUCCESS); - } }
\ No newline at end of file diff --git a/public/app/controllers/cms/Course.php b/public/app/controllers/cms/Course.php index 7e53d3a..0edc832 100644 --- a/public/app/controllers/cms/Course.php +++ b/public/app/controllers/cms/Course.php @@ -21,7 +21,7 @@ class Course { * shortcut method for checking access authorization * * returns true if user belogns to the admin group - * or has the specified permition/privilege + * OR has the specified permition/privilege * * @param $privilege_id (int) * @@ -35,7 +35,7 @@ class Course { { return ( Auth::in_admin_group() - || Auth::has_Permition([ $privilege_id ]) + || Auth::hasPermition([ $privilege_id ]) ); } @@ -99,24 +99,32 @@ class Course { * ------------------------------------------------------------------------- */ + /** course + * prepare and render the course view + * + * @param $id : course id + */ + public static function course($id) + { + $id = intval($id); // course id - public static function course($id) - { + // collect all data needed for course view + // --- -- -- - - - $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); + $course_path[] = $id; + // then Render + // --- -- -- - - - Render::view('templates/course', [ 'id' => $id, 'title' => $breadcrumbs[ $id ]['rec']['label'], @@ -125,19 +133,73 @@ class Course { 'lessons' => $lessons, 'course_path' => $course_path ]); - } + } + /** LESSONS + * ------------------------------------------------------------------------ + */ + /** lesson + * + * check if user is authorized to view the content; + * if so, prepare and render the lesson view + * + * @param $id : lesson id + */ + public static function lesson($id) + { + $id = intval($id); // lesson id - /** LESSONS - * ------------------------------------------------------------------------ - */ + $lesson = Course_model::lesson($id); // get lesson + $course_id = $lesson['course_id']; // get course id + $pri_id = $lesson['privilege_id']; // privilege needed + if (self::is_admin_or_permited($pri_id)) { + // collect all data needed for course view + // --- -- -- - - - + $cache = Cache_service::courses_struct(); + $tree = $cache['tree']; + $breadcrumbs = $cache['breadcrumbs']; + + // find parent_ids of current category (to open the menu tree) + // --- + $course_path = []; + foreach($breadcrumbs[$course_id]['parents'] as $key => $parent) { + $course_path[] = intval($parent['id']); + } + $course_path[] = intval($course_id); + + // then Render + // --- -- -- - - - + Render::view('templates/lesson', [ + // main content + 'id' => $id, + 'course_id' => $course_id, + 'title' => $lesson['title'], + 'lesson' => $lesson, + // needed for side panel and breadcrunbs + 'categories' => $tree, + 'breadcrumbs' => $breadcrumbs, + 'course_path' => $course_path + ]); + + } else { // user is not authorized + Render::view('error/general', [ + 'title' => 'Δεν έχετε πρόσβαση', + 'message' => 'Θα πρέπει να αγοράσετε το πακέτο πρόσβασης ' + . $pri_id + .' για να δείτε το περιεχόμενο! + <br><br> + Αγόρασε τώρα το <button class="btn">πακέτο πρόσβασης '. $pri_id .'</button>' + ]); + } + + } |
