1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cms extends CI_Controller {
/*
* Constructor
*/
function __construct() {
parent::__construct();
//Load required library
$this->load->model('user', '', TRUE);
$this->load->model('admin/admin_model', '', TRUE);
$this->load->model('filetree');
}
/*
*Temporary function to be able to be logged in to reach the page
*/
public function tempLogin() {
$this->load->model('user');
$loginDetails = array(
'username' => 'tempTeacher',
'name' => 'tempFoo',
'usertype' => 'Teacher',
'ssn' => '0000',
'activeCourse' => 'DA525G');
$this->session->set_userdata('authenticated', $loginDetails);
redirect(base_url().'cms', 'refresh');
}
public function tempLogout() {
$this->load->model('user');
$this->session->unset_userdata('authenticated');
redirect(base_url().'home', 'refresh');
}
/*
* This function runs when the user navigates directly to this controller
*/
public function index() {
if($this->user->isLoggedIn()) {
//User already logged in
$this->drawCmsPage('');
} else {
//Display the start page
redirect(base_url().'home', 'refresh');
}
}
public function test(){
$result = $this->admin_model->getStudentCourses("student");
foreach($result as $res) {
echo $res->courseID. ' - ';
echo $res->name;
echo "<br>";
}
//var_dump($result);
}
/*
* This function draws the cms page.
*/
private function drawCmsPage() {
$userName = $this->user->getUserName();
$userType = $this->user->getUserType();
$activeCourse = $this->user->getActiveCourse();
if($userName != "" && $userType == "Teacher") {
//Creates an array with all courses.
$courses = $this->admin_model->getCourses();
} elseif($userName != "" && $userType == "Student") {
$courses = $this->admin_model->getStudentCourses($userName);
} else {
$courses = $this->admin_model->getPublicCourses();
}
//Creates an array with all categories for active course
$categories = $this->admin_model->getCategories($activeCourse['courseID']);
//Creates an array with the variables that the bannermenu-view is expecting.
$data = array(
'userType' => $userType,
'userName' => $userName,
'courses' => $courses,
'categories' => $categories,
'activeCourse' => $activeCourse
);
//Creates an array with the variables that the cmsindex-view is expecting.
$filetree = array();
//Categories
$categories = $this->filetree->getCategories($data['activeCourse']['courseID']);
foreach ($categories as $category) {
$filetree[$category->categoryName] = array();
//Sub categories
$subcategories = $this->filetree->getSubCategories($category->categoryName, $data['activeCourse']['courseID']);
foreach ($subcategories as $subcategory) {
$filetree[$category->categoryName][$subcategory->subCategoryName] = array();
//Examples
$filetree[$category->categoryName][$subcategory->subCategoryName]['examples'] = array();
$examples = $this->filetree->getExamples($subcategory->subCategoryName, $category->categoryName, $data['activeCourse']['courseID']);
foreach ($examples as $example) {
$filetree[$category->categoryName][$subcategory->subCategoryName]['examples'][] = $example->exampleName;
}
//Quizzes
$filetree[$category->categoryName][$subcategory->subCategoryName]['quizzes'] = array();
$quizzes = $this->filetree->getQuizzes($subcategory->subCategoryName, $category->categoryName, $data['activeCourse']['courseID']);
foreach ($quizzes as $quiz) {
$filetree[$category->categoryName][$subcategory->subCategoryName]['quizzes'][] = $quiz->quizNr;
}
}
}
//Creates an array with the necessary css- and jsfiles needed for the views that are about to be shown.
$headTagData = array(
'cssFiles' => array('bannermenu', 'sidemenu', 'cmsindex'),
'jsFiles' => array('bannermenu')
);
//Puts the array above in <head></head>
$this->load->view('headTag', array('headTagData' => $headTagData));
$this->load->view('bannermenu', $data);
$this->load->view('sidemenu', $data);
$this->load->view('cmsindex', array('filetree' => $filetree));
}
}
?>
|