/** * Override of the standard objects_for_select, that allows the usage of the 'include_zero_custom' option * to insert a custom field returning the 0 value on top of the options * * @return String * @author Guglielmo Celata **/ function adv_objects_for_select($options = array(), $value_method, $text_method = null, $selected = null, $html_options = array()) { $select_options = array(); foreach ($options as $option) { // text method exists? if ($text_method && !is_callable(array($option, $text_method))) { $error = sprintf('Method "%s" doesn\'t exist for object of class "%s"', $text_method, _get_class_decorated($option)); throw new sfViewException($error); } // value method exists? if (!is_callable(array($option, $value_method))) { $error = sprintf('Method "%s" doesn\'t exist for object of class "%s"', $value_method, _get_class_decorated($option)); throw new sfViewException($error); } $value = $option->{$value_method}(); $key = $text_method != null ? $option->{$text_method}() : $value; $select_options[$value] = $key; } return adv_options_for_select($select_options, $selected, $html_options); }
function _get_object_value($object, $method, $default_value = null, $param = null) { // compatibility with the array syntax if (is_string($method)) { $param = $param == null ? array() : array($param); $method = array($method, $param); } // method exists? if (!is_callable(array($object, $method[0]))) { throw new sfViewException(sprintf('Method "%s" doesn\'t exist for object of class "%s".', $method[0], _get_class_decorated($object))); } $object_value = call_user_func_array(array($object, $method[0]), $method[1]); return $default_value !== null && $object_value === null ? $default_value : $object_value; }