/** * Reusable static fetch method * * Since many drivers end up needing this array driver's features, * the following method is provided in order to avoid subclassing * this class. * * @param integer $offset Limit offset (starting from 0) * @param integer $len Limit length * @param string $sortField Field to sort by * @param string $sortDir Sort direction : 'ASC' or 'DESC' * @static */ function &staticFetch($ar, $fieldList, $offset = 0, $len = null, $sortField = null, $sortDir = 'ASC') { // sorting if ($sortField) { Structures_DataGrid_DataSource_Array::sort($sortField, $sortDir, $ar); } // slicing if (is_null($len)) { $slice = array_slice($ar, $offset); } else { $slice = array_slice($ar, $offset, $len); } // Filter out fields that are to not be rendered // // With the new array_intersect_key() the following would be : // $records = array_intersect_key($slice, array_flip ($fieldList)); // One line... And faster... But this function is cvs-only. $records = array(); foreach ($slice as $rec) { $buf = array(); foreach ($rec as $key => $val) { if (in_array($key, $fieldList)) { $buf[$key] = $val; } } $records[] = $buf; } return $records; }
function Structures_DataGrid_DataSource_CSV() { parent::Structures_DataGrid_DataSource_Array(); }
/** * Fetch * * @param integer $offset Offset (starting from 0) * @param integer $limit Limit * @param string $sortField Field to sort by * @param string $sortDir Sort direction : 'ASC' or 'DES * @access public * @return array The 2D Array of the records */ function &fetch($offset = 0, $limit = null, $sortField = null, $sortDir = 'ASC') { $recordSet = array(); // Fetch the Data if ($numRows = $this->_result->numRows()) { while ($record = $this->_result->fetchRow(DB_FETCHMODE_ASSOC)) { $recordSet[] = $record; } } // Determine fields to render if (!$this->_options['fields']) { $this->setOptions(array('fields' => array_keys($recordSet[0]))); } // Limit and Sort the Data $recordSet =& Structures_DataGrid_DataSource_Array::staticFetch($recordSet, $this->_options['fields'], $offset, $limit, $sortField, $sortDir); return $recordSet; }
/** * Constructor * */ function Structures_DataGrid_DataSource_XML() { parent::Structures_DataGrid_DataSource_Array(); $this->_addDefaultOptions(array('xpath' => '')); }