<?php 
require_once 'class.systemrecording.php';
require_once 'class.queue.php';
//This class holds one representaion of a Users callForward, includes all defined callforwards and the active one
class QueueCallForward {
	
	private $mActive = "none";
	private $mDefinedCallforwards = array();
	private $mSimpleCallForward = null;
	private $mQueue = null;
	
	public function __construct(Queue $q){
		$this->mQueue = $q;
	}
	
	public function setActive($active) {
		$this->mActive = $active;		
	}
	
	public function getAcitve() {
		return $this->mActive;
	}

	public function getDefinedSimpleCallforward() {
		
		if($this->mSimpleCallForward == null) {
			$this->mSimpleCallForward = new CallForward($this);
			$this->mSimpleCallForward->setType("simple");
			$target = CallForwardingFactory::getCallNewCallForwardTargetByName("number", $this->mSimpleCallForward);
			$this->mSimpleCallForward->setCallForwardTarget($target);
		}
		return $this->mSimpleCallForward;
	}
	
	public function setDefinedSimpleCallForward(CallForward $forward) {
		$this->mSimpleCallForward = $forward;
		if($this->mSimpleCallForward != NULL) {
			$this->mSimpleCallForward->setParent($this);
		}
	}
	
	public function getDefinedAdvancedCallforwards() {
		return $this->mDefinedCallforwards;
	}
	
	public function setDefinedAdvancedCallForwards(Array $forwards) {

		foreach($forwards as $forward) {
			$forward->setParent($this);
			$this->mDefinedCallforwards[] = $forward;	
		}
		
		if (count($this->mDefinedCallforwards) == 0) {
			//add sample advanced callforward 
			$tmp = new CallForward($this);
			$tmp->setId(0);
			$tmp->setPosition(0);
			$tmp->setType("advanced");
			$target = CallForwardingFactory::getCallNewCallForwardTargetByName("number", $tmp);
			$target->setProperty("number", "");
			$tmp->setCallForwardTarget($target);
			
			$criteria = CallForwardingFactory::getCallNewCallForwardCriteriaByName("QueueStatus", $this);
			$criteria->setProperty("queuestatus","noagents");
			$tmp->addCriteria($criteria);
						
			$this->mDefinedCallforwards[] = $tmp;			
		}
		
	
	}
	
	public function getAvialableSystemRecordings() {
		return $this->mQueue->getAvialableSystemRecordings();
	}
	
	public function getAvialableAddressBooks() {
		return $this->mQueue->getAvialableAddressBooks();
	}		
	
	public function getDialedExtension() {
		return $this->mQueue->getExtension();
	}
	
}


