<?php

class Model_DbTable_Positions extends Zend_Db_Table
{
    
    protected $_name = "positions";
    
    public function getPos($code)
    {
    	if($code==7){
    		$select = $this->select();
        $select->from(array('U'=>"position_sevens"));
        $select->setIntegrityCheck(false);
				$select->where("PID < 8")->order("Sort ASC");
        return $this->fetchAll($select);
    	}else{
    		$select = $this->select();
        $select->from(array('U'=>$this->_name));
				$select->where("PID < 16")->order("PID ASC");
        $select->setIntegrityCheck(false);
        return $this->fetchAll($select);
    	}
         
    }
	
    public function getPosFull($code)
    {
    	if($code==7){
    		$select = $this->select();
        $select->from(array('U'=>"position_sevens"));
        $select->setIntegrityCheck(false)->order("Sort ASC");
        return $this->fetchAll($select);
    	}else{
    		$select = $this->select();
        $select->from(array('U'=>$this->_name))->order("PID ASC");
        $select->setIntegrityCheck(false);
        return $this->fetchAll($select);
    	}
         
    }
    public function getPosByPOS($code,$pos)
    {
    	if($code==7){
    		$select = $this->select();
        $select->from(array('U'=>"position_sevens"));
        $select->setIntegrityCheck(false);
				$select->where("PID ='".$pos."'");
        return $this->fetchAll($select);
    	}else{
    		$select = $this->select();
        $select->from(array('U'=>$this->_name));
		$select->where("PID ='".$pos."'");
        $select->setIntegrityCheck(false);
        return $this->fetchRow($select);
    	}
         
    }
		
		public function getCollectivePosition()
    {    	
		$auth = Zend_Auth::getInstance();
        $identity = $auth->getIdentity();
        $select = $this->select();
        $select->from(array('U'=>$this->_name));
				
        $select->setIntegrityCheck(false);
				
        return $this->fetchAll($select);
				
    }
		
	public function getAll()
    {
        $select = $this->select();
        $select->from(array('U'=>$this->_name));
				$select->where("PID < 16")->order("PID ASC");
        $select->setIntegrityCheck(false);
        return $this->fetchAll($select); 
    }
	
	public function getMost()
    {
        $select = $this->select();
        $select->from(array('U'=>$this->_name))->order("Position ASC");
		$select->where("PID < 24");
        $select->setIntegrityCheck(false);
        return $this->fetchAll($select); 
    }
		
	public function getRow($pos)
    {
        $select = $this->select();
        $select->from(array('U'=>$this->_name));
        $select->setIntegrityCheck(false);
				$select->where("PID ='".$pos."'");
        return $this->fetchRow($select); 
    }
    
		
		public function getRowCode($pos,$code)
    {
        $select = $this->select();
        if($code==7){
        $select->from(array('U'=>"position_sevens"));
        $select->setIntegrityCheck(false);
				$select->where("PID ='".$pos."'");
				}else{
					 $select->from(array('U'=>$this->_name));
        $select->setIntegrityCheck(false);
				$select->where("PID ='".$pos."'");
				}
        return $this->fetchRow($select); 
    }
}