TYPO3 CMS  TYPO3_7-6
rsfilter.inc.php
Go to the documentation of this file.
1 <?php
17 /*
18  Filter all fields and all rows in a recordset and returns the
19  processed recordset. We scroll to the beginning of the new recordset
20  after processing.
21 
22  We pass a recordset and function name to RSFilter($rs,'rowfunc');
23  and the function will be called multiple times, once
24  for each row in the recordset. The function will be passed
25  an array containing one row repeatedly.
26 
27  Example:
28 
29  // ucwords() every element in the recordset
30  function do_ucwords(&$arr,$rs)
31  {
32  foreach($arr as $k => $v) {
33  $arr[$k] = ucwords($v);
34  }
35  }
36  $rs = RSFilter($rs,'do_ucwords');
37  */
38 function RSFilter($rs,$fn)
39 {
40  if ($rs->databaseType != 'array') {
41  if (!$rs->connection) return false;
42 
43  $rs = $rs->connection->_rs2rs($rs);
44  }
45  $rows = $rs->RecordCount();
46  for ($i=0; $i < $rows; $i++) {
47  if (is_array ($fn)) {
48  $obj = $fn[0];
49  $method = $fn[1];
50  $obj->$method ($rs->_array[$i],$rs);
51  } else {
52  $fn($rs->_array[$i],$rs);
53  }
54 
55  }
56  if (!$rs->EOF) {
57  $rs->_currentRow = 0;
58  $rs->fields = $rs->_array[0];
59  }
60 
61  return $rs;
62 }
if(isset($_REQUEST['nrows'])) else $rs
Definition: server.php:94
RSFilter($rs, $fn)