/** * This global function loads the first row of a query into an object * * If an object is passed to this function, the returned row is bound to the existing elements of <var>object</var>. * If <var>object</var> has a value of null, then all of the returned query fields returned in the object. * * @param object The address of variable */ function loadObject(&$object) { if ($object != null) { if (!($cur = $this->query())) { return false; } if ($array = mysqli_fetch_assoc($cur)) { mysqli_free_result($cur); mosBindArrayToObject($array, $object, null, null, false); return true; } else { return false; } } else { $object = parent::loadObject(); return $object; } }
/** * Loads an array of typed objects of a given class (same class as current object by default) * * @param string $class [optional] class name * @param string $key [optional] key name in db to use as key of array * @param array $additionalVars [optional] array of string additional key names to add as vars to object * @return array of objects of the same class (empty array if no objects) */ function &loadTrueObjects($class = null, $key = "", $additionalVars = array()) { $objectsArray = array(); $resultsArray = $this->_db->loadAssocList($key); if (is_array($resultsArray)) { if ($class == null) { $class = get_class($this); } foreach ($resultsArray as $k => $value) { $objectsArray[$k] =& new $class($this->_db); mosBindArrayToObject($value, $objectsArray[$k], null, null, false); foreach ($additionalVars as $index) { if (array_key_exists($index, $value)) { $objectsArray[$k]->{$index} = $value[$index]; } } } } return $objectsArray; }
/** * binds a named array/hash to this object * * can be overloaded/supplemented by the child class * @param array $hash named array * @return null|string null is operation was satisfactory, otherwise returns an error */ function bind($array, $ignore = "") { if (!is_array($array)) { $this->_error = strtolower(get_class($this)) . "::bind failed."; return false; } else { return mosBindArrayToObject($array, $this, $ignore); } }
/** * binds a named array/hash to this object * * can be overloaded/supplemented by the child class * @param array $hash named array * @return null|string null is operation was satisfactory, otherwise returns an error */ function bind($array, $ignore = '') { if (!is_array($array)) { $this->_error = strtolower(get_class($this)) . "::Falha de ligação."; return false; } else { return mosBindArrayToObject($array, $this, $ignore); } }