summaryrefslogtreecommitdiff
path: root/public/app/controllers/cms
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-04-25 16:45:03 +0300
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-04-25 16:45:03 +0300
commitb594effb847b86fc6b1dae49d7948c46bba35e58 (patch)
tree8c5a090cf8746870521324797762bb0ff14c8ae5 /public/app/controllers/cms
parent65d07ba64d45c77d2db16272710ec5702b34d641 (diff)
downloadclassroom-b594effb847b86fc6b1dae49d7948c46bba35e58.tar.gz
classroom-b594effb847b86fc6b1dae49d7948c46bba35e58.tar.bz2
classroom-b594effb847b86fc6b1dae49d7948c46bba35e58.zip
alfa version; uploaded into test server (coder)
Diffstat (limited to 'public/app/controllers/cms')
-rw-r--r--public/app/controllers/cms/Course.php86
1 files changed, 74 insertions, 12 deletions
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>'
+ ]);
+ }
+
+ }