<?php
/**
 * YAWIK
 *
 * @filesource
 * @copyright https://yawik.org/COPYRIGHT.php
 * @license   MIT
 */
/**
 * generates the list of applications sent by an applicant
 */

$columns = array(
        /*@translate*/ 'Sent on'
                       => array('sort' => 'date'),
        /*@translate*/ 'Company'
                       => array(),
        /*@translate*/ 'Job'
                       => array('class' => 'cam-job'),
        /*@translate*/ 'Status'
                       => array('sort' => 'status'),
        /*@translate*/ 'Actions'
                       => array(),
);

if ('-' == $this->sort{0}) {
    $sortBy  = substr($this->sort, 1);
    $sortDir = false;
} else {
    $sortBy  = $this->sort;
    $sortDir = true;
}

?>
<table class="table table-striped table-bordered table-hover" id="cam-application-list">
<thead>
<tr>
<?php foreach ($columns as $label => $option):?>
    <th <?php echo isset($option['class'])?'class="'.$option['class'].'"':'';?>>
    <?php if (! isset($option['sort'])): echo $this->translate($label);
          else:
              if ($option['sort'] == $sortBy):
                  $icon = '<span class="pull-right text-right yk-icon yk-icon-sort' . ($sortDir ? '-desc' : '-asc') . '"></span>';
                  $dir = !$sortDir;
              else:
                  $dir = true;
                  $icon = '<span class="pull-right yk-icon yk-icon-sort"></span>';
              endif;
              $sortParam = array('sort' => ($dir ? '' : '-') . $option['sort']);
              $url = $this->url(
                  'lang/applications', array(),
                  array('query' => array_merge($this->params()->fromQuery(), $sortParam)),
                  true
              );
            ?>
            <a href="<?php echo $url?>"><?php echo $this->translate($label).$icon?></a>
    <?php endif; ?>
    </th>
<?php endforeach; ?>
</tr>
</thead>

<tbody>
<?php
foreach ($this->applications as $application): /* @var Applications\Entity\Application $application */?>
  <tr>
    <td>
        <?php echo $this->dateFormat($application->getDateCreated(),'short');?>
    </td>
    <td>
        <?php echo strip_tags($application->getJob()->getCompany()) ?>
    </td>
    <td class="cam-job">
        <a href="<?php echo strip_tags($application->getJob()->getLink()) ?>">
          <?php echo strip_tags($application->getJob()->getTitle()) ?>
        </a>
    </td>
    <td>
     <?php echo $this->translate($application->getStatus()->getName()) ?>
    </td>
    <td>
        <div class="btn-group">
            <a href="<?php echo $this->url('lang/applications/detail', array('id' => $application->getId()), true)?>" class="btn btn-mini btn-default" title="<?php echo $this->translate('view')?>"><span class="yk-icon yk-icon-view"></span></a>
        </div>
    </td>
</tr>
<?php endforeach?>
</tbody>

</table>
<?php echo $this->paginationControl($this->applications, 'Sliding', 'pagination-control', array('lang' => $this->params('lang'), 'route' => 'lang/applications'));?>
