Ejemplo n.º 1
0
function object_input_sf_asset_tag($object, $method, $options = array())
{
    $options = _parse_attributes($options);
    $name = _convert_method_to_name($method, $options);
    $value = _get_object_value($object, $method);
    return input_sf_asset_tag($name, $value, $options);
}
Ejemplo n.º 2
0
function my_object_select_tag($object, $method, $disabled, $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');
    $select_options = _get_options_from_objects(sfContext::getInstance()->retrieveObjects($related_class, $peer_method), $text_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 = my_options_for_select($select_options, $value, $disabled, $options);
    return select_tag(_convert_method_to_name($method, $options), $option_tags, $options);
}
function object_enum_tag($object, $method, $options)
{
    $enumValues = _get_option($options, 'enumValues', array());
    $currentValue = _get_object_value($object, $method);
    $enumValues = array_combine($enumValues, $enumValues);
    return select_tag(_convert_method_to_name($method, $options), options_for_select($enumValues, $currentValue), $options);
}
Ejemplo n.º 4
0
function object_input_auto_complete_tag($object, $method, $options = array(), $default_value = null)
{
    $peer_table = _get_option($options, 'peer_table');
    $peer_field = _get_option($options, 'peer_field');
    $input_name = _convert_method_to_name($method, $options);
    echo input_auto_complete_tag("{$peer_table}_{$peer_field}_search", '', sfContext::getInstance()->getModuleName() . "/autocomplete?table={$peer_table}&field={$peer_field}", array('autocomplete' => 'off'), array('use_style' => true, 'after_update_element' => "function (inputField, selectedItem) { \$('" . get_id_from_name($input_name) . "').value = selectedItem.id; }", 'method' => 'get'));
    echo input_hidden_tag($input_name);
}
function object_admin_input_file_tag($object, $method, $options = array())
{
    $options = _parse_attributes($options);
    $name = _convert_method_to_name($method, $options);
    $html = '';
    if ($object->{$method}()) {
        if (isset($options['include_link']) && $options['include_link']) {
            $image_path = image_path('/' . sfConfig::get('sf_upload_dir_name') . '/' . $options['include_link'] . '/' . $object->{$method}());
            $image_text = isset($options['include_text']) ? __($options['include_text']) : __('[show file]');
            $html .= sprintf('<a onclick="window.open(this.href);return false;" href="%s">%s</a>', $image_path, $image_text) . "\n";
        }
        if (isset($options['include_remove']) && $options['include_remove']) {
            $html .= checkbox_tag(strpos($name, ']') !== false ? substr($name, 0, -1) . '_remove]' : $name) . ' ' . ($options['include_remove'] != true ? __($options['include_remove']) : __('remove file')) . "\n";
        }
    }
    unset($options['include_link']);
    unset($options['include_text']);
    unset($options['include_remove']);
    return input_file_tag($name, $options) . "\n<br />" . $html;
}
Ejemplo n.º 6
0
/**
 * Returns a <select> tag populated with all the states in a country.
 *
 * @param  string object name 
 * @param  string method name 
 * @param  array  additional HTML compliant <select> tag parameters. May also include the following options:
 *                'states[]' -- an array containing a list of states to be removed from the list
 *                'country'  -- a value that will select the states from a country code
 *                'sort'     -- will cause the list to be re-sorted alphabetically
 * @param  string default object value (usually a two-character state code)
 * @return string <select> tag populated with all the states in the default or selected country.
 * @see select_state_tag
 */
function object_select_state_tag($object, $method, $options = array(), $default_value = null)
{
    $options = _parse_attributes($options);
    $value = _get_object_value($object, $method, $default_value);
    return select_state_tag(_convert_method_to_name($method, $options), $value, $options);
}
Ejemplo n.º 7
0
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 checkbox html tag.
 *
 * @param  object $object         An object.
 * @param  string $method         An object column.
 * @param  array  $options        Checkbox options.
 * @param  bool   $default_value  Checkbox value.
 *
 * @return string An html string which represents a checkbox tag.
 *
 */
function object_checkbox_tag($object, $method, $options = array(), $default_value = null)
{
    $options = _parse_attributes($options);
    $checked = (bool) _get_object_value($object, $method, $default_value);
    return checkbox_tag(_convert_method_to_name($method, $options), isset($options['value']) ? $options['value'] : 1, $checked, $options);
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
function object_radiobutton_tag($object, $method, $options = array(), $default_value = null)
{
    $options = _parse_attributes($options);
    $text_options = explode(":", $options['text_options']);
    $value_options = explode(":", $options['value_options']);
    $radiobuttons_html = "";
    $radionbutton_name = _convert_method_to_name($method, $options);
    unset($options['text_options'], $options['value_options']);
    $value = _get_object_value($object, $method, $default_value);
    if ($value == "") {
        $value = $options['default_value'];
    }
    foreach ($text_options as $key => $text) {
        $radiobuttons_html .= radiobutton_tag($radionbutton_name, $value_options[$key], $value_options[$key] == $value ? true : false, $options) . $text;
    }
    return $radiobuttons_html;
}