Agora::formatColumnHeaders PHP Метод

formatColumnHeaders() публичный Метод

Formats column headers have sort links and sort arrows.
public formatColumnHeaders ( array $columns, string $sort_by, string $sort_dir, string $view ) : array
$columns array The columns to format.
$sort_by string The current 'sort-by' column.
$sort_dir string The current sort direction.
$view string The view name, used to identify preference settings for sorting.
Результат array The formated column headers to be displayed.
    function formatColumnHeaders($columns, $sort_by, $sort_dir, $view)
    {
        /* Get the current url, remove any sorting parameters. */
        $url = Horde::selfUrl(true)->remove(array($view . '_sortby', $view . '_sortdir'));
        /* Go through the column headers to format and add sorting links. */
        $headers = array();
        foreach ($columns as $col_name => $col_title) {
            $extra = array();
            /* Is this a column with two headers? */
            if (is_array($col_title)) {
                $keys = array_keys($col_title);
                $extra_name = $keys[0];
                if ($sort_by == $keys[1]) {
                    $extra = array($keys[0] => $col_title[$keys[0]]);
                    $col_name = $keys[1];
                    $col_title = $col_title[$keys[1]];
                } else {
                    $extra = array($keys[1] => $col_title[$keys[1]]);
                    $col_name = $keys[0];
                    $col_title = $col_title[$keys[0]];
                }
            }
            if ($sort_by == $col_name) {
                /* This column is currently sorted by, plain title and
                 * add sort direction arrow. */
                $sort_img = $sort_dir ? 'za.png' : 'az.png';
                $sort_title = $sort_dir ? _("Sort Ascending") : _("Sort Descending");
                $col_arrow = Horde::link($url->add(array($view . '_sortby' => $col_name, $view . '_sortdir' => $sort_dir ? 0 : 1)), $sort_title) . Horde::img($sort_img, $sort_title) . '</a> ';
                $col_class = 'selected';
            } else {
                /* Column not currently sorted, add link to sort by
                 * this one and no sort arrow. */
                $col_arrow = '';
                $col_title = Horde::link($url->add($view . '_sortby', $col_name), sprintf(_("Sort by %s"), $col_title)) . $col_title . '</a>';
                $col_class = 'item';
            }
            $col_class .= ' leftAlign';
            if (count($extra)) {
                list($name, $title) = each($extra);
                $col_title .= '&nbsp;<small>[' . Horde::link($url->add($view . '_sortby', $name), sprintf(_("Sort by %s"), $title)) . $title . '</a>' . ']</small>';
                $col_name = $extra_name;
            }
            $headers[$col_name] = $col_arrow . $col_title;
            $headers[$col_name . '_class_plain'] = $col_class;
            $headers[$col_name . '_class'] = empty($col_class) ? '' : ' class="' . $col_class . '"';
        }
        return $headers;
    }

Usage Example

Пример #1
0
 /**
  */
 protected function _content()
 {
     /* Return empty if we don't have a thread set. */
     if (empty($this->_params['thread_id'])) {
         return '';
     }
     /* Set up the message object. */
     list($forum_id, $message_id) = explode('.', $this->_params['thread_id']);
     $messages = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create('agora', $forum_id);
     /* Check if valid thread, otherwise show forum list. */
     if ($messages instanceof PEAR_Error || empty($messages)) {
         throw new Horde_Exception(_("Unable to fetch selected thread."));
     }
     /* Get the sorting. */
     $sort_by = Agora::getSortBy('threads');
     $sort_dir = Agora::getSortDir('threads');
     $view_bodies = $GLOBALS['prefs']->getValue('thread_view_bodies');
     /* Get the message array and the sorted thread list. */
     $threads_list = $messages->getThreads($messages->getThreadRoot($message_id), true, $sort_by, $sort_dir, $view_bodies, Horde::selfUrl());
     /* Set up the column headers. */
     $col_headers = array(array('message_thread' => _("Thread"), 'message_subject' => _("Subject")), 'message_author' => _("Posted by"), 'message_timestamp' => _("Date"));
     $col_headers = Agora::formatColumnHeaders($col_headers, $sort_by, $sort_dir, 'threads');
     /* Set up the template tags. */
     $view = new Agora_View();
     $view->col_headers = $col_headers;
     $view->threads_list = $threads_list;
     $view->threads_list_header = _("Thread List");
     $view->thread_view_bodies = $view_bodies;
     return $view->render('block/thread');
 }
All Usage Examples Of Agora::formatColumnHeaders