-
Notifications
You must be signed in to change notification settings - Fork 8
/
BSQLQuery.php
1208 lines (1147 loc) · 33.8 KB
/
BSQLQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* A general SQL query
*/
/**
* Copyright (C) 2008 - Ian Homer & bemoko
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses>.
*/
abstract class BSQLQuery {
public $context;
public $connector;
#
# Parameter values
#
private $parameters=array();
#
# Arbitary cached values for private use
#
private $bsql_cache=array();
#
# Date long time in the future, useful for sorting purposes
# when null mapped to this
#
var $futureDate='2100-01-01';
#
# Work out what db data is required and record in
# $fieldsRequired array so we can optimise the SQL
# ... no point in wasting energy
#
var $fieldsRequired=array();
# Cached array of columns that we actually want to render
var $columnsToRender;
# Number of columns in a report
var $numberOfMainRowColumns;
# Columns implicitly removed or added, note that explict setting
# overrides this
private $implicityAddedColumns=array();
private $implicityRemovedColumns=array();
# Columns implicitly sort and order, note that explict setting
# overrides this
var $implicitParameters=array();
# Cached versions so we only calculate once
var $cache=array();
abstract protected function getFormats();
abstract protected function getDefaultSort();
#
# Override this to map sort value to appropriate SQL
#
protected function getSortMapping($column) {
if (array_key_exists($column,$this->sortMapping)) {
#
# Explicit sort mapping
#
return $this->sortMapping[$column];
} elseif (array_key_exists($column,$this->fieldSQLColumn)) {
#
# ... else match against an SQL column
#
return $this->fieldSQLColumn[$column];
} else {
#
# ... otherwise just use the column name
#
return $column;
}
}
protected function setSortMapping($column,$mapping) {
$this->sortMapping[$column]=$mapping;
}
public function setContext($context) {
$this->context=$context;
}
public function setConnector($connector) {
$this->connector=$connector;
}
#
# Set parameter value
#
public function set($name,$value) {
if (array_key_exists($name,$this->supportedParameters)) {
switch ($this->supportedParameters[$name]) {
case 'field' :
$this->parameters[$name]=
$this->tidyCommaSeparated($value);
break;
case 'columns' :
$this->parameters[$name]=
$this->tidyCommaSeparated($value);
break;
default:
$this->parameters[$name]=$value;
}
$this->context->debug &&
$this->context->debug("BSQLQuery parameter set $name=".
$this->parameters[$name]);
} else {
$this->context->warn("Setting parameter $name is not supported");
}
}
#
# Tidy a field value, which essentially means removing the spaces next
# to the columns
#
private function tidyCommaSeparated($value) {
$newValue;
foreach (explode(",",$value) as $singleValue) {
if (!isset($newValue)) {
$newValue=trim($singleValue);
} else {
$newValue.=",".trim($singleValue);
}
}
return $newValue;
}
#
# Return supported regex for each parameter
#
public function getParameterRegex($name) {
$regex;
$typ="default";
if (array_key_exists($name,$this->supportedParameters)) {
$type=$this->supportedParameters[$name];
}
switch ($type) {
case 'filters' :
$regex="/^[\w,@\.\s\*\/%!()+->]*$/";
break;
case 'column' :
$regex="/^[\w_+-]*$/";
break;
case 'columns' :
$regex="/^[\w,_+-~]*$/";
break;
case 'field-date' :
$regex="/^[\*\w+-:]*$/";
break;
case 'free' :
$regex="/^.*$/";
break;
case 'sort' :
$regex="/^[\w\s,_-]*$/";
break;
default :
if (substr($this->supportedParameters[$name],0,5)
== "field") {
$regex="/^[\w,@\.\s\*\/%!()+->]*$/";
} else {
$regex="/^[\w]*$/";
}
}
return $regex;
}
#
# Set implicit parameter value
#
protected function setImplicit($name,$value) {
if (array_key_exists($name,$this->supportedParameters)) {
$this->implicitParameters[$name]=$value;
$this->context->debug &&
$this->context->debug("Setting implicit $name=$value");
} else {
$this->context->warn("Setting parameter $name is not supported");
}
}
#
# Get parameter value
#
public function get($name) {
if (array_key_exists($name,$this->supportedParameters)) {
if (array_key_exists($name,$this->parameters)) {
return $this->parameters[$name];
} else {
if (array_key_exists($name,$this->defaultParameters)) {
return $this->defaultParameters[$name];
} else {
return NULL;
}
}
} else {
$this->context->warn("Getting parameter $name is not supported");
return NULL;
}
}
#
# Check whether a boolean field is true
public function is($name) {
$value=$this->get($name);
if ($value) {
switch ($value) {
case '1':
case 'y':
return TRUE;
default :
return FALSE;
}
} else {
return FALSE;
}
}
#
# Get implicit parameter value - an implicit parameter value is one that
# was implicitly add by this extension, since is was determined that it
# was need
#
protected function getImplicit($name) {
if (array_key_exists($name,$this->supportedParameters)) {
if (array_key_exists($name,$this->implicitParameters)) {
return $this->implicitParameters[$name];
} else {
return NULL;
}
} else {
$this->context->warn(
"Getting implicit parameter $name is not supported");
return NULL;
}
}
#
# Get explicit parameter value - an explicit parameter value is one that
# was explicitly set by the user
#
protected function getExplicit($name) {
if (array_key_exists($name,$this->supportedParameters)) {
if (array_key_exists($name,$this->parameters)) {
return $this->parameters[$name];
} else {
return NULL;
}
} else {
$this->context->warn(
"Getting explicit parameter $name is not supported");
return NULL;
}
}
#
# Get default parameter value
#
protected function getDefault($name) {
if (array_key_exists($name,$this->supportedParameters)) {
if (array_key_exists($name,$this->defaultParameters)) {
return $this->defaultParameters[$name];
} else {
return NULL;
}
} else {
$this->context->warn(
"Getting default parameter $name is not supported");
return NULL;
}
}
#
# Identify a field as required - a required field is one that
# will be included in the SQL query since it is needed for the
# generation of the report
#
public function requireField($column) {
$this->context->debug &&
$this->context
->debug("Field required : ".$column);
$this->fieldsRequired[$column]=1;
}
#
# Determine whether a field is required
#
public function isRequired($column) {
if (array_key_exists($column,$this->fieldsRequired)) {
return TRUE;
} else {
return FALSE;
}
}
#
# Convert date to nice words
#
private function getRadarFormat($value) {
if (!array_key_exists("today",$this->bsql_cache)) {
$this->bsql_cache["yesterday"]=date("Y-m-d",strtotime("-1 day"));
$this->bsql_cache["today"]=date("Y-m-d");
$this->bsql_cache["tomorrow"]=date("Y-m-d",strtotime("+1 day"));
$this->bsql_cache["thisweek"]=date("Y-W");
$this->bsql_cache["nextweek"]=date("Y-W",strtotime("+1 week"));
$this->bsql_cache["thismonth"]=date("Y-m");
$this->bsql_cache["nextmonth"]=date("Y-m",strtotime("+1 month"));
$this->bsql_cache["thisyear"]=date("Y");
$this->bsql_cache["nextyear"]=date("Y",strtotime("+1 year"));
}
if (date("Y-m-d",$value) == $this->bsql_cache["yesterday"]) {
return "yesterday";
} else if ($value < (time()-86400)) {
return "overdue";
} else if (date("Y-m-d",$value) == $this->bsql_cache["today"]) {
return "today";
} else if (date("Y-m-d",$value) == $this->bsql_cache["tomorrow"]) {
return "tomorrow";
} else if (date("Y-W",$value) == $this->bsql_cache["thisweek"]) {
return "this week";
} else if (date("Y-W",$value) == $this->bsql_cache["nextweek"]) {
return "next week";
} else if (date("Y-m",$value) == $this->bsql_cache["thismonth"]) {
return "this month";
} else if (date("Y-m",$value) == $this->bsql_cache["nextmonth"]) {
return "next month";
} else if (date("Y",$value) == $this->bsql_cache["thisyear"]) {
return "this year";
} else if (date("Y",$value) == $this->bsql_cache["nextyear"]) {
return "next year";
} else {
return "years away";
}
}
private function getRelativeDateFormat($value) {
$formatted;
$title;
$visible;
$now=time();
$diff=$now-$value;
if ($diff > 0) {
if ($diff < 3600 ) {
$visible="+++";
$title="< 1 hour";
$class="date2";
} elseif ($diff < 86400 ) {
$visible="++";
$title="< 1 day";
$class="date3";
} elseif ($diff < 172800 ) {
$visible="+";
$title="< 2 days";
$class="date3";
} elseif ($diff < 259200 ) {
$visible="-";
$title="< 3 days";
$class="date3";
} elseif ($diff < 345600 ) {
$visible=".";
$title="< 4 days";
$class="date3";
} elseif ($diff < 604800 ) {
$visible=" ";
$title="< 1 week";
$class="date4";
} elseif ($diff < 1029600 ) {
$visible=" ";
$title="< 2 weeks";
$class="date4";
} elseif ($diff < 2592000 ) {
$visible=" ";
$title="< 1 month";
$class="date5";
} elseif ($diff < 31536000 ) {
$visible=" ";
$title="< 1 year";
$class="date6";
} else {
$visible=date("Y-m-d",$value);
$title="";
$class="date6";
}
} else {
if ($diff > 60 ) {
$formatted="< 1 min to go";
$class="date1";
} elseif ($diff > 3600 ) {
$formatted="< 1 hr to go";
$class="date2";
} elseif ($diff > 86400 ) {
$formatted="< 1 day to go";
$class="date3";
} elseif ($diff > 604800 ) {
$formatted="> 1 week to go";
$class="date4";
} elseif ($diff < 2592000 ) {
$formatted="< 1 month to go";
$class="date5";
} else {
$formatted=date("Y-m-d",$value);
$class="date6";
}
}
$title.=" (".date("Y-m-d",$value).")";
return "<div class=\"$class\" title=\"$title\">$visible</div>";
}
private function formatForExplicitFormat($value,$format,$title) {
($this->context->debug==2) &&
$this->context->debug("$format - $value");
#
# Split format into format name and any arguments
#
$parts=explode("~",$format);
switch ($parts[0]) {
case "date" :
if ($value) {
$time=strtotime($value);
if ($time == strtotime($this->futureDate)) {
return "";
} else {
$formattedDate=date("Y-m-d",strtotime($value));
}
return $formattedDate;
} else {
return "";
}
case "relativedate" :
if ($value) {
$time=strtotime($value);
if ($time == strtotime($this->futureDate)) {
return "";
} else {
$formattedDate=
$this->getRelativeDateFormat(strtotime($value));
}
return $formattedDate;
} else {
return "";
}
case "radar" :
if ($value) {
$time=strtotime($value);
if ($time == strtotime($this->futureDate)) {
return "";
} else {
$formattedDate=
$this->getRadarFormat(strtotime($value));
}
return $formattedDate;
} else {
return "";
}
case "url" :
if ($value) {
return "[$value]";
} else {
return " ";
}
case "id" :
# Render as interwiki or external link
if ($value) {
$text;
if ($title) {
$flag="";
if ($title!=$value) {
$flag="<span class=\"flag\">+</span>";
}
$text="<span title=\"$title\">$value$flag</span>";
} else {
$text=$value;
}
if ($this->context->rawHTML) {
return "<a href=\"".$this->context->bzserver.
"/show_bug.cgi?id=".$value."\">$text</a>";
} else {
if ($this->context->interwiki) {
return "[[".$this->context->interwiki.
":".$value.
"|".$text."]]";
} else {
return "[".$this->context->bzserver.
"/show_bug.cgi?id=".$value.
" ".$text."]";
}
}
} else {
return " ";
}
case "number" :
$format="";
if ($value==0) {
if ($this->get("zeroasblank") == "true") {
return "";
} else {
return "0";
}
} else {
if ($value - floor($value)) {
if (10*$value -floor(10*$value)) {
$format="%1\$.2f";
} else {
$format="%1\$.1f";
}
} else {
$format="%d";
}
return sprintf($format,$value);
}
case "name" :
if ($value) {
if ($this->get("nameformat") == "tla") {
return $this->convertNameToTla($value);
} else {
#
# Convert spaces to non-breaking spaces in names
# to prevent wrapping in the middle of a name
#
return str_replace(" "," ",$value);
}
} else {
return " ";
}
case "link" :
$rendered="";
if ($value) {
foreach(explode(",",$value) as $valuePart) {
if ($rendered) {
$rendered.=", ";
}
if (sizeof($parts) > 1) {
$rendered.="[[".$parts[1]." $valuePart|$valuePart]]";
} else {
$rendered.="[[$valuePart]]";
}
}
}
return $rendered;
default :
$this->context->warn("Format ".
$format.
" not recognised");
return $value;
}
}
/**
* Convert a name to a TLA
*/
public function convertNameToTla($value) {
$names=explode(" ",$value);
$tla;
if (sizeof($names) ==1) {
if (strlen($value) > 3) {
$tla=substr($value,0,3);
} else {
$tla=$value;
}
} else {
if (strlen($names[1]) > 1) {
$tla=substr($names[0],0,1).substr($names[1],0,2);
} else if (strlen($name[0] > 1)) {
$tla=substr($names[0],0,2).substr($names[1],0,1);
} else {
$tla=$names[0].$names[1]."A";
}
}
return strtoupper($tla);
}
/**
* Format a value
*/
public function format($value,$column,$title) {
$formats=$this->getFormats();
if (array_key_exists($column,$formats)) {
return $this->formatForExplicitFormat($value,
$formats[$column],$title);
} else {
return $value;
}
}
/**
* Get a title for a given value
*/
public function getValueTitle($line,$column) {
$title="";
if (array_key_exists($column,$this->valueTitle)) {
$columns=explode(",",$this->valueTitle[$column]);
foreach ($columns as $column) {
$title.=$line[$column]." ";
}
$title=trim($title);
}
return $title;
}
#
# Formatting with null mapped to a string, useful for headings
#
public function formatForHeading($value,$column) {
if ($this->get('groupformat')) {
$this->context->debug &&
$this->context
->debug("Group format set : ".$this->get('groupformat'));
$value=$this->formatForExplicitFormat($value,
$this->get('groupformat'),"");
} else {
$value=$this->format($value,$column,"");
}
if ($value) {
return $value;
} else {
return "not set";
}
}
/**
* Get a where clause from a named field matching a comma separated list
*/
public function getWhereClause($match,$name) {
$this->context->debug &&
$this->context->debug("Generating where clause for $name=$match");
if (preg_match("/^[\*+-]$/",$match)) {
return $this->getWhereClauseSpecial($match,$name);
} else if (strstr($match,",")) {
$pos=strpos($match,"!(");
$where=" and (";
$operator;
$negate;
if ($pos===false) {
$operator="OR";
$negate=false;
} else {
$match=substr($match,2,-1);
$operator="AND";
$negate=true;
}
$first=true;
foreach (explode(",", $match) as $value) {
if ($first) {
$first=false;
} else {
$where.=" $operator ";
}
$where.=$this->getMatchExpression($value,$name,$negate);
}
$where.=") ";
return $where;
} else {
return " and ".$this->getMatchExpression($match,$name,false);
}
}
/**
* Get a int where clause
* ... very simple for now
*/
public function getIntWhereClause($match,$name) {
if (preg_match("/^[\*+-]/",$match)) {
switch ($match) {
case "+":
return " and $name > 0";
default:
$this->context->warn("Int match not recognised $name=$match");
}
} else {
$this->context->warn("Int match not recognised $name=$match");
return "";
}
}
/**
* Get a date where clause
* ... very simple for now
*/
public function getDateWhereClause($match,$name) {
if (preg_match("/:/",$match)) {
$range=explode(":",$match);
if ($range[0]=="*") {
return " and $name <='".$this->getAbsoluteDate($range[1])."'";
} else if ($range[1]=="*") {
return " and $name >='".$this->getAbsoluteDate($range[0])."'";
} else {
return " and $name >='".$this->getAbsoluteDate($range[0]).
"' and $name <='".$this->getAbsoluteDate($range[1])."'";
}
} else if (preg_match("/^[\+](.+)/",$match)) {
#
# Search for anything before the date in the future
#
return " and $name <='".$this->getAbsoluteDate($match)."'";
} else if (preg_match("/^[-](.+)/",$match)) {
#
# Search for anything after the date in past
#
return " and $name >='".$this->getAbsoluteDate($match)."'";
} else if (preg_match("/^[\*+-]/",$match)) {
return $this->getWhereClauseSpecial($match,$name);
} else {
$this->context->warn("Date match not recognised $name=$match");
return "";
}
}
public function getAbsoluteDate($date) {
if (preg_match("/^([\+-])([0-9]*)(.*)/",$date,$matches)) {
switch ($matches[3]) {
case "d":
$delta=86400*$matches[2];
break;
case "w":
$delta=604800*$matches[2];
break;
case "m":
$delta=2592000*$matches[2];
break;
default :
$delta=0;
}
if ($matches[1]=="+") {
$value=time()+$delta;
} else {
$value=time()-$delta;
}
return date("Y-m-d",$value);
} else {
return $date;
}
}
public function getWhereClauseSpecial($match,$name) {
switch ($match) {
case "+":
return " and $name IS NOT NULL";
case "-":
return " and $name IS NULL";
case "*":
return "";
default:
$this->context->warn("Special match not recognised $name=$match");
return "";
}
return " and $name IS NOT NULL";
}
/**
* Get maximum number of rows
*/
public function getMaxRows() {
if ($this->get('maxrows')) {
if ($this->get('maxrows') > $this->context->maxrowsFromConfig) {
$this->context->warn("Max rows in function parameter greater than in config -> ignoring");
return $this->context->maxrowsFromConfig;
} else {
return $this->get('maxrows');
}
} else {
return $this->context->maxrowsFromConfig;
}
}
/**
* Get maximum number of rows
*/
public function getMaxRowsForBarChart() {
if ($this->get('maxrowsbar')) {
if ($this->get('maxrowsbar') > $this->context->maxrowsForBarChartFromConfig) {
$this->context->warn("Max rows bar in function parameter greater than in config -> ignoring");
return $this->context->maxrowsForBarChartFromConfig;
} else {
return $this->get('maxrowsbar');
}
} else {
return $this->context->maxrowsForBarChartFromConfig;
}
}
/**
* Get sort
*/
public function getSort() {
# Not explicit on function call or notcached
if (!array_key_exists('sort',$this->cache)) {
$sort;
if ($this->getExplicit('sort')) {
$sort=$this->getExplicit('sort');
} else if ($this->getImplicit('sort')) {
# Implicit on usage and other function call parameters
$sort=$this->getImplicit('sort');
} else {
# Default behaviour
$sort=$this->getDefault('sort');
}
#
# Prepend with group (if set)
#
if ($this->getGroup()) {
$groupOrder=
$sort=$this->getGroup()." ".$this->getGroupOrder().
",".$sort;
}
$this->context->debug &&
$this->context->debug("Sort set to $sort");
$this->cache['sort']=$sort;
}
return $this->cache['sort'];
}
#
# Return sort with mapping
#
public function getMappedSort() {
$mappedSort=array();
foreach(explode(",",$this->getSort()) as $column) {
#
# Sort might already have an order on it (e.g. ASC or DESC)
# which we need to protect
#
$elements=explode(" ",$column);
$mapped=$this->getSortMapping($elements[0]);
if (sizeof($elements)==2) {
switch (strtoupper($elements[1])) {
case "DESC":
$mapped.=" DESC";
break;
case "ASC":
$mapped.=" ASC";
break;
default:
$this->context->warn("Sort argument not recognised".
$elements[1]);
}
}
array_push($mappedSort,$mapped);
}
$joinedMappedSort=join(",",$mappedSort);
$this->context->debug &&
$this->context->debug("Mapped sort is $joinedMappedSort");
return $joinedMappedSort;
}
/**
* Get order
*/
public function getOrder() {
if (!array_key_exists('order',$this->cache)) {
$order;
if ($this->getExplicit('order')) {
$order=$this->getExplicit('order');
} else if ($this->getImplicit('order')) {
$order=$this->getImplicit('order');
} else {
$order=$this->getDefault('order');
}
if ($order == "desc") {
$this->cache['order']="DESC";
} else {
$this->cache['order']="ASC";
}
$this->context->debug &&
$this->context->debug("Order set to ".$this->cache['order']);
}
return $this->cache['order'];
}
/**
* Get order
*/
public function getGroupOrder() {
if (!array_key_exists('grouporder',$this->cache)) {
$order;
if ($this->getExplicit('grouporder')) {
$order=$this->getExplicit('grouporder');
} else if ($this->getImplicit('grouporder')) {
$order=$this->getImplicit('grouporder');
} else {
$order=$this->getDefault('grouporder');
}
if ($order == "desc") {
$this->cache['grouporder']="DESC";
} else {
$this->cache['grouporder']="ASC";
}
$this->context->debug &&
$this->context->debug("Group order set to ".
$this->cache['grouporder']);
}
return $this->cache['grouporder'];
}
/**
* Get group
*/
public function getGroup() {
if (!array_key_exists('group',$this->cache)) {
$group;
if ($this->getExplicit('group')) {
# Explicit on function call
$group=$this->getExplicit('group');
} else if ($this->getImplicit('group')) {
# Implicit on usage and other function call parameters
$group=$this->getImplicit('group');
} else {
# Default behaviour is nothing
$group=FALSE;
}
$this->cache['group']=$group;
}
return $this->cache['group'];
}
public function implictlyRemoveColumn($column) {
$this->implicityRemovedColumns[$column]=$column;
$this->context->debug("Registering column for implicit removal : ".
$column);
}
public function implictlyAddColumn($column) {
$this->implicityAddedColumns[$column]=$column;
$this->context->debug("Registering column for implicit addition : ".
$column);
}
/**
* Get columns
*/
public function getColumns() {
if ($this->columnsToRender) {
return $this->columnsToRender;
}
if ($this->getExplicit('columns')) {
if (preg_match("/^([+-])(.*)$/",
$this->getExplicit('columns'), $array)) {
$this->context->debug &&
$this->context->
debug("Adjusting columns (comma separated) : ".
$array[1].":".$array[2]);
$baseColumns=explode(",",$this->getDefault('columns'));
$newColumns=array();
$deltaColumns=explode(",",$array[2]);
$defaultOperation=$array[1];
foreach ($deltaColumns as $deltaColumn) {
$newColumn=$deltaColumn;
$operation=$defaultOperation;
#
# Support operations on subsequent columns (not just the first)
#
if (preg_match("/^([+-])(.*)$/",
$deltaColumn, $pregDeltaColumn)) {
$operation=$pregDeltaColumn[1];
$newColumn=$pregDeltaColumn[2];
}
#
# Column name can have title in name, e.g. field:title
#
$newColumn=$this->getColumnNameAndRegisterTitle($newColumn);
$this->context->debug &&
$this->context->
debug("Adjusting columns (single string):".
$operation.":".$newColumn.":");
/**
* Add or remove column
*/
if ($operation == "+") {
$this->context->debug &&
$this->context->
debug("Adding column [$newColumn]");
array_push($newColumns,$newColumn);
if ($this->isCustomField($newColumn)) {
$this->addCustomField($newColumn);
}
if (array_key_exists($newColumn,
$this->implicityRemovedColumns)) {
$this->context->debug &&
$this->context->
debug("Removing implicit removal of column : $newColumn");
unset($this->implicityRemovedColumns[$newColumn]);
}
} else if ($operation == "-") {
$found=-1;