Passed
Branch master (535423)
by Gunnar
02:24
created
src/HTMLTable/CHTMLTable.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
      * specified, a table footer. It is possible to specify the table and the
48 48
      * tabel cells settings per column.
49 49
      *
50
-     * @param  [] $tableSpec    table settings.
50
+     * @param  [] $tableSpecs    table settings.
51 51
      * @param  [] $data         table cell data.
52 52
      * @param  [] $columnSpecs  table columns cell settings.
53 53
      *
54
-     * @return object           the html table object.
54
+     * @return CHTMLTable           the html table object.
55 55
      */
56 56
     public function create($tableSpecs = [], $data = [], $columnSpecs = [])
57 57
     {
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      * Merges the table specifications with the default specifications.
86 86
      * Default table CSS id is html-table.
87 87
      *
88
-     * @param [] $table     table settings.
88
+     * @param [] $tableSpec     table settings.
89 89
      *
90 90
      * @return void
91 91
      */
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
      *
463 463
      * Gets the table with table data.
464 464
      *
465
-     * @return html     the table with table data.
465
+     * @return string     the table with table data.
466 466
      */
467 467
     public function getHTMLTable()
468 468
     {
Please login to merge, or discard this patch.
Indentation   +462 added lines, -462 removed lines patch added patch discarded remove patch
@@ -17,466 +17,466 @@
 block discarded – undo
17 17
  */
18 18
 class CHTMLTable
19 19
 {
20
-    const FOOTER = 'footer';
21
-
22
-    private $tableSpec;
23
-    private $tableHead;
24
-    private $tableBody;
25
-    private $tableFoot;
26
-
27
-    /**
28
-     * Constructor
29
-     *
30
-     * Creates a table with table head, table body and if specified, a table
31
-     * footer. It is possible to specify the table and the tabel cells settings
32
-     * per column.
33
-     *
34
-     * @param [] $tableSpecs    table settings.
35
-     * @param [] $data          table cell data.
36
-     * @param [] $columnSpecs   table columns cell settings.
37
-     */
38
-    public function __construct($tableSpecs = [], $data = [], $columnSpecs = [])
39
-    {
40
-        $this->create($tableSpecs, $data, $columnSpecs);
41
-    }
42
-
43
-    /**
44
-     * Creates a table with cell data.
45
-     *
46
-     * Creates a table with table head, table body with table data and if
47
-     * specified, a table footer. It is possible to specify the table and the
48
-     * tabel cells settings per column.
49
-     *
50
-     * @param  [] $tableSpec    table settings.
51
-     * @param  [] $data         table cell data.
52
-     * @param  [] $columnSpecs  table columns cell settings.
53
-     *
54
-     * @return object           the html table object.
55
-     */
56
-    public function create($tableSpecs = [], $data = [], $columnSpecs = [])
57
-    {
58
-        $this->resetTableTags();
59
-        $this->setTableSpecifications($tableSpecs);
60
-
61
-        $this->createTableHead($data, $columnSpecs);
62
-        $this->createTableBody($data, $columnSpecs);
63
-        $this->createTableFooter($columnSpecs);
64
-
65
-        return $this;
66
-    }
67
-
68
-    /**
69
-     * Helper method to reset main parts of table tags.
70
-     *
71
-     * Sets the table head, table body and table foot tag to null.
72
-     *
73
-     * @return void
74
-     */
75
-    private function resetTableTags()
76
-    {
77
-        $this->tableHead = null;
78
-        $this->tableBody = null;
79
-        $this->tableFoot = null;
80
-    }
81
-
82
-    /**
83
-     * Helper method to set the table specifications.
84
-     *
85
-     * Merges the table specifications with the default specifications.
86
-     * Default table CSS id is html-table.
87
-     *
88
-     * @param [] $table     table settings.
89
-     *
90
-     * @return void
91
-     */
92
-    private function setTableSpecifications($tableSpec)
93
-    {
94
-        $defaults = [
95
-            // Always have a id for the form
96
-            'id' => 'html-table',
97
-        ];
98
-
99
-        if ($this->isClassPresent($tableSpec)) {
100
-            $tableSpec = $this->removeId($tableSpec);
101
-        }
102
-
103
-        $this->tableSpec = array_merge($defaults, $tableSpec);
104
-    }
105
-
106
-    /**
107
-     * Helper method to check if a CSS class tag is present
108
-     *
109
-     * Checks if a CSS class tag is present in the table specification.
110
-     *
111
-     * @param  []  $tableSpec the table specification.
112
-     *
113
-     * @return boolean true if class is present in the table specification,
114
-     *                 false otherwise.
115
-     */
116
-    private function isClassPresent($tableSpec)
117
-    {
118
-        return isset($tableSpec['class']) ? true : false;
119
-    }
120
-
121
-    /**
122
-     * Helper method to reset the id tag.
123
-     *
124
-     * Sets the CSS id tag to null.
125
-     *
126
-     * @param  [] $tableSpec the table specification.
127
-     *
128
-     * @return [] the table specification without the CSS id tag.
129
-     */
130
-    private function removeId($tableSpec) {
131
-        $tableSpec['id'] = null;
132
-
133
-        return $tableSpec;
134
-    }
135
-
136
-    /**
137
-     * Helper method to create the table head.
138
-     *
139
-     * Creates the table head. The title of the columns are set according to
140
-     * the table tag in the column specifications. Otherwise, the title is set
141
-     * to the keys name in the table cell data array.
142
-     *
143
-     * @param  [] $data         table cell data.
144
-     * @param  [] $columnSpecs  table columns cell settings.
145
-     *
146
-     * @return void
147
-     */
148
-    private function createTableHead($data, $columnSpecs)
149
-    {
150
-        $this->tableHead = "\n<thead>";
151
-        $this->tableHead .= "\n<tr>";
152
-
153
-        if (empty($columnSpecs))
154
-        {
155
-            $this->setColumnTitlesFromData($data);
156
-        } else {
157
-            $this->setColumnTitlesFromColumnSpecifications($columnSpecs);
158
-        }
159
-
160
-        $this->tableHead .= "\n</tr>";
161
-        $this->tableHead .= "\n</thead>";
162
-    }
163
-
164
-    /**
165
-     * Helper method to set the column titles from the data array.
166
-     *
167
-     * Uses the first row in the table cell data array to set the titles of
168
-     * the columns. The name of the columns are the key name in the associative
169
-     * array containing data for the table.
170
-     *
171
-     * @param  [] $data     table cell data.
172
-     *
173
-     * @return void
174
-     */
175
-    private function setColumnTitlesFromData($data)
176
-    {
177
-        $firstRow = isset($data[0]) ? $data[0] : [];
178
-        foreach ($firstRow as $key => $value) {
179
-            $this->tableHead .= "\n<th>";
180
-            $this->tableHead .= $key;
181
-            $this->tableHead .= "</th>";
182
-        }
183
-    }
184
-
185
-    /**
186
-     * Helper method to set the column titles from column specifications.
187
-     *
188
-     * Uses column specifications to set the name of the columns in the table
189
-     * head.
190
-     *
191
-     * @param  [] $columnSpecs    table columns cell settings
192
-     *
193
-     * @return void
194
-     */
195
-    private function setColumnTitlesFromColumnSpecifications($columnSpecs)
196
-    {
197
-        foreach ($columnSpecs as $key => $columnSpec) {
198
-            if (!$this->isTableFooter($columnSpec)) {
199
-                $this->tableHead .= "\n<th>";
200
-                $this->tableHead .= $this->getTitle($key, $columnSpec);
201
-                $this->tableHead .= "</th>";
202
-            }
203
-        }
204
-    }
205
-
206
-    /**
207
-     * Helper method to check if the column cell belongs to the footer.
208
-     *
209
-     * Checks the type tag, in the column specification for one column, if the
210
-     * tag is present and set to footer.
211
-     *
212
-     * @param  []  $columnSpec    cell settings for one column.
213
-     *
214
-     * @return boolean true if the cell type belongs to the footer, false otherwise.
215
-     */
216
-    private function isTableFooter($columnSpec)
217
-    {
218
-        $isFooter = false;
219
-        if (isset($columnSpec['type'])) {
220
-            if (strcmp($columnSpec['type'], self::FOOTER) === 0) {
221
-                $isFooter = true;
222
-            }
223
-        }
224
-
225
-        return $isFooter;
226
-    }
227
-
228
-    /**
229
-     * Helper method to get title from a column specification, if specified.
230
-     *
231
-     * Uses the title tag in the column specification for one column to get
232
-     * the title. If the title tag is not set, the title is the key name in
233
-     * the associative array containing data for the table.
234
-     *
235
-     * @param  [] $key          the name of the key for the table cell data.
236
-     * @param  [] $columnSpec   cell settings for one column.
237
-     *
238
-     * @return []   the name from the title tag in the cell specification.
239
-     *              Otherwise, the table cell data key name.
240
-     */
241
-    private function getTitle($key, $columnSpec)
242
-    {
243
-        return isset($columnSpec['title']) ? $columnSpec['title'] : $key;
244
-    }
245
-
246
-    /**
247
-     * Helper method to create the table body with table cell data.
248
-     *
249
-     * Sets the table cell data in the table body.
250
-     *
251
-     * @param  [] $data         table cell data.
252
-     * @param  [] $columnSpecs  table columns cell settings.
253
-     *
254
-     * @return void
255
-     */
256
-    private function createTableBody($data, $columnSpecs)
257
-    {
258
-        $this->tableBody = "\n<tbody>";
259
-        $this->setTableData($data, $columnSpecs);
260
-        $this->tableBody .= "\n</tbody>";
261
-    }
262
-
263
-    /**
264
-     * Helper method to set table data in table body.
265
-     *
266
-     * Sets table data according to the column specifications, if it is
267
-     * specified. Otherwise it sets the data as it is stored in the data array.
268
-     *
269
-     * @param  [] $data         table cell data.
270
-     * @param  [] $columnSpecs  table columns cell settings.
271
-     *
272
-     * @return void
273
-     */
274
-    private function setTableData($data, $columnSpecs)
275
-    {
276
-        if (empty($columnSpecs)) {
277
-            $this->setTableDataFromData($data);
278
-        } else {
279
-            $this->setTableDataAsSpecified($data, $columnSpecs);
280
-        }
281
-    }
282
-
283
-    /**
284
-     * Helper method to set table data from the data array.
285
-     *
286
-     * Sets table data from the data array.
287
-     *
288
-     * @param  [] $data     table cell data.
289
-     *
290
-     * @return void
291
-     */
292
-    private function setTableDataFromData($data)
293
-    {
294
-        foreach ($data as $row) {
295
-            $this->tableBody .= "\n<tr>";
296
-            foreach ($row as $value) {
297
-                $this->tableBody .= "\n<td>";
298
-                $this->tableBody .= $value;
299
-                $this->tableBody .= "</td>";
300
-            }
301
-            $this->tableBody .= "\n</tr>";
302
-        }
303
-    }
304
-
305
-    /**
306
-     * Helper method to set table data according to the column specifications.
307
-     *
308
-     * Sets the table data according to the column specifications, if the cell
309
-     * does not belong to the footer. Adds a colspan tag, if it is specified
310
-     * for the cell in the column.
311
-     *
312
-     * @param  [] $data         table cell data.
313
-     * @param  [] $columnSpecs  table columns cell settings.
314
-     *
315
-     * @return void
316
-     */
317
-    private function setTableDataAsSpecified($data, $columnSpecs)
318
-    {
319
-        foreach ($data as $row) {
320
-            $this->tableBody .= "\n<tr>";
321
-            foreach ($columnSpecs as $key => $columnSpec) {
322
-                if (!$this->isTableFooter($columnSpec)) {
323
-                    $colspan = $this->getColspan($columnSpec);
324
-                    $this->tableBody .= "\n<td{$colspan}>";
325
-                    $this->tableBody .= $this->getValue($row, $key, $columnSpec);
326
-                    $this->tableBody .= "</td>";
327
-                }
328
-            }
329
-            $this->tableBody .= "\n</tr>";
330
-        }
331
-    }
332
-
333
-    /**
334
-     * Helper method to get the colspan value, if specified in the column
335
-     * specification for the cell.
336
-     *
337
-     * @param  [] $columnSpec     cell settings for one column.
338
-     *
339
-     * @return int  the colspan value if specified. Otherwise null.
340
-     */
341
-    private function getColspan($columnSpec)
342
-    {
343
-        return isset($columnSpec['colspan']) ? " colspan='{$columnSpec['colspan']}'" : null;
344
-    }
345
-
346
-    /**
347
-     * Helper method to get the value for a specific position in one row in
348
-     * the data array.
349
-     *
350
-     * Gets the data from a specific position in one row in the data array.
351
-     * If a function is specified for the cell in the column, the data is
352
-     * runned through the function before it is returned.
353
-     *
354
-     * @param [] $row           one row of in the array of table data.
355
-     * @param string $key       the name of the key in the associative data array.
356
-     * @param [] $columnSpec    cell settings for one column.
357
-     */
358
-    private function getValue($row, $key, $columnSpec)
359
-    {
360
-        if ($this->isFunctionSpecified($columnSpec)) {
361
-            $dataValue = isset($row[$key]) ? $row[$key] : "";
362
-            return $this->getValueThroughFunction($columnSpec, $dataValue);
363
-        } else {
364
-            return isset($row[$key]) ? $row[$key] : "";
365
-        }
366
-    }
367
-
368
-    /**
369
-     * Helper method t check if the function tag is specified for the cells in
370
-     * one column.
371
-     *
372
-     * Checks if the function tag is set for the cell in one column.
373
-     *
374
-     * @param  []  $columnSpec    cell settings for one column.
375
-     *
376
-     * @return boolean true if a function is connected to the cell, false otherwise.
377
-     */
378
-    private function isFunctionSpecified($columnSpec)
379
-    {
380
-        return isset($columnSpec['function']) ? true : false;
381
-    }
382
-
383
-    /**
384
-     * Helper method to run the value through a function before it is returned.
385
-     *
386
-     * Runs the value through a function, if a function is connected to the cell
387
-     * in the column. If not function is connected to the cell through the
388
-     * column specification, the value is returned as it is.
389
-     *
390
-     * @param [] $columnSpec    cell settings for one column
391
-     * @param mixed $dataValue  the value to run through function, if specified.
392
-     *
393
-     * @return the value.
394
-     */
395
-    private function getValueThroughFunction($columnSpec, $dataValue)
396
-    {
397
-        if (!empty($columnSpec['function'])) {
398
-            return call_user_func($columnSpec['function'], $dataValue);
399
-        } else {
400
-            return $dataValue;
401
-        }
402
-    }
403
-
404
-    /**
405
-     * Helper method to create table footer with data.
406
-     *
407
-     * Creates table footer if the cell settings for the column is set to
408
-     * footer in the column specifications.
409
-     * Adds a colspan tag, if it is specified for the cell in the column.
410
-     *
411
-     * @param  [] $columnSpecs    table columns cell settings.
412
-     *
413
-     * @return void
414
-     */
415
-    private function createTableFooter($columnSpecs)
416
-    {
417
-        $isFooterDataAdded = false;
418
-
419
-        $this->tableFoot = "\n<tfoot>";
420
-        $this->tableFoot .= "\n<tr>";
421
-        foreach ($columnSpecs as $key => $columnSpec) {
422
-            if ($this->isTableFooter($columnSpec)) {
423
-                $colspan = $this->getColspan($columnSpec);
424
-                $this->tableFoot .= "\n<td{$colspan}>";
425
-                $this->tableFoot .= $this->getFooterData($columnSpec);
426
-                $this->tableFoot .= "</td>";
427
-                $isFooterDataAdded = true;
428
-            }
429
-        }
430
-
431
-        if ($isFooterDataAdded) {
432
-            $this->tableFoot .= "\n</tr>";
433
-            $this->tableFoot .= "\n</tfoot>";
434
-        } else {
435
-            $this->tableFoot = null;
436
-        }
437
-    }
438
-
439
-    /**
440
-     * Helper method to get table footer data.
441
-     *
442
-     * Gets table footer data from the column specification. Checks if the
443
-     * value should be fetched from a function or from the value tag.
444
-     * If either the function or the value specified, an empty string is
445
-     * returned.
446
-     *
447
-     * @param  [] $columnSpec   cell settings for one column.
448
-     *
449
-     * @return mixed    the cell data value.
450
-     */
451
-    private function getFooterData($columnSpec)
452
-    {
453
-        if ($this->isFunctionSpecified($columnSpec)) {
454
-            return call_user_func($columnSpec['function']);
455
-        } else {
456
-            return isset($columnSpec['value']) ? $columnSpec['value'] : "";
457
-        }
458
-    }
459
-
460
-    /**
461
-     * Gets the table.
462
-     *
463
-     * Gets the table with table data.
464
-     *
465
-     * @return html     the table with table data.
466
-     */
467
-    public function getHTMLTable()
468
-    {
469
-        $id = isset($this->tableSpec['id']) ? " id='{$this->tableSpec['id']}'" : null;
470
-        $class = isset($this->tableSpec['class']) ? " class='{$this->tableSpec['class']}'" : null;
471
-        $caption = isset($this->tableSpec['caption']) ? "<caption>{$this->tableSpec['caption']}</caption>" : null;
472
-
473
-        $htmlTable = "<table{$id}{$class}>";
474
-        $htmlTable .= $caption;
475
-        $htmlTable .= $this->tableHead;
476
-        $htmlTable .= $this->tableBody;
477
-        $htmlTable .= $this->tableFoot;
478
-        $htmlTable .= "\n</table>";
479
-
480
-        return $htmlTable;
481
-    }
20
+	const FOOTER = 'footer';
21
+
22
+	private $tableSpec;
23
+	private $tableHead;
24
+	private $tableBody;
25
+	private $tableFoot;
26
+
27
+	/**
28
+	 * Constructor
29
+	 *
30
+	 * Creates a table with table head, table body and if specified, a table
31
+	 * footer. It is possible to specify the table and the tabel cells settings
32
+	 * per column.
33
+	 *
34
+	 * @param [] $tableSpecs    table settings.
35
+	 * @param [] $data          table cell data.
36
+	 * @param [] $columnSpecs   table columns cell settings.
37
+	 */
38
+	public function __construct($tableSpecs = [], $data = [], $columnSpecs = [])
39
+	{
40
+		$this->create($tableSpecs, $data, $columnSpecs);
41
+	}
42
+
43
+	/**
44
+	 * Creates a table with cell data.
45
+	 *
46
+	 * Creates a table with table head, table body with table data and if
47
+	 * specified, a table footer. It is possible to specify the table and the
48
+	 * tabel cells settings per column.
49
+	 *
50
+	 * @param  [] $tableSpec    table settings.
51
+	 * @param  [] $data         table cell data.
52
+	 * @param  [] $columnSpecs  table columns cell settings.
53
+	 *
54
+	 * @return object           the html table object.
55
+	 */
56
+	public function create($tableSpecs = [], $data = [], $columnSpecs = [])
57
+	{
58
+		$this->resetTableTags();
59
+		$this->setTableSpecifications($tableSpecs);
60
+
61
+		$this->createTableHead($data, $columnSpecs);
62
+		$this->createTableBody($data, $columnSpecs);
63
+		$this->createTableFooter($columnSpecs);
64
+
65
+		return $this;
66
+	}
67
+
68
+	/**
69
+	 * Helper method to reset main parts of table tags.
70
+	 *
71
+	 * Sets the table head, table body and table foot tag to null.
72
+	 *
73
+	 * @return void
74
+	 */
75
+	private function resetTableTags()
76
+	{
77
+		$this->tableHead = null;
78
+		$this->tableBody = null;
79
+		$this->tableFoot = null;
80
+	}
81
+
82
+	/**
83
+	 * Helper method to set the table specifications.
84
+	 *
85
+	 * Merges the table specifications with the default specifications.
86
+	 * Default table CSS id is html-table.
87
+	 *
88
+	 * @param [] $table     table settings.
89
+	 *
90
+	 * @return void
91
+	 */
92
+	private function setTableSpecifications($tableSpec)
93
+	{
94
+		$defaults = [
95
+			// Always have a id for the form
96
+			'id' => 'html-table',
97
+		];
98
+
99
+		if ($this->isClassPresent($tableSpec)) {
100
+			$tableSpec = $this->removeId($tableSpec);
101
+		}
102
+
103
+		$this->tableSpec = array_merge($defaults, $tableSpec);
104
+	}
105
+
106
+	/**
107
+	 * Helper method to check if a CSS class tag is present
108
+	 *
109
+	 * Checks if a CSS class tag is present in the table specification.
110
+	 *
111
+	 * @param  []  $tableSpec the table specification.
112
+	 *
113
+	 * @return boolean true if class is present in the table specification,
114
+	 *                 false otherwise.
115
+	 */
116
+	private function isClassPresent($tableSpec)
117
+	{
118
+		return isset($tableSpec['class']) ? true : false;
119
+	}
120
+
121
+	/**
122
+	 * Helper method to reset the id tag.
123
+	 *
124
+	 * Sets the CSS id tag to null.
125
+	 *
126
+	 * @param  [] $tableSpec the table specification.
127
+	 *
128
+	 * @return [] the table specification without the CSS id tag.
129
+	 */
130
+	private function removeId($tableSpec) {
131
+		$tableSpec['id'] = null;
132
+
133
+		return $tableSpec;
134
+	}
135
+
136
+	/**
137
+	 * Helper method to create the table head.
138
+	 *
139
+	 * Creates the table head. The title of the columns are set according to
140
+	 * the table tag in the column specifications. Otherwise, the title is set
141
+	 * to the keys name in the table cell data array.
142
+	 *
143
+	 * @param  [] $data         table cell data.
144
+	 * @param  [] $columnSpecs  table columns cell settings.
145
+	 *
146
+	 * @return void
147
+	 */
148
+	private function createTableHead($data, $columnSpecs)
149
+	{
150
+		$this->tableHead = "\n<thead>";
151
+		$this->tableHead .= "\n<tr>";
152
+
153
+		if (empty($columnSpecs))
154
+		{
155
+			$this->setColumnTitlesFromData($data);
156
+		} else {
157
+			$this->setColumnTitlesFromColumnSpecifications($columnSpecs);
158
+		}
159
+
160
+		$this->tableHead .= "\n</tr>";
161
+		$this->tableHead .= "\n</thead>";
162
+	}
163
+
164
+	/**
165
+	 * Helper method to set the column titles from the data array.
166
+	 *
167
+	 * Uses the first row in the table cell data array to set the titles of
168
+	 * the columns. The name of the columns are the key name in the associative
169
+	 * array containing data for the table.
170
+	 *
171
+	 * @param  [] $data     table cell data.
172
+	 *
173
+	 * @return void
174
+	 */
175
+	private function setColumnTitlesFromData($data)
176
+	{
177
+		$firstRow = isset($data[0]) ? $data[0] : [];
178
+		foreach ($firstRow as $key => $value) {
179
+			$this->tableHead .= "\n<th>";
180
+			$this->tableHead .= $key;
181
+			$this->tableHead .= "</th>";
182
+		}
183
+	}
184
+
185
+	/**
186
+	 * Helper method to set the column titles from column specifications.
187
+	 *
188
+	 * Uses column specifications to set the name of the columns in the table
189
+	 * head.
190
+	 *
191
+	 * @param  [] $columnSpecs    table columns cell settings
192
+	 *
193
+	 * @return void
194
+	 */
195
+	private function setColumnTitlesFromColumnSpecifications($columnSpecs)
196
+	{
197
+		foreach ($columnSpecs as $key => $columnSpec) {
198
+			if (!$this->isTableFooter($columnSpec)) {
199
+				$this->tableHead .= "\n<th>";
200
+				$this->tableHead .= $this->getTitle($key, $columnSpec);
201
+				$this->tableHead .= "</th>";
202
+			}
203
+		}
204
+	}
205
+
206
+	/**
207
+	 * Helper method to check if the column cell belongs to the footer.
208
+	 *
209
+	 * Checks the type tag, in the column specification for one column, if the
210
+	 * tag is present and set to footer.
211
+	 *
212
+	 * @param  []  $columnSpec    cell settings for one column.
213
+	 *
214
+	 * @return boolean true if the cell type belongs to the footer, false otherwise.
215
+	 */
216
+	private function isTableFooter($columnSpec)
217
+	{
218
+		$isFooter = false;
219
+		if (isset($columnSpec['type'])) {
220
+			if (strcmp($columnSpec['type'], self::FOOTER) === 0) {
221
+				$isFooter = true;
222
+			}
223
+		}
224
+
225
+		return $isFooter;
226
+	}
227
+
228
+	/**
229
+	 * Helper method to get title from a column specification, if specified.
230
+	 *
231
+	 * Uses the title tag in the column specification for one column to get
232
+	 * the title. If the title tag is not set, the title is the key name in
233
+	 * the associative array containing data for the table.
234
+	 *
235
+	 * @param  [] $key          the name of the key for the table cell data.
236
+	 * @param  [] $columnSpec   cell settings for one column.
237
+	 *
238
+	 * @return []   the name from the title tag in the cell specification.
239
+	 *              Otherwise, the table cell data key name.
240
+	 */
241
+	private function getTitle($key, $columnSpec)
242
+	{
243
+		return isset($columnSpec['title']) ? $columnSpec['title'] : $key;
244
+	}
245
+
246
+	/**
247
+	 * Helper method to create the table body with table cell data.
248
+	 *
249
+	 * Sets the table cell data in the table body.
250
+	 *
251
+	 * @param  [] $data         table cell data.
252
+	 * @param  [] $columnSpecs  table columns cell settings.
253
+	 *
254
+	 * @return void
255
+	 */
256
+	private function createTableBody($data, $columnSpecs)
257
+	{
258
+		$this->tableBody = "\n<tbody>";
259
+		$this->setTableData($data, $columnSpecs);
260
+		$this->tableBody .= "\n</tbody>";
261
+	}
262
+
263
+	/**
264
+	 * Helper method to set table data in table body.
265
+	 *
266
+	 * Sets table data according to the column specifications, if it is
267
+	 * specified. Otherwise it sets the data as it is stored in the data array.
268
+	 *
269
+	 * @param  [] $data         table cell data.
270
+	 * @param  [] $columnSpecs  table columns cell settings.
271
+	 *
272
+	 * @return void
273
+	 */
274
+	private function setTableData($data, $columnSpecs)
275
+	{
276
+		if (empty($columnSpecs)) {
277
+			$this->setTableDataFromData($data);
278
+		} else {
279
+			$this->setTableDataAsSpecified($data, $columnSpecs);
280
+		}
281
+	}
282
+
283
+	/**
284
+	 * Helper method to set table data from the data array.
285
+	 *
286
+	 * Sets table data from the data array.
287
+	 *
288
+	 * @param  [] $data     table cell data.
289
+	 *
290
+	 * @return void
291
+	 */
292
+	private function setTableDataFromData($data)
293
+	{
294
+		foreach ($data as $row) {
295
+			$this->tableBody .= "\n<tr>";
296
+			foreach ($row as $value) {
297
+				$this->tableBody .= "\n<td>";
298
+				$this->tableBody .= $value;
299
+				$this->tableBody .= "</td>";
300
+			}
301
+			$this->tableBody .= "\n</tr>";
302
+		}
303
+	}
304
+
305
+	/**
306
+	 * Helper method to set table data according to the column specifications.
307
+	 *
308
+	 * Sets the table data according to the column specifications, if the cell
309
+	 * does not belong to the footer. Adds a colspan tag, if it is specified
310
+	 * for the cell in the column.
311
+	 *
312
+	 * @param  [] $data         table cell data.
313
+	 * @param  [] $columnSpecs  table columns cell settings.
314
+	 *
315
+	 * @return void
316
+	 */
317
+	private function setTableDataAsSpecified($data, $columnSpecs)
318
+	{
319
+		foreach ($data as $row) {
320
+			$this->tableBody .= "\n<tr>";
321
+			foreach ($columnSpecs as $key => $columnSpec) {
322
+				if (!$this->isTableFooter($columnSpec)) {
323
+					$colspan = $this->getColspan($columnSpec);
324
+					$this->tableBody .= "\n<td{$colspan}>";
325
+					$this->tableBody .= $this->getValue($row, $key, $columnSpec);
326
+					$this->tableBody .= "</td>";
327
+				}
328
+			}
329
+			$this->tableBody .= "\n</tr>";
330
+		}
331
+	}
332
+
333
+	/**
334
+	 * Helper method to get the colspan value, if specified in the column
335
+	 * specification for the cell.
336
+	 *
337
+	 * @param  [] $columnSpec     cell settings for one column.
338
+	 *
339
+	 * @return int  the colspan value if specified. Otherwise null.
340
+	 */
341
+	private function getColspan($columnSpec)
342
+	{
343
+		return isset($columnSpec['colspan']) ? " colspan='{$columnSpec['colspan']}'" : null;
344
+	}
345
+
346
+	/**
347
+	 * Helper method to get the value for a specific position in one row in
348
+	 * the data array.
349
+	 *
350
+	 * Gets the data from a specific position in one row in the data array.
351
+	 * If a function is specified for the cell in the column, the data is
352
+	 * runned through the function before it is returned.
353
+	 *
354
+	 * @param [] $row           one row of in the array of table data.
355
+	 * @param string $key       the name of the key in the associative data array.
356
+	 * @param [] $columnSpec    cell settings for one column.
357
+	 */
358
+	private function getValue($row, $key, $columnSpec)
359
+	{
360
+		if ($this->isFunctionSpecified($columnSpec)) {
361
+			$dataValue = isset($row[$key]) ? $row[$key] : "";
362
+			return $this->getValueThroughFunction($columnSpec, $dataValue);
363
+		} else {
364
+			return isset($row[$key]) ? $row[$key] : "";
365
+		}
366
+	}
367
+
368
+	/**
369
+	 * Helper method t check if the function tag is specified for the cells in
370
+	 * one column.
371
+	 *
372
+	 * Checks if the function tag is set for the cell in one column.
373
+	 *
374
+	 * @param  []  $columnSpec    cell settings for one column.
375
+	 *
376
+	 * @return boolean true if a function is connected to the cell, false otherwise.
377
+	 */
378
+	private function isFunctionSpecified($columnSpec)
379
+	{
380
+		return isset($columnSpec['function']) ? true : false;
381
+	}
382
+
383
+	/**
384
+	 * Helper method to run the value through a function before it is returned.
385
+	 *
386
+	 * Runs the value through a function, if a function is connected to the cell
387
+	 * in the column. If not function is connected to the cell through the
388
+	 * column specification, the value is returned as it is.
389
+	 *
390
+	 * @param [] $columnSpec    cell settings for one column
391
+	 * @param mixed $dataValue  the value to run through function, if specified.
392
+	 *
393
+	 * @return the value.
394
+	 */
395
+	private function getValueThroughFunction($columnSpec, $dataValue)
396
+	{
397
+		if (!empty($columnSpec['function'])) {
398
+			return call_user_func($columnSpec['function'], $dataValue);
399
+		} else {
400
+			return $dataValue;
401
+		}
402
+	}
403
+
404
+	/**
405
+	 * Helper method to create table footer with data.
406
+	 *
407
+	 * Creates table footer if the cell settings for the column is set to
408
+	 * footer in the column specifications.
409
+	 * Adds a colspan tag, if it is specified for the cell in the column.
410
+	 *
411
+	 * @param  [] $columnSpecs    table columns cell settings.
412
+	 *
413
+	 * @return void
414
+	 */
415
+	private function createTableFooter($columnSpecs)
416
+	{
417
+		$isFooterDataAdded = false;
418
+
419
+		$this->tableFoot = "\n<tfoot>";
420
+		$this->tableFoot .= "\n<tr>";
421
+		foreach ($columnSpecs as $key => $columnSpec) {
422
+			if ($this->isTableFooter($columnSpec)) {
423
+				$colspan = $this->getColspan($columnSpec);
424
+				$this->tableFoot .= "\n<td{$colspan}>";
425
+				$this->tableFoot .= $this->getFooterData($columnSpec);
426
+				$this->tableFoot .= "</td>";
427
+				$isFooterDataAdded = true;
428
+			}
429
+		}
430
+
431
+		if ($isFooterDataAdded) {
432
+			$this->tableFoot .= "\n</tr>";
433
+			$this->tableFoot .= "\n</tfoot>";
434
+		} else {
435
+			$this->tableFoot = null;
436
+		}
437
+	}
438
+
439
+	/**
440
+	 * Helper method to get table footer data.
441
+	 *
442
+	 * Gets table footer data from the column specification. Checks if the
443
+	 * value should be fetched from a function or from the value tag.
444
+	 * If either the function or the value specified, an empty string is
445
+	 * returned.
446
+	 *
447
+	 * @param  [] $columnSpec   cell settings for one column.
448
+	 *
449
+	 * @return mixed    the cell data value.
450
+	 */
451
+	private function getFooterData($columnSpec)
452
+	{
453
+		if ($this->isFunctionSpecified($columnSpec)) {
454
+			return call_user_func($columnSpec['function']);
455
+		} else {
456
+			return isset($columnSpec['value']) ? $columnSpec['value'] : "";
457
+		}
458
+	}
459
+
460
+	/**
461
+	 * Gets the table.
462
+	 *
463
+	 * Gets the table with table data.
464
+	 *
465
+	 * @return html     the table with table data.
466
+	 */
467
+	public function getHTMLTable()
468
+	{
469
+		$id = isset($this->tableSpec['id']) ? " id='{$this->tableSpec['id']}'" : null;
470
+		$class = isset($this->tableSpec['class']) ? " class='{$this->tableSpec['class']}'" : null;
471
+		$caption = isset($this->tableSpec['caption']) ? "<caption>{$this->tableSpec['caption']}</caption>" : null;
472
+
473
+		$htmlTable = "<table{$id}{$class}>";
474
+		$htmlTable .= $caption;
475
+		$htmlTable .= $this->tableHead;
476
+		$htmlTable .= $this->tableBody;
477
+		$htmlTable .= $this->tableFoot;
478
+		$htmlTable .= "\n</table>";
479
+
480
+		return $htmlTable;
481
+	}
482 482
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      * @param [] $data          table cell data.
36 36
      * @param [] $columnSpecs   table columns cell settings.
37 37
      */
38
-    public function __construct($tableSpecs = [], $data = [], $columnSpecs = [])
38
+    public function __construct($tableSpecs = [ ], $data = [ ], $columnSpecs = [ ])
39 39
     {
40 40
         $this->create($tableSpecs, $data, $columnSpecs);
41 41
     }
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      *
54 54
      * @return object           the html table object.
55 55
      */
56
-    public function create($tableSpecs = [], $data = [], $columnSpecs = [])
56
+    public function create($tableSpecs = [ ], $data = [ ], $columnSpecs = [ ])
57 57
     {
58 58
         $this->resetTableTags();
59 59
         $this->setTableSpecifications($tableSpecs);
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      */
116 116
     private function isClassPresent($tableSpec)
117 117
     {
118
-        return isset($tableSpec['class']) ? true : false;
118
+        return isset($tableSpec[ 'class' ]) ? true : false;
119 119
     }
120 120
 
121 121
     /**
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      * @return [] the table specification without the CSS id tag.
129 129
      */
130 130
     private function removeId($tableSpec) {
131
-        $tableSpec['id'] = null;
131
+        $tableSpec[ 'id' ] = null;
132 132
 
133 133
         return $tableSpec;
134 134
     }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      */
175 175
     private function setColumnTitlesFromData($data)
176 176
     {
177
-        $firstRow = isset($data[0]) ? $data[0] : [];
177
+        $firstRow = isset($data[ 0 ]) ? $data[ 0 ] : [ ];
178 178
         foreach ($firstRow as $key => $value) {
179 179
             $this->tableHead .= "\n<th>";
180 180
             $this->tableHead .= $key;
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
     private function isTableFooter($columnSpec)
217 217
     {
218 218
         $isFooter = false;
219
-        if (isset($columnSpec['type'])) {
220
-            if (strcmp($columnSpec['type'], self::FOOTER) === 0) {
219
+        if (isset($columnSpec[ 'type' ])) {
220
+            if (strcmp($columnSpec[ 'type' ], self::FOOTER) === 0) {
221 221
                 $isFooter = true;
222 222
             }
223 223
         }
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
      */
241 241
     private function getTitle($key, $columnSpec)
242 242
     {
243
-        return isset($columnSpec['title']) ? $columnSpec['title'] : $key;
243
+        return isset($columnSpec[ 'title' ]) ? $columnSpec[ 'title' ] : $key;
244 244
     }
245 245
 
246 246
     /**
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
      */
341 341
     private function getColspan($columnSpec)
342 342
     {
343
-        return isset($columnSpec['colspan']) ? " colspan='{$columnSpec['colspan']}'" : null;
343
+        return isset($columnSpec[ 'colspan' ]) ? " colspan='{$columnSpec[ 'colspan' ]}'" : null;
344 344
     }
345 345
 
346 346
     /**
@@ -358,10 +358,10 @@  discard block
 block discarded – undo
358 358
     private function getValue($row, $key, $columnSpec)
359 359
     {
360 360
         if ($this->isFunctionSpecified($columnSpec)) {
361
-            $dataValue = isset($row[$key]) ? $row[$key] : "";
361
+            $dataValue = isset($row[ $key ]) ? $row[ $key ] : "";
362 362
             return $this->getValueThroughFunction($columnSpec, $dataValue);
363 363
         } else {
364
-            return isset($row[$key]) ? $row[$key] : "";
364
+            return isset($row[ $key ]) ? $row[ $key ] : "";
365 365
         }
366 366
     }
367 367
 
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
      */
378 378
     private function isFunctionSpecified($columnSpec)
379 379
     {
380
-        return isset($columnSpec['function']) ? true : false;
380
+        return isset($columnSpec[ 'function' ]) ? true : false;
381 381
     }
382 382
 
383 383
     /**
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
      */
395 395
     private function getValueThroughFunction($columnSpec, $dataValue)
396 396
     {
397
-        if (!empty($columnSpec['function'])) {
398
-            return call_user_func($columnSpec['function'], $dataValue);
397
+        if (!empty($columnSpec[ 'function' ])) {
398
+            return call_user_func($columnSpec[ 'function' ], $dataValue);
399 399
         } else {
400 400
             return $dataValue;
401 401
         }
@@ -451,9 +451,9 @@  discard block
 block discarded – undo
451 451
     private function getFooterData($columnSpec)
452 452
     {
453 453
         if ($this->isFunctionSpecified($columnSpec)) {
454
-            return call_user_func($columnSpec['function']);
454
+            return call_user_func($columnSpec[ 'function' ]);
455 455
         } else {
456
-            return isset($columnSpec['value']) ? $columnSpec['value'] : "";
456
+            return isset($columnSpec[ 'value' ]) ? $columnSpec[ 'value' ] : "";
457 457
         }
458 458
     }
459 459
 
@@ -466,9 +466,9 @@  discard block
 block discarded – undo
466 466
      */
467 467
     public function getHTMLTable()
468 468
     {
469
-        $id = isset($this->tableSpec['id']) ? " id='{$this->tableSpec['id']}'" : null;
470
-        $class = isset($this->tableSpec['class']) ? " class='{$this->tableSpec['class']}'" : null;
471
-        $caption = isset($this->tableSpec['caption']) ? "<caption>{$this->tableSpec['caption']}</caption>" : null;
469
+        $id = isset($this->tableSpec[ 'id' ]) ? " id='{$this->tableSpec[ 'id' ]}'" : null;
470
+        $class = isset($this->tableSpec[ 'class' ]) ? " class='{$this->tableSpec[ 'class' ]}'" : null;
471
+        $caption = isset($this->tableSpec[ 'caption' ]) ? "<caption>{$this->tableSpec[ 'caption' ]}</caption>" : null;
472 472
 
473 473
         $htmlTable = "<table{$id}{$class}>";
474 474
         $htmlTable .= $caption;
Please login to merge, or discard this patch.
webroot/not-specified-table.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
 	],
42 42
 ];
43 43
 
44
-$table = $table->create([], $data, []);
44
+$table = $table->create([ ], $data, [ ]);
45 45
 
46 46
 ?>
47 47
 
Please login to merge, or discard this patch.
webroot/table-anax-mvc.php 2 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -27,81 +27,81 @@
 block discarded – undo
27 27
 
28 28
  // Home route
29 29
  $app->router->add('', function() use ($app) {
30
-     $app->theme->addStylesheet('css/html-table.css');
31
-     $app->theme->setTitle("Using CHTMLTable in ANAX-MVC");
30
+	 $app->theme->addStylesheet('css/html-table.css');
31
+	 $app->theme->setTitle("Using CHTMLTable in ANAX-MVC");
32 32
 
33
-     $data = [
34
-     	0 => [
35
-     		"column1" => "Table Cell 1",
36
-     		"column2" => "Table Cell 2",
37
-     		"column3" => "Table Cell 3",
38
-     		"column4" => "https://www.google.se",
39
-     		"column5" => "Table Cell 5",
40
-     		"column6" => "Table Cell 6",
41
-     	],
42
-     	1 => [
43
-     		"column1" => "Table Cell 7",
44
-     		"column2" => "Table Cell 8",
45
-     		"column3" => "Table Cell 9",
46
-     		"column4" => "https://www.google.se",
47
-     		"column5" => "Table Cell 11",
48
-     		"column6" => "Table Cell 12",
49
-     	],
50
-     	2 => [
51
-     		"column1" => "Table Cell 13",
52
-     		"column2" => "Table Cell 14",
53
-     		"column3" => "Table Cell 15",
54
-     		"column4" => "https://www.google.se",
55
-     		"column5" => "Table Cell 17",
56
-     		"column6" => "Table Cell 18",
57
-     	],
58
-     ];
33
+	 $data = [
34
+	 	0 => [
35
+	 		"column1" => "Table Cell 1",
36
+	 		"column2" => "Table Cell 2",
37
+	 		"column3" => "Table Cell 3",
38
+	 		"column4" => "https://www.google.se",
39
+	 		"column5" => "Table Cell 5",
40
+	 		"column6" => "Table Cell 6",
41
+	 	],
42
+	 	1 => [
43
+	 		"column1" => "Table Cell 7",
44
+	 		"column2" => "Table Cell 8",
45
+	 		"column3" => "Table Cell 9",
46
+	 		"column4" => "https://www.google.se",
47
+	 		"column5" => "Table Cell 11",
48
+	 		"column6" => "Table Cell 12",
49
+	 	],
50
+	 	2 => [
51
+	 		"column1" => "Table Cell 13",
52
+	 		"column2" => "Table Cell 14",
53
+	 		"column3" => "Table Cell 15",
54
+	 		"column4" => "https://www.google.se",
55
+	 		"column5" => "Table Cell 17",
56
+	 		"column6" => "Table Cell 18",
57
+	 	],
58
+	 ];
59 59
 
60
-     $tableSpecification = [
61
-     	//'id'        => 'test-table',
62
-     	//'class'	  => 'test-table',
63
-     	'caption'	=> 'The table'
64
-     ];
60
+	 $tableSpecification = [
61
+	 	//'id'        => 'test-table',
62
+	 	//'class'	  => 'test-table',
63
+	 	'caption'	=> 'The table'
64
+	 ];
65 65
 
66
-     $table = new \Guer\HTMLTable\CHTMLTable();
66
+	 $table = new \Guer\HTMLTable\CHTMLTable();
67 67
 
68
-     $table = $table->create($tableSpecification, $data, [
69
-         'column1' => [
70
-             'title' => 'Table Header 1',
71
-         ],
72
-         'column2' => [
73
-         ],
74
-         'column4' => [
75
-             'title'    => 'Table Header 4',
76
-             'function'	=> function($link) {
77
-                 return '<a href="'. $link . '">' . "Google" . '</a>';
78
-             }
79
-         ],
80
-         'column6' => [
81
-             'title'    => 'Table Header 6',
82
-             'function' => function($isPresent) {
83
-                 return empty($isPresent) ? 'Not present' :  'Present';
84
-        	}
85
-         ],
86
-         'tablefoot1' => [
87
-             'type'     => 'footer',
88
-             'colspan'  => '2',
89
-             'value'	=> 'Footer Cell 1',
90
-         ],
91
-         'tablefoot2' => [
92
-             'type'      => 'footer',
93
-             'colspan'    => 2,
94
-             'function'   => function() {
95
-                 return '<a href="https://www.google.se">Link</a>';
96
-        	}
97
-         ],
98
-     ]);
68
+	 $table = $table->create($tableSpecification, $data, [
69
+		 'column1' => [
70
+			 'title' => 'Table Header 1',
71
+		 ],
72
+		 'column2' => [
73
+		 ],
74
+		 'column4' => [
75
+			 'title'    => 'Table Header 4',
76
+			 'function'	=> function($link) {
77
+				 return '<a href="'. $link . '">' . "Google" . '</a>';
78
+			 }
79
+		 ],
80
+		 'column6' => [
81
+			 'title'    => 'Table Header 6',
82
+			 'function' => function($isPresent) {
83
+				 return empty($isPresent) ? 'Not present' :  'Present';
84
+			}
85
+		 ],
86
+		 'tablefoot1' => [
87
+			 'type'     => 'footer',
88
+			 'colspan'  => '2',
89
+			 'value'	=> 'Footer Cell 1',
90
+		 ],
91
+		 'tablefoot2' => [
92
+			 'type'      => 'footer',
93
+			 'colspan'    => 2,
94
+			 'function'   => function() {
95
+				 return '<a href="https://www.google.se">Link</a>';
96
+			}
97
+		 ],
98
+	 ]);
99 99
 
100 100
 
101
-     $app->views->add('default/page', [
102
-         'title'        => "Example on using specified HTML table with CHTMLTable",
103
-         'content'      => $table->getHTMLTable(),
104
-     ]);
101
+	 $app->views->add('default/page', [
102
+		 'title'        => "Example on using specified HTML table with CHTMLTable",
103
+		 'content'      => $table->getHTMLTable(),
104
+	 ]);
105 105
  });
106 106
 
107 107
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
  // Get environment & autoloader.
21
- require __DIR__.'/config.php';
21
+ require __DIR__ . '/config.php';
22 22
 
23 23
  // Create services and inject into the app.
24 24
  $di  = new \Anax\DI\CDIFactoryDefault();
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
          'column4' => [
75 75
              'title'    => 'Table Header 4',
76 76
              'function'	=> function($link) {
77
-                 return '<a href="'. $link . '">' . "Google" . '</a>';
77
+                 return '<a href="' . $link . '">' . "Google" . '</a>';
78 78
              }
79 79
          ],
80 80
          'column6' => [
81 81
              'title'    => 'Table Header 6',
82 82
              'function' => function($isPresent) {
83
-                 return empty($isPresent) ? 'Not present' :  'Present';
83
+                 return empty($isPresent) ? 'Not present' : 'Present';
84 84
         	}
85 85
          ],
86 86
          'tablefoot1' => [
Please login to merge, or discard this patch.
webroot/specified-table.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -55,34 +55,34 @@
 block discarded – undo
55 55
 
56 56
 $table = $table->create($tableSpecification, $data, [
57 57
 	'column1' => [
58
-        'title' => 'Table Header 1',
59
-    ],
58
+		'title' => 'Table Header 1',
59
+	],
60 60
 	'column2' => [
61
-    ],
62
-    'column4' => [
63
-        'title'     => 'Table Header 4',
61
+	],
62
+	'column4' => [
63
+		'title'     => 'Table Header 4',
64 64
 		'function'	=> function($link) {
65 65
 			return '<a href="'. $link . '">' . "Google" . '</a>';
66 66
 		}
67
-    ],
67
+	],
68 68
 	'column6' => [
69
-        'title'    	=> 'Table Header 6',
69
+		'title'    	=> 'Table Header 6',
70 70
 		'function' 	=> function($tableCell6) {
71
-        	return empty($tableCell6) ? 'Not present' :  'Present';
71
+			return empty($tableCell6) ? 'Not present' :  'Present';
72 72
    		}
73
-    ],
73
+	],
74 74
 	'tablefoot1' => [
75
-        'type'      => 'footer',
75
+		'type'      => 'footer',
76 76
 		'colspan'  	=> '2',
77 77
 		'value'		=> 'Footer Cell 1',
78
-    ],
78
+	],
79 79
 	'tablefoot2' => [
80
-        'type'      => 'footer',
80
+		'type'      => 'footer',
81 81
 		'colspan'  	=> 2,
82 82
 		'function'	=> function() {
83
-        	return '<a href="https://www.google.se">Link</a>';
83
+			return '<a href="https://www.google.se">Link</a>';
84 84
    		}
85
-    ],
85
+	],
86 86
 ]);
87 87
 
88 88
 ?>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,13 +62,13 @@
 block discarded – undo
62 62
     'column4' => [
63 63
         'title'     => 'Table Header 4',
64 64
 		'function'	=> function($link) {
65
-			return '<a href="'. $link . '">' . "Google" . '</a>';
65
+			return '<a href="' . $link . '">' . "Google" . '</a>';
66 66
 		}
67 67
     ],
68 68
 	'column6' => [
69 69
         'title'    	=> 'Table Header 6',
70 70
 		'function' 	=> function($tableCell6) {
71
-        	return empty($tableCell6) ? 'Not present' :  'Present';
71
+        	return empty($tableCell6) ? 'Not present' : 'Present';
72 72
    		}
73 73
     ],
74 74
 	'tablefoot1' => [
Please login to merge, or discard this patch.
autoloader.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -12,33 +12,33 @@
 block discarded – undo
12 12
  * @return void
13 13
  */
14 14
 spl_autoload_register(
15
-    function ($class) {
15
+	function ($class) {
16 16
 
17
-        // project-specific namespace prefix
18
-        //$prefix = 'Foo\\Bar\\';
19
-        $prefix = 'Guer\\';
17
+		// project-specific namespace prefix
18
+		//$prefix = 'Foo\\Bar\\';
19
+		$prefix = 'Guer\\';
20 20
 
21
-        // base directory for the namespace prefix
22
-        $base_dir = __DIR__ . '/src/';
21
+		// base directory for the namespace prefix
22
+		$base_dir = __DIR__ . '/src/';
23 23
 
24
-        // does the class use the namespace prefix?
25
-        $len = strlen($prefix);
26
-        if (strncmp($prefix, $class, $len) !== 0) {
27
-            // no, move to the next registered autoloader
28
-            return;
29
-        }
24
+		// does the class use the namespace prefix?
25
+		$len = strlen($prefix);
26
+		if (strncmp($prefix, $class, $len) !== 0) {
27
+			// no, move to the next registered autoloader
28
+			return;
29
+		}
30 30
 
31
-        // get the relative class name
32
-        $relative_class = substr($class, $len);
31
+		// get the relative class name
32
+		$relative_class = substr($class, $len);
33 33
 
34
-        // replace the namespace prefix with the base directory, replace namespace
35
-        // separators with directory separators in the relative class name, append
36
-        // with .php
37
-        $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
34
+		// replace the namespace prefix with the base directory, replace namespace
35
+		// separators with directory separators in the relative class name, append
36
+		// with .php
37
+		$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
38 38
 
39
-        // if the file exists, require it
40
-        if (file_exists($file)) {
41
-            include $file;
42
-        }
43
-    }
39
+		// if the file exists, require it
40
+		if (file_exists($file)) {
41
+			include $file;
42
+		}
43
+	}
44 44
 );
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
  * @return void
13 13
  */
14 14
 spl_autoload_register(
15
-    function ($class) {
15
+    function($class) {
16 16
 
17 17
         // project-specific namespace prefix
18 18
         //$prefix = 'Foo\\Bar\\';
Please login to merge, or discard this patch.