summaryrefslogtreecommitdiffstats
path: root/admin/survey/export/latexclasses/class.LatexAnalysis.php
blob: ec00834c5dd03f9809280532d592547c865c3d90 (plain) (blame)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php

/**
 *
 *	Class ki skrbi za izris porocila analiz v latex
 *
 *
 */


//include('../../function.php');
include('../../vendor/autoload.php');
include_once('../../function.php');
include_once('../survey/definition.php');

 
class LatexAnalysis{
	
	protected $anketa;
	protected $export_format;
	protected $pi=array('canCreate'=>false); // za shrambo parametrov in sporocil
	protected $pdf;
	protected $currentStyle;
	protected $spremenljivka = null;
	
	private $headFileName = null;					# pot do header fajla
	
	protected $current_loop = 'undefined';
	
	protected $texNewLine = '\\\\ ';
	protected $texBigSkip = '\bigskip';
	
	
	function __construct($anketa=null, $export_format='', $sprID = null){
		global $site_path, $global_user_id, $admin_type, $lang;
		
		// preverimo ali imamo stevilko ankete
		if ( is_numeric($anketa) ){
		
			$this->anketa['id'] = $anketa;
			
			$this->spremenljivka = $sprID;
			
			$this->export_format = $export_format;
			//echo 'To je tip analysis za anketo: '.$anketa.' za '.$this->export_format.'</br>';
			
			SurveyAnalysis::Init($this->anketa['id']);
			SurveyAnalysis::$setUpJSAnaliza = false;
						
            // Poskrbimo za datoteko s podatki
            $SDF = SurveyDataFile::get_instance();
            $SDF->init($this->anketa['id']);           
            $SDF->prepareFiles();  

            $this->headFileName = $SDF->getHeaderFileName();
			
			$loop = SurveyZankaProfiles :: Init($this->anketa, $global_user_id);

			$this->current_loop = ($loop != null) ? $loop : $this->current_loop;
		}else{
			$this->pi['msg'] = "Anketa ni izbrana!";
			$this->pi['canCreate'] = false;
			return false;
		}

		//if ( SurveyInfo::getInstance()->SurveyInit($this->anketa['id']) && $this->init()){
		if ( SurveyInfo::getInstance()->SurveyInit($this->anketa['id']) ){
			$this->anketa['uid'] = $global_user_id;
			SurveyUserSetting::getInstance()->Init($this->anketa['id'], $this->anketa['uid']);
		}else{
			return false;
		}
			
		// ce smo prisli do tu je vse ok
		$this->pi['canCreate'] = true;

		return true;		
	}
	
		
	public function displayAnalysis($export_subtype=''){
		global $lang;
		$tex = '';

		// Pripravimo podatke, ki se uporabijo v tabelah		
		# preberemo header
		if ($this->headFileName !== null) {
			//polovimo podatke o nastavitvah trenutnega profila (missingi..)
			//SurveyMissingProfiles :: Init(self::$sid,$global_user_id);
			SurveyMissingProfiles :: Init($this->spremenljivka,$this->anketa['uid']);
			SurveyAnalysis::$missingProfileData = SurveyMissingProfiles::getProfile(SurveyAnalysis::$currentMissingProfile);
			//echo "SurveyAnalysis::missingProfileData in displayAnalysis: ".SurveyAnalysis::$missingProfileData." </br>";
			//echo "Indeksi SurveyAnalysis::missingProfileData v displayAnalysis: ".print_r(array_keys(SurveyAnalysis::$missingProfileData))." </br>";

			//echo "display_mv_type in displayAnalysis: ".SurveyAnalysis::$missingProfileData['display_mv_type']." </br>";
			// Preverimo ce imamo zanke (po skupinah)
			SurveyAnalysis::$_LOOPS = SurveyZankaProfiles::getFiltersForLoops();

			#preberemo HEADERS iz datoteke
			SurveyAnalysis::$_HEADERS = unserialize(file_get_contents($this->headFileName));
			//echo $this->headFileName."</br>";

			# polovimo frekvence
			SurveyAnalysis::getFrequencys();

			#odstranimo sistemske variable
			SurveyAnalysis::removeSystemVariables();

			//echo in_array($this->$spremenljivka['tip'], SurveyAnalysis::$_FILTRED_TYPES );
			
			//$vars_count = count(SurveyAnalysis::$_FILTRED_VARIABLES);
			
			//echo 'sprID: '.$_GET['sprID'].'</br>';
			//echo 'export_subtype: '.$export_subtype.'</br>';
			
			/*Izpis naslova izvoza*/
			switch ( $export_subtype ){
				case 'sums':
					$naslovIzvoza = $lang['export_analisys_sums'];
				break;
				case 'freq':
					$naslovIzvoza = $lang['export_analisys_freq'];
				break;
				case 'desc':
					$naslovIzvoza = $lang['export_analisys_desc'];
				break;
				case 'chart':
					$naslovIzvoza = $lang['export_analisys_charts'];
				break;
				case 'crosstab':
					$naslovIzvoza = $lang['export_analisys_crosstabs'];
				break;
				case 'multicrosstab':
					$naslovIzvoza = $lang['export_analisys_multicrosstabs'];
				break;
				case 'mean':
					$naslovIzvoza = $lang['export_analisys_means'];
				break;
				case 'ttest':
					$naslovIzvoza = $lang['export_analisys_ttest'];
				break;
				case 'break':
					$naslovIzvoza = $lang['export_analisys_break'];
				break;
				case 'heatmap_image_pdf':
					$naslovIzvoza = $lang['export_analysis_heatmap_image'];
				break;
			}			
			
			if($export_subtype!='creport'){
				//$tex .= '\textbf{'.$naslovIzvoza.'}'.$this->texBigSkip.$this->texNewLine;
				$tex .= '\MakeUppercase{\huge \textbf{'.$naslovIzvoza.'}}'.$this->texBigSkip.$this->texNewLine;	//{\\huge {'.$imeAnkete.'} \\par}
			}

			
			/*Izpis naslova izvoza - konec*/
			
			//if($this->export_format == 'pdf'){
			if($this->export_format == 'pdf'&&$export_subtype!='creport'){
				$tex .= '\begin{tableAnalysis}';	/*zacetek environmenta z manjsim fontom*/
			}

 			switch ($export_subtype){
				case 'sums':
				case 'freq':
					foreach (SurveyAnalysis::$_HEADERS AS $spid => $spremenljivka) {
						$analysisTable = new LatexAnalysisElement($this->anketa, $spremenljivka, $this->export_format, 0, $spid, $this->headFileName, $export_subtype);
						//if(SurveyAnalysis::$_FILTRED_VARIABLES[$spid]){							
						if (($spremenljivka['tip'] != 'm'
						 && in_array($spremenljivka['tip'], SurveyAnalysis::$_FILTRED_TYPES )) 
						 && (!isset($_spid) || (isset($_spid) && $_spid == $spid))
						 &&	($this->spremenljivka == $spid || $this->spremenljivka == null) ){
							//echo "spremenljivka tip : ".$spremenljivka['tip']."</br>";
 							/*echo "spr_id: ".$this->spremenljivka."</br>";
							echo "spid : ".$spid."</br>"; */
							# če nimamo zank
							if(count(SurveyAnalysis::$_LOOPS) == 0){
								$tex .= $analysisTable->displayTablesLatex($spid, $this->export_format);
							}
							else{
								// izrisemo samo eno tabelo iz enega loopa
								if($this->current_loop > 0){
									
									$loop = SurveyAnalysis::$_LOOPS[(int)$this->current_loop-1];
									$loop['cnt'] = $this->current_loop;
									SurveyAnalysis::$_CURRENT_LOOP = $loop;
									
									// Izpisemo naslov zanke za skupino
									$tex .= $analysisTable->displayTablesLatex($spid, $this->export_format);
								}
								// Izrisemo vse tabele spremenljivka (iz vseh loopov)
								else{
									$loop_cnt = 0;
									# če mamo zanke
									foreach(SurveyAnalysis::$_LOOPS AS $loop) {
										$loop_cnt++;
										$loop['cnt'] = $loop_cnt;
										SurveyAnalysis::$_CURRENT_LOOP = $loop;
										$tex .= $analysisTable->displayTablesLatex($spid, $this->export_format);
									}
								}
							}
						}					
					} // end foreach SurveyAnalysis::$_HEADERS
				break;
				case 'desc':
					//$analysisTable = new LatexAnalysisElement($this->anketa, $spremenljivka, $this->export_format, 0, $spid, $this->headFileName, $export_subtype);
					
 					$analysisTable = new LatexAnalysisElement($this->anketa, 0, $this->export_format, 0, 0, $this->headFileName, $export_subtype);
						
						# če nimamo zank
						if(count(SurveyAnalysis::$_LOOPS) == 0){
							$tex .= $analysisTable->displayTablesLatex(0, $this->export_format);
						}
						else{
							// izrisemo samo eno tabelo iz enega loopa
							if($this->current_loop > 0){
								
								$loop = SurveyAnalysis::$_LOOPS[(int)$this->current_loop-1];
								$loop['cnt'] = $this->current_loop;
								SurveyAnalysis::$_CURRENT_LOOP = $loop;
								
								// Izpisemo naslov zanke za skupino
								$tex .= $analysisTable->displayTablesLatex(0, $this->export_format);
							}
							// Izrisemo vse tabele spremenljivka (iz vseh loopov)
							else{
								$loop_cnt = 0;
								# če mamo zanke
								foreach(SurveyAnalysis::$_LOOPS AS $loop) {
									$loop_cnt++;
									$loop['cnt'] = $loop_cnt;
									SurveyAnalysis::$_CURRENT_LOOP = $loop;
									$tex .= $analysisTable->displayTablesLatex(0, $this->export_format);
								}
							}
						}
					
				break;
				case 'crosstab':
					$crossData1 = explode(",", $_GET['data1']);
					$crossData2 = explode(",", $_GET['data2']);					
					$analysisTable = new LatexAnalysisElement($this->anketa, 0, $this->export_format, 0, 0, $this->headFileName, $export_subtype);
					$tex .= $analysisTable->displayCrosstabsTablesLatex($crossData1, $crossData2);
				break;
				case 'multicrosstab':
					$analysisTable = new LatexAnalysisElement($this->anketa, 0, $this->export_format, 0, 0, $this->headFileName, $export_subtype);
					$tex .= $analysisTable->displayMultiCrosstabsTablesLatex();
				break;
				case 'mean':
					$analysisTable = new LatexAnalysisElement($this->anketa, 0, $this->export_format, 0, 0, $this->headFileName, $export_subtype);
					$tex .= $analysisTable->displayMeanTablesLatex();					
				break;
				case 'ttest':
					$analysisTable = new LatexAnalysisElement($this->anketa, 0, $this->export_format, 0, 0, $this->headFileName, $export_subtype);
					$tex .= $analysisTable->displayTTestTablesLatex();
				break;
				case 'break':
					$analysisTable = new LatexAnalysisElement($this->anketa, 0, $this->export_format, 0, 0, $this->headFileName, $export_subtype);
					$tex .= $analysisTable->displayBreakTablesLatex();
				break;
				case 'heatmap_image_pdf':
					$analysisHeatmapImage = new LatexAnalysisElement($this->anketa, 0, $this->export_format, 0, 0, $this->headFileName, $export_subtype);
					$tex .= $analysisHeatmapImage->displayHeatmapImageLatex($_GET['sprID']);
				break;
				case 'chart':
					$analysisChart = new LatexAnalysisElement($this->anketa, 0, $this->export_format, 0, 0, $this->headFileName, $export_subtype);
					$tex .= $analysisChart->displayChartLatex($_GET['sprID']);
				break;
				case 'creport':
					$analysisCreport = new LatexAnalysisElement($this->anketa, 0, $this->export_format, 0, 0, $this->headFileName, $export_subtype);
					$tex .= $analysisCreport->displayCreportLatex();
				break;
			}
			
			
			//if($this->export_format == 'pdf'){
			if($this->export_format == 'pdf'&&$export_subtype!='creport'){
				$tex .= '\end{tableAnalysis}';	/*zakljucek environmenta z manjsim fontom*/
			}
			
		} // end if else ($_headFileName == null)
		return $tex;
		// Loop cez vsa vprasanja
		// Znotraj loopa vsak element posebej izrisemo kot objekt LatexFreqElement - pomembno, ker zelimo recimo posamezno tabelo frekvenc (sa specificno vprasanje) izrisati tudi v kaksnem drugem porocilu (npr custom report). Zato se mora vsak element neodvisno izrisovati.
	}
}