/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/application/controllers/cms.php

  • Committer: Gustav Hatvigsson
  • Date: 2013-05-30 08:51:07 UTC
  • mfrom: (85.1.24 lenasys)
  • Revision ID: gustav.hartvigsson@gmail.com-20130530085107-jxb6v4mgj35om70n
merged Ohlson:s changes:

updated branch
modified the sidemenu to not display full name if overflowing

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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);
 
13
                        $this->load->model('filetree');
 
14
                        $this->load->model('stats');
 
15
                }
 
16
                
 
17
                /*
 
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();
 
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
 
 
48
                        //Creates an array with all categories for active course
 
49
                        $categories = $this->admin_model->getCategories($activeCourse['courseID']);
 
50
                        
 
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
                        
 
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
                        
 
89
                        //Creates an array with the necessary css- and jsfiles needed for the views that are about to be shown.
 
90
                        $headTagData = array(
 
91
                                'cssFiles' => array('bannermenu', 'sidemenu', 'cmsindex'),
 
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;
 
101
                        
 
102
                        //Puts the array above in <head></head>
 
103
                        $this->load->view('headTag', array('headTagData' => $headTagData));     
 
104
                        
 
105
                        $this->load->view('bannermenu', $data);
 
106
                        $this->load->view('sidemenu', $data);
 
107
                        $this->load->view('cmsindex', array('filetree' => $filetree));
 
108
                }
 
109
        }
 
110
?>