/lenasys/trunk

To get this branch, use:
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
2
class Codeviewer_model extends CI_Model {
3
4
	function __construct(){
5
		$this->load->database();
6
	}
7
53.1.1 by galaxyAbstractor
fixed adminpanel and codeviewer a bit
8
	function getCode($cid, $category, $subcategory, $example) {
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
9
39.2.1 by c11oscjo
Change attribute and table names according to the database.
10
		$this->db->from('Files');
53.1.1 by galaxyAbstractor
fixed adminpanel and codeviewer a bit
11
		$this->db->join("Containers", "Containers.fileName = Files.fileName");
12
		$this->db->where("Containers.categoryName", $category);
13
		$this->db->where("Containers.subcategoryName", $subcategory);
14
		$this->db->where("Containers.exampleName", $example);
15
		$this->db->where("Containers.courseID", $cid);
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
16
		//$this->db->not_like("Containers.fileName", $cid."/".$category."/".$subcategory."/".$example."/documentation");
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
17
18
		$query = $this->db->get();
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
19
		$outarr = array();
68.2.1 by a11patfr at his
Codeviewer working?
20
		$column1 = 0;
21
		$column2 = 0;
22
		foreach ($query->result() as $row) {
23
			if ($row->columnNr == 1) $column1++;		
24
			if ($row->columnNr == 2) $column2++;		
25
		}
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
26
		foreach ($query->result() as $row) { //creats array with array consisting of columnNr and code file.
27
			$output = "";
68.2.1 by a11patfr at his
Codeviewer working?
28
			if($row->columnNr == 1 && $column1 == 1 ) {
29
				$output .= '<div class="singleColumn1">';
30
			} else if($row->columnNr == 1 && $column1 == 2) {
31
				$output .= '<div class="doubleColumn1">';
32
			} else if($row->columnNr == 2 && $column2 == 1) {
33
				$output .= '<div class="singleColumn2">';
34
			} else if($row->columnNr == 2 && $column2 == 2) {
35
				$output .= '<div class="doubleColumn2">';
36
			} else if($row->columnNr == 2 && $column2 == 3) {
37
				$output .= '<div class="tripleColumn2">';
38
			} else {
39
				$output .= '<div class="tripleColumn2">';
40
			}
41
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
42
			if($row->fileType == 'Code') {
68.2.1 by a11patfr at his
Codeviewer working?
43
				$filename = $row->fileName;
44
				$pieces = explode("/", $filename);
45
				$filename = $pieces[4];
46
				$output .= '<div class="editorinfo"><span class="codeLanguage">'.$row->codeLanguage.'</span><span class="codeFilename">'.$filename.'</span></div>';
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
47
				$output .= '<div id="ace_'.str_replace(".", "", $row->fileName).'" class="ace">';
48
				$output .= $row->dataBlob;
49
				$output .= '</div>';
50
68.2.1 by a11patfr at his
Codeviewer working?
51
				$output .= '<script type="text/javascript">
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
52
				var Range = require("ace/range").Range;
53
				var editor = ace.edit("ace_'.str_replace(".", "", $row->fileName).'");
62.3.1 by a11patfr at his
Codeviewer work underway.
54
				editor.setTheme("ace/theme/eclipse");
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
55
				editor.getSession().setMode("ace/mode/'.$row->codeLanguage.'");
56
				editor.setReadOnly(true);
57
				editor.setShowPrintMargin(false);
58
				editor.setDisplayIndentGuides(false);
59
				editor.setHighlightSelectedWord(true);
60
				lines = editor.getSession().getLength();
61
				$("#ace_'.str_replace(".", "", $row->fileName).'").height(Math.min(500,lines*16));
62
				aceeditors.push("ace_'.str_replace(".", "", $row->fileName).'");';
63
64
				/*
65
				for($i = 0; $i < count($interestingrows); $i++) {
66
				$output .= 'editor.getSession().addMarker(new Range('.$interestingrows[$i][0].', 0, '
67
					.$interestingrows[$i][1].', Number.POSITIVE_INFINITY), "interesting", "text",false);';
68
				}
69
				*/
70
				$output .= '</script>';
71
			} else if($row->fileType == 'Text') {
66.1.1 by a11patfr at his
Codeviewer has one working view. Yay
72
				$output .= '<div class="editorinfo"><span class="codeFilename">Description</span></div>';
73
				$output .= '<div class="textContainer">';
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
74
				$output .= $row->dataBlob;
66.1.1 by a11patfr at his
Codeviewer has one working view. Yay
75
				$output .= '</div>';
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
76
			}
66.1.1 by a11patfr at his
Codeviewer has one working view. Yay
77
			$output .= '</div>';
78
			$outarr[] = array($row->columnNr,$output);
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
79
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
80
		}
81
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
82
		return $outarr;
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
83
	}
84
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
85
	/*
53.1.1 by galaxyAbstractor
fixed adminpanel and codeviewer a bit
86
	function getDoc($cid, $category, $subcategory, $example){
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
87
		$this->db->select('dataBlob');
39.2.1 by c11oscjo
Change attribute and table names according to the database.
88
		$this->db->from('Files');
53.1.1 by galaxyAbstractor
fixed adminpanel and codeviewer a bit
89
		$this->db->join("Containers", "Containers.fileName = Files.fileName");
90
		$this->db->where("Containers.categoryName", $category);
91
		$this->db->where("Containers.subcategoryName", $subcategory);
92
		$this->db->where("Containers.exampleName", $example);
93
		$this->db->where("Containers.courseID", $cid);
94
		$this->db->where("Containers.fileName", $cid."/".$category."/".$subcategory."/".$example."/"."documentation");
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
95
96
		$query = $this->db->get();
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
97
		$result = $query->result();
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
98
		return $result[0]->dataBlob;
58.1.2 by a11patfr at his
First steps to working codeviewer, can now show all files.
99
	}*/
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
100
}