bzr branch
http://gegoxaren.bato24.eu/bzr/lenasys/trunk
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
1 |
<?php
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
2 |
/**
|
3 |
* This is a model. It holds the logic.
|
|
4 |
* It's loaded like this in the controllers: $this->load->model("path/to/model");
|
|
5 |
* This specific model is: $this->load->model("admin/admin_model")
|
|
6 |
*
|
|
7 |
* This model is the logic behind the admin panel. It let's you manage courses, pages etc
|
|
8 |
*/
|
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
9 |
class Admin_model extends CI_Model { |
10 |
||
11 |
function __construct() { |
|
12 |
$this->load->database(); |
|
13 |
}
|
|
14 |
||
15 |
function getCourses() { |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
16 |
$query = $this->db->get('Courses'); |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
17 |
return $query->result(); |
18 |
}
|
|
19 |
||
20 |
function addCourse($cid, $name){ |
|
21 |
$data = array( |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
22 |
'courseID' => $cid , |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
23 |
'name' => $name |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
24 |
);
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
25 |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
26 |
$this->db->insert('Courses', $data); |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
27 |
mkdir("../courses/".$cid); |
28 |
||
29 |
}
|
|
30 |
||
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
31 |
function getMenu(){ |
32 |
$menu = array(); |
|
|
55.1.1
by Gustav Hartvigsson
fixed bug bug #1176808 |
33 |
$courses = $this->db->get("Courses"); |
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
34 |
foreach ($courses->result() as $course) { |
35 |
$menu[$course->name] = array(); |
|
36 |
$menu[$course->name]['CID'] = $course->courseID; |
|
|
55.1.1
by Gustav Hartvigsson
fixed bug bug #1176808 |
37 |
$categories = $this->db->get_where("Categories", array("courseID" => $course->courseID)); |
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
38 |
|
39 |
foreach($categories->result() as $category){ |
|
40 |
$menu[$course->name][$category->categoryName] = array(); |
|
41 |
||
|
55.1.1
by Gustav Hartvigsson
fixed bug bug #1176808 |
42 |
$subcategories = $this->db->get_where("SubCategories", array("courseID" => $course->courseID, "categoryName" => $category->categoryName)); |
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
43 |
|
44 |
foreach($subcategories->result() as $subcategory){ |
|
45 |
$menu[$course->name][$category->categoryName][$subcategory->subCategoryName] = array(); |
|
46 |
||
47 |
}
|
|
48 |
}
|
|
49 |
}
|
|
50 |
||
51 |
return $menu; |
|
52 |
||
53 |
}
|
|
54 |
||
55 |
function getCategories($cid) { |
|
56 |
$query = $this->db->get_where('Categories', array("courseID" => $cid)); |
|
57 |
return $query->result(); |
|
58 |
}
|
|
59 |
||
60 |
function addCategory($cid, $categoryName){ |
|
61 |
$this->db->select_max("orderNr"); |
|
62 |
$query = $this->db->get_where('Categories', array("courseID" => $cid)); |
|
63 |
||
64 |
$result = $query->result(); |
|
65 |
$data = array( |
|
66 |
'courseID' => $cid , |
|
67 |
'categoryName' => $categoryName, |
|
68 |
'orderNr' => $result[0]->orderNr+1 |
|
69 |
);
|
|
70 |
||
71 |
$this->db->insert('Categories', $data); |
|
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
72 |
mkdir("../courses/".$cid."/".$categoryName); |
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
73 |
|
74 |
}
|
|
75 |
||
76 |
function getSubCategories($cid, $categoryName) { |
|
|
55.1.2
by Gustav Hartvigsson
fixed some more things. |
77 |
$query = $this->db->get_where('SubCategories', array("courseID" => $cid, "categoryName" => $categoryName)); |
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
78 |
return $query->result(); |
79 |
}
|
|
80 |
||
81 |
function addSubCategory($cid, $categoryName, $subCategoryName){ |
|
82 |
$this->db->select_max("orderNr"); |
|
|
55.1.2
by Gustav Hartvigsson
fixed some more things. |
83 |
$query = $this->db->get_where('SubCategories', array("courseID" => $cid, "categoryName" => $categoryName)); |
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
84 |
|
85 |
$result = $query->result(); |
|
86 |
$data = array( |
|
87 |
'courseID' => $cid , |
|
88 |
'subCategoryName' => $subCategoryName, |
|
89 |
'categoryName' => $categoryName, |
|
90 |
'orderNr' => $result[0]->orderNr+1 |
|
91 |
);
|
|
92 |
||
|
55.1.2
by Gustav Hartvigsson
fixed some more things. |
93 |
$this->db->insert('SubCategories', $data); |
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
94 |
mkdir("../courses/".$cid."/".$categoryName."/".$subCategoryName); |
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
95 |
|
96 |
}
|
|
97 |
||
98 |
function getExamples($cid, $categoryName, $subCategoryName) { |
|
99 |
$query = $this->db->get_where('Examples', array("courseID" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName)); |
|
100 |
return $query->result(); |
|
101 |
}
|
|
102 |
||
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
103 |
function getQuizzes($cid, $categoryName, $subCategoryName) { |
104 |
$query = $this->db->get_where('Quizzes', array("courseID" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName)); |
|
105 |
return $query->result(); |
|
106 |
}
|
|
107 |
||
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
108 |
function addExample($cid, $categoryName, $subCategoryName, $example, $description){ |
109 |
$this->db->select_max("orderNr"); |
|
|
55.1.2
by Gustav Hartvigsson
fixed some more things. |
110 |
$query = $this->db->get_where('Examples', array("courseID" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName)); |
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
111 |
$result = $query->result(); |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
112 |
$data = array( |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
113 |
'courseID' => $cid , |
114 |
'exampleName' => $example, |
|
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
115 |
'description' => $description, |
116 |
'categoryName' => $categoryName, |
|
117 |
'subCategoryName' => $subCategoryName, |
|
118 |
'orderNr' => $result[0]->orderNr+1 |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
119 |
);
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
120 |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
121 |
$this->db->insert('Examples', $data); |
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
122 |
|
123 |
$data = array( |
|
124 |
'fileName' => $cid."/".$categoryName."/".$subCategoryName."/".$example."/documentation", |
|
125 |
'codeLanguage' => "text", |
|
126 |
'fileType' => "text", |
|
127 |
'dataBlob' => "" |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
128 |
);
|
129 |
||
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
130 |
$this->db->insert('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
131 |
|
132 |
$data = array( |
|
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
133 |
'fileName' => $cid."/".$categoryName."/".$subCategoryName."/".$example."/documentation", |
134 |
'categoryName' => $categoryName, |
|
135 |
'subCategoryName' => $subCategoryName, |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
136 |
'exampleName' => $example, |
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
137 |
'courseID' => $cid, |
138 |
'columnNr' => 1, |
|
139 |
'orderNr' => 1 |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
140 |
);
|
141 |
||
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
142 |
$this->db->insert('Containers', $data); |
143 |
mkdir("../courses/".$cid."/".$categoryName."/".$subCategoryName."/".$example); |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
144 |
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
145 |
}
|
146 |
||
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
147 |
function updateExample($cid, $categoryName, $subCategoryName, $example, $documentation, $files){ |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
148 |
|
149 |
$filearr = json_decode($files); |
|
150 |
||
151 |
foreach ($filearr as $file) { |
|
152 |
$output = ""; |
|
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
153 |
$handle = @fopen("../courses/".$cid."/".$categoryName."/".$subCategoryName."/".$example."/".$file->filename, "r"); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
154 |
if ($handle) { |
155 |
||
156 |
while (($buffer = fgets($handle, 4096)) !== false) { |
|
157 |
||
158 |
$buffer = str_replace("&", "&", $buffer); |
|
159 |
$buffer = str_replace("<", "<", $buffer); |
|
160 |
$buffer = str_replace(">", ">", $buffer); |
|
161 |
||
162 |
$output .= $buffer; |
|
163 |
}
|
|
164 |
if (!feof($handle)) { |
|
165 |
$output .= "Error: unexpected fgets() fail\n"; |
|
166 |
}
|
|
167 |
fclose($handle); |
|
168 |
}
|
|
169 |
||
170 |
$data = array( |
|
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
171 |
'fileName' => $cid."/".$categoryName."/".$subCategoryName."/".$example."/".$file->filename , |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
172 |
'codeLanguage' => $file->lang, |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
173 |
'fileType' => $file->type, |
174 |
'dataBlob' => $output |
|
175 |
);
|
|
176 |
||
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
177 |
$this->db->insert('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
178 |
|
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
179 |
$this->db->select_max("orderNr"); |
|
55.1.2
by Gustav Hartvigsson
fixed some more things. |
180 |
$query = $this->db->get_where('Containers', array("courseID" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName, "exampleName" => $example, "columnNr" => $file->columnNr)); |
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
181 |
$result = $query->result(); |
182 |
||
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
183 |
$data = array( |
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
184 |
'fileName' => $cid."/".$categoryName."/".$subCategoryName."/".$example."/".$file->filename , |
185 |
'categoryName' => $categoryName, |
|
186 |
'subCategoryName' => $subCategoryName, |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
187 |
'exampleName' => $example, |
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
188 |
'courseID' => $cid, |
189 |
'columnNr' => $file->columnNr, |
|
190 |
'orderNr' => $result[0]->orderNr+1 |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
191 |
);
|
192 |
||
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
193 |
$this->db->insert('Containers', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
194 |
}
|
195 |
||
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
196 |
$data = array( |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
197 |
'dataBlob' => $documentation |
198 |
);
|
|
199 |
||
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
200 |
$this->db->where("fileName",$cid."/".$categoryName."/".$subCategoryName."/".$example."/documentation"); |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
201 |
$this->db->update('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
202 |
|
203 |
||
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
204 |
}
|
205 |
||
|
53.1.1
by galaxyAbstractor
fixed adminpanel and codeviewer a bit |
206 |
function uploadFile($files, $cid, $categoryName, $subCategoryName, $example){ |
207 |
if(move_uploaded_file($files['tmp_name'], "../courses/".$cid."/".$categoryName."/".$subCategoryName."/".$example."/".$files['name'])){ |
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
208 |
echo json_encode(array('status'=>'File was uploaded successfuly!')); |
209 |
}
|
|
210 |
}
|
|
211 |
}
|