<?php

$wrapperLayout      =  (!empty($this->options['wrapperLayout']) ) ? $this->options['wrapperLayout']:'';
$wrapperLayoutClass = (!empty($this->options['wrapperLayoutClass']) ) ? ' class="'.$this->options['wrapperLayoutClass'].'" ':'';
 

$wrapperBlock      = (!empty($this->options['wrapperBlock']) ) ? $this->options['wrapperBlock']:'';
$wrapperBlockClass = (!empty($this->options['wrapperBlockClass']) ) ? ' class="'.$this->options['wrapperBlockClass'].'" ':'';


$wrapperItem       = (!empty($this->options['wrapperItem']) ) ? $this->options['wrapperItem']:'';
$wrapperItemClass = (!empty($this->options['wrapperItemClass']) ) ? $this->options['wrapperItemClass']:'';

$currentRef = ( !empty( $this->options['ref'] ) ) ? $this->options['ref'] : null ;

if( !empty($wrapperLayout))
    echo '<'.$wrapperLayout.$wrapperLayoutClass.'>'.PHP_EOL;

if( !empty($wrapperBlock))
    echo '<'.$wrapperBlock.$wrapperBlockClass.'>'.PHP_EOL;
    $cpt = 0;
    foreach( $this->rows as $row){
        $url = $this->url(array('ref' => $row->ref, 'type'=> $row->type ) , 'jobs-view' , true );
            if( !empty($wrapperItem)){


                 $cls = $wrapperItemClass;
                 if( empty($currentRef) && $cpt == 0 ){
                     $cls .=' active';
                 }
                 else{
                     if( !empty($currentRef) &&  $this->options['ref'] == $row->ref ){
                         $cls .=' active';
                     }
                 }
                 echo '<'.$wrapperItem.' class="'.$cls.'">'.PHP_EOL;
            }
            if( $this->options['showTitle'])
                echo '<div class="job-title"><a href="'.$url.'">'.$row->title.'</a></div>'.PHP_EOL;
            $annonce = $this->options['short'] ? $this->truncate($row->annonce , $this->options['shortCount'] ) : $row->annonce ;
            echo '<div class="job-annonce">'.$annonce.'</div>'.PHP_EOL;
            
            if( $this->options['showMore'] || $this->options['showApply'])
                    echo '<div class="footer">';
            
            if( $this->options['showMore']){
                
               echo '<a class="more"  href="'.$url.'">'.$this->translate('#see more#').'</a>';
            }
            
            if( $this->options['showApply']){
                $applyurl = $this->url(array('ref' => $row->ref , 'action' => 'apply') , 'jobs', true  );
               echo '<a class="apply"  href="'.$applyurl.'">'.$this->translate('#apply##').'</a>';
            }
            if( $this->options['showMore'] || $this->options['showApply'])
                    echo '</div>';
       
            if( !empty($wrapperItem))
                echo '</'.$wrapperItem.'>'.PHP_EOL;
            $cpt++;
    }

if( !empty($wrapperBlock))
    echo '</'.$wrapperBlock.'>';

if( !empty($wrapperLayout))
    echo '</'.$wrapperLayout.'>';
