<?php

Doo::loadCore('db/DooModel');

class position extends DooModel {

    public $pid;
    
    public $positionName;
    public $positionDescribe;
    public $baseWage;
    public $postWage;
    public $achievementBonus;
    
    public $_table = 'CLD_position';
    public $_primarykey = 'pid';
    
    public $_fields = array('pid', 'positionName', 'positionDescribe', 'baseWage', 'postWage', 'achievementBonus');

    /**
     * 获得所有岗位
     */
    function getPositionByAll(){
    	Doo::loadClass ( 'XDeode' );
    	$XDeode = new XDeode ( 5 );
    	Doo::loadModel ( 'staff' );
    	$staff = new staff ();
    	
    	$list=$this->find ( array (
    			'asArray' => TRUE
    	) );
    	
    	foreach ($list as $key=>$value){
    		$list [$key] ['pidKey'] = $XDeode->encode ( $value ['pid'] );
    		$list [$key] ['staffCount']=$staff->count(array ('where' => 'positionId = "' . $value ['pid'] . '"'));
    		
    	}
    	
    	return $list;
    }
    
    /**
     * 根据ID获取相关信息
     * @param number $sid 用户ID
     */
    public function getPositionByPid($pid = 0) {
    	Doo::loadClass ( 'XDeode' );
    	$XDeode = new XDeode ( 5 );
    	if (!is_numeric($pid)){
    		$pid = $XDeode->decode ( $pid );
    	}
    	
    	$detail = array ();
    	if (! empty ( $pid )){
    		
    		Doo::loadModel ( 'staff' );
    		$staff = new staff ();
    		
    		$detail = $this->getOne ( array (
    				'where' => "pid= '" . $pid . "'",
    				'asArray' => TRUE
    		) );
    		if (!empty($detail)){
    			$detail ['pidKey'] = $XDeode->encode ( $detail ['pid'] );
    			$detail ['staffCount']=$staff->count(array ('where' => 'positionId = "' . $detail ['pid'] . '"'));
    		}
    			
    	}
    	
    	return $detail;
    }
    
    //public function getPositionByPid
    
}

?>