PatternBrowsableSearchResults.inc
6.03 KB
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
<?php
class PatternBrowseableSearchResults {
/** query to be executed */
var $sQuery;
/** columns in query to be displayed */
var $aColumns;
/** column types */
var $aColumnTypes;
/** column headings to display */
var $aColumnHeadings;
/** link href for column type 3 */
var $aLinkURLs;
/** database column values to append to link url if a column type of 3 is specified */
var $aDBQueryStringColumns;
/** variables names to give $aDBQueryStringColumns on the query string */
var $aQueryStringVariableNames;
/** number of results to display per page */
var $iResultsToDisplay;
/* Result number to start on */
var $iStartIndex;
/** Column to order by */
var $sOrderByColumn;
/** direction of ordering, ascending or descending */
var $sOrderDirection = "ASC";
function PatternBrowseableSearchResults($sTmpQuery, $iTmpResultsToDisplay, $aTmpColumns, $aTmpColumnTypes, $aTmpColumnHeaders, $aTmpLinkURLs = null, $aTmpDBQueryStringColumns = null, $aTmpQueryStringVariableNames = null) {
$this->sQuery = $sTmpQuery;
$this->iResultsToDisplay = $iTmpResultsToDisplay;
$this->aColumns = $aTmpColumns;
$this->aColumnHeadings = $aTmpColumnHeaders;
$this->aColumnTypes = $aTmpColumnTypes;
$this->aLinkURLs = $aTmpLinkURLs;
$this->aDBQueryStringColumns = $aTmpDBQueryStringColumns;
$this->aQueryStringVariableNames = $aTmpQueryStringVariableNames;
}
function setStartIndex($iNewValue) {
$this->iStartIndex = $iNewValue;
}
function setOrderByColumn($sNewValue) {
$this->sOrderByColumn = $sNewValue;
}
function setOrderDirection($sNewValue) {
$this->sOrderDirection = $sNewValue;
}
/**
* Build the HTML string used to render the object
*
* @return String of HTML used to render object
*
* @todo possibly add in image size restraints for link types 2 and 3
*/
function & render() {
global $default;
//add the limit and offset stuff for cutting down result set
$sLimitQuery = $this->sQuery . " LIMIT " . $this->iStartIndex . ", " . $this->iResultsToDisplay;
$sql = & $default->db;
$sql->query($sLimitQuery);
$sToRender = "<table width=\"100%\" height=\"100%\">\n";
$sToRender .= "<tr>\n";
for ($i = 0; $i < count($this->aColumnHeadings); $i++) {
if (! (strcmp($this->sOrderByColumn, $this->aColumns[$i]) === false) && (strcmp($this->sOrderByColumn, $this->aColumns[$i]) == 0)) {
if (!(strcmp($this->sOrderDirection,"ASC") === false) && (strcmp($this->sOrderDirection,"ASC") == 0)) {
$sToRender .= "<th align=\"left\"><a href=\"" . $_SERVER["PHP_SELF"] . "?fOrderBy=" . $this->aColumns[$i] . "&fOrderDirection=DESC&fStartIndex=" . $this->iStartIndex . "\">" . $this->aColumnHeadings[$i]."</a></th>\n";
} else {
$sToRender .= "<th align=\"left\"><a href=\"" . $_SERVER["PHP_SELF"] . "?fOrderBy=" . $this->aColumns[$i] . "&fOrderDirection=ASC&fStartIndex=" . $this->iStartIndex . "\">" . $this->aColumnHeadings[$i]."</a></th>\n";
}
} else {
$sToRender .= "<th align=\"left\"><a href=\"" . $_SERVER["PHP_SELF"] . "?fOrderBy=" . $this->aColumns[$i] . "&fOrderDirection=ASC&fStartIndex=" . $this->iStartIndex . "\">" . $this->aColumnHeadings[$i]."</a></th>\n";
}
}
$sToRender .= "</tr>\n";
$iDisplayed = 0;
//limit the result set displayed
while($sql->next_record() && ($iDisplayed < $this->iResultsToDisplay)) {
$sToRender .= "<tr>";
for ($i = 0; $i < count($this->aColumns); $i++) {
switch ($this->aColumnTypes[$i]) {
case 1:
//display text
$sToRender .= "<td>" . $sql->f($this->aColumns[$i]) . "</td>\n";
break;
case 2:
//diplay a checkbox
$sToRender .= "<td>" . ($sql->f($this->aColumns[$i]) ? "Yes" : "No") . "</td>\n";
break;
case 3:
//display a url
$sToRender .= "<td><a href=\"" . $this->aLinkURLs[$i];
for ($j = 0; $j < count($this->aDBQueryStringColumns); $j++) {
if (strpos($sToRender, "?") === false) {
$sToRender .= "?" . $this->aQueryStringVariableNames[$j] . "=" . $sql->f($this->aDBQueryStringColumns[$j]);
} else {
$sToRender .= "&" . $this->aQueryStringVariableNames[$j] . "=" . $sql->f($this->aDBQueryStringColumns[$j]);
}
}
$sToRender .= "\">" . $sql->f($this->aColumns[$i]) . "</a></td>\n";
break;
default:
break;
}
}
$sToRender .= "</tr>\n";
$iDisplayed++;
}
//if we displayed less results than the number to display
//simply pad the table
while ($iDisplayed < $this->iResultsToDisplay) {
$sToRender .= "<tr><td> </td></tr>\n";
$iDisplayed++;
}
$sToRender .= "<tr>\n";
/* Display only the next button */
if (($this->iStartIndex + $this->iResultsToDisplay) < $this->getResultCount($sql) && $this->iStartIndex == 0) {
$sToRender .= "<td>";
$sToRender .= ("<a href=\"" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex + $this->iResultsToDisplay) . "\">Next</a>");
$sToRender .= "</td>\n";
}
/* Display both the next and the previous buttons */
else if (($this->iStartIndex + $this->iResultsToDisplay) < $this->getResultCount($sql) && $this->iStartIndex > 0) {
$sToRender .= "<td>";
$sToRender .= ("<a href=\"" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex + $this->iResultsToDisplay) . "\">Next</a>");
$sToRender .= "</td>";
$sToRender .= "<td>";
$sToRender .= ("<a href=\"" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex - $this->iResultsToDisplay) . "\">Previous</a>");
$sToRender .= "</td>\n";
}
/* Display only the previous button */
else if ($this->iStartIndex > 0) {
$sToRender .= "<td>\n";
$sToRender .= (" ");
$sToRender .= "</td>";
$sToRender .= "<td>\n";
$sToRender .= ("<a href=\"" . $_SERVER["PHP_SELF"] . "?fStartIndex=" . ($this->iStartIndex - $this->iResultsToDisplay) . "\">Previous</a>");
$sToRender .= "</td>";
}
$sToRender .= "</tr>\n";
$sToRender .= "</table>\n";
return $sToRender;
}
function getResultCount($sql) {
if ($sql->query($this->sQuery)) {
return $sql->num_rows();
}
return 0;
}
}
?>