/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
85.1.8 by a11andoh
added the cms controller to load all content pages.
1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3
	class Cms extends CI_Controller {
4
	
5
		/*
6
		 *	Constructor
7
		 */
8
		function __construct() {
9
			parent::__construct();
10
			//Load required library
11
			$this->load->model('user', '', TRUE);
12
			$this->load->model('admin/admin_model', '', TRUE);
90.1.13 by a11emmjo
Changed so that cms-controller loads filetree (before known as examplesController, examplesBody, examplesMenu).
13
			$this->load->model('filetree');
85.1.8 by a11andoh
added the cms controller to load all content pages.
14
		}
90.1.10 by a11emmjo
Removed coursemenu and statsmenu and replaced it with new combined sidemenu.
15
		
16
		/*
85.1.8 by a11andoh
added the cms controller to load all content pages.
17
		 *	This function runs when the user navigates directly to this controller
18
		 */
19
		public function index() {
20
			if($this->user->isLoggedIn()) {
21
				//User already logged in
22
				$this->drawCmsPage('');
23
			} else {
24
				//Display the start page
25
				redirect(base_url().'home', 'refresh');
26
			}
27
		}		
28
		
29
		/*
30
		 *	This function draws the cms page.
31
		 */
32
		private function drawCmsPage() {
33
			$userName = $this->user->getUserName();
34
			$userType = $this->user->getUserType();
35
			$activeCourse = $this->user->getActiveCourse();
83.2.22 by elof.bigestans at gmail
* Moved login JS to bannermenu.js and removed login.js
36
37
			if($userName != "" && $userType == "Teacher") {
38
				//Creates an array with all courses.
39
				$courses = $this->admin_model->getCourses();
40
			} elseif($userName != "" && $userType == "Student") {
41
				$courses = $this->admin_model->getStudentCourses($userName);
42
			} else {
43
				$courses = $this->admin_model->getPublicCourses();
44
			}
45
46
90.1.10 by a11emmjo
Removed coursemenu and statsmenu and replaced it with new combined sidemenu.
47
			//Creates an array with all categories for active course
48
			$categories = $this->admin_model->getCategories($activeCourse['courseID']);
49
			
85.1.8 by a11andoh
added the cms controller to load all content pages.
50
			//Creates an array with the variables that the bannermenu-view is expecting.
51
			$data = array(
52
				'userType' => $userType,
53
				'userName' => $userName,
54
				'courses' => $courses,
55
				'categories' => $categories,
56
				'activeCourse' => $activeCourse
57
			);
58
			
90.1.13 by a11emmjo
Changed so that cms-controller loads filetree (before known as examplesController, examplesBody, examplesMenu).
59
			//Creates an array with the variables that the cmsindex-view is expecting.
60
			$filetree = array();
61
			
62
			//Categories
63
			$categories = $this->filetree->getCategories($data['activeCourse']['courseID']);
64
			foreach ($categories as $category) {
65
				$filetree[$category->categoryName] = array();
66
				
67
				//Sub categories
68
				$subcategories = $this->filetree->getSubCategories($category->categoryName, $data['activeCourse']['courseID']);
69
				foreach ($subcategories as $subcategory) {
70
					$filetree[$category->categoryName][$subcategory->subCategoryName] = array();
71
					
72
					//Examples
73
					$filetree[$category->categoryName][$subcategory->subCategoryName]['examples'] = array();
74
					$examples = $this->filetree->getExamples($subcategory->subCategoryName, $category->categoryName, $data['activeCourse']['courseID']);
75
					foreach ($examples as $example) {
76
						$filetree[$category->categoryName][$subcategory->subCategoryName]['examples'][] = $example->exampleName;
77
					}
78
					
79
					//Quizzes
80
					$filetree[$category->categoryName][$subcategory->subCategoryName]['quizzes'] = array();
81
					$quizzes = $this->filetree->getQuizzes($subcategory->subCategoryName, $category->categoryName, $data['activeCourse']['courseID']);
82
					foreach ($quizzes as $quiz) {
83
						$filetree[$category->categoryName][$subcategory->subCategoryName]['quizzes'][] = $quiz->quizNr;
84
					}
85
				}
86
			}
87
			
85.1.8 by a11andoh
added the cms controller to load all content pages.
88
			//Creates an array with the necessary css- and jsfiles needed for the views that are about to be shown.
89
			$headTagData = array(
90.1.13 by a11emmjo
Changed so that cms-controller loads filetree (before known as examplesController, examplesBody, examplesMenu).
90
				'cssFiles' => array('bannermenu', 'sidemenu', 'cmsindex'),
85.1.8 by a11andoh
added the cms controller to load all content pages.
91
				'jsFiles' => array('bannermenu')
92
			);
93
			
94
			//Puts the array above in <head></head>
95
			$this->load->view('headTag', array('headTagData' => $headTagData));	
96
			
97
			$this->load->view('bannermenu', $data);
90.1.10 by a11emmjo
Removed coursemenu and statsmenu and replaced it with new combined sidemenu.
98
			$this->load->view('sidemenu', $data);
90.1.13 by a11emmjo
Changed so that cms-controller loads filetree (before known as examplesController, examplesBody, examplesMenu).
99
			$this->load->view('cmsindex', array('filetree' => $filetree));
85.1.8 by a11andoh
added the cms controller to load all content pages.
100
		}
101
	}
102
?>