コード例 #1
0
 /**
  * Save leave request 
  * 
  * @param LeaveRequest $leaveRequest Leave request object
  * @param Array $leaveList Array of leave objects linked to the leave request
  * @param Array $entitlements Array of entitlements to be modified 
  * @return boolean
  */
 public function saveLeaveRequest(LeaveRequest $leaveRequest, $leaveList, $entitlements)
 {
     $conn = Doctrine_Manager::connection();
     $conn->beginTransaction();
     try {
         $leaveRequest->save();
         $current = array();
         if (isset($entitlements['current'])) {
             $current = $entitlements['current'];
         }
         foreach ($leaveList as $leave) {
             $leave->setLeaveRequestId($leaveRequest->getId());
             $leave->setLeaveTypeId($leaveRequest->getLeaveTypeId());
             $leave->setEmpNumber($leaveRequest->getEmpNumber());
             $leave->save();
             $leaveId = $leave->getId();
             if (isset($current[$leave->getDate()])) {
                 $entitlementsForDate = $current[$leave->getDate()];
                 foreach ($entitlementsForDate as $entitlementId => $length) {
                     $le = new LeaveLeaveEntitlement();
                     $le->setLeaveId($leaveId);
                     $le->setEntitlementId($entitlementId);
                     $le->setLengthDays($length);
                     $le->save();
                     Doctrine_Query::create()->update('LeaveEntitlement e')->set('e.days_used', 'e.days_used + ?', $length)->where('e.id = ?', $entitlementId)->execute();
                 }
             }
         }
         if (isset($entitlements['change'])) {
             // TODO: Need to update days_used here
             // Also need to check if we need to delete all entitlements or only have changes
             $changes = $entitlements['change'];
             foreach ($changes as $leaveId => $change) {
                 Doctrine_Query::create()->delete('LeaveLeaveEntitlement l')->where('l.leave_id = ?', $leaveId)->execute();
                 foreach ($change as $entitlementId => $length) {
                     $le = new LeaveLeaveEntitlement();
                     $le->setLeaveId($leaveId);
                     $le->setEntitlementId($entitlementId);
                     $le->setLengthDays($length);
                     $le->save();
                 }
             }
         }
         $conn->commit();
         return $leaveRequest;
     } catch (Exception $e) {
         $conn->rollback();
         throw new DaoException($e->getMessage());
     }
 }
コード例 #2
0
 protected function compareLeaveRequest(LeaveRequest $expected, LeaveRequest $result)
 {
     $this->assertTrue($result instanceof LeaveRequest);
     $expectedId = $expected->getId();
     if (!empty($expectedId)) {
         $this->assertEquals($expectedId, $result->getId());
     } else {
         $leaveRequestId = $result->getId();
         $this->assertTrue(!empty($leaveRequestId));
     }
     $this->assertEquals($expected->getLeaveTypeId(), $result->getLeaveTypeId());
     $this->assertEquals($expected->getDateApplied(), $result->getDateApplied());
     $this->assertEquals($expected->getEmpNumber(), $result->getEmpNumber());
     $this->assertEquals($expected->getComments(), $result->getComments());
 }