/** * function to return the results of an options query as array. This function assumes that * the query returns two columns optionvalue and optiontext which correspond to the corresponding key * and values respectively. * * The selection of the names is to avoid name collisions with database reserved words * * @param String $query The database query * * @return Array of values for the query */ function getOptionValuesFromDatabaseQuery($query) { $conn = Doctrine_Manager::connection(); $result = $conn->fetchAll($query); $valuesarray = array(); foreach ($result as $value) { $valuesarray[$value['optionvalue']] = htmlentities($value['optiontext']); } return decodeHtmlEntitiesInArray($valuesarray); }
/** * Decode all html entities of an array * @param Array $elem the array to be decoded */ function decodeHtmlEntitiesInArray(&$elem) { if (!is_array($elem)) { $elem = html_entity_decode($elem); } else { foreach ($elem as $key => $value) { $elem[$key] = decodeHtmlEntitiesInArray($value); } } return $elem; }