/** * Remove a Voucher Group * * @param VoucherGroup $oVoucherGroup The Voucher Group Entity * @throws VoucherException if the database query fails or entity has id assigned. * @returns boolean true if the insert operation was successful */ public function execute(VoucherGroup $oVoucherGroup) { $oGateway = $this->oGateway; $oVoucherBuilder = $oGateway->getEntityBuilder(); $bSuccess = false; if (true === empty($oVoucherGroup->getVoucherGroupId())) { throw new VoucherException('Unable to remove a voucher group the Entity does not have a database id'); } try { // Note: the FK will stop voucher groups from being removed if they are used. $bSuccess = $oGateway->deleteQuery()->start()->filterByGroup($oVoucherGroup->getVoucherGroupId())->end()->delete(); if (!$bSuccess) { throw new VoucherException('Unable to remove voucher at id::' . $oVoucherGroup->getVoucherGroupID()); } } catch (DBALGatewayException $e) { throw new VoucherException($e->getMessage(), 0, $e); } return $bSuccess; }
public function testVoucherGroupProperties() { $aGroup = new VoucherGroup(); $sName = 'Sales Vouchers'; $iID = 1; $bDisabled = false; $iSort = 100; $oCreated = new DateTime(); $sSlugName = 'sales_vouchers'; $aGroup->setVoucherGroupID($iID); $this->assertEquals($iID, $aGroup->getVoucherGroupID()); $aGroup->setDisabledStatus($bDisabled); $this->assertEquals($bDisabled, $aGroup->getDisabledStatus()); $aGroup->setVoucherGroupName($sName); $this->assertEquals($sName, $aGroup->getVoucherGroupName()); $aGroup->setSortOrder($iSort); $this->assertEquals($iSort, $aGroup->getSortOrder()); $aGroup->setDateCreated($oCreated); $this->assertEquals($oCreated, $aGroup->getDateCreated()); $aGroup->setSlugName($sSlugName); $this->assertEquals($sSlugName, $aGroup->getSlugName()); }