Ejemplo n.º 1
0
    /**
     * Renders a F0FForm for a Browse view and returns the corresponding HTML
     *
     * @param   F0FForm   &$form  The form to render
     * @param   F0FModel  $model  The model providing our data
     * @param   F0FInput  $input  The input object
     *
     * @return  string    The HTML rendering of the form
     */
    protected function renderFormBrowse(F0FForm &$form, F0FModel $model, F0FInput $input)
    {
        $html = '';
        JHtml::_('behavior.multiselect');
        // Joomla! 3.0+ support
        if (version_compare(JVERSION, '3.0', 'ge')) {
            JHtml::_('bootstrap.tooltip');
            JHtml::_('dropdown.init');
            JHtml::_('formbehavior.chosen', 'select');
            $view = $form->getView();
            $order = $view->escape($view->getLists()->order);
            $html .= <<<HTML
<script type="text/javascript">
\tJoomla.orderTable = function() {
\t\ttable = document.getElementById("sortTable");
\t\tdirection = document.getElementById("directionTable");
\t\torder = table.options[table.selectedIndex].value;
\t\tif (order != '{$order}')
\t\t{
\t\t\tdirn = 'asc';
\t\t}
\t\telse {
\t\t\tdirn = direction.options[direction.selectedIndex].value;
\t\t}
\t\tJoomla.tableOrdering(order, dirn);
\t};
</script>

HTML;
        } else {
            JHtml::_('behavior.tooltip');
        }
        // Getting all header row elements
        $headerFields = $form->getHeaderset();
        // Get form parameters
        $show_header = $form->getAttribute('show_header', 1);
        $show_filters = $form->getAttribute('show_filters', 1);
        $show_pagination = $form->getAttribute('show_pagination', 1);
        $norows_placeholder = $form->getAttribute('norows_placeholder', '');
        // Joomla! 3.0 sidebar support
        if (version_compare(JVERSION, '3.0', 'gt')) {
            $form_class = '';
            if ($show_filters) {
                JHtmlSidebar::setAction("index.php?option=" . $input->getCmd('option') . "&view=" . F0FInflector::pluralize($input->getCmd('view')));
            }
            // Reorder the fields with ordering first
            $tmpFields = array();
            $i = 1;
            foreach ($headerFields as $tmpField) {
                if ($tmpField instanceof F0FFormHeaderOrdering) {
                    $tmpFields[0] = $tmpField;
                } else {
                    $tmpFields[$i] = $tmpField;
                }
                $i++;
            }
            $headerFields = $tmpFields;
            ksort($headerFields, SORT_NUMERIC);
        } else {
            $form_class = 'class="form-horizontal"';
        }
        // Pre-render the header and filter rows
        $header_html = '';
        $filter_html = '';
        $sortFields = array();
        if ($show_header || $show_filters) {
            foreach ($headerFields as $headerField) {
                $header = $headerField->header;
                $filter = $headerField->filter;
                $buttons = $headerField->buttons;
                $options = $headerField->options;
                $sortable = $headerField->sortable;
                $tdwidth = $headerField->tdwidth;
                // Under Joomla! < 3.0 we can't have filter-only fields
                if (version_compare(JVERSION, '3.0', 'lt') && empty($header)) {
                    continue;
                }
                // If it's a sortable field, add to the list of sortable fields
                if ($sortable) {
                    $sortFields[$headerField->name] = JText::_($headerField->label);
                }
                // Get the table data width, if set
                if (!empty($tdwidth)) {
                    $tdwidth = 'width="' . $tdwidth . '"';
                } else {
                    $tdwidth = '';
                }
                if (!empty($header)) {
                    $header_html .= "\t\t\t\t\t<th {$tdwidth}>" . PHP_EOL;
                    $header_html .= "\t\t\t\t\t\t" . $header;
                    $header_html .= "\t\t\t\t\t</th>" . PHP_EOL;
                }
                if (version_compare(JVERSION, '3.0', 'ge')) {
                    // Joomla! 3.0 or later
                    if (!empty($filter)) {
                        $filter_html .= '<div class="filter-search btn-group pull-left">' . "\n";
                        $filter_html .= "\t" . '<label for="title" class="element-invisible">';
                        $filter_html .= JText::_($headerField->label);
                        $filter_html .= "</label>\n";
                        $filter_html .= "\t{$filter}\n";
                        $filter_html .= "</div>\n";
                        if (!empty($buttons)) {
                            $filter_html .= '<div class="btn-group pull-left hidden-phone">' . "\n";
                            $filter_html .= "\t{$buttons}\n";
                            $filter_html .= '</div>' . "\n";
                        }
                    } elseif (!empty($options)) {
                        $label = $headerField->label;
                        JHtmlSidebar::addFilter('- ' . JText::_($label) . ' -', (string) $headerField->name, JHtml::_('select.options', $options, 'value', 'text', $model->getState($headerField->name, ''), true));
                    }
                } else {
                    // Joomla! 2.5
                    $filter_html .= "\t\t\t\t\t<td>" . PHP_EOL;
                    if (!empty($filter)) {
                        $filter_html .= "\t\t\t\t\t\t{$filter}" . PHP_EOL;
                        if (!empty($buttons)) {
                            $filter_html .= '<div class="btn-group hidden-phone">' . PHP_EOL;
                            $filter_html .= "\t\t\t\t\t\t{$buttons}" . PHP_EOL;
                            $filter_html .= '</div>' . PHP_EOL;
                        }
                    } elseif (!empty($options)) {
                        $label = $headerField->label;
                        $emptyOption = JHtml::_('select.option', '', '- ' . JText::_($label) . ' -');
                        array_unshift($options, $emptyOption);
                        $attribs = array('onchange' => 'document.adminForm.submit();');
                        $filter = JHtml::_('select.genericlist', $options, $headerField->name, $attribs, 'value', 'text', $headerField->value, false, true);
                        $filter_html .= "\t\t\t\t\t\t{$filter}" . PHP_EOL;
                    }
                    $filter_html .= "\t\t\t\t\t</td>" . PHP_EOL;
                }
            }
        }
        // Start the form
        $filter_order = $form->getView()->getLists()->order;
        $filter_order_Dir = $form->getView()->getLists()->order_Dir;
        $html .= '<form action="index.php" method="post" name="adminForm" id="adminForm" ' . $form_class . '>' . PHP_EOL;
        if (version_compare(JVERSION, '3.0', 'ge')) {
            // Joomla! 3.0+
            // Get and output the sidebar, if present
            $sidebar = JHtmlSidebar::render();
            if ($show_filters && !empty($sidebar)) {
                $html .= '<div id="j-sidebar-container" class="span2">' . "\n";
                $html .= "\t{$sidebar}\n";
                $html .= "</div>\n";
                $html .= '<div id="j-main-container" class="span10">' . "\n";
            } else {
                $html .= '<div id="j-main-container">' . "\n";
            }
            // Render header search fields, if the header is enabled
            if ($show_header) {
                $html .= "\t" . '<div id="filter-bar" class="btn-toolbar">' . "\n";
                $html .= "{$filter_html}\n";
                if ($show_pagination) {
                    // Render the pagination rows per page selection box, if the pagination is enabled
                    $html .= "\t" . '<div class="btn-group pull-right hidden-phone">' . "\n";
                    $html .= "\t\t" . '<label for="limit" class="element-invisible">' . JText::_('JFIELD_PLG_SEARCH_SEARCHLIMIT_DESC') . '</label>' . "\n";
                    $html .= "\t\t" . $model->getPagination()->getLimitBox() . "\n";
                    $html .= "\t" . '</div>' . "\n";
                }
                if (!empty($sortFields)) {
                    // Display the field sort order
                    $asc_sel = $view->getLists()->order_Dir == 'asc' ? 'selected="selected"' : '';
                    $desc_sel = $view->getLists()->order_Dir == 'desc' ? 'selected="selected"' : '';
                    $html .= "\t" . '<div class="btn-group pull-right hidden-phone">' . "\n";
                    $html .= "\t\t" . '<label for="directionTable" class="element-invisible">' . JText::_('JFIELD_ORDERING_DESC') . '</label>' . "\n";
                    $html .= "\t\t" . '<select name="directionTable" id="directionTable" class="input-medium" onchange="Joomla.orderTable()">' . "\n";
                    $html .= "\t\t\t" . '<option value="">' . JText::_('JFIELD_ORDERING_DESC') . '</option>' . "\n";
                    $html .= "\t\t\t" . '<option value="asc" ' . $asc_sel . '>' . JText::_('JGLOBAL_ORDER_ASCENDING') . '</option>' . "\n";
                    $html .= "\t\t\t" . '<option value="desc" ' . $desc_sel . '>' . JText::_('JGLOBAL_ORDER_DESCENDING') . '</option>' . "\n";
                    $html .= "\t\t" . '</select>' . "\n";
                    $html .= "\t" . '</div>' . "\n\n";
                    // Display the sort fields
                    $html .= "\t" . '<div class="btn-group pull-right">' . "\n";
                    $html .= "\t\t" . '<label for="sortTable" class="element-invisible">' . JText::_('JGLOBAL_SORT_BY') . '</label>' . "\n";
                    $html .= "\t\t" . '<select name="sortTable" id="sortTable" class="input-medium" onchange="Joomla.orderTable()">' . "\n";
                    $html .= "\t\t\t" . '<option value="">' . JText::_('JGLOBAL_SORT_BY') . '</option>' . "\n";
                    $html .= "\t\t\t" . JHtml::_('select.options', $sortFields, 'value', 'text', $view->getLists()->order) . "\n";
                    $html .= "\t\t" . '</select>' . "\n";
                    $html .= "\t" . '</div>' . "\n";
                }
                $html .= "\t</div>\n\n";
                $html .= "\t" . '<div class="clearfix"> </div>' . "\n\n";
            }
        }
        // Start the table output
        $html .= "\t\t" . '<table class="table table-striped" id="itemsList">' . PHP_EOL;
        // Open the table header region if required
        if ($show_header || $show_filters && version_compare(JVERSION, '3.0', 'lt')) {
            $html .= "\t\t\t<thead>" . PHP_EOL;
        }
        // Render the header row, if enabled
        if ($show_header) {
            $html .= "\t\t\t\t<tr>" . PHP_EOL;
            $html .= $header_html;
            $html .= "\t\t\t\t</tr>" . PHP_EOL;
        }
        // Render filter row if enabled
        if ($show_filters && version_compare(JVERSION, '3.0', 'lt')) {
            $html .= "\t\t\t\t<tr>";
            $html .= $filter_html;
            $html .= "\t\t\t\t</tr>";
        }
        // Close the table header region if required
        if ($show_header || $show_filters && version_compare(JVERSION, '3.0', 'lt')) {
            $html .= "\t\t\t</thead>" . PHP_EOL;
        }
        // Loop through rows and fields, or show placeholder for no rows
        $html .= "\t\t\t<tbody>" . PHP_EOL;
        $fields = $form->getFieldset('items');
        $num_columns = count($fields);
        $items = $model->getItemList();
        if ($count = count($items)) {
            $m = 1;
            foreach ($items as $i => $item) {
                $table_item = $model->getTable();
                $table_item->reset();
                $table_item->bind($item);
                $form->bind($item);
                $m = 1 - $m;
                $class = 'row' . $m;
                $html .= "\t\t\t\t<tr class=\"{$class}\">" . PHP_EOL;
                $fields = $form->getFieldset('items');
                // Reorder the fields to have ordering first
                if (version_compare(JVERSION, '3.0', 'gt')) {
                    $tmpFields = array();
                    $j = 1;
                    foreach ($fields as $tmpField) {
                        if ($tmpField instanceof F0FFormFieldOrdering) {
                            $tmpFields[0] = $tmpField;
                        } else {
                            $tmpFields[$j] = $tmpField;
                        }
                        $j++;
                    }
                    $fields = $tmpFields;
                    ksort($fields, SORT_NUMERIC);
                }
                foreach ($fields as $field) {
                    $field->rowid = $i;
                    $field->item = $table_item;
                    $labelClass = $field->labelClass ? $field->labelClass : $field->labelclass;
                    // Joomla! 2.5/3.x use different case for the same name
                    $class = $labelClass ? 'class ="' . $labelClass . '"' : '';
                    $html .= "\t\t\t\t\t<td {$class}>" . $field->getRepeatable() . '</td>' . PHP_EOL;
                }
                $html .= "\t\t\t\t</tr>" . PHP_EOL;
            }
        } elseif ($norows_placeholder) {
            $html .= "\t\t\t\t<tr><td colspan=\"{$num_columns}\">";
            $html .= JText::_($norows_placeholder);
            $html .= "</td></tr>\n";
        }
        $html .= "\t\t\t</tbody>" . PHP_EOL;
        // Render the pagination bar, if enabled, on J! 2.5
        if ($show_pagination && version_compare(JVERSION, '3.0', 'lt')) {
            $pagination = $model->getPagination();
            $html .= "\t\t\t<tfoot>" . PHP_EOL;
            $html .= "\t\t\t\t<tr><td colspan=\"{$num_columns}\">";
            if ($pagination->total > 0) {
                $html .= $pagination->getListFooter();
            }
            $html .= "</td></tr>\n";
            $html .= "\t\t\t</tfoot>" . PHP_EOL;
        }
        // End the table output
        $html .= "\t\t" . '</table>' . PHP_EOL;
        // Render the pagination bar, if enabled, on J! 3.0+
        if ($show_pagination && version_compare(JVERSION, '3.0', 'ge')) {
            $html .= $model->getPagination()->getListFooter();
        }
        // Close the wrapper element div on Joomla! 3.0+
        if (version_compare(JVERSION, '3.0', 'ge')) {
            $html .= "</div>\n";
        }
        $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
        $html .= "\t" . '<input type="hidden" name="view" value="' . F0FInflector::pluralize($input->getCmd('view')) . '" />' . PHP_EOL;
        $html .= "\t" . '<input type="hidden" name="task" value="' . $input->getCmd('task', 'browse') . '" />' . PHP_EOL;
        // The id field is required in Joomla! 3 front-end to prevent the pagination limit box from screwing it up. Huh!!
        if (version_compare(JVERSION, '3.0', 'ge') && F0FPlatform::getInstance()->isFrontend()) {
            $html .= "\t" . '<input type="hidden" name="id" value="' . $input->getCmd('id', '') . '" />' . PHP_EOL;
        }
        $html .= "\t" . '<input type="hidden" name="boxchecked" value="" />' . PHP_EOL;
        $html .= "\t" . '<input type="hidden" name="hidemainmenu" value="" />' . PHP_EOL;
        $html .= "\t" . '<input type="hidden" name="filter_order" value="' . $filter_order . '" />' . PHP_EOL;
        $html .= "\t" . '<input type="hidden" name="filter_order_Dir" value="' . $filter_order_Dir . '" />' . PHP_EOL;
        if (F0FPlatform::getInstance()->isFrontend() && $input->getCmd('Itemid', 0) != 0) {
            $html .= "\t" . '<input type="hidden" name="Itemid" value="' . $input->getCmd('Itemid', 0) . '" />' . PHP_EOL;
        }
        $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
        // End the form
        $html .= '</form>' . PHP_EOL;
        return $html;
    }
Ejemplo n.º 2
0
 /**
  * Creates a F0FHalDocument using the provided data
  *
  * @param   array     $data   The data to put in the document
  * @param   F0FModel  $model  The model of this view
  *
  * @return  F0FHalDocument  A HAL-enabled document
  */
 protected function _createDocumentWithHypermedia($data, $model = null)
 {
     // Create a new HAL document
     if (is_array($data)) {
         $count = count($data);
     } else {
         $count = null;
     }
     if ($count == 1) {
         reset($data);
         $document = new F0FHalDocument(end($data));
     } else {
         $document = new F0FHalDocument($data);
     }
     // Create a self link
     $uri = (string) JUri::getInstance();
     $uri = $this->_removeURIBase($uri);
     $uri = JRoute::_($uri);
     $document->addLink('self', new F0FHalLink($uri));
     // Create relative links in a record list context
     if (is_array($data) && $model instanceof F0FModel) {
         $pagination = $model->getPagination();
         if ($pagination->get('pages.total') > 1) {
             // Try to guess URL parameters and create a prototype URL
             // NOTE: You are better off specialising this method
             $protoUri = $this->_getPrototypeURIForPagination();
             // The "first" link
             $uri = clone $protoUri;
             $uri->setVar('limitstart', 0);
             $uri = JRoute::_((string) $uri);
             $document->addLink('first', new F0FHalLink($uri));
             // Do we need a "prev" link?
             if ($pagination->get('pages.current') > 1) {
                 $prevPage = $pagination->get('pages.current') - 1;
                 $limitstart = ($prevPage - 1) * $pagination->limit;
                 $uri = clone $protoUri;
                 $uri->setVar('limitstart', $limitstart);
                 $uri = JRoute::_((string) $uri);
                 $document->addLink('prev', new F0FHalLink($uri));
             }
             // Do we need a "next" link?
             if ($pagination->get('pages.current') < $pagination->get('pages.total')) {
                 $nextPage = $pagination->get('pages.current') + 1;
                 $limitstart = ($nextPage - 1) * $pagination->limit;
                 $uri = clone $protoUri;
                 $uri->setVar('limitstart', $limitstart);
                 $uri = JRoute::_((string) $uri);
                 $document->addLink('next', new F0FHalLink($uri));
             }
             // The "last" link?
             $lastPage = $pagination->get('pages.total');
             $limitstart = ($lastPage - 1) * $pagination->limit;
             $uri = clone $protoUri;
             $uri->setVar('limitstart', $limitstart);
             $uri = JRoute::_((string) $uri);
             $document->addLink('last', new F0FHalLink($uri));
         }
     }
     return $document;
 }