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 |
||
|
109.1.2
by c11emian
Added the functions getPublicCourses(), getPrivateCourses() and getStudentCourses(). |
15 |
/* Get all of the courses */
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
16 |
function getCourses() { |
|
85.1.1
by a11andoh
Added line for coursename sorting in getCourses function |
17 |
$this->db->order_by("name", "asc"); |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
18 |
$query = $this->db->get('Courses'); |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
19 |
return $query->result(); |
20 |
}
|
|
|
109.1.2
by c11emian
Added the functions getPublicCourses(), getPrivateCourses() and getStudentCourses(). |
21 |
|
22 |
/* Get all the public courses */
|
|
23 |
function getPublicCourses() { |
|
24 |
$this->db->from("Courses"); |
|
25 |
$this->db->where("isHidden","0"); |
|
26 |
$this->db->where("isPublic","1"); |
|
27 |
$query = $this->db->get(); |
|
28 |
return $query->result(); |
|
29 |
}
|
|
30 |
||
31 |
/* Get all the private courses for a student - If they are published and private*/
|
|
32 |
function getPrivateCourses($studentID) { |
|
33 |
$this->db->from("Courses"); |
|
34 |
$this->db->join("StudentCourseRegistrations", "Courses.courseID = StudentCourseRegistrations.courseID"); |
|
35 |
$this->db->where("userName", $studentID); |
|
36 |
$this->db->where("isPublic", "0"); |
|
37 |
$this->db->where("isHidden","0"); |
|
38 |
$query = $this->db->get(); |
|
39 |
return $query->result(); |
|
40 |
}
|
|
41 |
||
42 |
/* Get all the courses for a student, both private from getPrivateCourses(), and public from getPublicCourses() */
|
|
43 |
function getStudentCourses($studentID) { |
|
44 |
$private = $this->getPrivateCourses($studentID); |
|
45 |
$public = $this->getPublicCourses(); |
|
46 |
return array_merge($private, $public); |
|
47 |
}
|
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
48 |
|
|
83.2.5
by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller. |
49 |
function setCourseHidden($courseID) { |
|
83.2.3
by elof.bigestans at gmail
Working on functionality for managecourses |
50 |
$this->db->where("courseID", $courseID); |
|
83.2.5
by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller. |
51 |
$this->db->update("Courses", array("isHidden" => 1)); |
|
83.2.3
by elof.bigestans at gmail
Working on functionality for managecourses |
52 |
}
|
53 |
||
|
83.2.5
by elof.bigestans at gmail
* Updated ManageCourses, including JS+Jquery, popups, controller. |
54 |
function unsetCourseHidden($courseID){ |
|
83.2.3
by elof.bigestans at gmail
Working on functionality for managecourses |
55 |
$this->db->where("courseID", $courseID); |
56 |
$this->db->update("Courses", array("isHidden" => 0)); |
|
57 |
}
|
|
58 |
||
|
79.1.1
by a10rolch
- Updated admin_model function addCourse to also include courseData. |
59 |
function addCourse($cid, $name, $courseData){ |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
60 |
$data = array( |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
61 |
'courseID' => $cid , |
|
79.1.1
by a10rolch
- Updated admin_model function addCourse to also include courseData. |
62 |
'name' => $name, |
63 |
'courseData' => $courseData |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
64 |
);
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
65 |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
66 |
$this->db->insert('Courses', $data); |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
67 |
mkdir("../courses/".$cid); |
68 |
||
69 |
}
|
|
70 |
||
|
83.2.1
by elof.bigestans at gmail
Fixed various bugs in the ManageCourses function |
71 |
function editCourse($cid, $name, $courseData) { |
72 |
$data = array( |
|
73 |
'name' => $name, |
|
74 |
'courseData' => $courseData |
|
75 |
);
|
|
76 |
||
77 |
$this->db->where('courseID', $cid); |
|
78 |
$this->db->update('Courses', $data); |
|
79 |
}
|
|
80 |
||
|
69.2.1
by galaxyAbstractor
Replaced admin model |
81 |
function getMenu(){ |
82 |
$menu = array(); |
|
83 |
$courses = $this->db->get("Courses"); |
|
84 |
foreach ($courses->result() as $course) { |
|
85 |
$menu[$course->name] = array(); |
|
86 |
$menu[$course->name]['CID'] = $course->courseID; |
|
87 |
$categories = $this->db->get_where("Categories", array("courseID" => $course->courseID)); |
|
88 |
||
89 |
foreach($categories->result() as $category){ |
|
90 |
$menu[$course->name][$category->categoryName] = array(); |
|
91 |
||
92 |
$subcategories = $this->db->get_where("SubCategories", array("courseID" => $course->courseID, "categoryName" => $category->categoryName)); |
|
93 |
||
94 |
foreach($subcategories->result() as $subcategory){ |
|
95 |
$menu[$course->name][$category->categoryName][$subcategory->subCategoryName] = array(); |
|
96 |
||
97 |
}
|
|
98 |
}
|
|
99 |
}
|
|
100 |
||
101 |
return $menu; |
|
102 |
||
103 |
}
|
|
104 |
||
105 |
function getCategories($cid) { |
|
|
85.1.8
by a11andoh
added the cms controller to load all content pages. |
106 |
$this->db->order_by("orderNr", "asc"); |
|
69.2.1
by galaxyAbstractor
Replaced admin model |
107 |
$query = $this->db->get_where('Categories', array("courseID" => $cid)); |
108 |
return $query->result(); |
|
109 |
}
|
|
110 |
||
111 |
function addCategory($cid, $categoryName){ |
|
112 |
$this->db->select_max("orderNr"); |
|
113 |
$query = $this->db->get_where('Categories', array("courseID" => $cid)); |
|
114 |
||
115 |
$result = $query->result(); |
|
116 |
$data = array( |
|
117 |
'courseID' => $cid , |
|
118 |
'categoryName' => $categoryName, |
|
119 |
'orderNr' => $result[0]->orderNr+1 |
|
120 |
);
|
|
121 |
||
122 |
$this->db->insert('Categories', $data); |
|
123 |
mkdir("../courses/".$cid."/".$categoryName); |
|
124 |
||
125 |
}
|
|
126 |
||
127 |
function getSubCategories($cid, $categoryName) { |
|
128 |
$query = $this->db->get_where('SubCategories', array("courseID" => $cid, "categoryName" => $categoryName)); |
|
129 |
return $query->result(); |
|
130 |
}
|
|
131 |
||
132 |
function addSubCategory($cid, $categoryName, $subCategoryName){ |
|
133 |
$this->db->select_max("orderNr"); |
|
134 |
$query = $this->db->get_where('SubCategories', array("courseID" => $cid, "categoryName" => $categoryName)); |
|
135 |
||
136 |
$result = $query->result(); |
|
137 |
$data = array( |
|
138 |
'courseID' => $cid , |
|
139 |
'subCategoryName' => $subCategoryName, |
|
140 |
'categoryName' => $categoryName, |
|
141 |
'orderNr' => $result[0]->orderNr+1 |
|
142 |
);
|
|
143 |
||
144 |
$this->db->insert('SubCategories', $data); |
|
145 |
mkdir("../courses/".$cid."/".$categoryName."/".$subCategoryName); |
|
146 |
||
147 |
}
|
|
148 |
||
149 |
function getExamples($cid, $categoryName, $subCategoryName) { |
|
150 |
$query = $this->db->get_where('Examples', array("courseID" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName)); |
|
151 |
return $query->result(); |
|
152 |
}
|
|
153 |
||
154 |
function getQuizzes($cid, $categoryName, $subCategoryName) { |
|
155 |
$query = $this->db->get_where('Quizzes', array("courseID" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName)); |
|
156 |
return $query->result(); |
|
157 |
}
|
|
158 |
||
159 |
function addExample($cid, $categoryName, $subCategoryName, $example, $description){ |
|
160 |
$this->db->select_max("orderNr"); |
|
161 |
$query = $this->db->get_where('Examples', array("courseID" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName)); |
|
162 |
$result = $query->result(); |
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
163 |
$data = array( |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
164 |
'courseID' => $cid , |
165 |
'exampleName' => $example, |
|
|
69.2.1
by galaxyAbstractor
Replaced admin model |
166 |
'description' => $description, |
167 |
'categoryName' => $categoryName, |
|
168 |
'subCategoryName' => $subCategoryName, |
|
169 |
'orderNr' => $result[0]->orderNr+1 |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
170 |
);
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
171 |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
172 |
$this->db->insert('Examples', $data); |
|
69.2.1
by galaxyAbstractor
Replaced admin model |
173 |
|
174 |
$data = array( |
|
175 |
'fileName' => $cid."/".$categoryName."/".$subCategoryName."/".$example."/documentation", |
|
176 |
'codeLanguage' => "text", |
|
177 |
'fileType' => "text", |
|
178 |
'dataBlob' => "" |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
179 |
);
|
180 |
||
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
181 |
$this->db->insert('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
182 |
|
183 |
$data = array( |
|
|
69.2.1
by galaxyAbstractor
Replaced admin model |
184 |
'fileName' => $cid."/".$categoryName."/".$subCategoryName."/".$example."/documentation", |
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, |
|
69.2.1
by galaxyAbstractor
Replaced admin model |
188 |
'courseID' => $cid, |
189 |
'columnNr' => 1, |
|
190 |
'orderNr' => 1 |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
191 |
);
|
192 |
||
|
69.2.1
by galaxyAbstractor
Replaced admin model |
193 |
$this->db->insert('Containers', $data); |
194 |
mkdir("../courses/".$cid."/".$categoryName."/".$subCategoryName."/".$example); |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
195 |
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
196 |
}
|
197 |
||
|
69.2.1
by galaxyAbstractor
Replaced admin model |
198 |
function updateExample($cid, $categoryName, $subCategoryName, $example, $documentation, $files){ |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
199 |
|
200 |
$filearr = json_decode($files); |
|
201 |
||
202 |
foreach ($filearr as $file) { |
|
203 |
$output = ""; |
|
|
69.2.1
by galaxyAbstractor
Replaced admin model |
204 |
$handle = @fopen("../courses/".$cid."/".$categoryName."/".$subCategoryName."/".$example."/".$file->filename, "r"); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
205 |
if ($handle) { |
206 |
||
207 |
while (($buffer = fgets($handle, 4096)) !== false) { |
|
208 |
||
209 |
$buffer = str_replace("&", "&", $buffer); |
|
210 |
$buffer = str_replace("<", "<", $buffer); |
|
211 |
$buffer = str_replace(">", ">", $buffer); |
|
212 |
||
213 |
$output .= $buffer; |
|
214 |
}
|
|
215 |
if (!feof($handle)) { |
|
216 |
$output .= "Error: unexpected fgets() fail\n"; |
|
217 |
}
|
|
218 |
fclose($handle); |
|
219 |
}
|
|
220 |
||
221 |
$data = array( |
|
|
69.2.1
by galaxyAbstractor
Replaced admin model |
222 |
'fileName' => $cid."/".$categoryName."/".$subCategoryName."/".$example."/".$file->filename , |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
223 |
'codeLanguage' => $file->lang, |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
224 |
'fileType' => $file->type, |
225 |
'dataBlob' => $output |
|
226 |
);
|
|
227 |
||
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
228 |
$this->db->insert('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
229 |
|
|
69.2.1
by galaxyAbstractor
Replaced admin model |
230 |
$this->db->select_max("orderNr"); |
231 |
$query = $this->db->get_where('Containers', array("courseID" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName, "exampleName" => $example, "columnNr" => $file->columnNr)); |
|
232 |
$result = $query->result(); |
|
233 |
||
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
234 |
$data = array( |
|
69.2.1
by galaxyAbstractor
Replaced admin model |
235 |
'fileName' => $cid."/".$categoryName."/".$subCategoryName."/".$example."/".$file->filename , |
236 |
'categoryName' => $categoryName, |
|
237 |
'subCategoryName' => $subCategoryName, |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
238 |
'exampleName' => $example, |
|
69.2.1
by galaxyAbstractor
Replaced admin model |
239 |
'courseID' => $cid, |
240 |
'columnNr' => $file->columnNr, |
|
241 |
'orderNr' => $result[0]->orderNr+1 |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
242 |
);
|
243 |
||
|
69.2.1
by galaxyAbstractor
Replaced admin model |
244 |
$this->db->insert('Containers', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
245 |
}
|
246 |
||
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
247 |
$data = array( |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
248 |
'dataBlob' => $documentation |
249 |
);
|
|
250 |
||
|
69.2.1
by galaxyAbstractor
Replaced admin model |
251 |
$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 |
252 |
$this->db->update('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
253 |
|
254 |
||
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
255 |
}
|
256 |
||
|
69.2.1
by galaxyAbstractor
Replaced admin model |
257 |
function uploadFile($files, $cid, $categoryName, $subCategoryName, $example){ |
258 |
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 |
259 |
echo json_encode(array('status'=>'File was uploaded successfuly!')); |
260 |
}
|
|
261 |
}
|
|
|
83.2.3
by elof.bigestans at gmail
Working on functionality for managecourses |
262 |
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
263 |
}
|