<?php

class Zend_View_Helper_GetItensPai extends Zend_View_Helper_Abstract {
  

  /**
   *
   * @param integer $language_id
   * @return Array
   */
private $model;
  public function getItensPai($obra_id,$item_pai = -1){
    
    // index all languages
    
    $this->model = new Model_Obras_Itens();
      
     $txt = '';
      
       $itens = $this->model->getByObra( $obra_id);
    foreach ($itens as $key => $item) {
        $selected = "";
        if ( $item->id == $item_pai) {          
          $selected = " selected='selected' ";
        }
        $txt .="<option value='".$item->id."' ".$selected.">".$this->_getTexto($item)."</option>";
      }
    
    return $txt;
  }
  private function _getTexto($item){
    
     $txt = "--";
     if(!empty($item)){

          if(!empty($item->titulo)) {
             $txt =  $item->titulo  ;
            }else{
              $txt = Pampa_Util_String::crop(strip_tags($item->texto),50,"…");
            }
            
     if ($item->item_pai!= -1 ) {
        $pai = $this->model->find($item->item_pai)->current() ;

        if (strlen($txt)>0 && strpos("-", $txt)>=0) {
          $texto = explode("-", $txt);
          $txt = $texto[0];
        }
        $txt = $this->_getTexto( $pai)." > ". $txt;
     }
   }
      
      return $txt;
      

      
  }

}