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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
<?php
class Codeviewer_model extends CI_Model {
function __construct(){
$this->load->database();
}
function getCode($cid, $category, $subcategory, $example) {
$this->db->from('Files');
$this->db->join("Containers", "Containers.fileName = Files.fileName");
$this->db->where("Containers.categoryName", $category);
$this->db->where("Containers.subcategoryName", $subcategory);
$this->db->where("Containers.exampleName", $example);
$this->db->where("Containers.courseID", $cid);
//$this->db->not_like("Containers.fileName", $cid."/".$category."/".$subcategory."/".$example."/documentation");
$query = $this->db->get();
$outarr = array();
$column1 = 0;
$column2 = 0;
foreach ($query->result() as $row) {
if ($row->columnNr == 1) $column1++;
if ($row->columnNr == 2) $column2++;
}
foreach ($query->result() as $row) { //creats array with array consisting of columnNr and code file.
$output = "";
if($row->columnNr == 1 && $column1 == 1 ) {
$output .= '<div class="singleColumn1">';
} else if($row->columnNr == 1 && $column1 == 2) {
$output .= '<div class="doubleColumn1">';
} else if($row->columnNr == 2 && $column2 == 1) {
$output .= '<div class="singleColumn2">';
} else if($row->columnNr == 2 && $column2 == 2) {
$output .= '<div class="doubleColumn2">';
} else if($row->columnNr == 2 && $column2 == 3) {
$output .= '<div class="tripleColumn2">';
} else {
$output .= '<div class="tripleColumn2">';
}
if($row->fileType == 'Code') {
$filename = $row->fileName;
$pieces = explode("/", $filename);
$filename = $pieces[4];
$output .= '<div class="editorinfo"><span class="codeLanguage">'.$row->codeLanguage.'</span><span class="codeFilename">'.$filename.'</span></div>';
$output .= '<div id="ace_'.str_replace(".", "", $row->fileName).'" class="ace">';
$output .= $row->dataBlob;
$output .= '</div>';
$output .= '<script type="text/javascript">
var Range = require("ace/range").Range;
var editor = ace.edit("ace_'.str_replace(".", "", $row->fileName).'");
editor.setTheme("ace/theme/eclipse");
editor.getSession().setMode("ace/mode/'.$row->codeLanguage.'");
editor.setReadOnly(true);
editor.setShowPrintMargin(false);
editor.setDisplayIndentGuides(false);
editor.setHighlightSelectedWord(true);
lines = editor.getSession().getLength();
$("#ace_'.str_replace(".", "", $row->fileName).'").height(Math.min(500,lines*16));
aceeditors.push("ace_'.str_replace(".", "", $row->fileName).'");';
/*
for($i = 0; $i < count($interestingrows); $i++) {
$output .= 'editor.getSession().addMarker(new Range('.$interestingrows[$i][0].', 0, '
.$interestingrows[$i][1].', Number.POSITIVE_INFINITY), "interesting", "text",false);';
}
*/
$output .= '</script>';
} else if($row->fileType == 'Text') {
$output .= '<div class="editorinfo"><span class="codeFilename">Description</span></div>';
$output .= '<div class="textContainer">';
$output .= $row->dataBlob;
$output .= '</div>';
}
$output .= '</div>';
$outarr[] = array($row->columnNr,$output);
}
return $outarr;
}
/*
function getDoc($cid, $category, $subcategory, $example){
$this->db->select('dataBlob');
$this->db->from('Files');
$this->db->join("Containers", "Containers.fileName = Files.fileName");
$this->db->where("Containers.categoryName", $category);
$this->db->where("Containers.subcategoryName", $subcategory);
$this->db->where("Containers.exampleName", $example);
$this->db->where("Containers.courseID", $cid);
$this->db->where("Containers.fileName", $cid."/".$category."/".$subcategory."/".$example."/"."documentation");
$query = $this->db->get();
$result = $query->result();
return $result[0]->dataBlob;
}*/
}
|