<?php

/**
 * PluginLeaveEntitlement
 * 
 * This class has been auto-generated by the Doctrine ORM Framework
 * 
 * @package    ##PACKAGE##
 * @subpackage ##SUBPACKAGE##
 * @author     ##NAME## <##EMAIL##>
 * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
 */
abstract class PluginLeaveEntitlement extends BaseLeaveEntitlement
{
    const ENTITLEMENT_TYPE_ADD = 1;
    
    public function getAvailableDays() {
        $available = $this->getNoOfDays();        
        $daysUsed = $this->getDaysUsed();
        
        if (!empty($daysUsed)) {
            $available -= $daysUsed;
        }
        
        // Get other leaves
//        $allowedStatuses = array(
//                    Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL,
//                    Leave::LEAVE_STATUS_LEAVE_APPROVED);
//        
//        // TODO: Improve performance
//        $leaves = $this->getLeave();
//        foreach ($leaves as $leave) {
//            $status = $leave->getStatus();
//            if (in_array($status, $allowedStatuses)) {
//                $available -= $leave->getLengthDays();
//            }
//        }
        
        return $available;
    }
    
    public function withinPeriod($date) {
        $fromTimestamp = strtotime($this->getFromDate());
        $toTimestamp = strtotime($this->getToDate());
        $timestamp = strtotime($date);
        
        if (($timestamp >= $fromTimestamp) && ($timestamp <= $toTimestamp)) {
            return true;
        } else {
            return false;
        }
    }
}