/** * Fetch * * @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' * @access public * @return array The 2D Array of the records */ function &fetch($offset = 0, $len = null, $sortField = null, $sortDir = 'ASC') { // Check to see if Query has already been submitted if ($this->_dataobject->_DB_resultid != '') { $this->_rowNum = $this->_dataobject->N; } else { // Caching the number of rows if (PEAR::isError($count = $this->count())) { return $count; } else { $this->_rowNum = $count; } // Sorting if ($sortField) { $this->sort($sortField, $sortDir); } elseif (($sortProperty = $this->_options['sort_property']) && isset($this->_dataobject->{$sortProperty})) { foreach ($this->_dataobject->{$sortProperty} as $sort) { $this->sort($sort); } } // Limiting if ($offset) { $this->_dataobject->limit($offset, $len); } elseif ($len) { $this->_dataobject->limit($len); } $result = $this->_dataobject->find(); } // Retrieving data $records = array(); if ($this->_rowNum) { if ($this->_options['formbuilder_integration']) { require_once 'DB/DataObject/FormBuilder.php'; $links = $this->_dataobject->links(); } while ($this->_dataobject->fetch()) { // Determine Fields if (!$this->_options['fields']) { $this->_options['fields'] = array_keys($this->_dataobject->toArray()); //$this->_options['fields'] = array_filter(array_keys(get_object_vars($this->_dataobject)), array(&$this, '_fieldsFilter')); } $fieldList = $this->_options['fields']; // Build DataSet $rec = array(); foreach ($fieldList as $fName) { $getMethod = 'get' . $fName; if (method_exists($this->_dataobject, $getMethod)) { //$rec[$fName] = $this->_dataobject->$getMethod(&$this); $rec[$fName] = $this->_dataobject->{$getMethod}; } elseif (isset($this->_dataobject->{$fName})) { $rec[$fName] = $this->_dataobject->{$fName}; } else { $rec[$fName] = null; } } // Get Linked FormBuilder Fields if ($this->_options['formbuilder_integration']) { foreach (array_keys($rec) as $field) { if (isset($links[$field]) && ($linkedDo =& $this->_dataobject->getLink($field))) { $rec[$field] = DB_DataObject_FormBuilder::getDataObjectString($linkedDo); } } } $records[] = $rec; } } return $records; }
/** * DB_DataObject_FormBuilder::getDataObjectString() * * Returns a string which identitfies this dataobject. * If multiple display fields are given, will display them all seperated by ", ". * If a display field is a foreign key (link) the display value for the record it * points to will be used as long as the linkDisplayLevel has not been reached. * Its display value will be surrounded by parenthesis as it may have multiple * display fields of its own. * * May be called statically. * * Will use display field configurations from these locations, in this order: * 1) $displayFields parameter * 2) the fb_linkDisplayFields member variable of the dataobject * 3) the linkDisplayFields member variable of this class (if not called statically) * 4) all fields returned by the DO's table() function * * @param DB_DataObject the dataobject to get the display value for, must be populated * @param mixed field to use to display, may be an array with field names or a single field. * Will only be used for this DO, not linked DOs. If you wish to set the display fields * all DOs the same, set the option in the FormBuilder class instance. * @param int the maximum link display level. If null, $this->linkDisplayLebel will be used * if it exists, otherwise 3 will be used. {@see DB_DataObject_FormBuilder::linkDisplayLevel} * @param int the current recursion level. For internal use only. * @return string select display value for this field * @access public */ function getDataObjectString(&$do, $displayFields = false, $linkDisplayLevel = null, $level = 1) { if ($linkDisplayLevel === null) { $linkDisplayLevel = isset($this) && isset($this->linkDisplayLevel) ? $this->linkDisplayLevel : 3; } if (!is_array($links = $do->links())) { $links = array(); } if ($displayFields === false) { if (isset($do->fb_linkDisplayFields)) { $displayFields = $do->fb_linkDisplayFields; } elseif (isset($this) && isset($this->linkDisplayFields) && $this->linkDisplayFields) { $displayFields = $this->linkDisplayFields; } if (!$displayFields) { $displayFields = array_keys($do->table()); } } $ret = ''; $first = true; foreach ($displayFields as $field) { if ($first) { $first = false; } else { $ret .= ', '; } if (isset($do->{$field})) { if ($linkDisplayLevel > $level && isset($links[$field])) { /*list ($linkTable, $linkField) = $links[$field]; $subDo = DB_DataObject::factory($linkTable); $subDo->$linkField = $do->$field;*/ if ($subDo = $do->getLink($field)) { if (isset($this) && is_a($this, 'DB_DataObject_FormBuilder')) { $ret .= '(' . $this->getDataObjectString($subDo, false, $linkDisplayLevel, $level + 1) . ')'; } else { $ret .= '(' . DB_DataObject_FormBuilder::getDataObjectString($subDo, false, $linkDisplayLevel, $level + 1) . ')'; } continue; } } $ret .= $do->{$field}; } } return $ret; }
function getDataObjectString(&$do, $displayFields = false, $linkDisplayLevel = null, $level = 1, $preferHtml = false) { if (DB_DataObject_FormBuilder::isCallableAndExists(array($do, 'toHtml')) && $preferHtml) { return $do->toHtml(); } if (DB_DataObject_FormBuilder::isCallableAndExists(array($do, '__toString'))) { return $do->__toString(); } else { return parent::getDataObjectString($do, $displayFields, $linkDisplayLevel, $level); } }