/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/flibRPCDataListSource.inc
ViewVC logotype

Contents of /nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/flibRPCDataListSource.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Fri Feb 28 17:16:38 2003 UTC (21 years, 6 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
FILE REMOVED
+ renamed to MemoryDataListSource.inc

1 <?php
2 /**
3 * This file contains the DataListSource class
4 * that gets the data from flib::Remote().
5 *
6 *
7 * $Id: flibRPCDataListSource.inc,v 1.2 2003/01/31 08:44:53 jonen Exp $
8 *
9 */
10
11
12
13 /**
14 *
15 * This DataListSource child class gets the data from a
16 * RPC call via the php-flip libary.
17 *
18 *
19 */
20 class flibRPCDataListSource extends DataListSource {
21
22
23 /**
24 * given result hash
25 *
26 */
27 var $_object_list = array();
28
29
30
31 /**
32 * this holds the headers read
33 * from the top of the csv file
34 */
35 var $_object_keys = array();
36
37
38 /**
39 * The constructor.
40 *
41 * @param hash - a hashed data object
42 *
43 */
44 function flibRPCDataListSource( $object_list ) {
45 $this->_object_list = $object_list;
46 //print_r($object_list);
47 }
48
49
50 /**
51 * The prequery. We use this to read the file
52 * into memory so we can do operations on the data
53 * (search, sort, etc.)
54 */
55 function do_prequery() {
56 $this->_get_header();
57 }
58
59 /**
60 * This function does the query
61 * and search/sort
62 */
63 function do_query() {
64 foreach ($this->_object_list as $value) {
65 if ($this->add_data_row( $value)) {
66 $count++;
67 }
68 }
69
70 $this->set_total_rows( $count );
71 $this->sort();
72 }
73
74 /**
75 * This function returns the next row of
76 * valid data.
77 *
78 */
79 function get_next_data_row() {
80 $index = $this->get_data_index();
81 $limit = $this->get_limit();
82 $offset = $this->get_offset();
83
84 if ($limit == -1) {
85 //don't limit the data
86 if ($index > $this->get_total_rows()) {
87 return NULL;
88 } else {
89 return $this->_data[$index];
90 }
91 } else {
92 $left_to_show = $limit - ($index - $offset);
93 if ($left_to_show > 0) {
94 return $this->_data[$index];
95 } else {
96 return NULL;
97 }
98 }
99 }
100
101
102
103
104 /**
105 * This file trys to get the Object Hash Keys.
106 *
107 */
108 function _get_header() {
109 foreach($this->_object_list[0] as $key => $value) {
110 array_push($this->_object_keys, $key);
111 }
112 }
113
114
115 function get_header() {
116 $this->_get_header();
117 return $this->_object_keys;
118 }
119
120
121 function get_data_source() {
122
123 }
124
125
126 /**
127 * This function adds a row of data
128 * if necesarry to the data array
129 *
130 */
131 function add_data_row($row) {
132 if ($row != NULL) {
133 if ($this->get_searchby_value()) {
134 //user wants to search the data
135 if ($this->_find_data($row) ) {
136 $this->_data[] = $row;
137 return TRUE;
138 } else {
139 return FALSE;
140 }
141 } else {
142 $this->_data[] = $row;
143 return TRUE;
144 }
145 } else {
146 return FALSE;
147 }
148 }
149
150 function sort() {
151 $sortby = $this->get_orderby();
152 //ok we need to sort the data by the
153 //column in the table
154 if ($this->_is_column_sortable($sortby)) {
155 //looks like we can sort this column
156 usort($this->_data, array($this, "cmp"));
157 }
158 }
159
160 function cmp($data1, $data2) {
161 $sortby = $this->get_orderby();
162 $ret = strnatcmp( $data1[$sortby], $data2[$sortby]);
163 if ($this->get_reverseorder() == "true") {
164 $ret *= -1;
165 }
166 return $ret;
167 }
168
169 function _find_data( $row_data ) {
170 //look for the 'needle' in the 'haystack'
171
172 $needle = $this->get_searchby_value();
173 $haystack = $row_data[$this->get_searchby()];
174
175 switch ($this->get_simplesearch_modifier()) {
176 case "BEGINS":
177 if (strncasecmp($needle, $haystack, strlen($needle)) == 0) {
178 return TRUE;
179 } else {
180 return FALSE;
181 }
182 break;
183
184 case "CONTAINS":
185 if (stristr($haystack, $needle)) {
186 return TRUE;
187 } else {
188 return FALSE;
189 }
190 break;
191 case "EXACT":
192 if (strcasecmp($needle, $haystack) == 0) {
193 return TRUE;
194 } else {
195 return FALSE;
196 }
197 break;
198 case "ENDS":
199 $needle_len = strlen( $needle );
200 $haystack_len = strlen( $haystack );
201 if ($needle_len > $haystack_len) {
202 return FALSE;
203 } else if ($needle_len == $haystack_len) {
204 $tmp = $haystack;
205 } else {
206 $tmp = substr($haystack, $haystack_len - $needle_len);
207 }
208 if (strncasecmp($needle, $tmp, $needle_len) == 0) {
209 return TRUE;
210 } else {
211 return FALSE;
212 }
213 break;
214 }
215 }
216
217 }
218 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed