Пример #1
0
/**
 * 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;'>&nbsp;</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);
}
Пример #2
0
function object_admin_check_list($object, $method, $options = array(), $callback = null)
{
    $options = _parse_attributes($options);
    // get the lists of objects
    list($objects, $objects_associated, $assoc_ids) = _get_object_list($object, $method, $options, $callback);
    // override field name
    unset($options['control_name']);
    $name = 'associated_' . _convert_method_to_name($method, $options) . '[]';
    $html = '';
    if (!empty($objects)) {
        // which method to call?
        $methodToCall = '__toString';
        foreach (array('__toString', 'toString', 'getPrimaryKey') as $method) {
            if (method_exists($objects[0], $method)) {
                $methodToCall = $method;
                break;
            }
        }
        $html .= "<ul class=\"sf_admin_checklist\">\n";
        foreach ($objects as $related_object) {
            $relatedPrimaryKey = $related_object->getPrimaryKey();
            // multi primary key handling
            if (is_array($relatedPrimaryKey)) {
                $relatedPrimaryKeyHtmlId = implode('/', $relatedPrimaryKey);
            } else {
                $relatedPrimaryKeyHtmlId = $relatedPrimaryKey;
            }
            $html .= '<li>' . checkbox_tag($name, $relatedPrimaryKeyHtmlId, in_array($relatedPrimaryKey, $assoc_ids)) . ' <label for="' . get_id_from_name($name, $relatedPrimaryKeyHtmlId) . '">' . $related_object->{$methodToCall}() . "</label></li>\n";
        }
        $html .= "</ul>\n";
    }
    return $html;
}