/**
  * if configured, Prints the "order by" icons in each table heading cell
  * @param Table $tableHelper
  * @param $columnName
  * @return string|void
  */
 public static function printOrderOption(Table $tableHelper, $columnName)
 {
     $downUrl = $tableHelper->getView()->UrlWithQuery(array('sort' => $columnName, 'order' => 'desc'));
     $upUrl = $tableHelper->getView()->UrlWithQuery(array('sort' => $columnName, 'order' => 'asc'));
     $iconClass = 'glyphicon glyphicon-chevron';
     $html = '<span class="pull-right">
                 <a href="' . $downUrl . '" class="tabelHeadOpties"><i class="' . $iconClass . '-down"></i></a>
                 <a href="' . $upUrl . '" class="tabelHeadOpties"><i class="' . $iconClass . '-up"></i></a>
              </span>';
     return $html;
 }
 /**
  * If configured, prints the table pagination to navigate to a next set of data
  * @param Table $tableHelper
  * @return string
  */
 public static function printPagination(Table $tableHelper)
 {
     $maxPages = $tableHelper->getTableModel()->getMaxPageNumber();
     $currentPage = $tableHelper->getTableModel()->getPageNumber();
     $html = '<nav class="text-center"><ul class="pagination">';
     $html .= sprintf('<li class="%s"><a href="%s" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>', $currentPage <= 1 ? 'disabled' : '', $tableHelper->getView()->UrlWithQuery(array('page' => $currentPage - 1)));
     for ($i = 1; $i <= $maxPages; $i++) {
         $html .= $i == $currentPage ? '<li class="active">' : '<li>';
         $html .= sprintf('<a href="%s">%d</a></li>', $tableHelper->getView()->UrlWithQuery(array('page' => $i)), $i);
     }
     $html .= sprintf('<li class="%s"><a href="%s" aria-label="Next"><span aria-hidden="true">&raquo;</span></a></li>', $currentPage >= $maxPages ? 'disabled' : '', $tableHelper->getView()->UrlWithQuery(array('page' => $currentPage + 1)));
     $html .= '</ul></nav>';
     return $html;
 }
 /**
  * If the TableModel contains FilterData this method will fill the element with these values
  *
  * @param ElementInterface $element
  * @param $fieldName
  * @param Table $tableHelper
  * @return Element
  */
 public static function setElementValues(ElementInterface $element, $fieldName, Table $tableHelper)
 {
     $values = $tableHelper->getTableModel()->getPrefetchedValuesByName($fieldName);
     if ($values && method_exists($element, 'setValueOptions')) {
         $valueOptions = array();
         foreach ($values as $value) {
             if ($value instanceof \DateTime) {
                 $valueOptions[$value->format('Y-m-d')] = $value->format('Y-m-d');
                 continue;
             }
             $valueOptions[$value] = $value;
         }
         $element->setValueOptions($valueOptions);
     }
     if (method_exists($element, 'setEmptyOption')) {
         $emptyLabel = $tableHelper->getView()->Translate('Select') . ' ' . $tableHelper->getView()->Translate($fieldName);
         $element->setEmptyOption($emptyLabel);
     }
     return $element;
 }
 /**
  * Tries to add a glyph icon to an action link
  *
  * @param $action
  * @param $url
  * @param $id
  * @param Table $tableHelper
  * @return string
  */
 public static function getActionLink($action, $url, $id, Table $tableHelper)
 {
     $knownActions = array('edit' => 'pencil', 'delete' => 'trash', 'view' => 'search');
     $title = $tableHelper->translator->translate($action);
     if (in_array('noStyling', $tableHelper->getDisplaySettings()) || !array_key_exists($action, $knownActions)) {
         return sprintf('<a class="options btn btn-mini %s" href="%s" title="%s" data-id="%s">%s</a>', $action, $tableHelper->getView()->url($url, array('action' => $action, 'id' => $id)), $title, $id, $action);
     }
     return sprintf('<a href="%s" title="%s" data-id="%s"><i class="glyphicon glyphicon-%s icoonNaarLinks %s"></i></a>', $tableHelper->getView()->url($url, array('action' => $action, 'id' => $id)), $title, $id, $knownActions[$action], $action);
 }