Passed
Push — master ( 4a18b4...f89bd2 )
by Patrick
01:52
created
library/Trapdirector/Tables/TrapDirectorTable.php 3 patches
Indentation   +346 added lines, -346 removed lines patch added patch discarded remove patch
@@ -5,284 +5,284 @@  discard block
 block discarded – undo
5 5
 
6 6
 abstract class TrapDirectorTable
7 7
 {
8
-    /** @var array $titles table titles (name, display value) */
9
-    protected $titles = null;
8
+	/** @var array $titles table titles (name, display value) */
9
+	protected $titles = null;
10 10
 
11
-    /** @var array $content table content  (name, sb column name). name index must be the same as $titles*/
12
-    protected $content = null;
11
+	/** @var array $content table content  (name, sb column name). name index must be the same as $titles*/
12
+	protected $content = null;
13 13
     
14
-    /** @var array $columnNames names of columns for filtering */
15
-    protected $columnNames = array();
14
+	/** @var array $columnNames names of columns for filtering */
15
+	protected $columnNames = array();
16 16
     
17
-    /** @var mixed $dbConn connection to database  */
18
-    protected $dbConn = null;
17
+	/** @var mixed $dbConn connection to database  */
18
+	protected $dbConn = null;
19 19
     
20
-    /** Current view **/
21
-    protected $view;
20
+	/** Current view **/
21
+	protected $view;
22 22
     
23
-    protected $urlPath;
23
+	protected $urlPath;
24 24
     
25
-    // Database stuff
25
+	// Database stuff
26 26
    /** @var array $table (db ref, name) */
27
-    protected $table = array();
27
+	protected $table = array();
28 28
     
29
-    /** @var mixed  $query Query in database; */
30
-    protected $query = null;
29
+	/** @var mixed  $query Query in database; */
30
+	protected $query = null;
31 31
     
32
-    /** @var array $order : (db column, 'ASC' | 'DESC') */
33
-    protected $order = array();
34
-    protected $orderQuery = '';
32
+	/** @var array $order : (db column, 'ASC' | 'DESC') */
33
+	protected $order = array();
34
+	protected $orderQuery = '';
35 35
     
36
-    /********* Filter ********/
37
-    /** @var string $filterString : string filter for db columns */
38
-    protected $filterString = '';
36
+	/********* Filter ********/
37
+	/** @var string $filterString : string filter for db columns */
38
+	protected $filterString = '';
39 39
     
40
-    /** @var array $filterColumn : columns to apply filter to */
41
-    protected $filterColumn = array();
40
+	/** @var array $filterColumn : columns to apply filter to */
41
+	protected $filterColumn = array();
42 42
     
43
-    protected $filterQuery='';
43
+	protected $filterQuery='';
44 44
     
45
-    /*************** Paging *************/
46
-    protected $maxPerPage = 25;
45
+	/*************** Paging *************/
46
+	protected $maxPerPage = 25;
47 47
     
48
-    protected $currentPage = 0;
48
+	protected $currentPage = 0;
49 49
     
50
-    function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath)
51
-    {
52
-        $this->table = $table;
53
-        $this->titles = $titles;
54
-        $this->content = $columns;
55
-        $this->columnNames = $columnNames;
56
-        $this->dbConn = $dbConn;
50
+	function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath)
51
+	{
52
+		$this->table = $table;
53
+		$this->titles = $titles;
54
+		$this->content = $columns;
55
+		$this->columnNames = $columnNames;
56
+		$this->dbConn = $dbConn;
57 57
         
58
-        $this->view = $view;
59
-        $this->urlPath = $urlPath;
58
+		$this->view = $view;
59
+		$this->urlPath = $urlPath;
60 60
         
61
-        return $this;
62
-    }
61
+		return $this;
62
+	}
63 63
 
64 64
     
65
-    /************** GET variables and URLs *************/
66
-    public function getParams(array $getVars)
67
-    {
68
-        $this->getFilterQuery($getVars);
69
-        $this->getPagingQuery($getVars);
70
-        $this->getOrderQuery($getVars);
71
-    }
72
-    
73
-    public function getCurrentURL()
74
-    {
75
-        return '?';
76
-    }
77
-    
78
-    protected function getCurrentURLAndQS(string $caller)
79
-    {
80
-        $actionURL = $this->getCurrentURL() . '?' ;
81
-        $QSList=array();
82
-        if ($caller != 'filter' && $this->curFilterQuery() != '')
83
-            array_push($QSList , $this->curFilterQuery());
65
+	/************** GET variables and URLs *************/
66
+	public function getParams(array $getVars)
67
+	{
68
+		$this->getFilterQuery($getVars);
69
+		$this->getPagingQuery($getVars);
70
+		$this->getOrderQuery($getVars);
71
+	}
72
+    
73
+	public function getCurrentURL()
74
+	{
75
+		return '?';
76
+	}
77
+    
78
+	protected function getCurrentURLAndQS(string $caller)
79
+	{
80
+		$actionURL = $this->getCurrentURL() . '?' ;
81
+		$QSList=array();
82
+		if ($caller != 'filter' && $this->curFilterQuery() != '')
83
+			array_push($QSList , $this->curFilterQuery());
84 84
         
85
-        if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '')
86
-            array_push($QSList , $this->curPagingQuery());
85
+		if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '')
86
+			array_push($QSList , $this->curPagingQuery());
87 87
  
88
-        if ($caller != 'order' && $this->curOrderQuery() != '')
89
-            array_push($QSList , $this->curOrderQuery());
88
+		if ($caller != 'order' && $this->curOrderQuery() != '')
89
+			array_push($QSList , $this->curOrderQuery());
90 90
         
91
-        if (count($QSList) != 0)
92
-            $actionURL .=  implode('&', $QSList) . '&';
91
+		if (count($QSList) != 0)
92
+			$actionURL .=  implode('&', $QSList) . '&';
93 93
         
94
-        return $actionURL;
95
-    }
96
-    
97
-    /************* DB queries ******************/
98
-    /**
99
-     * Get base query in $this->query
100
-     * @return  TrapDirectorTable
101
-     */
102
-    public function getBaseQuery()
103
-    {
104
-        $this->query = $this->dbConn->select();
105
-        $this->query = $this->query->from(
106
-            $this->table,
107
-            $this->content
108
-            );
94
+		return $actionURL;
95
+	}
96
+    
97
+	/************* DB queries ******************/
98
+	/**
99
+	 * Get base query in $this->query
100
+	 * @return  TrapDirectorTable
101
+	 */
102
+	public function getBaseQuery()
103
+	{
104
+		$this->query = $this->dbConn->select();
105
+		$this->query = $this->query->from(
106
+			$this->table,
107
+			$this->content
108
+			);
109 109
         
110
-        return $this;
111
-    }
112
-    
113
-    public function fullQuery()
114
-    {
115
-        $this->getBaseQuery()
116
-        ->applyFilter()
117
-        ->applyPaging()
118
-        ->applyOrder();
110
+		return $this;
111
+	}
112
+    
113
+	public function fullQuery()
114
+	{
115
+		$this->getBaseQuery()
116
+		->applyFilter()
117
+		->applyPaging()
118
+		->applyOrder();
119 119
         
120
-        return $this->dbConn->fetchAll($this->query);
121
-        //return $this->query->fetchAll();
122
-    }
123
-    
124
-    
125
-    /**************** Filtering ******************/
126
-    
127
-    public function applyFilter()
128
-    {
129
-        if ($this->filterString == '' || count($this->filterColumn) == 0)
130
-        {
131
-            return $this;
132
-        }
133
-        $filter='';
134
-        foreach ($this->filterColumn as $column)
135
-        {
136
-            if ($filter != "") $filter.=' OR ';
137
-            //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'";
138
-            $filter .= $column  . " LIKE '%" . $this->filterString. "%'";
139
-        }
140
-        //echo $filter;
120
+		return $this->dbConn->fetchAll($this->query);
121
+		//return $this->query->fetchAll();
122
+	}
123
+    
124
+    
125
+	/**************** Filtering ******************/
126
+    
127
+	public function applyFilter()
128
+	{
129
+		if ($this->filterString == '' || count($this->filterColumn) == 0)
130
+		{
131
+			return $this;
132
+		}
133
+		$filter='';
134
+		foreach ($this->filterColumn as $column)
135
+		{
136
+			if ($filter != "") $filter.=' OR ';
137
+			//$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'";
138
+			$filter .= $column  . " LIKE '%" . $this->filterString. "%'";
139
+		}
140
+		//echo $filter;
141 141
         
142
-        $this->query=$this->query->where($filter);
142
+		$this->query=$this->query->where($filter);
143 143
 
144
-        return $this;
145
-    }
144
+		return $this;
145
+	}
146 146
 
147
-    public function setFilter(string $filter, array $filterCol)
148
-    {
149
-        $this->filterString = $filter;
150
-        $this->filterColumn = $filterCol;
151
-        return $this;
152
-    }
147
+	public function setFilter(string $filter, array $filterCol)
148
+	{
149
+		$this->filterString = $filter;
150
+		$this->filterColumn = $filterCol;
151
+		return $this;
152
+	}
153 153
    
154
-    public function renderFilter()
155
-    {
154
+	public function renderFilter()
155
+	{
156 156
         
157
-        $html=' <form id="genfilter" name="mainFilterGen"
157
+		$html=' <form id="genfilter" name="mainFilterGen"
158 158
 			enctype="application/x-www-form-urlencoded"
159 159
 			action="'.$this->getCurrentURLAndQS('filter').'"
160 160
 			method="get">';
161
-        $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words"
161
+		$html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words"
162 162
 	placeholder="Search..."  value="'.$this->filterQuery.'">';
163 163
 
164
-        $html.='</form>';
165
-        return $html;
166
-    }
164
+		$html.='</form>';
165
+		return $html;
166
+	}
167 167
  
168
-    public function getFilterQuery(array $getVars)
169
-    {
170
-        if (isset($getVars['f']))
171
-        {
172
-            $this->filterQuery = $getVars['f'];
173
-            $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames);
174
-        }
175
-    }
176
-    
177
-    protected function curFilterQuery()
178
-    {
179
-        if ($this->filterQuery == '') return '';
180
-        return 'f='.$this->filterQuery;
181
-    }
182
-    
183
-    /***************** Ordering ********************/
184
-    
185
-    public function applyOrder()
186
-    {
187
-        if (count($this->order) == 0)
188
-        {
189
-            return $this;
190
-        }
191
-        $orderSQL='';
192
-        foreach ($this->order as $column => $direction)
193
-        {
194
-            if ($orderSQL != "") $orderSQL.=',';
168
+	public function getFilterQuery(array $getVars)
169
+	{
170
+		if (isset($getVars['f']))
171
+		{
172
+			$this->filterQuery = $getVars['f'];
173
+			$this->setFilter(html_entity_decode($getVars['f']), $this->columnNames);
174
+		}
175
+	}
176
+    
177
+	protected function curFilterQuery()
178
+	{
179
+		if ($this->filterQuery == '') return '';
180
+		return 'f='.$this->filterQuery;
181
+	}
182
+    
183
+	/***************** Ordering ********************/
184
+    
185
+	public function applyOrder()
186
+	{
187
+		if (count($this->order) == 0)
188
+		{
189
+			return $this;
190
+		}
191
+		$orderSQL='';
192
+		foreach ($this->order as $column => $direction)
193
+		{
194
+			if ($orderSQL != "") $orderSQL.=',';
195 195
             
196
-            $orderSQL .= $column . ' ' . $direction;
197
-        }
198
-        $this->query = $this->query->order($orderSQL);
196
+			$orderSQL .= $column . ' ' . $direction;
197
+		}
198
+		$this->query = $this->query->order($orderSQL);
199 199
         
200
-        return $this;
201
-    }
202
-    
203
-    public function setOrder(array $order)
204
-    {
205
-        $this->order = $order;
206
-        return $this;
207
-    }
208
-    
209
-    public function getOrderQuery(array $getVars)
210
-    {
211
-        if (isset($getVars['o']))
212
-        {
213
-            $this->orderQuery = $getVars['o'];
214
-            $match = array();
215
-            if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match))
216
-            {
217
-                $orderArray=array($match[1] => $match[2]);
218
-                echo "$match[1] => $match[2]";
219
-                $this->setOrder($orderArray);
220
-            }
221
-        }
222
-    }
223
-    
224
-    protected function curOrderQuery()
225
-    {
226
-        if ($this->orderQuery == '') return '';
227
-        return 'o='.$this->orderQuery;
228
-    }
229
-    
230
-    /*****************  Paging and counting *********/
231
-    
232
-    public function countQuery()
233
-    {
234
-        $this->query = $this->dbConn->select();
235
-        $this->query = $this->query
236
-            ->from(
237
-                $this->table,
238
-                array('COUNT(*)')
239
-                );
240
-        $this->applyFilter();                   
241
-    }
242
-    
243
-    public function count()
244
-    {
245
-        $this->countQuery();
246
-        return $this->dbConn->fetchOne($this->query);
247
-    }
248
-    
249
-    public function setMaxPerPage(int $max)
250
-    {
251
-        $this->maxPerPage = $max;
252
-    }
253
-    
254
-    protected function getPagingQuery(array $getVars)
255
-    {
256
-        if (isset($getVars['page']))
257
-        {
258
-            $this->currentPage = $getVars['page'];
259
-        }
260
-    }
200
+		return $this;
201
+	}
202
+    
203
+	public function setOrder(array $order)
204
+	{
205
+		$this->order = $order;
206
+		return $this;
207
+	}
208
+    
209
+	public function getOrderQuery(array $getVars)
210
+	{
211
+		if (isset($getVars['o']))
212
+		{
213
+			$this->orderQuery = $getVars['o'];
214
+			$match = array();
215
+			if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match))
216
+			{
217
+				$orderArray=array($match[1] => $match[2]);
218
+				echo "$match[1] => $match[2]";
219
+				$this->setOrder($orderArray);
220
+			}
221
+		}
222
+	}
223
+    
224
+	protected function curOrderQuery()
225
+	{
226
+		if ($this->orderQuery == '') return '';
227
+		return 'o='.$this->orderQuery;
228
+	}
229
+    
230
+	/*****************  Paging and counting *********/
231
+    
232
+	public function countQuery()
233
+	{
234
+		$this->query = $this->dbConn->select();
235
+		$this->query = $this->query
236
+			->from(
237
+				$this->table,
238
+				array('COUNT(*)')
239
+				);
240
+		$this->applyFilter();                   
241
+	}
242
+    
243
+	public function count()
244
+	{
245
+		$this->countQuery();
246
+		return $this->dbConn->fetchOne($this->query);
247
+	}
248
+    
249
+	public function setMaxPerPage(int $max)
250
+	{
251
+		$this->maxPerPage = $max;
252
+	}
253
+    
254
+	protected function getPagingQuery(array $getVars)
255
+	{
256
+		if (isset($getVars['page']))
257
+		{
258
+			$this->currentPage = $getVars['page'];
259
+		}
260
+	}
261 261
 
262
-    protected function curPagingQuery()
263
-    {
264
-        if ($this->currentPage == '') return '';
265
-        return 'page='.$this->currentPage;
266
-    }
267
-    
268
-    public function renderPagingHeader()
269
-    {
270
-        $count = $this->count();
271
-        if ($count <= $this->maxPerPage )
272
-        {
273
-            return  'count : ' . $this->count() . '<br>';
274
-        }
262
+	protected function curPagingQuery()
263
+	{
264
+		if ($this->currentPage == '') return '';
265
+		return 'page='.$this->currentPage;
266
+	}
267
+    
268
+	public function renderPagingHeader()
269
+	{
270
+		$count = $this->count();
271
+		if ($count <= $this->maxPerPage )
272
+		{
273
+			return  'count : ' . $this->count() . '<br>';
274
+		}
275 275
         
276
-        if ($this->currentPage == 0) $this->currentPage = 1;
276
+		if ($this->currentPage == 0) $this->currentPage = 1;
277 277
         
278
-        $numPages = intdiv($count , $this->maxPerPage);
279
-        if ($count % $this->maxPerPage != 0 ) $numPages++;
278
+		$numPages = intdiv($count , $this->maxPerPage);
279
+		if ($count % $this->maxPerPage != 0 ) $numPages++;
280 280
         
281
-        $html = '<div class="pagination-control" role="navigation">';
282
-        $html .= '<ul class="nav tab-nav">';
283
-        if ($this->currentPage <=1)
284
-        {
285
-            $html .= '
281
+		$html = '<div class="pagination-control" role="navigation">';
282
+		$html .= '<ul class="nav tab-nav">';
283
+		if ($this->currentPage <=1)
284
+		{
285
+			$html .= '
286 286
                 <li class="nav-item disabled" aria-hidden="true">
287 287
                     <span class="previous-page">
288 288
                             <span class="sr-only">Previous page</span>
@@ -290,35 +290,35 @@  discard block
 block discarded – undo
290 290
                      </span>
291 291
                 </li>
292 292
                ';
293
-        }
294
-        else 
295
-        {
296
-            $html .= '
293
+		}
294
+		else 
295
+		{
296
+			$html .= '
297 297
                 <li class="nav-item">
298 298
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" >
299 299
                             <i aria-hidden="true" class="icon-angle-double-left"></i>            
300 300
                      </a>
301 301
                 </li>
302 302
             ';
303
-        }
303
+		}
304 304
         
305
-        for ($i=1; $i <= $numPages ; $i++)
306
-        {
307
-            $active = ($this->currentPage == $i) ? 'active' : '';
308
-            $first = ($i-1)*$this->maxPerPage+1;
309
-            $last = $i * $this->maxPerPage;
310
-            if ($last > $count) $last = $count;
311
-            $display = 'Show rows '. $first . ' to '. $last .' of '. $count;
312
-            $html .= '<li class="' . $active . ' nav-item">
305
+		for ($i=1; $i <= $numPages ; $i++)
306
+		{
307
+			$active = ($this->currentPage == $i) ? 'active' : '';
308
+			$first = ($i-1)*$this->maxPerPage+1;
309
+			$last = $i * $this->maxPerPage;
310
+			if ($last > $count) $last = $count;
311
+			$display = 'Show rows '. $first . ' to '. $last .' of '. $count;
312
+			$html .= '<li class="' . $active . ' nav-item">
313 313
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '">
314 314
                     '.$i.'                
315 315
                     </a>
316 316
                 </li>';
317
-        }
317
+		}
318 318
         
319
-        if ($this->currentPage == $numPages)
320
-        {
321
-            $html .= '
319
+		if ($this->currentPage == $numPages)
320
+		{
321
+			$html .= '
322 322
                 <li class="nav-item disabled" aria-hidden="true">
323 323
                     <span class="previous-page">
324 324
                             <span class="sr-only">Previous page</span>
@@ -326,112 +326,112 @@  discard block
 block discarded – undo
326 326
                      </span>
327 327
                 </li>
328 328
                ';
329
-        }
330
-        else
331
-        {
332
-            $html .= '
329
+		}
330
+		else
331
+		{
332
+			$html .= '
333 333
                 <li class="nav-item">
334 334
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page">
335 335
                             <i aria-hidden="true" class="icon-angle-double-right"></i>
336 336
                      </a>
337 337
                 </li>
338 338
             ';
339
-        }
339
+		}
340 340
         
341
-        $html .= '</ul> </div>';
341
+		$html .= '</ul> </div>';
342 342
         
343
-        return $html;
344
-    }
345
-    
346
-    public function applyPaging()
347
-    {
348
-        $this->query->limitPage($this->currentPage,$this->maxPerPage);
349
-        return $this;
350
-    }
351
-    
352
-    /*************** Rendering *************************/
353
-    
354
-    public function titleOrder($name)
355
-    {
356
-        return $this->content[$name];
357
-    }
358
-    
359
-    public function renderTitles()
360
-    {
361
-        $html = "<thead>\n<tr>\n";
362
-        foreach ($this->titles as $name => $values)
363
-        {
364
-            $titleOrder = $this->titleOrder($name);
365
-            if ($titleOrder != NULL)
366
-            {
367
-                if (isset($this->order[$titleOrder]))
368
-                {
369
-                    if ($this->order[$titleOrder] == 'ASC')
370
-                    {
371
-                        $titleOrder.='DESC';
372
-                    }
373
-                    else
374
-                    {
375
-                        $titleOrder.='ASC';
376
-                    }
377
-                }
378
-                else 
379
-                {
380
-                    $titleOrder.='ASC';
381
-                }
382
-                $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder;
383
-                $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>';
384
-            }
385
-            else 
386
-            {
387
-                $html .= '<th>' . $values . '</th>';
388
-            }          
389
-        }
390
-        $html .= "</tr>\n</thead>\n";
391
-        return $html;
392
-    }
393
-    
394
-    public function renderLine( $value)
395
-    {
396
-        $html = '';
397
-        $titleNames = array_keys($this->titles);
398
-        foreach ($titleNames as $name )
399
-        {
400
-            $html .= '<td>';
401
-            $html .= $value->$name;
402
-            $html .= "</td>\n";
403
-        }
404
-        return $html;
405
-    }
406
-    
407
-    public function renderTable(array $values)
408
-    {
409
-       $html = '<tbody id="obj_table_body">';
410
-       foreach($values as $value)
411
-       {
412
-           $html .= "<tr>\n";
413
-           $html .= $this->renderLine($value);
414
-           $html .= "</tr>\n";
415
-       }
416
-       $html .= '</tbody>';
417
-       return $html;
418
-    }
419
-    
420
-    public function render()
421
-    {
422
-        $html = '';
343
+		return $html;
344
+	}
345
+    
346
+	public function applyPaging()
347
+	{
348
+		$this->query->limitPage($this->currentPage,$this->maxPerPage);
349
+		return $this;
350
+	}
351
+    
352
+	/*************** Rendering *************************/
353
+    
354
+	public function titleOrder($name)
355
+	{
356
+		return $this->content[$name];
357
+	}
358
+    
359
+	public function renderTitles()
360
+	{
361
+		$html = "<thead>\n<tr>\n";
362
+		foreach ($this->titles as $name => $values)
363
+		{
364
+			$titleOrder = $this->titleOrder($name);
365
+			if ($titleOrder != NULL)
366
+			{
367
+				if (isset($this->order[$titleOrder]))
368
+				{
369
+					if ($this->order[$titleOrder] == 'ASC')
370
+					{
371
+						$titleOrder.='DESC';
372
+					}
373
+					else
374
+					{
375
+						$titleOrder.='ASC';
376
+					}
377
+				}
378
+				else 
379
+				{
380
+					$titleOrder.='ASC';
381
+				}
382
+				$actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder;
383
+				$html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>';
384
+			}
385
+			else 
386
+			{
387
+				$html .= '<th>' . $values . '</th>';
388
+			}          
389
+		}
390
+		$html .= "</tr>\n</thead>\n";
391
+		return $html;
392
+	}
393
+    
394
+	public function renderLine( $value)
395
+	{
396
+		$html = '';
397
+		$titleNames = array_keys($this->titles);
398
+		foreach ($titleNames as $name )
399
+		{
400
+			$html .= '<td>';
401
+			$html .= $value->$name;
402
+			$html .= "</td>\n";
403
+		}
404
+		return $html;
405
+	}
406
+    
407
+	public function renderTable(array $values)
408
+	{
409
+	   $html = '<tbody id="obj_table_body">';
410
+	   foreach($values as $value)
411
+	   {
412
+		   $html .= "<tr>\n";
413
+		   $html .= $this->renderLine($value);
414
+		   $html .= "</tr>\n";
415
+	   }
416
+	   $html .= '</tbody>';
417
+	   return $html;
418
+	}
419
+    
420
+	public function render()
421
+	{
422
+		$html = '';
423 423
         
424 424
         
425
-        $values = $this->fullQuery();
425
+		$values = $this->fullQuery();
426 426
         
427
-        $html.="<table class='simple common-table table-row-selectable'>\n";
427
+		$html.="<table class='simple common-table table-row-selectable'>\n";
428 428
         
429
-        $html .= $this->renderTitles();
430
-        $html .= $this->renderTable($values);
431
-        $html .= '</table>'; 
429
+		$html .= $this->renderTitles();
430
+		$html .= $this->renderTable($values);
431
+		$html .= '</table>'; 
432 432
         
433 433
 
434
-        return $html;
435
-    }
434
+		return $html;
435
+	}
436 436
     
437 437
 }
438 438
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -6,16 +6,16 @@  discard block
 block discarded – undo
6 6
 abstract class TrapDirectorTable
7 7
 {
8 8
     /** @var array $titles table titles (name, display value) */
9
-    protected $titles = null;
9
+    protected $titles=null;
10 10
 
11 11
     /** @var array $content table content  (name, sb column name). name index must be the same as $titles*/
12
-    protected $content = null;
12
+    protected $content=null;
13 13
     
14 14
     /** @var array $columnNames names of columns for filtering */
15
-    protected $columnNames = array();
15
+    protected $columnNames=array();
16 16
     
17 17
     /** @var mixed $dbConn connection to database  */
18
-    protected $dbConn = null;
18
+    protected $dbConn=null;
19 19
     
20 20
     /** Current view **/
21 21
     protected $view;
@@ -24,39 +24,39 @@  discard block
 block discarded – undo
24 24
     
25 25
     // Database stuff
26 26
    /** @var array $table (db ref, name) */
27
-    protected $table = array();
27
+    protected $table=array();
28 28
     
29 29
     /** @var mixed  $query Query in database; */
30
-    protected $query = null;
30
+    protected $query=null;
31 31
     
32 32
     /** @var array $order : (db column, 'ASC' | 'DESC') */
33
-    protected $order = array();
34
-    protected $orderQuery = '';
33
+    protected $order=array();
34
+    protected $orderQuery='';
35 35
     
36 36
     /********* Filter ********/
37 37
     /** @var string $filterString : string filter for db columns */
38
-    protected $filterString = '';
38
+    protected $filterString='';
39 39
     
40 40
     /** @var array $filterColumn : columns to apply filter to */
41
-    protected $filterColumn = array();
41
+    protected $filterColumn=array();
42 42
     
43 43
     protected $filterQuery='';
44 44
     
45 45
     /*************** Paging *************/
46
-    protected $maxPerPage = 25;
46
+    protected $maxPerPage=25;
47 47
     
48
-    protected $currentPage = 0;
48
+    protected $currentPage=0;
49 49
     
50
-    function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath)
50
+    function __construct(array $table, array $titles, array $columns, array $columnNames, $dbConn, $view, $urlPath)
51 51
     {
52
-        $this->table = $table;
53
-        $this->titles = $titles;
54
-        $this->content = $columns;
55
-        $this->columnNames = $columnNames;
56
-        $this->dbConn = $dbConn;
52
+        $this->table=$table;
53
+        $this->titles=$titles;
54
+        $this->content=$columns;
55
+        $this->columnNames=$columnNames;
56
+        $this->dbConn=$dbConn;
57 57
         
58
-        $this->view = $view;
59
-        $this->urlPath = $urlPath;
58
+        $this->view=$view;
59
+        $this->urlPath=$urlPath;
60 60
         
61 61
         return $this;
62 62
     }
@@ -77,19 +77,19 @@  discard block
 block discarded – undo
77 77
     
78 78
     protected function getCurrentURLAndQS(string $caller)
79 79
     {
80
-        $actionURL = $this->getCurrentURL() . '?' ;
80
+        $actionURL=$this->getCurrentURL().'?';
81 81
         $QSList=array();
82 82
         if ($caller != 'filter' && $this->curFilterQuery() != '')
83
-            array_push($QSList , $this->curFilterQuery());
83
+            array_push($QSList, $this->curFilterQuery());
84 84
         
85 85
         if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '')
86
-            array_push($QSList , $this->curPagingQuery());
86
+            array_push($QSList, $this->curPagingQuery());
87 87
  
88 88
         if ($caller != 'order' && $this->curOrderQuery() != '')
89
-            array_push($QSList , $this->curOrderQuery());
89
+            array_push($QSList, $this->curOrderQuery());
90 90
         
91 91
         if (count($QSList) != 0)
92
-            $actionURL .=  implode('&', $QSList) . '&';
92
+            $actionURL.=implode('&', $QSList).'&';
93 93
         
94 94
         return $actionURL;
95 95
     }
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public function getBaseQuery()
103 103
     {
104
-        $this->query = $this->dbConn->select();
105
-        $this->query = $this->query->from(
104
+        $this->query=$this->dbConn->select();
105
+        $this->query=$this->query->from(
106 106
             $this->table,
107 107
             $this->content
108 108
             );
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         {
136 136
             if ($filter != "") $filter.=' OR ';
137 137
             //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'";
138
-            $filter .= $column  . " LIKE '%" . $this->filterString. "%'";
138
+            $filter.=$column." LIKE '%".$this->filterString."%'";
139 139
         }
140 140
         //echo $filter;
141 141
         
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 
147 147
     public function setFilter(string $filter, array $filterCol)
148 148
     {
149
-        $this->filterString = $filter;
150
-        $this->filterColumn = $filterCol;
149
+        $this->filterString=$filter;
150
+        $this->filterColumn=$filterCol;
151 151
         return $this;
152 152
     }
153 153
    
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
     {
170 170
         if (isset($getVars['f']))
171 171
         {
172
-            $this->filterQuery = $getVars['f'];
172
+            $this->filterQuery=$getVars['f'];
173 173
             $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames);
174 174
         }
175 175
     }
@@ -193,16 +193,16 @@  discard block
 block discarded – undo
193 193
         {
194 194
             if ($orderSQL != "") $orderSQL.=',';
195 195
             
196
-            $orderSQL .= $column . ' ' . $direction;
196
+            $orderSQL.=$column.' '.$direction;
197 197
         }
198
-        $this->query = $this->query->order($orderSQL);
198
+        $this->query=$this->query->order($orderSQL);
199 199
         
200 200
         return $this;
201 201
     }
202 202
     
203 203
     public function setOrder(array $order)
204 204
     {
205
-        $this->order = $order;
205
+        $this->order=$order;
206 206
         return $this;
207 207
     }
208 208
     
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
     {
211 211
         if (isset($getVars['o']))
212 212
         {
213
-            $this->orderQuery = $getVars['o'];
214
-            $match = array();
215
-            if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery , $match))
213
+            $this->orderQuery=$getVars['o'];
214
+            $match=array();
215
+            if (preg_match('/(.*)(ASC|DESC)$/', $this->orderQuery, $match))
216 216
             {
217 217
                 $orderArray=array($match[1] => $match[2]);
218 218
                 echo "$match[1] => $match[2]";
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
     
232 232
     public function countQuery()
233 233
     {
234
-        $this->query = $this->dbConn->select();
235
-        $this->query = $this->query
234
+        $this->query=$this->dbConn->select();
235
+        $this->query=$this->query
236 236
             ->from(
237 237
                 $this->table,
238 238
                 array('COUNT(*)')
@@ -248,14 +248,14 @@  discard block
 block discarded – undo
248 248
     
249 249
     public function setMaxPerPage(int $max)
250 250
     {
251
-        $this->maxPerPage = $max;
251
+        $this->maxPerPage=$max;
252 252
     }
253 253
     
254 254
     protected function getPagingQuery(array $getVars)
255 255
     {
256 256
         if (isset($getVars['page']))
257 257
         {
258
-            $this->currentPage = $getVars['page'];
258
+            $this->currentPage=$getVars['page'];
259 259
         }
260 260
     }
261 261
 
@@ -267,22 +267,22 @@  discard block
 block discarded – undo
267 267
     
268 268
     public function renderPagingHeader()
269 269
     {
270
-        $count = $this->count();
271
-        if ($count <= $this->maxPerPage )
270
+        $count=$this->count();
271
+        if ($count <= $this->maxPerPage)
272 272
         {
273
-            return  'count : ' . $this->count() . '<br>';
273
+            return  'count : '.$this->count().'<br>';
274 274
         }
275 275
         
276
-        if ($this->currentPage == 0) $this->currentPage = 1;
276
+        if ($this->currentPage == 0) $this->currentPage=1;
277 277
         
278
-        $numPages = intdiv($count , $this->maxPerPage);
279
-        if ($count % $this->maxPerPage != 0 ) $numPages++;
278
+        $numPages=intdiv($count, $this->maxPerPage);
279
+        if ($count % $this->maxPerPage != 0) $numPages++;
280 280
         
281
-        $html = '<div class="pagination-control" role="navigation">';
282
-        $html .= '<ul class="nav tab-nav">';
283
-        if ($this->currentPage <=1)
281
+        $html='<div class="pagination-control" role="navigation">';
282
+        $html.='<ul class="nav tab-nav">';
283
+        if ($this->currentPage <= 1)
284 284
         {
285
-            $html .= '
285
+            $html.='
286 286
                 <li class="nav-item disabled" aria-hidden="true">
287 287
                     <span class="previous-page">
288 288
                             <span class="sr-only">Previous page</span>
@@ -293,24 +293,24 @@  discard block
 block discarded – undo
293 293
         }
294 294
         else 
295 295
         {
296
-            $html .= '
296
+            $html.='
297 297
                 <li class="nav-item">
298
-                    <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" >
298
+                    <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage - 1).'" class="previous-page" >
299 299
                             <i aria-hidden="true" class="icon-angle-double-left"></i>            
300 300
                      </a>
301 301
                 </li>
302 302
             ';
303 303
         }
304 304
         
305
-        for ($i=1; $i <= $numPages ; $i++)
305
+        for ($i=1; $i <= $numPages; $i++)
306 306
         {
307
-            $active = ($this->currentPage == $i) ? 'active' : '';
308
-            $first = ($i-1)*$this->maxPerPage+1;
309
-            $last = $i * $this->maxPerPage;
310
-            if ($last > $count) $last = $count;
311
-            $display = 'Show rows '. $first . ' to '. $last .' of '. $count;
312
-            $html .= '<li class="' . $active . ' nav-item">
313
-                    <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '">
307
+            $active=($this->currentPage == $i) ? 'active' : '';
308
+            $first=($i - 1) * $this->maxPerPage + 1;
309
+            $last=$i * $this->maxPerPage;
310
+            if ($last > $count) $last=$count;
311
+            $display='Show rows '.$first.' to '.$last.' of '.$count;
312
+            $html.='<li class="'.$active.' nav-item">
313
+                    <a href="'. $this->getCurrentURLAndQS('paging').'&page='.$i.'" title="'.$display.'" aria-label="'.$display.'">
314 314
                     '.$i.'                
315 315
                     </a>
316 316
                 </li>';
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
         
319 319
         if ($this->currentPage == $numPages)
320 320
         {
321
-            $html .= '
321
+            $html.='
322 322
                 <li class="nav-item disabled" aria-hidden="true">
323 323
                     <span class="previous-page">
324 324
                             <span class="sr-only">Previous page</span>
@@ -329,23 +329,23 @@  discard block
 block discarded – undo
329 329
         }
330 330
         else
331 331
         {
332
-            $html .= '
332
+            $html.='
333 333
                 <li class="nav-item">
334
-                    <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page">
334
+                    <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage + 1).'" class="next-page">
335 335
                             <i aria-hidden="true" class="icon-angle-double-right"></i>
336 336
                      </a>
337 337
                 </li>
338 338
             ';
339 339
         }
340 340
         
341
-        $html .= '</ul> </div>';
341
+        $html.='</ul> </div>';
342 342
         
343 343
         return $html;
344 344
     }
345 345
     
346 346
     public function applyPaging()
347 347
     {
348
-        $this->query->limitPage($this->currentPage,$this->maxPerPage);
348
+        $this->query->limitPage($this->currentPage, $this->maxPerPage);
349 349
         return $this;
350 350
     }
351 351
     
@@ -358,10 +358,10 @@  discard block
 block discarded – undo
358 358
     
359 359
     public function renderTitles()
360 360
     {
361
-        $html = "<thead>\n<tr>\n";
361
+        $html="<thead>\n<tr>\n";
362 362
         foreach ($this->titles as $name => $values)
363 363
         {
364
-            $titleOrder = $this->titleOrder($name);
364
+            $titleOrder=$this->titleOrder($name);
365 365
             if ($titleOrder != NULL)
366 366
             {
367 367
                 if (isset($this->order[$titleOrder]))
@@ -379,56 +379,56 @@  discard block
 block discarded – undo
379 379
                 {
380 380
                     $titleOrder.='ASC';
381 381
                 }
382
-                $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder;
383
-                $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>';
382
+                $actionURL=$this->getCurrentURLAndQS('order').'o='.$titleOrder;
383
+                $html.='<th><a href="'.$actionURL.'">'.$values.'</a></th>';
384 384
             }
385 385
             else 
386 386
             {
387
-                $html .= '<th>' . $values . '</th>';
387
+                $html.='<th>'.$values.'</th>';
388 388
             }          
389 389
         }
390
-        $html .= "</tr>\n</thead>\n";
390
+        $html.="</tr>\n</thead>\n";
391 391
         return $html;
392 392
     }
393 393
     
394
-    public function renderLine( $value)
394
+    public function renderLine($value)
395 395
     {
396
-        $html = '';
397
-        $titleNames = array_keys($this->titles);
398
-        foreach ($titleNames as $name )
396
+        $html='';
397
+        $titleNames=array_keys($this->titles);
398
+        foreach ($titleNames as $name)
399 399
         {
400
-            $html .= '<td>';
401
-            $html .= $value->$name;
402
-            $html .= "</td>\n";
400
+            $html.='<td>';
401
+            $html.=$value->$name;
402
+            $html.="</td>\n";
403 403
         }
404 404
         return $html;
405 405
     }
406 406
     
407 407
     public function renderTable(array $values)
408 408
     {
409
-       $html = '<tbody id="obj_table_body">';
410
-       foreach($values as $value)
409
+       $html='<tbody id="obj_table_body">';
410
+       foreach ($values as $value)
411 411
        {
412
-           $html .= "<tr>\n";
413
-           $html .= $this->renderLine($value);
414
-           $html .= "</tr>\n";
412
+           $html.="<tr>\n";
413
+           $html.=$this->renderLine($value);
414
+           $html.="</tr>\n";
415 415
        }
416
-       $html .= '</tbody>';
416
+       $html.='</tbody>';
417 417
        return $html;
418 418
     }
419 419
     
420 420
     public function render()
421 421
     {
422
-        $html = '';
422
+        $html='';
423 423
         
424 424
         
425
-        $values = $this->fullQuery();
425
+        $values=$this->fullQuery();
426 426
         
427 427
         $html.="<table class='simple common-table table-row-selectable'>\n";
428 428
         
429
-        $html .= $this->renderTitles();
430
-        $html .= $this->renderTable($values);
431
-        $html .= '</table>'; 
429
+        $html.=$this->renderTitles();
430
+        $html.=$this->renderTable($values);
431
+        $html.='</table>'; 
432 432
         
433 433
 
434 434
         return $html;
Please login to merge, or discard this patch.
Braces   +41 added lines, -26 removed lines patch added patch discarded remove patch
@@ -79,17 +79,21 @@  discard block
 block discarded – undo
79 79
     {
80 80
         $actionURL = $this->getCurrentURL() . '?' ;
81 81
         $QSList=array();
82
-        if ($caller != 'filter' && $this->curFilterQuery() != '')
83
-            array_push($QSList , $this->curFilterQuery());
82
+        if ($caller != 'filter' && $this->curFilterQuery() != '') {
83
+                    array_push($QSList , $this->curFilterQuery());
84
+        }
84 85
         
85
-        if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '')
86
-            array_push($QSList , $this->curPagingQuery());
86
+        if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') {
87
+                    array_push($QSList , $this->curPagingQuery());
88
+        }
87 89
  
88
-        if ($caller != 'order' && $this->curOrderQuery() != '')
89
-            array_push($QSList , $this->curOrderQuery());
90
+        if ($caller != 'order' && $this->curOrderQuery() != '') {
91
+                    array_push($QSList , $this->curOrderQuery());
92
+        }
90 93
         
91
-        if (count($QSList) != 0)
92
-            $actionURL .=  implode('&', $QSList) . '&';
94
+        if (count($QSList) != 0) {
95
+                    $actionURL .=  implode('&', $QSList) . '&';
96
+        }
93 97
         
94 98
         return $actionURL;
95 99
     }
@@ -133,7 +137,9 @@  discard block
 block discarded – undo
133 137
         $filter='';
134 138
         foreach ($this->filterColumn as $column)
135 139
         {
136
-            if ($filter != "") $filter.=' OR ';
140
+            if ($filter != "") {
141
+            	$filter.=' OR ';
142
+            }
137 143
             //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'";
138 144
             $filter .= $column  . " LIKE '%" . $this->filterString. "%'";
139 145
         }
@@ -176,7 +182,9 @@  discard block
 block discarded – undo
176 182
     
177 183
     protected function curFilterQuery()
178 184
     {
179
-        if ($this->filterQuery == '') return '';
185
+        if ($this->filterQuery == '') {
186
+        	return '';
187
+        }
180 188
         return 'f='.$this->filterQuery;
181 189
     }
182 190
     
@@ -191,7 +199,9 @@  discard block
 block discarded – undo
191 199
         $orderSQL='';
192 200
         foreach ($this->order as $column => $direction)
193 201
         {
194
-            if ($orderSQL != "") $orderSQL.=',';
202
+            if ($orderSQL != "") {
203
+            	$orderSQL.=',';
204
+            }
195 205
             
196 206
             $orderSQL .= $column . ' ' . $direction;
197 207
         }
@@ -223,7 +233,9 @@  discard block
 block discarded – undo
223 233
     
224 234
     protected function curOrderQuery()
225 235
     {
226
-        if ($this->orderQuery == '') return '';
236
+        if ($this->orderQuery == '') {
237
+        	return '';
238
+        }
227 239
         return 'o='.$this->orderQuery;
228 240
     }
229 241
     
@@ -261,7 +273,9 @@  discard block
 block discarded – undo
261 273
 
262 274
     protected function curPagingQuery()
263 275
     {
264
-        if ($this->currentPage == '') return '';
276
+        if ($this->currentPage == '') {
277
+        	return '';
278
+        }
265 279
         return 'page='.$this->currentPage;
266 280
     }
267 281
     
@@ -273,10 +287,14 @@  discard block
 block discarded – undo
273 287
             return  'count : ' . $this->count() . '<br>';
274 288
         }
275 289
         
276
-        if ($this->currentPage == 0) $this->currentPage = 1;
290
+        if ($this->currentPage == 0) {
291
+        	$this->currentPage = 1;
292
+        }
277 293
         
278 294
         $numPages = intdiv($count , $this->maxPerPage);
279
-        if ($count % $this->maxPerPage != 0 ) $numPages++;
295
+        if ($count % $this->maxPerPage != 0 ) {
296
+        	$numPages++;
297
+        }
280 298
         
281 299
         $html = '<div class="pagination-control" role="navigation">';
282 300
         $html .= '<ul class="nav tab-nav">';
@@ -290,8 +308,7 @@  discard block
 block discarded – undo
290 308
                      </span>
291 309
                 </li>
292 310
                ';
293
-        }
294
-        else 
311
+        } else 
295 312
         {
296 313
             $html .= '
297 314
                 <li class="nav-item">
@@ -307,7 +324,9 @@  discard block
 block discarded – undo
307 324
             $active = ($this->currentPage == $i) ? 'active' : '';
308 325
             $first = ($i-1)*$this->maxPerPage+1;
309 326
             $last = $i * $this->maxPerPage;
310
-            if ($last > $count) $last = $count;
327
+            if ($last > $count) {
328
+            	$last = $count;
329
+            }
311 330
             $display = 'Show rows '. $first . ' to '. $last .' of '. $count;
312 331
             $html .= '<li class="' . $active . ' nav-item">
313 332
                     <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '">
@@ -326,8 +345,7 @@  discard block
 block discarded – undo
326 345
                      </span>
327 346
                 </li>
328 347
                ';
329
-        }
330
-        else
348
+        } else
331 349
         {
332 350
             $html .= '
333 351
                 <li class="nav-item">
@@ -369,20 +387,17 @@  discard block
 block discarded – undo
369 387
                     if ($this->order[$titleOrder] == 'ASC')
370 388
                     {
371 389
                         $titleOrder.='DESC';
372
-                    }
373
-                    else
390
+                    } else
374 391
                     {
375 392
                         $titleOrder.='ASC';
376 393
                     }
377
-                }
378
-                else 
394
+                } else 
379 395
                 {
380 396
                     $titleOrder.='ASC';
381 397
                 }
382 398
                 $actionURL = $this->getCurrentURLAndQS('order').'o='.$titleOrder;
383 399
                 $html .= '<th><a href="'.$actionURL.'">' . $values . '</a></th>';
384
-            }
385
-            else 
400
+            } else 
386 401
             {
387 402
                 $html .= '<th>' . $values . '</th>';
388 403
             }          
Please login to merge, or discard this patch.