<?php

class Agro_View_Helper_ListHeader extends Zend_Controller_Action_Helper_Abstract
{
    public static function listHeader(array $colunas, $order, $orderType = 'asc')
    {
        $view = Zend_Layout::getMvcInstance()->getView();
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $order = !empty($order) ? $order : $request->getParam('o');

        ob_start();
        ?>
      <thead>
        <tr>
          <?php
          if (is_array($colunas)) {
              foreach ($colunas as $coluna) {
                  ?>
                <th style="<?= $coluna['style'] ?>"
                    <?php
                    if ($coluna['colspan'] > 0) echo "colspan=" . $coluna['colspan'];
                    if ($coluna['align']) echo "align=" . $coluna['align']; ?>
                >
                    <?php

                    if ($coluna['id']) {
                        if (($coluna['id'] == $order) && ($request->getParam('s') == 'asc')) {
                            $orderType = 'desc';
                        }
                        ?>
                      <a
                        href="/<?= $view->moduleName ?>/<?= $view->controllerName ?>/list/o/<?= $coluna['id'] ?>/s/<?= $orderType ?>">
                          <?php
                          echo $coluna['descricao'];

                          if ($coluna['id'] == $order) {
                              ?>
                            <img src="/resources/imagens/<?= $request->getParam('s') ?>.gif" border="0"/>
                              <?php
                          }
                          ?>
                      </a>
                        <?php
                    } else {
                        echo $coluna['descricao'];
                    }
                    ?>
                </th>
                  <?php
              }
          }
          ?>
        </tr>
      </thead>
        <?php

        $html = ob_get_contents();
        ob_end_clean();

        return $html;
    }
}