<?php

class Model_DbTable_Unions extends Zend_Db_Table
{
    protected $_name = 'ef_unions';
    
  /*  Filter New */
	
	 public function insertData($data)
    {
       
       try{
           $id = $this->insert($data);
           return $id;
       }catch(Exception $expression){
          echo "<pre>";
		  print_r($expression);
		  exit;
       }
       
    }
    
    public function updateData($data,$id)
    {
       
       try{
           $this->update($data,"un_id ='".$id."'");
           return $id;
       }catch(Exception $expression){
          echo "<pre>";
		  print_r($expression);
		  exit;
       }
       
    }
	
	public function listUnionsByUserLogin($User){
		$select = $this->select();
            $select->from(array('O' => $this->_name),array("un_id"=>"un_id","un_name"=>"un_name","un_type"=>"un_type","parentid")); 
            if($User->UnionType > 2){
            	$select->where("un_id ='".$User->UnionID."' OR parentid = '".$User->UnionID."'");
                
                
            }
						$select->order("un_name ASC");
            $select->setIntegrityCheck(false);
						
            return $this->fetchAll($select);
            
						
		}
		public function listUnionsByUserLoginDrop($User){
		$select = $this->select();
            $select->from(array('O' => $this->_name),array("un_id"=>"un_id","un_name"=>"un_name","un_type"=>"un_type","parentid")); 
            $select->joinLeft(array('T'=>'ef_institutions_type'),'O.un_type = T.type_id',array("Type"=>"Text")) ;
            if($User->UnionType > 2){
            	$select->where("un_id ='".$User->UnionID."' OR parentid = '".$User->UnionID."'");
                
                
            }
						$select->order(array("un_name ASC","type_id ASC"));
            $select->setIntegrityCheck(false);
						
            return $this->fetchAll($select);
            
						
		}
		
		public function getName($id)
    {
      
		$select = $this->select();
        $select->from(array('O'=> $this->_name),array("un_name"=>"un_name"))->where("un_id ='".$id."'"); 
        $select->setIntegrityCheck(false);
        return $this->fetchRow($select);
    }
}