/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/codeviewer/codeviewer_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:
5
5
                $this->load->database();
6
6
        }
7
7
 
8
 
        function showFile($filename, $lang, $interestingrows = array()) {
 
8
        function getCode($cid, $example, $page) {
 
9
 
 
10
                $this->db->from('files');
 
11
                $this->db->join("pagesfiles", "pagesfiles.Files_fileName = files.fileName");
 
12
                $this->db->where("pagesfiles.Pages_name", $page);
 
13
                $this->db->where("pagesfiles.Pages_Examples_Name", $example);
 
14
                $this->db->where("pagesfiles.Pages_Examples_Courses_courseID", $cid);
 
15
                $this->db->not_like("pagesfiles.Files_fileName", $cid."/".$example."/".$page."/"."documentation");
 
16
 
 
17
                $query = $this->db->get();
9
18
                $output = "";
10
 
                $output .= '<div class="editorinfo">'.$lang.'&nbsp;&nbsp;&nbsp;&nbsp;'.$filename.'</div>';
11
 
                $output .= '<div id="ace_'.str_replace(".", "", $filename).'" class="ace">';
12
 
                $handle = @fopen($filename, "r");
13
 
                if ($handle) {
14
 
 
15
 
                        while (($buffer = fgets($handle, 4096)) !== false) {
16
 
 
17
 
                                $buffer = str_replace("&", "&amp;", $buffer);
18
 
                                $buffer = str_replace("<", "&lt;", $buffer);
19
 
                                $buffer = str_replace(">", "&gt;", $buffer);
20
 
 
21
 
                                $output .= $buffer;
22
 
                        }
23
 
                        if (!feof($handle)) {
24
 
                                $output .= "Error: unexpected fgets() fail\n";
25
 
                        }
26
 
                        fclose($handle);
27
 
                }
28
 
                $output .= '</div>';
29
 
 
30
 
                $output .=  '<script type="text/javascript">
31
 
                var Range = require("ace/range").Range;
32
 
                var editor = ace.edit("ace_'.str_replace(".", "", $filename).'");
33
 
                editor.setTheme("ace/theme/merbivore");
34
 
                editor.getSession().setMode("ace/mode/'.$lang.'");
35
 
                editor.setReadOnly(true);
36
 
                editor.setShowPrintMargin(false);
37
 
                editor.setDisplayIndentGuides(false);
38
 
                editor.setHighlightSelectedWord(true);
39
 
                lines = editor.getSession().getLength();
40
 
                $("#ace_'.str_replace(".", "", $filename).'").height(Math.min(500,lines*16));
41
 
                aceeditors.push("ace_'.str_replace(".", "", $filename).'");';
42
 
                for($i = 0; $i < count($interestingrows); $i++) {
 
19
                foreach ($query->result() as $row) {
 
20
                        $output .= '<div class="editorinfo">'.$row->language.'&nbsp;&nbsp;&nbsp;&nbsp;'.$row->fileName.'</div>';
 
21
                        $output .= '<div id="ace_'.str_replace(".", "", $row->fileName).'" class="ace">';
 
22
                        $output .= $row->dataBlob;
 
23
                        $output .= '</div>';
 
24
 
 
25
                        $output .=  '<script type="text/javascript">
 
26
                        var Range = require("ace/range").Range;
 
27
                        var editor = ace.edit("ace_'.str_replace(".", "", $row->fileName).'");
 
28
                        editor.setTheme("ace/theme/merbivore");
 
29
                        editor.getSession().setMode("ace/mode/'.$row->language.'");
 
30
                        editor.setReadOnly(true);
 
31
                        editor.setShowPrintMargin(false);
 
32
                        editor.setDisplayIndentGuides(false);
 
33
                        editor.setHighlightSelectedWord(true);
 
34
                        lines = editor.getSession().getLength();
 
35
                        $("#ace_'.str_replace(".", "", $row->fileName).'").height(Math.min(500,lines*16));
 
36
                        aceeditors.push("ace_'.str_replace(".", "", $row->fileName).'");';
 
37
 
 
38
                        /*
 
39
                        for($i = 0; $i < count($interestingrows); $i++) {
43
40
                        $output .= 'editor.getSession().addMarker(new Range('.$interestingrows[$i][0].', 0, '
44
41
                                .$interestingrows[$i][1].', Number.POSITIVE_INFINITY), "interesting", "text",false);';
 
42
                        }
 
43
                        */
 
44
                        $output .= '</script>';
 
45
 
45
46
                }
46
 
                $output .= '</script>';
47
47
 
48
48
                return $output;
49
49
        }
50
50
 
51
 
        function getFiles($course, $example, $page){
52
 
                $files = array();
53
 
                if ($handle = opendir("../courses/".$course."/". $example."/".$page."/")) {
54
 
                        while (false !== ($entry = readdir($handle))) {
55
 
                                if($entry == "." || $entry == "..") continue;
56
 
                                $files[] = "../courses/".$course."/". $example."/".$page."/".$entry;
57
 
                        }
58
 
                }
59
 
 
60
 
                return $files;
61
 
        }
62
 
 
63
51
        function getDoc($cid, $example, $page){
64
 
                $this->db->select('documentation');
65
 
                $query = $this->db->get_where('pages', array('cid' => $cid, 'example' => $example, 'page' => $page));
 
52
                $this->db->select('dataBlob');
 
53
                $this->db->from('files');
 
54
                $this->db->join("pagesfiles", "pagesfiles.Files_fileName = files.fileName");
 
55
                $this->db->where("pagesfiles.Pages_name", $page);
 
56
                $this->db->where("pagesfiles.Pages_Examples_Name", $example);
 
57
                $this->db->where("pagesfiles.Pages_Examples_Courses_courseID", $cid);
 
58
                $this->db->where("pagesfiles.Files_fileName", $cid."/".$example."/".$page."/"."documentation");
 
59
 
 
60
                $query = $this->db->get();
66
61
                $result = $query->result();
67
 
                return $result[0]->documentation;
 
62
                return $result[0]->dataBlob;
68
63
        }
69
64
 
70
65
}