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
|
<?php
/**
* This is a controller. It links the views related to the codeviewer together with the model, which holds
* the logic.
*
* Function names equals path. Example: codeviewer/show in the url calls the function show in the controller
* codeviewer (this file below).
*
* The params after the url equals the input arguments of the function. Function show() has 3 arguments
* and therefore requires 3 arguments to be given in the url, like so: codeviewer/show/courseid/exampleid/pageid
*/
class Codeviewer extends CI_Controller {
/*Temporarily redirects the user to the startpage*/
public function index(){
redirect('/');
}
/**
* This shows the codeviewer page
*/
public function show($cid = null, $category = null, $subcategory = null, $example = null){
if(!is_null($cid) && !is_null($category) && !is_null($subcategory) && !is_null($example)){
$headTagData['cssFiles'] = array('headTag', 'header', 'codeviewer');
$headTagData['jsFiles'] = array('ace/ace', 'header');
$this->load->model('codeviewer/Codeviewer_model');
$this->load->model('user', '', TRUE);
$this->load->model('admin/admin_model', '', TRUE);
$editorHTML = $this->Codeviewer_model->getCode($cid, $category, $subcategory, $example);
$activeCourse = $this->user->getActiveCourse();
$userInfo = array(
'userType' => $this->user->getUserType(),
'userName' => $this->user->getUserName(),
'courses' => $this->admin_model->getCourses(),
'categories' => $this->admin_model->getCategories($activeCourse['courseID']),
'activeCourse' => $activeCourse
);
$this->load->helper('form');
/* $doc = $this->Codeviewer_model->getDoc($cid, $category, $subcategory, $example);
* This loads the view. It's stored in application/views/codeviewer/codeviewer.php
* Do note that application/views should not be in the first argument of view()
* The second argument is data to be shown in the view. "editors" => "test" would
* generate an $editors variable in the view containing "test"
*/
$this->load->view('headTag', array('headTagData' => $headTagData));
$this->load->view('bannermenu', $userInfo);
$this->load->view('codeviewer/codeviewer', array("editors" => $editorHTML));
} else {
/*Redirects to the startpage if no arguments are supplied.*/
redirect('/');
}
}
}
|