Exemplo n.º 1
0
/**
 * Returns HTML code for a uiWindow.
 * 
 * @uses   jquery, jquery UI/Draggable
 * @uses   ui_box_rounded() for the window border
 * 
 * @param  string  $content  HTML content for the uiWindow div.window-body
 * @param  array   $options  Tag attributes as for tag() helper (to set id, etc)
 *                           Classes can be set, "uiWindow" class is merged
 * 
 * @return string  HTML code
 */
function ui_window($content = '', $options = array())
{
    // add uiWindow class
    $options['class'] = _merge_class_names(isset($options['class']) ? $options['class'] : array(), array('uiWindow'));
    $view = new coreView(coreContext::getInstance());
    $view->getParameterHolder()->add(array('content' => $content, 'options' => $options));
    $view->setTemplate(dirname(__FILE__) . '/templates/ui_window.php');
    return $view->render();
}
Exemplo n.º 2
0
/**
 * uiProgressBar
 * 
 * Generate markup for a progress bar.
 * 
 * Bars is an array of 'bar' definitions as associative arrays:
 * 
 *   value   => value for this bar, between 0 and maxValue
 *   label   => optional label to output within SPAN and as title attribute on the SPAN, defaults to "min/max"
 *   class   => a class name for this SPAN, defaults to "g" (green), specify if using multiple bars    
 *   
 *    => <span class="r" title="optional label" style="width:15%;">optional label</span>
 * 
 * Does not support minValue for now, so bars must be defined in order of size from largest to smallest,
 * the smallest will show on top of others.
 * 
 * Options:
 * - optional attributes, as for the tag helpers
 * - "borderColor" with a proper css color value ("red" or "#f00") to override the default gray
 *   border from the stylesheet.
 *   
 * @param  $bars           Associative array definitions for bars
 * @param  $maxValue       The max value corresponds to 100% of the bar width, related to each bar's value
 * 
 * @return string          HTML markup 
 */
function ui_progress_bar(array $bars, $maxValue, $options = array())
{
    if (!is_int($maxValue)) {
        throw new coreException('ui_progress_bar()  "maxValue" must be an integer');
    }
    // border color for the bar, override border-color from the stylesheet
    $innerDivOptions = array();
    if (isset($options['borderColor'])) {
        // override background color on outer div
        $options['style'] = "background:{$options['borderColor']};";
        // override border-color on inner div
        $innerDivOptions['style'] = "border-color:{$options['borderColor']};";
        unset($options['borderColor']);
    }
    // merge widget class name
    $options['class'] = _merge_class_names(isset($options['class']) ? $options['class'] : array(), array('uiProgressBar'));
    // generate the bars as SPANs
    $spans = array();
    foreach ($bars as $bar) {
        if (!ctype_digit((string) $bar['value'])) {
            throw new coreException('ui_progress_bar()  "value" must be numeric');
        }
        if ($bar['value'] >= 0) {
            $percent = $bar['value'] > 0 ? ceil($bar['value'] / $maxValue * 100) : 0;
            $label = isset($bar['label']) ? $bar['label'] : "{$bar['value']}/{$maxValue}";
            $spanOptions = array('class' => isset($bar['class']) ? $bar['class'] : "g", 'title' => $label, 'style' => "width:{$percent}%;");
            array_push($spans, content_tag('span', $label, $spanOptions));
        }
    }
    $content = content_tag('div', implode('', $spans), $innerDivOptions);
    // generate the outer div
    return content_tag('div', $content, $options);
}