/** * Save Leave Period History * * @param LeavePeriodHistory $leavePeriodHistory * @return \LeavePeriodHistory * @throws DaoException */ public function saveLeavePeriodHistory(LeavePeriodHistory $leavePeriodHistory) { try { $leavePeriodHistory->save(); return $leavePeriodHistory; // @codeCoverageIgnoreStart } catch (Exception $e) { throw new DaoException($e->getMessage(), $e->getCode(), $e); } // @codeCoverageIgnoreEnd }
public function testSaveLeavePeriodHistory() { $leavePeriodHistory = new LeavePeriodHistory(); $leavePeriodHistory->setLeavePeriodStartMonth(1); $leavePeriodHistory->setLeavePeriodStartDay(1); $leavePeriodHistory->setCreatedAt('2012-01-01'); $result = $this->leavePeriodDao->saveLeavePeriodHistory($leavePeriodHistory); $this->assertEquals(1, $result->getLeavePeriodStartMonth()); $this->assertEquals(1, $result->getLeavePeriodStartDay()); $this->assertEquals('2012-01-01', $result->getCreatedAt()); }
public function testGetCurrentLeavePeriodByDate() { $leavePeriodHistory = new LeavePeriodHistory(); $leavePeriodHistory->setLeavePeriodStartMonth(1); $leavePeriodHistory->setLeavePeriodStartDay(1); $leavePeriodHistory->setCreatedAt('2010-01-02'); $this->leavePeriodService->saveLeavePeriodHistory($leavePeriodHistory); $result = $this->leavePeriodService->getCurrentLeavePeriodByDate('2012-01-01', true); $this->assertEquals(array('2012-01-01', '2012-12-31'), $result); $result = $this->leavePeriodService->getCurrentLeavePeriodByDate('2013-01-04', true); $this->assertEquals(array('2013-01-01', '2013-12-31'), $result); }
public function execute($request) { $this->leavePeriodPermissions = $this->getDataGroupPermissions('leave_period'); if (!Auth::instance()->hasRole(Auth::ADMIN_ROLE) && !$this->leavePeriodPermissions->canRead()) { $this->forward('leave', 'showLeavePeriodNotDefinedWarning'); } $values = array('leavePeriodPermissions' => $this->leavePeriodPermissions); $this->setForm(new LeavePeriodForm(array(), $values, true)); $this->isLeavePeriodDefined = OrangeConfig::getInstance()->getAppConfValue(ConfigService::KEY_LEAVE_PERIOD_DEFINED); $this->latestSatrtDate = $this->getLeavePeriodService()->getCurrentLeavePeriodStartDateAndMonth(); if ($this->isLeavePeriodDefined) { $this->currentLeavePeriod = $this->getLeavePeriodService()->getCurrentLeavePeriodByDate(date('Y-m-d')); $endDate = date('F d', strtotime($this->currentLeavePeriod[1])); $startMonthValue = $this->latestSatrtDate->getLeavePeriodStartMonth(); $startDateValue = $this->latestSatrtDate->getLeavePeriodStartDay(); } else { $endDate = '-'; $startMonthValue = 0; $startDateValue = 0; } $this->endDate = $endDate; $this->startMonthValue = $startMonthValue; $this->startDateValue = $startDateValue; if ($this->getUser()->hasFlash('templateMessage')) { list($this->messageType, $this->message) = $this->getUser()->getFlash('templateMessage'); } // this section is for saving leave period if ($request->isMethod('post')) { if ($this->leavePeriodPermissions->canUpdate()) { $leavePeriodService = $this->getLeavePeriodService(); $this->form->bind($request->getParameter($this->form->getName())); if ($this->form->isValid()) { $leavePeriodHistory = new LeavePeriodHistory(); $leavePeriodHistory->setLeavePeriodStartMonth($this->form->getValue('cmbStartMonth')); $leavePeriodHistory->setLeavePeriodStartDay($this->form->getValue('cmbStartDate')); $leavePeriodHistory->setCreatedAt(date('Y-m-d')); $this->getLeavePeriodService()->saveLeavePeriodHistory($leavePeriodHistory); // Enable leave module menu items the first time leave period is defined if (!$this->isLeavePeriodDefined) { $this->getMenuService()->enableModuleMenuItems('leave'); } $this->getUser()->getAttributeHolder()->remove(mainMenuComponent::MAIN_MENU_USER_ATTRIBUTE); $this->getUser()->setFlash('success', __(TopLevelMessages::SAVE_SUCCESS)); $this->redirect('leave/defineLeavePeriod'); } } } }