/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');
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
14
			$this->load->model('stats');
85.1.8 by a11andoh
added the cms controller to load all content pages.
15
		}
90.1.10 by a11emmjo
Removed coursemenu and statsmenu and replaced it with new combined sidemenu.
16
		
17
		/*
85.1.8 by a11andoh
added the cms controller to load all content pages.
18
		 *	This function runs when the user navigates directly to this controller
19
		 */
20
		public function index() {
21
			if($this->user->isLoggedIn()) {
22
				//User already logged in
23
				$this->drawCmsPage('');
24
			} else {
25
				//Display the start page
26
				redirect(base_url().'home', 'refresh');
27
			}
28
		}		
29
		
30
		/*
31
		 *	This function draws the cms page.
32
		 */
33
		private function drawCmsPage() {
34
			$userName = $this->user->getUserName();
35
			$userType = $this->user->getUserType();
36
			$activeCourse = $this->user->getActiveCourse();
83.2.22 by elof.bigestans at gmail
* Moved login JS to bannermenu.js and removed login.js
37
38
			if($userName != "" && $userType == "Teacher") {
39
				//Creates an array with all courses.
40
				$courses = $this->admin_model->getCourses();
41
			} elseif($userName != "" && $userType == "Student") {
42
				$courses = $this->admin_model->getStudentCourses($userName);
43
			} else {
44
				$courses = $this->admin_model->getPublicCourses();
45
			}
46
47
90.1.10 by a11emmjo
Removed coursemenu and statsmenu and replaced it with new combined sidemenu.
48
			//Creates an array with all categories for active course
49
			$categories = $this->admin_model->getCategories($activeCourse['courseID']);
50
			
85.1.8 by a11andoh
added the cms controller to load all content pages.
51
			//Creates an array with the variables that the bannermenu-view is expecting.
52
			$data = array(
53
				'userType' => $userType,
54
				'userName' => $userName,
55
				'courses' => $courses,
56
				'categories' => $categories,
57
				'activeCourse' => $activeCourse
58
			);
59
			
90.1.13 by a11emmjo
Changed so that cms-controller loads filetree (before known as examplesController, examplesBody, examplesMenu).
60
			//Creates an array with the variables that the cmsindex-view is expecting.
61
			$filetree = array();
62
			
63
			//Categories
64
			$categories = $this->filetree->getCategories($data['activeCourse']['courseID']);
65
			foreach ($categories as $category) {
66
				$filetree[$category->categoryName] = array();
67
				
68
				//Sub categories
69
				$subcategories = $this->filetree->getSubCategories($category->categoryName, $data['activeCourse']['courseID']);
70
				foreach ($subcategories as $subcategory) {
71
					$filetree[$category->categoryName][$subcategory->subCategoryName] = array();
72
					
73
					//Examples
74
					$filetree[$category->categoryName][$subcategory->subCategoryName]['examples'] = array();
75
					$examples = $this->filetree->getExamples($subcategory->subCategoryName, $category->categoryName, $data['activeCourse']['courseID']);
76
					foreach ($examples as $example) {
77
						$filetree[$category->categoryName][$subcategory->subCategoryName]['examples'][] = $example->exampleName;
78
					}
79
					
80
					//Quizzes
81
					$filetree[$category->categoryName][$subcategory->subCategoryName]['quizzes'] = array();
82
					$quizzes = $this->filetree->getQuizzes($subcategory->subCategoryName, $category->categoryName, $data['activeCourse']['courseID']);
83
					foreach ($quizzes as $quiz) {
84
						$filetree[$category->categoryName][$subcategory->subCategoryName]['quizzes'][] = $quiz->quizNr;
85
					}
86
				}
87
			}
88
			
85.1.8 by a11andoh
added the cms controller to load all content pages.
89
			//Creates an array with the necessary css- and jsfiles needed for the views that are about to be shown.
90
			$headTagData = array(
90.1.13 by a11emmjo
Changed so that cms-controller loads filetree (before known as examplesController, examplesBody, examplesMenu).
91
				'cssFiles' => array('bannermenu', 'sidemenu', 'cmsindex'),
124.1.1 by Erik Wikström
Added display of statistics in the sidepane
92
				'jsFiles' => array('bannermenu', 'sidemenu')
93
			);
94
			
95
			$stats = array(
96
				'system' => $this->stats->getSystemStats(),
97
				'course' => $this->stats->getCourseStats($data['activeCourse']['courseID']),
98
				'user' => $this->stats->getUserStats()
99
			);
100
			$data['stats'] = $stats;
85.1.8 by a11andoh
added the cms controller to load all content pages.
101
			
102
			//Puts the array above in <head></head>
103
			$this->load->view('headTag', array('headTagData' => $headTagData));	
104
			
105
			$this->load->view('bannermenu', $data);
90.1.10 by a11emmjo
Removed coursemenu and statsmenu and replaced it with new combined sidemenu.
106
			$this->load->view('sidemenu', $data);
90.1.13 by a11emmjo
Changed so that cms-controller loads filetree (before known as examplesController, examplesBody, examplesMenu).
107
			$this->load->view('cmsindex', array('filetree' => $filetree));
85.1.8 by a11andoh
added the cms controller to load all content pages.
108
		}
109
	}
110
?>