/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: a11emmjo
  • Date: 2013-05-28 08:51:26 UTC
  • mto: This revision was merged to the branch mainline in revision 110.
  • Revision ID: a11emmjo@student.his.se-20130528085126-16sx38szwbsx1coh
Changed so that cms-controller loads filetree (before known as examplesController, examplesBody, examplesMenu).

Also changed to describing filenames and names for attributes and functions in css, php-view and in model that is used for this.

Started working on cmsindex-view and -css.

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
                }
 
15
                
 
16
                /*
 
17
                 *Temporary function to be able to be logged in to reach the page
 
18
                 */
 
19
                public function tempLogin() {
 
20
                        $this->load->model('user');
 
21
                        $loginDetails = array(
 
22
                        'username' => 'tempTeacher',
 
23
                        'name' => 'tempFoo',
 
24
                        'usertype' => 'Teacher',
 
25
                        'ssn' => '0000',
 
26
                        'activeCourse' => 'DA525G');
 
27
                        $this->session->set_userdata('authenticated', $loginDetails);
 
28
                        redirect(base_url().'cms', 'refresh');
 
29
                }
 
30
                public function tempLogout() {
 
31
                        $this->load->model('user');
 
32
                        $this->session->unset_userdata('authenticated');
 
33
                        redirect(base_url().'home', 'refresh');
 
34
                }
 
35
                
 
36
                /*
 
37
                 *      This function runs when the user navigates directly to this controller
 
38
                 */
 
39
                public function index() {
 
40
                        if($this->user->isLoggedIn()) {
 
41
                                //User already logged in
 
42
                                $this->drawCmsPage('');
 
43
                        } else {
 
44
                                //Display the start page
 
45
                                redirect(base_url().'home', 'refresh');
 
46
                        }
 
47
                }               
 
48
                
 
49
                /*
 
50
                 *      This function draws the cms page.
 
51
                 */
 
52
                private function drawCmsPage() {
 
53
                        $userName = $this->user->getUserName();
 
54
                        $userType = $this->user->getUserType();
 
55
                        $activeCourse = $this->user->getActiveCourse();
 
56
                        //Creates an array with all courses.
 
57
                        $courses = $this->admin_model->getCourses();
 
58
                        //Creates an array with all categories for active course
 
59
                        $categories = $this->admin_model->getCategories($activeCourse['courseID']);
 
60
                        
 
61
                        //Creates an array with the variables that the bannermenu-view is expecting.
 
62
                        $data = array(
 
63
                                'userType' => $userType,
 
64
                                'userName' => $userName,
 
65
                                'courses' => $courses,
 
66
                                'categories' => $categories,
 
67
                                'activeCourse' => $activeCourse
 
68
                        );
 
69
                        
 
70
                        //Creates an array with the variables that the cmsindex-view is expecting.
 
71
                        $filetree = array();
 
72
                        
 
73
                        //Categories
 
74
                        $categories = $this->filetree->getCategories($data['activeCourse']['courseID']);
 
75
                        foreach ($categories as $category) {
 
76
                                $filetree[$category->categoryName] = array();
 
77
                                
 
78
                                //Sub categories
 
79
                                $subcategories = $this->filetree->getSubCategories($category->categoryName, $data['activeCourse']['courseID']);
 
80
                                foreach ($subcategories as $subcategory) {
 
81
                                        $filetree[$category->categoryName][$subcategory->subCategoryName] = array();
 
82
                                        
 
83
                                        //Examples
 
84
                                        $filetree[$category->categoryName][$subcategory->subCategoryName]['examples'] = array();
 
85
                                        $examples = $this->filetree->getExamples($subcategory->subCategoryName, $category->categoryName, $data['activeCourse']['courseID']);
 
86
                                        foreach ($examples as $example) {
 
87
                                                $filetree[$category->categoryName][$subcategory->subCategoryName]['examples'][] = $example->exampleName;
 
88
                                        }
 
89
                                        
 
90
                                        //Quizzes
 
91
                                        $filetree[$category->categoryName][$subcategory->subCategoryName]['quizzes'] = array();
 
92
                                        $quizzes = $this->filetree->getQuizzes($subcategory->subCategoryName, $category->categoryName, $data['activeCourse']['courseID']);
 
93
                                        foreach ($quizzes as $quiz) {
 
94
                                                $filetree[$category->categoryName][$subcategory->subCategoryName]['quizzes'][] = $quiz->quizNr;
 
95
                                        }
 
96
                                }
 
97
                        }
 
98
                        
 
99
                        //Creates an array with the necessary css- and jsfiles needed for the views that are about to be shown.
 
100
                        $headTagData = array(
 
101
                                'cssFiles' => array('bannermenu', 'sidemenu', 'cmsindex'),
 
102
                                'jsFiles' => array('bannermenu')
 
103
                        );
 
104
                        
 
105
                        //Puts the array above in <head></head>
 
106
                        $this->load->view('headTag', array('headTagData' => $headTagData));     
 
107
                        
 
108
                        $this->load->view('bannermenu', $data);
 
109
                        $this->load->view('sidemenu', $data);
 
110
                        $this->load->view('cmsindex', array('filetree' => $filetree));
 
111
                }
 
112
        }
 
113
?>