1 : <?php
2 : require_once "JetPager.class.php";
3 : require_once "JetAttribute.class.php";
4 : require_once "JetAttributeColumn.class.php";
5 : require_once "JetAttributeColumnEreg.class.php";
6 : require_once "JetRadioButtonDataCell.class.php";
7 : require_once "JetCheckBoxDataCell.class.php";
8 : require_once "JetSelectBoxDataCell.class.php";
9 : require_once "JetTextBoxDataCell.class.php";
10 : require_once "JetTextAreaDataCell.class.php";
11 : require_once "JetLabelDataCell.class.php";
12 : require_once "JetHtmlUtil.class.php";
13 : require_once "JetCsvDownload.class.php";
14 : require_once "JetExcelDownload.class.php";
15 : require_once "JetDateFormatter.class.php";
16 :
17 :
18 :
19 :
20 :
21 :
22 :
23 :
24 :
25 :
26 :
27 :
28 : class JetTable{
29 : private $header;
30 : private $records;
31 : private $attribute;
32 : private $attributeRow;
33 : private $attributeColumn;
34 : private $attributeHeaderRow;
35 : private $attributeHeaderColumn;
36 : private $attributeColumnEreg;
37 : private $attributeRowEreg;
38 :
39 : private $formatter;
40 :
41 : private $margeHeaderColumn;
42 : private $margeColumnRow;
43 :
44 : private $attributeColumnAll;
45 : private $attributeHeaderColumnAll;
46 :
47 : private $useSort;
48 : private $sortKey;
49 : private $sortType;
50 : private $sortableHeaderKeys;
51 :
52 : private $usePager;
53 : private $pager;
54 :
55 : private $usePlugin;
56 :
57 : private $scriptName;
58 :
59 : private $plugin;
60 :
61 : private $outputForm;
62 :
63 : private $parameterPageString = "page";
64 : private $parameterPageParString = "pagePar";
65 : private $parameterSortKeyString = "sortKey";
66 : private $parameterSortTypeString = "sortType";
67 : private $parameterSortTypeAsc = "asc";
68 : private $parameterSortTypeDesc = "desc";
69 : private $sortTypeAscMarkString = "▲";
70 : private $sortTypeDescMarkString = "▼";
71 : private $rowidName = "rowidentifier";
72 :
73 : private $roundBackgroundColors;
74 :
75 :
76 :
77 :
78 :
79 :
80 :
81 : public function __construct(){
82 26 : $this->header = array();
83 26 : $this->records = array();
84 26 : $this->attribute = array();
85 26 : $this->attributeRow = array();
86 26 : $this->attributeColumn = array();
87 26 : $this->attributeColumnAll = array();
88 26 : $this->attributeHeaderRow = array();
89 26 : $this->attributeHeaderColumn = array();
90 26 : $this->attributeHeaderColumnAll = array();
91 26 : $this->attributeColumnEreg = array();
92 26 : $this->attributeRowEreg = array();
93 26 : $this->sortableHeaderKeys = array();
94 26 : $this->plugin = array();
95 26 : $this->margeHeaderColumn = array();
96 26 : $this->margeColumnRow = array();
97 26 : $this->roundBackgroundColors = array();
98 26 : $this->outputForm = array();
99 26 : $this->formatter = array();
100 :
101 26 : $this->useSort = false;
102 26 : $this->usePager = false;
103 26 : $this->usePlugin = false;
104 :
105 26 : $this->scriptName = "";
106 :
107 26 : $this->pager = new JetPager();
108 26 : }
109 :
110 :
111 :
112 :
113 :
114 :
115 :
116 :
117 :
118 : public function appendAttribute($key, $value){
119 1 : $attribute = new JetAttribute();
120 1 : $attribute->key = $key;
121 1 : $attribute->value = $value;
122 1 : $this->attribute[] = $attribute;
123 1 : }
124 :
125 :
126 :
127 :
128 :
129 :
130 :
131 :
132 :
133 : public function appendAttributeHeaderRow($key, $value){
134 1 : $attributeHeaderRow = new JetAttribute();
135 1 : $attributeHeaderRow->key = $key;
136 1 : $attributeHeaderRow->value = $value;
137 1 : $this->attributeHeaderRow[] = $attributeHeaderRow;
138 1 : }
139 :
140 :
141 :
142 :
143 :
144 :
145 :
146 :
147 :
148 :
149 : public function appendAttributeHeaderColumn($columnName, $key, $value){
150 1 : $attributeHeaderColumn = new JetAttributeColumn();
151 1 : $attributeHeaderColumn->columnName = $columnName;
152 1 : $attributeHeaderColumn->key = $key;
153 1 : $attributeHeaderColumn->value = $value;
154 1 : $this->attributeHeaderColumn[] = $attributeHeaderColumn;
155 1 : }
156 :
157 :
158 :
159 :
160 :
161 :
162 :
163 :
164 :
165 : public function appendAttributeRow($key, $value){
166 1 : $attributeRow = new JetAttribute();
167 1 : $attributeRow->key = $key;
168 1 : $attributeRow->value = $value;
169 1 : $this->attributeRow[] = $attributeRow;
170 1 : }
171 :
172 :
173 :
174 :
175 :
176 :
177 :
178 :
179 :
180 :
181 : public function appendAttributeColumn($columnName, $key, $value){
182 1 : $attributeColumn = new JetAttributeColumn();
183 1 : $attributeColumn->columnName = $columnName;
184 1 : $attributeColumn->key = $key;
185 1 : $attributeColumn->value = $value;
186 1 : $this->attributeColumn[] = $attributeColumn;
187 1 : }
188 :
189 :
190 :
191 :
192 :
193 :
194 :
195 :
196 :
197 :
198 :
199 :
200 : public function appendAttributeRowEreg($columnName, $ereg, $key, $value){
201 1 : $attributeRowEreg = new JetAttributeColumnEreg();
202 1 : $attributeRowEreg->columnName = $columnName;
203 1 : $attributeRowEreg->key = $key;
204 1 : $attributeRowEreg->value = $value;
205 1 : $attributeRowEreg->ereg = $ereg;
206 1 : $this->attributeRowEreg[] = $attributeRowEreg;
207 1 : }
208 :
209 :
210 :
211 :
212 :
213 :
214 :
215 :
216 :
217 :
218 :
219 :
220 : public function appendAttributeColumnEreg($columnName, $ereg, $key, $value){
221 1 : $attributeColumnEreg = new JetAttributeColumnEreg();
222 1 : $attributeColumnEreg->columnName = $columnName;
223 1 : $attributeColumnEreg->key = $key;
224 1 : $attributeColumnEreg->value = $value;
225 1 : $attributeColumnEreg->ereg = $ereg;
226 1 : $this->attributeColumnEreg[] = $attributeColumnEreg;
227 1 : }
228 :
229 :
230 :
231 :
232 :
233 :
234 :
235 :
236 :
237 : public function appendAttributeColumnAll($key, $value){
238 1 : $attribute = new JetAttribute();
239 1 : $attribute->key = $key;
240 1 : $attribute->value = $value;
241 1 : $this->attributeColumnAll[] = $attribute;
242 1 : }
243 :
244 :
245 :
246 :
247 :
248 :
249 :
250 :
251 :
252 : public function appendAttributeHeaderColumnAll($key, $value){
253 1 : $attribute = new JetAttribute();
254 1 : $attribute->key = $key;
255 1 : $attribute->value = $value;
256 1 : $this->attributeHeaderColumnAll[] = $attribute;
257 1 : }
258 :
259 :
260 :
261 :
262 :
263 :
264 :
265 :
266 : public function useSort($useSort){
267 5 : $this->useSort = $useSort;
268 5 : }
269 :
270 :
271 :
272 :
273 :
274 :
275 :
276 :
277 : public function usePlugin($usePlugin){
278 3 : $this->usePlugin = $usePlugin;
279 3 : }
280 :
281 :
282 :
283 :
284 :
285 :
286 :
287 :
288 : public function usePager($usePager){
289 3 : $this->usePager = $usePager;
290 3 : }
291 :
292 :
293 :
294 :
295 :
296 :
297 :
298 :
299 : public function setSortableHeader($headerKeys){
300 1 : if(is_array($headerKeys)){
301 1 : foreach($headerKeys as $headerKey){
302 1 : $this->sortableHeaderKeys[] = $headerKey;
303 1 : }
304 1 : }else{
305 0 : $this->sortableHeaderKeys[] = $headerKeys;
306 : }
307 1 : }
308 :
309 : private function sort(){
310 5 : $sortKey = $this->sortKey;
311 5 : if(!empty($sortKey)){
312 3 : $recordCount = count($this->records);
313 3 : for($i = 0; $i < $recordCount; $i++){
314 3 : $this->records[$i][$this->rowidName] = $i;
315 3 : }
316 3 : $sortArray = array();
317 3 : foreach($this->records as $record){
318 3 : $sortArray[$record[$this->rowidName]] = $record[$sortKey];
319 3 : }
320 3 : if($this->sortType == $this->parameterSortTypeAsc){
321 2 : asort($sortArray);
322 2 : }else{
323 1 : arsort($sortArray);
324 : }
325 3 : $sortRecords = array();
326 3 : foreach($sortArray as $sortKey=>$sortValue){
327 3 : foreach($this->records as $record){
328 3 : if($record[$this->rowidName] == $sortKey){
329 3 : unset($record[$this->rowidName]);
330 3 : $sortRecords[] = $record;
331 3 : break;
332 : }
333 0 : }
334 3 : }
335 3 : $this->records = $sortRecords;
336 : }
337 5 : }
338 :
339 :
340 :
341 :
342 :
343 :
344 :
345 :
346 : public function setData($records){
347 25 : $this->records = $records;
348 25 : $this->pager->setTotalItemCount(count($records));
349 25 : }
350 :
351 :
352 :
353 :
354 :
355 :
356 :
357 :
358 : public function setHeader($header){
359 1 : $this->header = $header;
360 1 : }
361 :
362 :
363 :
364 :
365 :
366 :
367 :
368 :
369 :
370 : public function initializeSort($sortKey, $sortType){
371 3 : $this->sortKey = $sortKey;
372 3 : $this->sortType = $sortType;
373 3 : }
374 :
375 :
376 :
377 :
378 :
379 :
380 :
381 :
382 :
383 : public function initializePager($currentPageNumber, $pageParItems){
384 3 : if(!empty($currentPageNumber)){
385 3 : $this->pager->setCurrentPageNumber($currentPageNumber);
386 : }
387 3 : if(!empty($pageParItems)){
388 3 : $this->pager->setPageParItems($pageParItems);
389 : }
390 3 : }
391 :
392 :
393 :
394 :
395 :
396 :
397 :
398 :
399 :
400 :
401 : public function setOutputForm($column, $type, $attribute = array()){
402 1 : $this->outputForm[$column] = $type;
403 1 : $this->outputForm[$column . "Attribute"] = $attribute;
404 1 : }
405 :
406 :
407 :
408 :
409 :
410 :
411 :
412 :
413 :
414 :
415 : public function setDateFormatColumn($column, $format){
416 1 : if(empty($column)){
417 0 : return;
418 : }
419 :
420 1 : $formatter = new JetDateFormatter($format);
421 1 : $this->formatter[$column] = $formatter;
422 1 : }
423 :
424 :
425 :
426 :
427 :
428 :
429 :
430 : public function getTableText(){
431 2 : $records = $this->getRecords();
432 2 : if(empty($records)){
433 1 : return null;
434 : }
435 1 : $headerArray = $this->getHeaderArray($records);
436 :
437 1 : $text .= implode("\t", $headerArray);
438 1 : $text .= "\r\n";
439 :
440 1 : if($this->usePager){
441 0 : $records = $this->getViewRecords();
442 : }
443 :
444 1 : foreach($records as $record){
445 1 : foreach($headerArray as $headerKey=>$headerValue){
446 1 : $text .= $record[$headerKey];
447 1 : $text .= "\t";
448 1 : }
449 1 : $text .= "\r\n";
450 1 : }
451 :
452 1 : return $text;
453 : }
454 :
455 : private function getHeaderArray($records){
456 25 : if(empty($this->header)){
457 24 : $headerArray = array();
458 24 : foreach($records as $record){
459 24 : if(count($headerArray) < count($record)){
460 24 : $workHeaderArray = array();
461 24 : foreach($record as $itemKey=>$itemValue){
462 24 : $workHeaderArray[$itemKey] = $itemKey;
463 24 : }
464 24 : $headerArray = $workHeaderArray;
465 : }
466 24 : }
467 24 : }else{
468 1 : $headerArray = $this->header;
469 : }
470 :
471 25 : return $headerArray;
472 : }
473 :
474 : private function getUrlAttributeString(){
475 1 : $attributeArray = $this->getUrlAttribute();
476 1 : if(!empty($attributeArray)){
477 1 : foreach($attributeArray as $attribute){
478 1 : $attributeString .= "&" . $attribute->key . "=" . urlencode($attribute->value);
479 1 : }
480 : }
481 1 : return $attributeString;
482 : }
483 :
484 : private function getUrlAttribute(){
485 3 : $attributeArray = array();
486 3 : if($this->useSort){
487 1 : if(!empty($this->sortKey)){
488 1 : $attribute = new JetAttribute();
489 1 : $attribute->key = $this->parameterSortKeyString;
490 1 : $attribute->value = $this->sortKey;
491 1 : $attributeArray[] = $attribute;
492 : }
493 1 : if(!empty($this->sortType)){
494 1 : $attribute = new JetAttribute();
495 1 : $attribute->key = $this->parameterSortTypeString;
496 1 : $attribute->value = $this->sortType;
497 1 : $attributeArray[] = $attribute;
498 : }
499 : }
500 3 : if($this->usePager){
501 2 : $attribute = new JetAttribute();
502 2 : $attribute->key = $this->parameterPageString;
503 2 : $attribute->value = $this->pager->getCurrentPageNumber();
504 2 : $attributeArray[] = $attribute;
505 :
506 2 : $attribute = new JetAttribute();
507 2 : $attribute->key = $this->parameterPageParString;
508 2 : $attribute->value = $this->pager->getPageParItems();
509 2 : $attributeArray[] = $attribute;
510 : }
511 3 : return $attributeArray;
512 : }
513 :
514 :
515 :
516 :
517 :
518 :
519 :
520 : public function getPagerHtml(){
521 3 : return $this->pager->getBasicPagerHtml($this->getUrlAttribute());
522 : }
523 :
524 : private function getRecords(){
525 26 : if(empty($this->records)){
526 2 : return array();
527 : }
528 :
529 25 : if($this->useSort){
530 5 : $this->sort();
531 : }
532 :
533 25 : return $this->records;
534 : }
535 :
536 : private function getViewRecords(){
537 3 : $records = $this->getRecords();
538 :
539 3 : if(empty($records)){
540 0 : return null;
541 : }
542 :
543 3 : if($this->usePager){
544 3 : $page = $this->pager->getCurrentPageNumber();
545 3 : $pageitem = $this->pager->getPageParItems();
546 3 : $startIndex = ($page - 1) * $pageitem;
547 3 : $endIndex = ($page - 1) * $pageitem + $pageitem - 1;
548 3 : }else{
549 0 : $endIndex = 999999;
550 : }
551 :
552 3 : $viewRecordArray = array();
553 3 : $i = 0;
554 3 : foreach($records as $record){
555 3 : if($i >= $startIndex && $i <= $endIndex){
556 3 : $viewRecordArray[] = $record;
557 : }
558 3 : $i = $i + 1;
559 3 : }
560 3 : return $viewRecordArray;
561 : }
562 :
563 :
564 :
565 :
566 :
567 :
568 :
569 : public function getTableHtml(){
570 25 : $records = $this->getRecords();
571 25 : if(empty($records)){
572 2 : return null;
573 : }
574 :
575 24 : $tableTag .= "<table>";
576 24 : foreach($this->attribute as $attributeClass){
577 1 : $tableTag = JetHtmlUtil::joinTagAttribute($tableTag, $attributeClass->key, $attributeClass->value);
578 1 : }
579 24 : $text .= $tableTag;
580 :
581 24 : $trTag .= "<tr>";
582 24 : foreach($this->attributeHeaderRow as $attributeHeaderRowClass){
583 1 : $trTag = JetHtmlUtil::joinTagAttribute($trTag, $attributeHeaderRowClass->key, $attributeHeaderRowClass->value);
584 1 : }
585 24 : $text .= $trTag;
586 :
587 24 : $headerArray = $this->getHeaderArray($records);
588 :
589 24 : $margeCount = 0;
590 24 : foreach($headerArray as $headerKey=>$headerValue){
591 24 : if($margeCount > 0){
592 1 : $margeCount = $margeCount - 1;
593 1 : continue;
594 : }
595 :
596 24 : $tdTag = "<th>";
597 24 : if(!empty($this->margeHeaderColumn)){
598 1 : foreach($this->margeHeaderColumn as $margeHeaderColumnName=>$margeHeaderColumnCount){
599 1 : if($margeHeaderColumnName == $headerKey){
600 1 : $tdTag = JetHtmlUtil::joinTagAttribute($tdTag, "colspan", $margeHeaderColumnCount);
601 1 : $margeCount = $margeHeaderColumnCount - 1;
602 : }
603 1 : }
604 : }
605 :
606 24 : foreach($this->attributeHeaderColumnAll as $attributeHeaderColumnAllClass){
607 1 : $tdTag = JetHtmlUtil::joinTagAttribute($tdTag, $attributeHeaderColumnAllClass->key, $attributeHeaderColumnAllClass->value);
608 1 : }
609 :
610 24 : foreach($this->attributeHeaderColumn as $attributeHeaderColumnClass){
611 1 : if($headerKey == $attributeHeaderColumnClass->columnName){
612 1 : $tdTag = JetHtmlUtil::joinTagAttribute($tdTag, $attributeHeaderColumnClass->key, $attributeHeaderColumnClass->value);
613 : }
614 1 : }
615 :
616 24 : if($this->useSort){
617 5 : if(!empty($this->sortableHeaderKeys) && !in_array($headerKey, $this->sortableHeaderKeys)){
618 1 : $text .= $tdTag;
619 1 : $text .= $headerValue;
620 1 : continue;
621 : }
622 :
623 5 : $outputFormKey = array_keys($this->outputForm);
624 5 : if(in_array($headerKey, $outputFormKey)){
625 0 : $text .= $tdTag;
626 0 : $text .= $headerValue;
627 0 : continue;
628 : }
629 :
630 5 : $urlSortKey = urlencode($headerValue);
631 5 : if($headerValue == $this->sortKey){
632 3 : if($this->sortType == $this->parameterSortTypeAsc){
633 2 : $urlSortType = $this->parameterSortTypeDesc;
634 3 : }else if($this->sortType == $this->parameterSortTypeDesc){
635 1 : $urlSortType = "";
636 1 : $urlSortKey = "";
637 1 : }else{
638 0 : $urlSortType = $this->parameterSortTypeAsc;
639 : }
640 0 : }else{
641 5 : $urlSortType = $this->parameterSortTypeAsc;
642 : }
643 5 : $text .= $tdTag . "<a href=\"" . $this->scriptName . "?";
644 5 : if($this->usePager){
645 2 : $text .= "&" . $this->parameterPageString . "=" . $this->pager->getCurrentPageNumber();
646 2 : $text .= "&" . $this->parameterPageParString . "=" . $this->pager->getPageParItems();
647 : }
648 5 : if(!empty($urlSortKey)){
649 5 : $text .= "&" . $this->parameterSortKeyString . "=" . $urlSortKey;
650 : }
651 5 : if(!empty($urlSortType)){
652 5 : $text .= "&" . $this->parameterSortTypeString . "=" . $urlSortType;
653 : }
654 5 : $text .= "\">";
655 5 : $text .= $headerValue;
656 5 : $text .= "</a>";
657 :
658 5 : if($headerValue == $this->sortKey){
659 3 : if(empty($this->sortType) || $this->sortType == $this->parameterSortTypeAsc){
660 2 : $text .= " " . $this->sortTypeAscMarkString;
661 3 : }else if($this->sortType == $this->parameterSortTypeDesc){
662 1 : $text .= " " . $this->sortTypeDescMarkString;
663 : }
664 : }
665 :
666 1 : }else{
667 20 : $text .= $tdTag;
668 20 : $text .= $headerValue;
669 : }
670 24 : $text .= "</th>";
671 24 : }
672 24 : $text .= "</tr>";
673 24 : if($this->usePager){
674 3 : $records = $this->getViewRecords();
675 : }
676 :
677 24 : $rowColorIndex = 0;
678 24 : $rowspanWorkArray = array();
679 24 : $rowId = 0;
680 24 : foreach($records as $record){
681 24 : $rowId++;
682 24 : $trTag = "<tr>";
683 :
684 24 : if(!empty($this->roundBackgroundColors)){
685 1 : $trTag = JetHtmlUtil::joinTagAttribute($trTag, "style", "background-color:" . $this->roundBackgroundColors[$rowColorIndex]);
686 1 : $rowColorIndex++;
687 1 : if($rowColorIndex >= count($this->roundBackgroundColors)){
688 1 : $rowColorIndex = 0;
689 : }
690 : }
691 :
692 24 : foreach($this->attributeRowEreg as $attributeRowEregClass){
693 1 : foreach($headerArray as $headerKey=>$headerValue){
694 1 : if($headerKey == $attributeRowEregClass->columnName){
695 1 : if(mbereg($attributeRowEregClass->ereg, $record[$headerKey])){
696 1 : $trTag = JetHtmlUtil::joinTagAttribute($trTag, $attributeRowEregClass->key, $attributeRowEregClass->value);
697 : }
698 : }
699 1 : }
700 1 : }
701 :
702 24 : foreach($this->attributeRow as $attributeRowClass){
703 1 : $trTag = JetHtmlUtil::joinTagAttribute($trTag, $attributeRowClass->key, $attributeRowClass->value);
704 1 : }
705 24 : $text .= $trTag;
706 :
707 24 : foreach($headerArray as $headerKey=>$headerValue){
708 24 : $tdTag = "<td>";
709 24 : foreach($this->attributeColumnAll as $attributeColumnAllClass){
710 1 : $tdTag = JetHtmlUtil::joinTagAttribute($tdTag, $attributeColumnAllClass->key, $attributeColumnAllClass->value);
711 1 : }
712 :
713 24 : foreach($this->attributeColumnEreg as $attributeColumnEregClass){
714 1 : if($headerKey == $attributeColumnEregClass->columnName){
715 1 : if(mbereg($attributeColumnEregClass->ereg, $record[$headerKey])){
716 1 : $tdTag = JetHtmlUtil::joinTagAttribute($tdTag, $attributeColumnEregClass->key, $attributeColumnEregClass->value);
717 : }
718 : }
719 1 : }
720 24 : foreach($this->attributeColumn as $attributeColumnClass){
721 1 : if($headerKey == $attributeColumnClass->columnName){
722 1 : $tdTag = JetHtmlUtil::joinTagAttribute($tdTag, $attributeColumnClass->key, $attributeColumnClass->value);
723 : }
724 1 : }
725 :
726 24 : if($rowspanWorkArray[$headerKey] < 2){
727 24 : $margeColumnKey = array_keys($this->margeColumnRow);
728 24 : if(in_array($headerKey, $margeColumnKey)){
729 1 : $rowspanWorkArray[$headerKey] = $this->margeColumnRow[$headerKey];
730 1 : $tdTag = JetHtmlUtil::joinTagAttribute($tdTag, "rowspan", $rowspanWorkArray[$headerKey]);
731 : }
732 :
733 24 : $text .= $tdTag;
734 :
735 24 : $outputForm = $this->outputForm[$headerKey];
736 24 : $outputFormAttribute = $this->outputForm[$headerKey . "Attribute"];
737 24 : if(empty($outputFormAttribute)){
738 24 : $outputFormAttribute = array();
739 : }
740 24 : $dataCellValue = $this->formatValue($headerKey, $record[$headerKey]);
741 24 : $text .= $this->outputDataCell($outputForm, $dataCellValue, $outputFormAttribute, $headerKey);
742 :
743 24 : }else{
744 1 : $rowspanWorkArray[$headerKey] = $rowspanWorkArray[$headerKey] - 1;
745 : }
746 1 : }
747 24 : $text .= "</tr>";
748 24 : }
749 24 : $text .= "</table>";
750 :
751 24 : return $text;
752 : }
753 :
754 : private function formatValue($key, $value){
755 24 : if(empty($value)){
756 1 : return null;
757 : }
758 24 : if(empty($key)){
759 0 : return $value;
760 : }
761 :
762 24 : $formatter = $this->formatter[$key];
763 24 : if(empty($formatter)){
764 24 : return $value;
765 : }
766 :
767 1 : return $formatter->format($value);
768 : }
769 :
770 :
771 :
772 :
773 :
774 :
775 :
776 :
777 :
778 : private function getColulmnList($columnName){
779 1 : if(empty($columnName)){
780 0 : return null;
781 : }
782 1 : $records = $this->getRecords();
783 1 : if(empty($records)){
784 0 : return null;
785 : }
786 :
787 1 : $list = array();
788 1 : foreach($records as $record){
789 1 : if(empty($record[$columnName])){
790 0 : continue;
791 : }
792 1 : $list[$record[$columnName]] = $record[$columnName];
793 1 : }
794 1 : return $list;
795 : }
796 :
797 :
798 :
799 :
800 :
801 :
802 :
803 :
804 :
805 :
806 :
807 : private function outputDataCell($key, $value, $attribute = array(), $columnName = null){
808 24 : if($key == "text"){
809 1 : $dataCell = new JetTextBoxDataCell($value, $attribute);
810 :
811 24 : }else if($key == "textarea"){
812 1 : $dataCell = new JetTextAreaDataCell($value, $attribute);
813 :
814 24 : }else if($key == "select"){
815 1 : $dataCell = new JetSelectBoxDataCell($value, $attribute, $this->getColulmnList($columnName));
816 :
817 24 : }else if($key == "checkbox"){
818 1 : $dataCell = new JetCheckBoxDataCell($value, $attribute);
819 :
820 24 : }else if($key == "radio"){
821 1 : $dataCell = new JetRadioButtonDataCell($value, $attribute);
822 :
823 1 : }else{
824 24 : $dataCell = new JetLabelDataCell($value);
825 : }
826 :
827 24 : return $dataCell->getHtml();
828 : }
829 :
830 :
831 :
832 :
833 :
834 :
835 :
836 :
837 :
838 :
839 :
840 :
841 : public function getFullStackTableHtml(){
842 4 : $records = $this->getRecords();
843 4 : if(empty($records)){
844 1 : return null;
845 : }
846 :
847 3 : if($this->usePager){
848 2 : $text .= $this->getPagerHtml();
849 : }
850 :
851 3 : if($this->usePlugin){
852 2 : $text .= " ";
853 2 : $text .= " ";
854 2 : $text .= " ";
855 2 : $text .= "Plugin:";
856 : }
857 3 : foreach($this->plugin as $plugin){
858 1 : $text .= " ";
859 1 : $text .= $plugin->getLinkTag($this->getUrlAttributeString(), $this->scriptName);
860 1 : }
861 :
862 3 : $text .= $this->getTableHtml();
863 :
864 3 : return $text;
865 : }
866 :
867 :
868 :
869 :
870 :
871 :
872 :
873 :
874 : public function initialize($request){
875 1 : $this->scriptName = basename($_SERVER["SCRIPT_NAME"]);
876 :
877 1 : if($this->usePager){
878 1 : $currentPage = $request{$this->parameterPageString};
879 1 : $pagePar = $request{$this->parameterPageParString};
880 1 : $this->initializePager($currentPage, $pagePar);
881 : }
882 :
883 1 : if($this->useSort){
884 1 : $urlencodeSortKey = $request{$this->parameterSortKeyString};
885 1 : $sortKey = urldecode($urlencodeSortKey);
886 1 : $sortType = $request{$this->parameterSortTypeString};
887 1 : if(!empty($sortKey)){
888 1 : $this->initializeSort($sortKey, $sortType);
889 : }
890 : }
891 :
892 1 : if($this->usePlugin){
893 1 : $this->plugin = $this->initializePlugin();
894 1 : $this->doPlugin($request{"logic"});
895 : }
896 1 : }
897 :
898 :
899 :
900 :
901 :
902 :
903 :
904 :
905 :
906 : public function fullStackInitialize($request){
907 1 : $this->scriptName = basename($_SERVER["SCRIPT_NAME"]);
908 :
909 1 : $currentPage = $request{$this->parameterPageString};
910 1 : $pagePar = $request{$this->parameterPageParString};
911 :
912 1 : $urlencodeSortKey = $request{$this->parameterSortKeyString};
913 1 : $sortKey = urldecode($urlencodeSortKey);
914 1 : $sortType = $request{$this->parameterSortTypeString};
915 :
916 1 : $this->useSort(true);
917 1 : $this->usePager(true);
918 1 : $this->usePlugin(true);
919 :
920 1 : $this->initializePager($currentPage, $pagePar);
921 :
922 1 : if(!empty($sortKey)){
923 1 : $this->initializeSort($sortKey, $sortType);
924 : }
925 :
926 1 : if($this->usePlugin){
927 1 : $this->plugin = $this->initializePlugin();
928 1 : $this->doPlugin($request{"logic"});
929 : }
930 1 : }
931 :
932 :
933 : private function initializePlugin(){
934 2 : $plugin = array();
935 :
936 2 : $plugin[] = new JetCsvDownload();
937 2 : $plugin[] = new JetExcelDownload();
938 :
939 2 : return $plugin;
940 : }
941 :
942 :
943 :
944 :
945 :
946 :
947 :
948 :
949 :
950 : public function margeHeaderColumn($columnName, $margeCount){
951 1 : if(empty($columnName)){
952 1 : return;
953 : }
954 :
955 1 : if(empty($margeCount)){
956 1 : return;
957 : }
958 :
959 1 : if($margeCount < 2){
960 1 : return;
961 : }
962 :
963 1 : if(!is_numeric($margeCount)){
964 0 : return;
965 : }
966 :
967 1 : $this->margeHeaderColumn[$columnName] = $margeCount;
968 1 : }
969 :
970 :
971 :
972 :
973 :
974 :
975 :
976 :
977 :
978 : public function margeColumnRow($columnName, $margeCount){
979 1 : if(empty($columnName)){
980 1 : return;
981 : }
982 :
983 1 : if(empty($margeCount)){
984 1 : return;
985 : }
986 :
987 1 : if($margeCount < 2){
988 1 : return;
989 : }
990 :
991 1 : if(!is_numeric($margeCount)){
992 0 : return;
993 : }
994 :
995 1 : $this->margeColumnRow[$columnName] = $margeCount;
996 1 : }
997 :
998 : private function doPlugin($logic){
999 2 : if(empty($logic)){
1000 2 : return;
1001 : }
1002 :
1003 0 : foreach($this->plugin as $plugin){
1004 0 : if($plugin->key == $logic){
1005 0 : $records = $this->getRecords();
1006 0 : $header = $this->getHeaderArray($records);
1007 0 : $plugin->action($header, $records);
1008 0 : return;
1009 : }
1010 0 : }
1011 0 : }
1012 :
1013 :
1014 :
1015 :
1016 :
1017 :
1018 :
1019 :
1020 :
1021 : public function setRoundBackgroundColor($roundBackgroundColors){
1022 1 : $this->roundBackgroundColors = $roundBackgroundColors;
1023 1 : }
1024 : }
1025 : ?>
|