source: moodle/trunk/fuentes/lib/adodb/rsfilter.inc.php @ 1331

Last change on this file since 1331 was 1331, checked in by jrpelegrina, 3 years ago

Updated to moodle 3.0.3

File size: 1.6 KB
Line 
1<?php
2/**
3 * @version   v5.20.1  06-Dec-2015
4 * @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
5 * @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
6 * Released under both BSD license and Lesser GPL library license.
7 * Whenever there is any discrepancy between the two licenses,
8 * the BSD license will take precedence.
9 *
10 * Set tabs to 4 for best viewing.
11 *
12 * Latest version is available at http://php.weblogs.com
13 *
14 * Requires PHP4.01pl2 or later because it uses include_once
15*/
16
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 */
38function 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}
Note: See TracBrowser for help on using the repository browser.