/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/models/admin/admin_model.php

  • Committer: Gustav Hartvigsson
  • Date: 2013-04-12 17:00:09 UTC
  • mfrom: (23.1.4 lenasys)
  • Revision ID: gustav.hartvigsson@gmail.com-20130412170009-gla04s3anpjep68p
Merging implementation group one's team bnanch in to trunk.
This is also end of this cycle.

Good work guys.

20130412.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
 
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
*/
2
9
class Admin_model extends CI_Model {
3
10
 
4
11
        function __construct() {
12
19
 
13
20
        function addCourse($cid, $name){
14
21
                $data = array(
15
 
                        'cid' => $cid ,
16
 
                        'name' => $name
17
 
                );
 
22
                        'courseID' => $cid ,
 
23
                        'courseName' => $name
 
24
                        );
18
25
 
19
26
                $this->db->insert('courses', $data); 
20
27
                mkdir("../courses/".$cid);
22
29
        }
23
30
 
24
31
        function getExamples($cid) {
25
 
                $query = $this->db->get_where('examples', array("cid" => $cid));
 
32
                $query = $this->db->get_where('examples', array("Courses_courseID" => $cid));
26
33
                return $query->result();
27
34
        }
28
35
 
29
 
        function addExample($cid, $example){
 
36
        function addExample($cid, $example, $description){
30
37
                $data = array(
31
 
                        'cid' => $cid ,
32
 
                        'example' => $example
33
 
                );
 
38
                        'Courses_courseID' => $cid ,
 
39
                        'Name' => $example,
 
40
                        'description' => $description
 
41
                        );
34
42
 
35
43
                $this->db->insert('examples', $data); 
36
44
                mkdir("../courses/".$cid."/".$example);
38
46
        }
39
47
 
40
48
        function getPages($cid, $example) {
41
 
                $query = $this->db->get_where('pages', array("cid" => $cid, "example" => $example));
 
49
                $query = $this->db->get_where('pages', array("Examples_Courses_courseID" => $cid, "Examples_Name" => $example));
42
50
                return $query->result();
43
51
        }
44
52
 
45
 
        function addPage($cid, $example, $page, $documentation){
 
53
        function addPage($cid, $example, $page){
46
54
                $data = array(
47
 
                        'cid' => $cid ,
48
 
                        'example' => $example,
49
 
                        'page' => $page ,
50
 
                        'documentation' => $documentation 
51
 
                );
 
55
                        'Examples_Courses_courseID' => $cid ,
 
56
                        'Examples_Name' => $example,
 
57
                        'name' => $page
 
58
                        );
52
59
 
53
60
                $this->db->insert('pages', $data); 
54
61
                mkdir("../courses/".$cid."/".$example."/".$page);
55
62
 
 
63
                $data = array(
 
64
                        'fileName' => $cid."/".$example."/".$page."/documentation",
 
65
                        'language' => $file->lang,
 
66
                        'fileType' => $file->type,
 
67
                        'dataBlob' => $output
 
68
                        );
 
69
 
 
70
                $this->db->insert('files', $data); 
 
71
 
 
72
                $data = array(
 
73
                        'Files_fileName' =>  $cid."/".$example."/".$page."/documentation"  ,
 
74
                        'Pages_name' => $page,
 
75
                        'Pages_Examples_Name' => $example,
 
76
                        'Pages_Examples_Courses_courseID' => $cid
 
77
                        );
 
78
 
 
79
                $this->db->insert('pagesfiles', $data); 
 
80
 
56
81
        }
57
82
 
58
 
        function updatePage($cid, $example, $page, $documentation){
 
83
        function updatePage($cid, $example, $page, $documentation, $files){
 
84
 
 
85
                $filearr = json_decode($files);
 
86
 
 
87
                foreach ($filearr as $file) {
 
88
                        $output = "";
 
89
                        $handle = @fopen("../courses/".$cid."/".$example."/".$page."/".$file->filename, "r");
 
90
                        if ($handle) {
 
91
 
 
92
                                while (($buffer = fgets($handle, 4096)) !== false) {
 
93
 
 
94
                                        $buffer = str_replace("&", "&amp;", $buffer);
 
95
                                        $buffer = str_replace("<", "&lt;", $buffer);
 
96
                                        $buffer = str_replace(">", "&gt;", $buffer);
 
97
 
 
98
                                        $output .= $buffer;
 
99
                                }
 
100
                                if (!feof($handle)) {
 
101
                                        $output .= "Error: unexpected fgets() fail\n";
 
102
                                }
 
103
                                fclose($handle);
 
104
                        }
 
105
                        
 
106
                        $data = array(
 
107
                                'fileName' => $file->filename ,
 
108
                                'language' => $file->lang,
 
109
                                'fileType' => $file->type,
 
110
                                'dataBlob' => $output
 
111
                                );
 
112
 
 
113
                        $this->db->insert('files', $data); 
 
114
 
 
115
                        $data = array(
 
116
                                'Files_fileName' =>  $file->filename  ,
 
117
                                'Pages_name' => $page,
 
118
                                'Pages_Examples_Name' => $example,
 
119
                                'Pages_Examples_Courses_courseID' => $cid
 
120
                                );
 
121
 
 
122
                        $this->db->insert('pagesfiles', $data); 
 
123
                }
 
124
 
59
125
                $data = array(
60
 
                        'documentation' => $documentation 
61
 
                );
62
 
 
63
 
                $this->db->where('cid', $cid);
64
 
                $this->db->where('example', $example);
65
 
                $this->db->where('page', $page);
66
 
                $this->db->update('pages', $data); 
 
126
                        'dataBlob' => $documentation
 
127
                        );
 
128
 
 
129
                $this->db->where("fileName",$cid."/".$example."/".$page."/"."documentation" );
 
130
                $this->db->update('files', $data); 
 
131
                
 
132
 
67
133
        }
68
134
 
69
135
        function uploadFile($files, $cid, $example, $page){