Source for file strapper.php

Documentation is available at strapper.php

  1. <?php
  2. /**
  3.  * @package     FrameworkOnFramework
  4.  * @subpackage  render
  5.  * @copyright   Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8. defined('_JEXEC'or die;
  9.  
  10. /**
  11.  * Akeeba Strapper view renderer class.
  12.  *
  13.  * @package  FrameworkOnFramework
  14.  * @since    2.0
  15.  */
  16. {
  17.     /**
  18.      * Public constructor. Determines the priority of this class and if it should be enabled
  19.      */
  20.     public function __construct()
  21.     {
  22.         $this->priority     = 60;
  23.         $this->enabled     = class_exists('AkeebaStrapper');
  24.     }
  25.  
  26.     /**
  27.      * Echoes any HTML to show before the view template
  28.      *
  29.      * @param   string    $view    The current view
  30.      * @param   string    $task    The current task
  31.      * @param   FOFInput  $input   The input array (request parameters)
  32.      * @param   array     $config  The view configuration array
  33.      *
  34.      * @return  void 
  35.      */
  36.     public function preRender($view$task$input$config array())
  37.     {
  38.         $format     $input->getCmd('format''html');
  39.  
  40.         if (empty($format))
  41.         {
  42.             $format     'html';
  43.         }
  44.  
  45.         if ($format != 'html')
  46.         {
  47.             return;
  48.         }
  49.  
  50.         if (!FOFPlatform::getInstance()->isCli())
  51.         {
  52.             // Wrap output in a Joomla-versioned div
  53.             $version new JVersion;
  54.             $version str_replace('.'''$version->RELEASE);
  55.             echo "<div class=\"joomla-version-$version\">\n";
  56.  
  57.             // Wrap output in an akeeba-bootstrap class div
  58.             echo "<div class=\"akeeba-bootstrap\">\n";
  59.         }
  60.  
  61.         // Render submenu and toolbar (only if asked to)
  62.         if ($input->getBool('render_toolbar'true))
  63.         {
  64.             $this->renderButtons($view$task$input$config);
  65.             $this->renderLinkbar($view$task$input$config);
  66.         }
  67.     }
  68.  
  69.     /**
  70.      * Echoes any HTML to show after the view template
  71.      *
  72.      * @param   string    $view    The current view
  73.      * @param   string    $task    The current task
  74.      * @param   FOFInput  $input   The input array (request parameters)
  75.      * @param   array     $config  The view configuration array
  76.      *
  77.      * @return  void 
  78.      */
  79.     public function postRender($view$task$input$config array())
  80.     {
  81.         $format $input->getCmd('format''html');
  82.  
  83.         if ($format != 'html' || FOFPlatform::getInstance()->isCli())
  84.         {
  85.             return;
  86.         }
  87.  
  88.         if (!FOFPlatform::getInstance()->isCli(&& FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  89.         {
  90.             $sidebarEntries JHtmlSidebar::getEntries();
  91.  
  92.             if (!empty($sidebarEntries))
  93.             {
  94.                 echo '</div>';
  95.             }
  96.         }
  97.  
  98.         echo "</div>\n";
  99.         echo "</div>\n";
  100.     }
  101.  
  102.     /**
  103.      * Loads the validation script for an edit form
  104.      *
  105.      * @param   FOFForm  &$form  The form we are rendering
  106.      *
  107.      * @return  void 
  108.      */
  109.     protected function loadValidationScript(FOFForm &$form)
  110.     {
  111.         $message $form->getView()->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));
  112.  
  113.         $js = <<<ENDJAVASCRIPT
  114.         Joomla.submitbutton = function(task)
  115.         {
  116.             if (task == 'cancel' || document.formvalidator.isValid(document.id('adminForm')))
  117.             {
  118.                 Joomla.submitform(task, document.getElementById('adminForm'));
  119.             }
  120.             else {
  121.                 alert('$message');
  122.             }
  123.         }
  124. ENDJAVASCRIPT;
  125.  
  126.         $document FOFPlatform::getInstance()->getDocument();
  127.  
  128.         if ($document instanceof JDocument)
  129.         {
  130.             $document->addScriptDeclaration($js);
  131.         }
  132.     }
  133.  
  134.     /**
  135.      * Renders the submenu (link bar)
  136.      *
  137.      * @param   string    $view    The active view name
  138.      * @param   string    $task    The current task
  139.      * @param   FOFInput  $input   The input object
  140.      * @param   array     $config  Extra configuration variables for the toolbar
  141.      *
  142.      * @return  void 
  143.      */
  144.     protected function renderLinkbar($view$task$input$config array())
  145.     {
  146.         $style 'classic';
  147.  
  148.         if (array_key_exists('linkbar_style'$config))
  149.         {
  150.             $style $config['linkbar_style'];
  151.         }
  152.  
  153.         if (!FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  154.         {
  155.             $style 'classic';
  156.         }
  157.  
  158.         switch ($style)
  159.         {
  160.             case 'joomla':
  161.                 $this->renderLinkbar_joomla($view$task$input);
  162.                 break;
  163.  
  164.             case 'classic':
  165.             default:
  166.                 $this->renderLinkbar_classic($view$task$input);
  167.                 break;
  168.         }
  169.     }
  170.  
  171.     /**
  172.      * Renders the submenu (link bar) in FOF's classic style, using a Bootstrapped
  173.      * tab bar.
  174.      *
  175.      * @param   string    $view    The active view name
  176.      * @param   string    $task    The current task
  177.      * @param   FOFInput  $input   The input object
  178.      * @param   array     $config  Extra configuration variables for the toolbar
  179.      *
  180.      * @return  void 
  181.      */
  182.     protected function renderLinkbar_classic($view$task$input$config array())
  183.     {
  184.         if (FOFPlatform::getInstance()->isCli())
  185.         {
  186.             return;
  187.         }
  188.  
  189.         // Do not render a submenu unless we are in the the admin area
  190.         $toolbar                 FOFToolbar::getAnInstance($input->getCmd('option''com_foobar')$config);
  191.         $renderFrontendSubmenu     $toolbar->getRenderFrontendSubmenu();
  192.  
  193.         if (!FOFPlatform::getInstance()->isBackend(&& !$renderFrontendSubmenu)
  194.         {
  195.             return;
  196.         }
  197.  
  198.         $links $toolbar->getLinks();
  199.  
  200.         if (!empty($links))
  201.         {
  202.             echo "<ul class=\"nav nav-tabs\">\n";
  203.  
  204.             foreach ($links as $link)
  205.             {
  206.                 $dropdown false;
  207.  
  208.                 if (array_key_exists('dropdown'$link))
  209.                 {
  210.                     $dropdown $link['dropdown'];
  211.                 }
  212.  
  213.                 if ($dropdown)
  214.                 {
  215.                     echo "<li";
  216.                     $class 'dropdown';
  217.  
  218.                     if ($link['active'])
  219.                     {
  220.                         $class .= ' active';
  221.                     }
  222.  
  223.                     echo ' class="' $class '">';
  224.  
  225.                     echo '<a class="dropdown-toggle" data-toggle="dropdown" href="#">';
  226.  
  227.                     if ($link['icon'])
  228.                     {
  229.                         echo "<i class=\"icon icon-" $link['icon'"\"></i>";
  230.                     }
  231.  
  232.                     echo $link['name'];
  233.                     echo '<b class="caret"></b>';
  234.                     echo '</a>';
  235.  
  236.                     echo "\n<ul class=\"dropdown-menu\">";
  237.  
  238.                     foreach ($link['items'as $item)
  239.                     {
  240.                         echo "<li";
  241.  
  242.                         if ($item['active'])
  243.                         {
  244.                             echo ' class="active"';
  245.                         }
  246.  
  247.                         echo ">";
  248.  
  249.                         if ($item['icon'])
  250.                         {
  251.                             echo "<i class=\"icon icon-" $item['icon'"\"></i>";
  252.                         }
  253.  
  254.                         if ($item['link'])
  255.                         {
  256.                             echo "<a tabindex=\"-1\" href=\"" $item['link'"\">" $item['name'"</a>";
  257.                         }
  258.                         else
  259.                         {
  260.                             echo $item['name'];
  261.                         }
  262.  
  263.                         echo "</li>";
  264.                     }
  265.  
  266.                     echo "</ul>\n";
  267.                 }
  268.                 else
  269.                 {
  270.                     echo "<li";
  271.  
  272.                     if ($link['active'])
  273.                     {
  274.                         echo ' class="active"';
  275.                     }
  276.  
  277.                     echo ">";
  278.  
  279.                     if ($link['icon'])
  280.                     {
  281.                         echo "<i class=\"icon icon-" $link['icon'"\"></i>";
  282.                     }
  283.  
  284.                     if ($link['link'])
  285.                     {
  286.                         echo "<a href=\"" $link['link'"\">" $link['name'"</a>";
  287.                     }
  288.                     else
  289.                     {
  290.                         echo $link['name'];
  291.                     }
  292.                 }
  293.  
  294.                 echo "</li>\n";
  295.             }
  296.  
  297.             echo "</ul>\n";
  298.         }
  299.     }
  300.  
  301.     /**
  302.      * Renders the submenu (link bar) using Joomla!'s style. On Joomla! 2.5 this
  303.      * is a list of bar separated links, on Joomla! 3 it's a sidebar at the
  304.      * left-hand side of the page.
  305.      *
  306.      * @param   string    $view    The active view name
  307.      * @param   string    $task    The current task
  308.      * @param   FOFInput  $input   The input object
  309.      * @param   array     $config  Extra configuration variables for the toolbar
  310.      *
  311.      * @return  void 
  312.      */
  313.     protected function renderLinkbar_joomla($view$task$input$config array())
  314.     {
  315.         // On command line don't do anything
  316.         if (FOFPlatform::getInstance()->isCli())
  317.         {
  318.             return;
  319.         }
  320.  
  321.         // Do not render a submenu unless we are in the the admin area
  322.         $toolbar                 FOFToolbar::getAnInstance($input->getCmd('option''com_foobar')$config);
  323.         $renderFrontendSubmenu     $toolbar->getRenderFrontendSubmenu();
  324.  
  325.         if (!FOFPlatform::getInstance()->isBackend(&& !$renderFrontendSubmenu)
  326.         {
  327.             return;
  328.         }
  329.  
  330.         $this->renderLinkbarItems($toolbar);
  331.     }
  332.  
  333.     /**
  334.      * do the rendering job for the linkbar
  335.      *
  336.      * @param   FOFToolbar  $toolbar  A toolbar object
  337.      *
  338.      * @return  void 
  339.      */
  340.     protected function renderLinkbarItems($toolbar)
  341.     {
  342.         $links $toolbar->getLinks();
  343.  
  344.         if (!empty($links))
  345.         {
  346.             foreach ($links as $link)
  347.             {
  348.                 JHtmlSidebar::addEntry($link['name']$link['link']$link['active']);
  349.  
  350.                 $dropdown false;
  351.  
  352.                 if (array_key_exists('dropdown'$link))
  353.                 {
  354.                     $dropdown $link['dropdown'];
  355.                 }
  356.  
  357.                 if ($dropdown)
  358.                 {
  359.                     foreach ($link['items'as $item)
  360.                     {
  361.                         JHtmlSidebar::addEntry('– ' $item['name']$item['link']$item['active']);
  362.                     }
  363.                 }
  364.             }
  365.         }
  366.     }
  367.  
  368.     /**
  369.      * Renders the toolbar buttons
  370.      *
  371.      * @param   string    $view    The active view name
  372.      * @param   string    $task    The current task
  373.      * @param   FOFInput  $input   The input object
  374.      * @param   array     $config  Extra configuration variables for the toolbar
  375.      *
  376.      * @return  void 
  377.      */
  378.     protected function renderButtons($view$task$input$config array())
  379.     {
  380.         if (FOFPlatform::getInstance()->isCli())
  381.         {
  382.             return;
  383.         }
  384.  
  385.         // Do not render buttons unless we are in the the frontend area and we are asked to do so
  386.         $toolbar                 FOFToolbar::getAnInstance($input->getCmd('option''com_foobar')$config);
  387.         $renderFrontendButtons     $toolbar->getRenderFrontendButtons();
  388.  
  389.         if (FOFPlatform::getInstance()->isBackend(|| !$renderFrontendButtons)
  390.         {
  391.             return;
  392.         }
  393.  
  394.         $bar     JToolBar::getInstance('toolbar');
  395.         $items     $bar->getItems();
  396.  
  397.         $substitutions array(
  398.             'icon-32-new'         => 'icon-plus',
  399.             'icon-32-publish'     => 'icon-eye-open',
  400.             'icon-32-unpublish'     => 'icon-eye-close',
  401.             'icon-32-delete'     => 'icon-trash',
  402.             'icon-32-edit'         => 'icon-edit',
  403.             'icon-32-copy'         => 'icon-th-large',
  404.             'icon-32-cancel'     => 'icon-remove',
  405.             'icon-32-back'         => 'icon-circle-arrow-left',
  406.             'icon-32-apply'         => 'icon-ok',
  407.             'icon-32-save'         => 'icon-hdd',
  408.             'icon-32-save-new'     => 'icon-repeat',
  409.         );
  410.  
  411.         $html     array();
  412.         $html[]     '<div class="well" id="' $bar->getName('">';
  413.  
  414.         foreach ($items as $node)
  415.         {
  416.             $type     $node[0];
  417.             $button     $bar->loadButtonType($type);
  418.  
  419.             if ($button !== false)
  420.             {
  421.                 if (method_exists($button'fetchId'))
  422.                 {
  423.                     $id call_user_func_array(array(&$button'fetchId')$node);
  424.                 }
  425.                 else
  426.                 {
  427.                     $id null;
  428.                 }
  429.  
  430.                 $action     call_user_func_array(array(&$button'fetchButton')$node);
  431.                 $action     str_replace('class="toolbar"''class="toolbar btn"'$action);
  432.                 $action     str_replace('<span ''<i '$action);
  433.                 $action     str_replace('</span>''</i>'$action);
  434.                 $action     str_replace(array_keys($substitutions)array_values($substitutions)$action);
  435.                 $html[]     $action;
  436.             }
  437.         }
  438.  
  439.         $html['</div>';
  440.  
  441.         echo implode("\n"$html);
  442.     }
  443.  
  444.     /**
  445.      * Renders a FOFForm for a Browse view and returns the corresponding HTML
  446.      *
  447.      * @param   FOFForm   &$form  The form to render
  448.      * @param   FOFModel  $model  The model providing our data
  449.      * @param   FOFInput  $input  The input object
  450.      *
  451.      * @return  string    The HTML rendering of the form
  452.      */
  453.     protected function renderFormBrowse(FOFForm &$formFOFModel $modelFOFInput $input)
  454.     {
  455.         $html '';
  456.  
  457.         JHtml::_('behavior.multiselect');
  458.  
  459.         // Joomla! 3.0+ support
  460.         if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  461.         {
  462.             JHtml::_('bootstrap.tooltip');
  463.             JHtml::_('dropdown.init');
  464.             JHtml::_('formbehavior.chosen''select');
  465.             $view     $form->getView();
  466.             $order     $view->escape($view->getLists()->order);
  467.             $html .= <<<ENDJS
  468. <script type="text/javascript">
  469.     Joomla.orderTable = function() {
  470.         table = document.getElementById("sortTable");
  471.         direction = document.getElementById("directionTable");
  472.         order = table.options[table.selectedIndex].value;
  473.         if (order != '$order')
  474.         {
  475.             dirn = 'asc';
  476.         }
  477.         else {
  478.             dirn = direction.options[direction.selectedIndex].value;
  479.         }
  480.         Joomla.tableOrdering(order, dirn);
  481.     }
  482. </script>
  483.  
  484. ENDJS;
  485.         }
  486.  
  487.         // Getting all header row elements
  488.         $headerFields $form->getHeaderset();
  489.  
  490.         // Get form parameters
  491.         $show_header         $form->getAttribute('show_header'1);
  492.         $show_filters         $form->getAttribute('show_filters'1);
  493.         $show_pagination     $form->getAttribute('show_pagination'1);
  494.         $norows_placeholder     $form->getAttribute('norows_placeholder''');
  495.  
  496.         // Joomla! 3.0 sidebar support
  497.  
  498.         if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''gt'))
  499.         {
  500.             if ($show_filters)
  501.             {
  502.                 JHtmlSidebar::setAction("index.php?option=" .
  503.                     $input->getCmd('option'"&view=" .
  504.                     FOFInflector::pluralize($input->getCmd('view'))
  505.                 );
  506.             }
  507.  
  508.             // Reorder the fields with ordering first
  509.             $tmpFields array();
  510.             $i 1;
  511.  
  512.             foreach ($headerFields as $tmpField)
  513.             {
  514.                 if ($tmpField instanceof FOFFormHeaderOrdering)
  515.                 {
  516.                     $tmpFields[0$tmpField;
  517.                 }
  518.  
  519.                 else
  520.                 {
  521.                     $tmpFields[$i$tmpField;
  522.                 }
  523.  
  524.                 $i++;
  525.             }
  526.  
  527.             $headerFields $tmpFields;
  528.             ksort($headerFieldsSORT_NUMERIC);
  529.         }
  530.  
  531.         // Pre-render the header and filter rows
  532.         $header_html '';
  533.         $filter_html '';
  534.         $sortFields     array();
  535.  
  536.         if ($show_header || $show_filters)
  537.         {
  538.             foreach ($headerFields as $headerField)
  539.             {
  540.                 $header         $headerField->header;
  541.                 $filter         $headerField->filter;
  542.                 $buttons     $headerField->buttons;
  543.                 $options     $headerField->options;
  544.                 $sortable     $headerField->sortable;
  545.                 $tdwidth     $headerField->tdwidth;
  546.  
  547.                 // Under Joomla! < 3.0 we can't have filter-only fields
  548.  
  549.                 if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''lt'&& empty($header))
  550.                 {
  551.                     continue;
  552.                 }
  553.  
  554.                 // If it's a sortable field, add to the list of sortable fields
  555.  
  556.                 if ($sortable)
  557.                 {
  558.                     $sortFields[$headerField->nameJText::_($headerField->label);
  559.                 }
  560.  
  561.                 // Get the table data width, if set
  562.  
  563.                 if (!empty($tdwidth))
  564.                 {
  565.                     $tdwidth 'width="' $tdwidth '"';
  566.                 }
  567.                 else
  568.                 {
  569.                     $tdwidth '';
  570.                 }
  571.  
  572.                 if (!empty($header))
  573.                 {
  574.                     $header_html .= "\t\t\t\t\t<th $tdwidth>PHP_EOL;
  575.                     $header_html .= "\t\t\t\t\t\t" $header;
  576.                     $header_html .= "\t\t\t\t\t</th>" PHP_EOL;
  577.                 }
  578.  
  579.                 if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  580.                 {
  581.                     // Joomla! 3.0 or later
  582.                     if (!empty($filter))
  583.                     {
  584.                         $filter_html .= '<div class="filter-search btn-group pull-left">' "\n";
  585.                         $filter_html .= "\t" '<label for="title" class="element-invisible">';
  586.                         $filter_html .= JText::_($headerField->label);
  587.                         $filter_html .= "</label>\n";
  588.                         $filter_html .= "\t$filter\n";
  589.                         $filter_html .= "</div>\n";
  590.  
  591.                         if (!empty($buttons))
  592.                         {
  593.                             $filter_html .= '<div class="btn-group pull-left hidden-phone">' "\n";
  594.                             $filter_html .= "\t$buttons\n";
  595.                             $filter_html .= '</div>' "\n";
  596.                         }
  597.                     }
  598.                     elseif (!empty($options))
  599.                     {
  600.                         $label $headerField->label;
  601.  
  602.                         JHtmlSidebar::addFilter(
  603.                             '- ' JText::_($label' -'(string) $headerField->name,
  604.                             JHtml::_(
  605.                                 'select.options',
  606.                                 $options,
  607.                                 'value',
  608.                                 'text',
  609.                                 $model->getState($headerField->name'')true
  610.                             )
  611.                         );
  612.                     }
  613.                 }
  614.                 else
  615.                 {
  616.                     // Joomla! 2.5
  617.                     $filter_html .= "\t\t\t\t\t<td>" PHP_EOL;
  618.  
  619.                     if (!empty($filter))
  620.                     {
  621.                         $filter_html .= "\t\t\t\t\t\t$filterPHP_EOL;
  622.  
  623.                         if (!empty($buttons))
  624.                         {
  625.                             $filter_html .= '<div class="btn-group pull-left hidden-phone">' PHP_EOL;
  626.                             $filter_html .= "\t\t\t\t\t\t$buttonsPHP_EOL;
  627.                             $filter_html .= '</div>' PHP_EOL;
  628.                         }
  629.                     }
  630.                     elseif (!empty($options))
  631.                     {
  632.                         $label         $headerField->label;
  633.                         $emptyOption JHtml::_('select.option''''- ' JText::_($label' -');
  634.                         array_unshift($options$emptyOption);
  635.                         $attribs     array(
  636.                             'onchange' => 'document.adminForm.submit();'
  637.                         );
  638.                         $filter         JHtml::_('select.genericlist'$options$headerField->name$attribs'value''text'$headerField->valuefalsetrue);
  639.                         $filter_html .= "\t\t\t\t\t\t$filterPHP_EOL;
  640.                     }
  641.  
  642.                     $filter_html .= "\t\t\t\t\t</td>" PHP_EOL;
  643.                 }
  644.             }
  645.         }
  646.  
  647.         // Start the form
  648.         $filter_order         $form->getView()->getLists()->order;
  649.         $filter_order_Dir     $form->getView()->getLists()->order_Dir;
  650.  
  651.         $html .= '<form action="index.php" method="post" name="adminForm" id="adminForm">' PHP_EOL;
  652.  
  653.         if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  654.         {
  655.             // Joomla! 3.0+
  656.             // Get and output the sidebar, if present
  657.             $sidebar JHtmlSidebar::render();
  658.  
  659.             if ($show_filters && !empty($sidebar))
  660.             {
  661.                 $html .= '<div id="j-sidebar-container" class="span2">' "\n";
  662.                 $html .= "\t$sidebar\n";
  663.                 $html .= "</div>\n";
  664.                 $html .= '<div id="j-main-container" class="span10">' "\n";
  665.             }
  666.             else
  667.             {
  668.                 $html .= '<div id="j-main-container">' "\n";
  669.             }
  670.  
  671.             // Render header search fields, if the header is enabled
  672.  
  673.             if ($show_header)
  674.             {
  675.                 $html .= "\t" '<div id="filter-bar" class="btn-toolbar">' "\n";
  676.                 $html .= "$filter_html\n";
  677.  
  678.                 if ($show_pagination)
  679.                 {
  680.                     // Render the pagination rows per page selection box, if the pagination is enabled
  681.                     $html .= "\t" '<div class="btn-group pull-right hidden-phone">' "\n";
  682.                     $html .= "\t\t" '<label for="limit" class="element-invisible">' JText::_('JFIELD_PLG_SEARCH_SEARCHLIMIT_DESC''</label>' "\n";
  683.                     $html .= "\t\t" $model->getPagination()->getLimitBox("\n";
  684.                     $html .= "\t" '</div>' "\n";
  685.                 }
  686.  
  687.                 if (!empty($sortFields))
  688.                 {
  689.                     // Display the field sort order
  690.                     $asc_sel     ($view->getLists()->order_Dir == 'asc''selected="selected"' '';
  691.                     $desc_sel     ($view->getLists()->order_Dir == 'desc''selected="selected"' '';
  692.                     $html .= "\t" '<div class="btn-group pull-right hidden-phone">' "\n";
  693.                     $html .= "\t\t" '<label for="directionTable" class="element-invisible">' JText::_('JFIELD_ORDERING_DESC''</label>' "\n";
  694.                     $html .= "\t\t" '<select name="directionTable" id="directionTable" class="input-medium" onchange="Joomla.orderTable()">' "\n";
  695.                     $html .= "\t\t\t" '<option value="">' JText::_('JFIELD_ORDERING_DESC''</option>' "\n";
  696.                     $html .= "\t\t\t" '<option value="asc" ' $asc_sel '>' JText::_('JGLOBAL_ORDER_ASCENDING''</option>' "\n";
  697.                     $html .= "\t\t\t" '<option value="desc" ' $desc_sel '>' JText::_('JGLOBAL_ORDER_DESCENDING''</option>' "\n";
  698.                     $html .= "\t\t" '</select>' "\n";
  699.                     $html .= "\t" '</div>' "\n\n";
  700.  
  701.                     // Display the sort fields
  702.                     $html .= "\t" '<div class="btn-group pull-right">' "\n";
  703.                     $html .= "\t\t" '<label for="sortTable" class="element-invisible">' JText::_('JGLOBAL_SORT_BY''</label>' "\n";
  704.                     $html .= "\t\t" '<select name="sortTable" id="sortTable" class="input-medium" onchange="Joomla.orderTable()">' "\n";
  705.                     $html .= "\t\t\t" '<option value="">' JText::_('JGLOBAL_SORT_BY''</option>' "\n";
  706.                     $html .= "\t\t\t" JHtml::_('select.options'$sortFields'value''text'$view->getLists()->order"\n";
  707.                     $html .= "\t\t" '</select>' "\n";
  708.                     $html .= "\t" '</div>' "\n";
  709.                 }
  710.  
  711.                 $html .= "\t</div>\n\n";
  712.                 $html .= "\t" '<div class="clearfix"> </div>' "\n\n";
  713.             }
  714.         }
  715.  
  716.         // Start the table output
  717.         $html .= "\t\t" '<table class="table table-striped" id="itemsList">' PHP_EOL;
  718.  
  719.         // Open the table header region if required
  720.  
  721.         if ($show_header || ($show_filters && FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''lt')))
  722.         {
  723.             $html .= "\t\t\t<thead>" PHP_EOL;
  724.         }
  725.  
  726.         // Render the header row, if enabled
  727.  
  728.         if ($show_header)
  729.         {
  730.             $html .= "\t\t\t\t<tr>" PHP_EOL;
  731.             $html .= $header_html;
  732.             $html .= "\t\t\t\t</tr>" PHP_EOL;
  733.         }
  734.  
  735.         // Render filter row if enabled
  736.  
  737.         if ($show_filters && FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''lt'))
  738.         {
  739.             $html .= "\t\t\t\t<tr>";
  740.             $html .= $filter_html;
  741.             $html .= "\t\t\t\t</tr>";
  742.         }
  743.  
  744.         // Close the table header region if required
  745.  
  746.         if ($show_header || ($show_filters && FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''lt')))
  747.         {
  748.             $html .= "\t\t\t</thead>" PHP_EOL;
  749.         }
  750.  
  751.         // Loop through rows and fields, or show placeholder for no rows
  752.         $html .= "\t\t\t<tbody>" PHP_EOL;
  753.         $fields         $form->getFieldset('items');
  754.         $num_columns count($fields);
  755.         $items         $model->getItemList();
  756.  
  757.         if ($count count($items))
  758.         {
  759.             $m 1;
  760.  
  761.             foreach ($items as $i => $item)
  762.             {
  763.                 $table_item $model->getTable();
  764.                 $table_item->reset();
  765.                 $table_item->bind($item);
  766.  
  767.                 $form->bind($item);
  768.  
  769.                 $m         $m;
  770.                 $class     'row' $m;
  771.  
  772.                 $html .= "\t\t\t\t<tr class=\"$class\">PHP_EOL;
  773.  
  774.                 $fields $form->getFieldset('items');
  775.  
  776.                 // Reorder the fields to have ordering first
  777.                 if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''gt'))
  778.                 {
  779.                     $tmpFields array();
  780.                     $j 1;
  781.  
  782.                     foreach ($fields as $tmpField)
  783.                     {
  784.                         if ($tmpField instanceof FOFFormFieldOrdering)
  785.                         {
  786.                             $tmpFields[0$tmpField;
  787.                         }
  788.  
  789.                         else
  790.                         {
  791.                             $tmpFields[$j$tmpField;
  792.                         }
  793.  
  794.                         $j++;
  795.                     }
  796.  
  797.                     $fields $tmpFields;
  798.                     ksort($fieldsSORT_NUMERIC);
  799.                 }
  800.  
  801.                 foreach ($fields as $field)
  802.                 {
  803.                     $field->rowid     $i;
  804.                     $field->item     $table_item;
  805.                     $class             $field->labelClass 'class ="' $field->labelClass '"' '';
  806.                     $html .= "\t\t\t\t\t<td $class>$field->getRepeatable('</td>' PHP_EOL;
  807.                 }
  808.  
  809.                 $html .= "\t\t\t\t</tr>" PHP_EOL;
  810.             }
  811.         }
  812.         elseif ($norows_placeholder)
  813.         {
  814.             $html .= "\t\t\t\t<tr><td colspan=\"$num_columns\">";
  815.             $html .= JText::_($norows_placeholder);
  816.             $html .= "</td></tr>\n";
  817.         }
  818.  
  819.         $html .= "\t\t\t</tbody>" PHP_EOL;
  820.  
  821.         // Render the pagination bar, if enabled, on J! 2.5
  822.         if ($show_pagination && FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''lt'))
  823.         {
  824.             $pagination $model->getPagination();
  825.             $html .= "\t\t\t<tfoot>" PHP_EOL;
  826.             $html .= "\t\t\t\t<tr><td colspan=\"$num_columns\">";
  827.  
  828.             if (($pagination->total 0))
  829.             {
  830.                 $html .= $pagination->getListFooter();
  831.             }
  832.  
  833.             $html .= "</td></tr>\n";
  834.             $html .= "\t\t\t</tfoot>" PHP_EOL;
  835.         }
  836.  
  837.         // End the table output
  838.         $html .= "\t\t" '</table>' PHP_EOL;
  839.  
  840.         // Render the pagination bar, if enabled, on J! 3.0+
  841.  
  842.         if ($show_pagination && FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  843.         {
  844.             $html .= $model->getPagination()->getListFooter();
  845.         }
  846.  
  847.         // Close the wrapper element div on Joomla! 3.0+
  848.  
  849.         if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  850.         {
  851.             $html .= "</div>\n";
  852.         }
  853.  
  854.         $html .= "\t" '<input type="hidden" name="option" value="' $input->getCmd('option''" />' PHP_EOL;
  855.         $html .= "\t" '<input type="hidden" name="view" value="' FOFInflector::pluralize($input->getCmd('view')) '" />' PHP_EOL;
  856.         $html .= "\t" '<input type="hidden" name="task" value="' $input->getCmd('task''browse''" />' PHP_EOL;
  857.  
  858.         // The id field is required in Joomla! 3 front-end to prevent the pagination limit box from screwing it up. Huh!!
  859.  
  860.         if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'&& FOFPlatform::getInstance()->isFrontend())
  861.         {
  862.             $html .= "\t" '<input type="hidden" name="id" value="' $input->getCmd('id''''" />' PHP_EOL;
  863.         }
  864.  
  865.         $html .= "\t" '<input type="hidden" name="boxchecked" value="" />' PHP_EOL;
  866.         $html .= "\t" '<input type="hidden" name="hidemainmenu" value="" />' PHP_EOL;
  867.         $html .= "\t" '<input type="hidden" name="filter_order" value="' $filter_order '" />' PHP_EOL;
  868.         $html .= "\t" '<input type="hidden" name="filter_order_Dir" value="' $filter_order_Dir '" />' PHP_EOL;
  869.         $html .= "\t" '<input type="hidden" name="' JFactory::getSession()->getFormToken('" value="1" />' PHP_EOL;
  870.  
  871.         // End the form
  872.         $html .= '</form>' PHP_EOL;
  873.  
  874.         return $html;
  875.     }
  876.  
  877.     /**
  878.      * Renders a FOFForm for a Read view and returns the corresponding HTML
  879.      *
  880.      * @param   FOFForm   &$form  The form to render
  881.      * @param   FOFModel  $model  The model providing our data
  882.      * @param   FOFInput  $input  The input object
  883.      *
  884.      * @return  string    The HTML rendering of the form
  885.      */
  886.     protected function renderFormRead(FOFForm &$formFOFModel $modelFOFInput $input)
  887.     {
  888.         $html $this->renderFormRaw($form$model$input'read');
  889.  
  890.         return $html;
  891.     }
  892.  
  893.     /**
  894.      * Renders a FOFForm for an Edit view and returns the corresponding HTML
  895.      *
  896.      * @param   FOFForm   &$form  The form to render
  897.      * @param   FOFModel  $model  The model providing our data
  898.      * @param   FOFInput  $input  The input object
  899.      *
  900.      * @return  string    The HTML rendering of the form
  901.      */
  902.     protected function renderFormEdit(FOFForm &$formFOFModel $modelFOFInput $input)
  903.     {
  904.         // Get the key for this model's table
  905.         $key         $model->getTable()->getKeyName();
  906.         $keyValue     $model->getId();
  907.  
  908.         $html '';
  909.  
  910.         $validate     strtolower($form->getAttribute('validate'));
  911.  
  912.         if (in_array($validatearray('true''yes''1''on')))
  913.         {
  914.             JHTML::_('behavior.framework'true);
  915.             JHTML::_('behavior.formvalidation');
  916.             $class ' form-validate';
  917.             $this->loadValidationScript($form);
  918.         }
  919.         else
  920.         {
  921.             $class '';
  922.         }
  923.  
  924.         // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form.
  925.         $template_form_enctype $form->getAttribute('enctype');
  926.  
  927.         if (!empty($template_form_enctype))
  928.         {
  929.             $enctype ' enctype="' $form->getAttribute('enctype''" ';
  930.         }
  931.         else
  932.         {
  933.             $enctype '';
  934.         }
  935.  
  936.         // Check form name. Use name="yourformname" to modify the name of your form.
  937.         $formname $form->getAttribute('name');
  938.  
  939.         if (empty($formname))
  940.         {
  941.             $formname 'adminForm';
  942.         }
  943.  
  944.         // Check form ID. Use id="yourformname" to modify the id of your form.
  945.         $formid $form->getAttribute('name');
  946.  
  947.         if (empty($formid))
  948.         {
  949.             $formid 'adminForm';
  950.         }
  951.  
  952.         $html .= '<form action="index.php" method="post" name="' $formname .
  953.             '" id="' $formid '"' $enctype ' class="form-horizontal' .
  954.             $class '">' PHP_EOL;
  955.         $html .= "\t" '<input type="hidden" name="option" value="' $input->getCmd('option''" />' PHP_EOL;
  956.         $html .= "\t" '<input type="hidden" name="view" value="' $input->getCmd('view''edit''" />' PHP_EOL;
  957.         $html .= "\t" '<input type="hidden" name="task" value="" />' PHP_EOL;
  958.         $html .= "\t" '<input type="hidden" name="' $key '" value="' $keyValue '" />' PHP_EOL;
  959.         $html .= "\t" '<input type="hidden" name="' JFactory::getSession()->getFormToken('" value="1" />' PHP_EOL;
  960.  
  961.         $html .= $this->renderFormRaw($form$model$input'edit');
  962.         $html .= '</form>';
  963.  
  964.         return $html;
  965.     }
  966.  
  967.     /**
  968.      * Renders a raw FOFForm and returns the corresponding HTML
  969.      *
  970.      * @param   FOFForm   &$form     The form to render
  971.      * @param   FOFModel  $model     The model providing our data
  972.      * @param   FOFInput  $input     The input object
  973.      * @param   string    $formType  The form type e.g. 'edit' or 'read'
  974.      *
  975.      * @return  string    The HTML rendering of the form
  976.      */
  977.     protected function renderFormRaw(FOFForm &$formFOFModel $modelFOFInput $input$formType)
  978.     {
  979.         $html '';
  980.  
  981.         foreach ($form->getFieldsets(as $fieldset)
  982.         {
  983.             $fields $form->getFieldset($fieldset->name);
  984.  
  985.             if (isset($fieldset->class))
  986.             {
  987.                 $class 'class="' $fieldset->class '"';
  988.             }
  989.             else
  990.             {
  991.                 $class '';
  992.             }
  993.  
  994.             $html .= "\t" '<div id="' $fieldset->name '" ' $class '>' PHP_EOL;
  995.  
  996.             if (isset($fieldset->label&& !empty($fieldset->label))
  997.             {
  998.                 $html .= "\t\t" '<h3>' JText::_($fieldset->label'</h3>' PHP_EOL;
  999.             }
  1000.  
  1001.             foreach ($fields as $field)
  1002.             {
  1003.                 $required     $field->required;
  1004.                 $labelClass     $field->labelClass;
  1005.                 $groupClass     $form->getFieldAttribute($field->fieldname'groupclass'''$field->group);
  1006.  
  1007.                 // Auto-generate label and description if needed
  1008.                 // Field label
  1009.                 $title          $form->getFieldAttribute($field->fieldname'label'''$field->group);
  1010.                 $emptylabel  $form->getFieldAttribute($field->fieldname'emptylabel'false$field->group);
  1011.  
  1012.                 if (empty($title&& !$emptylabel)
  1013.                 {
  1014.                     $model->getName();
  1015.                     $title strtoupper($input->get('option''_' $model->getName('_' $field->id '_LABEL');
  1016.                 }
  1017.  
  1018.                 // Field description
  1019.                 $description $form->getFieldAttribute($field->fieldname'description'''$field->group);
  1020.  
  1021.                 /**
  1022.                  * The following code is backwards incompatible. Most forms don't require a description in their form
  1023.                  * fields. Having to use emptydescription="1" on each one of them is an overkill. Removed.
  1024.                  */
  1025.                 /*
  1026.                 $emptydescription   = $form->getFieldAttribute($field->fieldname, 'emptydescription', false, $field->group);
  1027.                 if (empty($description) && !$emptydescription)
  1028.                 {
  1029.                     $description = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_DESC');
  1030.                 }
  1031.                 */
  1032.  
  1033.                 if ($formType == 'read')
  1034.                 {
  1035.                     $inputField $field->static;
  1036.                 }
  1037.                 elseif ($formType == 'edit')
  1038.                 {
  1039.                     $inputField $field->input;
  1040.                 }
  1041.  
  1042.                 if (empty($title))
  1043.                 {
  1044.                     $html .= "\t\t\t" $inputField PHP_EOL;
  1045.  
  1046.                     if (!empty($description&& $formType == 'edit')
  1047.                     {
  1048.                         $html .= "\t\t\t\t" '<span class="help-block">';
  1049.                         $html .= JText::_($description'</span>' PHP_EOL;
  1050.                     }
  1051.                 }
  1052.                 else
  1053.                 {
  1054.                     $html .= "\t\t\t" '<div class="control-group ' $groupClass '">' PHP_EOL;
  1055.                     $html .= "\t\t\t\t" '<label class="control-label ' $labelClass '" for="' $field->id '">' PHP_EOL;
  1056.                     $html .= "\t\t\t\t" JText::_($titlePHP_EOL;
  1057.  
  1058.                     if ($required)
  1059.                     {
  1060.                         $html .= ' *';
  1061.                     }
  1062.  
  1063.                     $html .= "\t\t\t\t" '</label>' PHP_EOL;
  1064.                     $html .= "\t\t\t\t" '<div class="controls">' PHP_EOL;
  1065.                     $html .= "\t\t\t\t" $inputField PHP_EOL;
  1066.  
  1067.                     if (!empty($description))
  1068.                     {
  1069.                         $html .= "\t\t\t\t" '<span class="help-block">';
  1070.                         $html .= JText::_($description'</span>' PHP_EOL;
  1071.                     }
  1072.  
  1073.                     $html .= "\t\t\t\t" '</div>' PHP_EOL;
  1074.                     $html .= "\t\t\t" '</div>' PHP_EOL;
  1075.                 }
  1076.             }
  1077.  
  1078.             $html .= "\t" '</div>' PHP_EOL;
  1079.         }
  1080.  
  1081.         return $html;
  1082.     }
  1083. }

Documentation generated on Tue, 19 Nov 2013 15:14:25 +0100 by phpDocumentor 1.4.3