function object_double_list($object, $method, $options = array(), $callback = null, $criteria = null) { $options = _parse_attributes($options); $options['multiple'] = true; $options['class'] = 'sf_multiple'; if (!isset($options['size'])) { $options['size'] = 10; } if (is_null($criteria)) { $criteria = new Criteria(); } $label_all = __(isset($options['unassociated_label']) ? $options['unassociated_label'] : 'Unassociated'); $label_assoc = __(isset($options['associated_label']) ? $options['associated_label'] : 'Associated'); // get the lists of objects list($all_objects, $objects_associated, $associated_ids) = _get_object_list_nuevo($object, $method, $options, $callback, $criteria); $objects_unassociated = array(); foreach ($all_objects as $object) { if (!in_array($object->getPrimaryKey(), $associated_ids)) { $objects_unassociated[] = $object; } } // override field name unset($options['control_name']); $name = _convert_method_to_name($method, $options); $name1 = 'unassociated_' . $name; $name2 = 'associated_' . $name; $select1 = select_tag($name1, options_for_select(_get_options_from_objects($objects_unassociated), '', $options), $options); $options['class'] = 'sf_multiple-selected'; $select2 = select_tag($name2, options_for_select(_get_options_from_objects($objects_associated), '', $options), $options); $html = '<div> <div style="float: left"> <div style="font-weight: bold; padding-bottom: 0.5em">%s</div> %s </div> <div style="float: left"> %s<br /> %s </div> <div style="float: left"> <div style="font-weight: bold; padding-bottom: 0.5em">%s</div> %s </div> <br style="clear: both" /> </div> '; $response = sfContext::getInstance()->getResponse(); $response->addJavascript(sfConfig::get('sf_prototype_web_dir') . '/js/prototype'); $response->addJavascript('/js/mis_funciones'); //neofis return sprintf($html, $label_all, $select1, submit_image_tag('/images/icons/next.png', "style=\"border: 0\" onclick=\"double_list_move(\$('{$name1}'), \$('{$name2}')); return false;\""), submit_image_tag('/images/icons/previous.png', "style=\"border: 0\" onclick=\"double_list_move(\$('{$name2}'), \$('{$name1}')); return false;\""), $label_assoc, $select2); }
/** * Returns a list html tag. * * @param object $object An object or the selected value * @param string $method An object column. * @param array $options Input options (related_class option is mandatory). * @param string $default_value Input default value. * * @return string A list string which represents an input tag. * */ function object_select_tag($object, $method, $options = array(), $default_value = null) { $options = _parse_attributes($options); $related_class = _get_option($options, 'related_class', false); if (false === $related_class && preg_match('/^get(.+?)Id$/', $method, $match)) { $related_class = $match[1]; } $peer_method = _get_option($options, 'peer_method'); $text_method = _get_option($options, 'text_method'); $key_method = _get_option($options, 'key_method', 'getPrimaryKey'); $select_options = _get_options_from_objects(sfContext::getInstance()->retrieveObjects($related_class, $peer_method), $text_method, $key_method); if ($value = _get_option($options, 'include_custom')) { $select_options = array('' => $value) + $select_options; } else { if (_get_option($options, 'include_title')) { $select_options = array('' => '-- ' . _convert_method_to_name($method, $options) . ' --') + $select_options; } else { if (_get_option($options, 'include_blank')) { $select_options = array('' => '') + $select_options; } } } if (is_object($object)) { $value = _get_object_value($object, $method, $default_value); } else { $value = $object; } $option_tags = options_for_select($select_options, $value, $options); return select_tag(_convert_method_to_name($method, $options), $option_tags, $options); }
/** * two multiline select tags with associated and unassociated items * * @return string * @param object object * @param string method of object * @param array options * @param array html options of select tags **/ function double_list($object, $method, $options = array(), $html_options = array()) { $options = _parse_attributes($options); // get the lists of objects list($all_objects, $objects_associated, $associated_ids) = _get_object_list($object, $method, _get_option($options, 'through_class'), _get_option($options, 'peer_method')); // options $html_options['multiple'] = _get_option($html_options, 'multiple', true); $html_options['size'] = _get_option($html_options, 'size', 5); $html_options['class'] = 'double_list'; $label_assoc = _get_option($options, 'associated_label', 'Zugeh�rige Gruppen'); $label_all = _get_option($options, 'unassociated_label', 'Gruppenliste'); $name1 = _get_option($options, 'associated', 'isSelected'); $name2 = _get_option($options, 'unassociated', 'unSelected'); $form = _get_option($options, 'form_id', 'editForm'); // unassociated objects $objects_unassociated = array(); foreach ($all_objects as $object) { if (!in_array($object->getPrimaryKey(), $associated_ids)) { $objects_unassociated[] = $object; } } // select tags $select1 = select_tag($name1, options_for_select(_get_options_from_objects($objects_associated), '', $options), $html_options); unset($html_options['class']); $select2 = select_tag($name2, options_for_select(_get_options_from_objects($objects_unassociated), '', $options), $html_options); // output skeloton $html = "\n<table><tr>\n\t<td class='first'><div class='first' style='padding-bottom:0px;padding-left:15px;'>{$label_assoc}</div>%s</td>\n\t<td class='first'><div class='first' style='padding-bottom:0px;padding-left:15px;'> </div>%s<br/>%s</td>\n\t<td class='first'><div class='first' style='padding-bottom:0px;padding-left:15px;'>{$label_all}</div>%s</td>\n</tr></table>\n"; // include js library $response = sfContext::getInstance()->getResponse(); $response->addJavascript('/js/double_list.js', 'last'); return sprintf($html, $select1, link_to_function(image_tag('resultset_previous'), "double_list_move(\$('{$name2}'), \$('{$name1}'))"), link_to_function(image_tag('resultset_next'), "double_list_move(\$('{$name1}'), \$('{$name2}'))", 'style=display:block'), $select2, $form); }
function object_admin_select_list($object, $method, $options = array(), $callback = null) { $options = _parse_attributes($options); $options['multiple'] = true; $options['class'] = 'sf_admin_multiple'; if (!isset($options['size'])) { $options['size'] = 10; } // get the lists of objects list($objects, $objects_associated, $ids) = _get_object_list($object, $method, $options, $callback); // override field name unset($options['control_name']); $name = 'associated_' . _convert_method_to_name($method, $options); return select_tag($name, options_for_select(_get_options_from_objects($objects), $ids, $options), $options); }
<?php echo select_tag($nombre, options_for_select(array('' => 'Seleccione') + _get_options_from_objects($actividades), isset($id_actividad) ? $id_actividad : ''), array());