/** * Create 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 (false === empty($oVoucherGroup->getVoucherGroupId())) { throw new VoucherException('Unable to create new voucher group the Entity has a database id assigned already'); } try { $oQuery = $oGateway->insertQuery()->start(); foreach ($oVoucherBuilder->demolish($oVoucherGroup) as $sColumn => $mValue) { if ($sColumn !== 'voucher_group_id' && $sColumn !== 'date_created') { $oQuery->addColumn($sColumn, $mValue); } elseif ($sColumn === 'date_created') { $oQuery->addColumn('date_created', $this->oNow); } } $bSuccess = $oQuery->end()->insert(); if ($bSuccess) { $oVoucherGroup->setVoucherGroupId($oGateway->lastInsertId()); } } catch (DBALGatewayException $e) { throw new VoucherException($e->getMessage(), 0, $e); } return $bSuccess; }
public function testVoucherGroupRemove() { $oContainer = $this->getContainer(); $aOperations = $oContainer->getVoucherGroupOperations(); $oRemoveOperation = $aOperations['delete']; # assert correct operation was returned $this->assertInstanceOf('\\IComeFromTheNet\\Ledger\\Voucher\\Operations\\GroupRemove', $oRemoveOperation); $oGroup = new VoucherGroup(); $iID = 1; $oGroup->setVoucherGroupId($iID); $oRemoveOperation->execute($oGroup); }
/** * 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; }
/** * Create 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(); if (true === empty($oVoucherGroup->getVoucherGroupId())) { throw new VoucherException('Unable to save voucher group the Entity has no database id assigned'); } try { $oQuery = $oGateway->updateQuery()->start(); foreach ($oVoucherBuilder->demolish($oVoucherGroup) as $sColumn => $mValue) { if ($sColumn !== 'voucher_group_id' && $sColumn !== 'date_created') { $oQuery->addColumn($sColumn, $mValue); } } $bSuccess = $oQuery->where()->filterByGroup($oVoucherGroup->getVoucherGroupId())->end()->update(); if ($bSuccess) { $oVoucherGroup->setVoucherGroupID($oGateway->lastInsertId()); } } catch (DBALGatewayException $e) { throw new VoucherException($e->getMessage(), 0, $e); } return $bSuccess; }
public function testVoucherGroupValidateFails() { $aGroup = new VoucherGroup(); $sName = ''; $iID = null; $bDisabled = null; $iSort = 100; $oCreated = new DateTime(); $sSlugName = ''; $aGroup->setVoucherGroupID($iID); //$aGroup->setDisabledStatus($bDisabled); $aGroup->setVoucherGroupName($sName); $aGroup->setSortOrder($iSort); $aGroup->setDateCreated($oCreated); $aGroup->setSlugName($sSlugName); $aValidateErrors = $aGroup->validate(); $this->assertEquals(count($aValidateErrors['slugName']), 3); $this->assertEquals(count($aValidateErrors['name']), 2); $this->assertEquals(count($aValidateErrors['isDisabled']), 1); $this->assertEquals(count($aValidateErrors['voucherID']), 1); }
/** * Convert and entity into a data array that match database columns in table * * @return array * @access public * @param VoucherGroup $entity A voucher group entity */ public function demolish($entity) { $aData = array('voucher_gen_rule_id' => $entity->getVoucherGenRuleId(), 'voucher_rule_slug' => $entity->getSlugRuleName(), 'voucher_rule_name' => $entity->getVoucherRuleName(), 'voucher_padding_char' => $entity->getVoucherPaddingCharacter(), 'voucher_suffix' => $entity->getVoucherSuffix(), 'voucher_prefix' => $entity->getVoucherPrefix(), 'voucher_length' => $entity->getVoucherLength(), 'date_created' => $entity->getDateCreated(), 'voucher_sequence_strategy' => $entity->getSequenceStrategyName()); return $aData; }
/** * Convert and entity into a data array that match database columns in table * * @return array * @access public * @param VoucherGroup $entity A voucher group entity */ public function demolish($entity) { $aData = array('voucher_instance_id' => $entity->getVoucherInstanceId(), 'voucher_type_id' => $entity->getVoucherTypeId(), 'voucher_code' => $entity->getVoucherCode(), 'date_created' => $entity->getDateCreated()); return $aData; }
/** * Convert and entity into a data array that match database columns in table * * @return array * @access public * @param VoucherGroup $entity A voucher group entity */ public function demolish($entity) { $aData = array('voucher_group_id' => $entity->getVoucherGroupId(), 'voucher_group_name' => $entity->getVoucherGroupName(), 'voucher_group_slug' => $entity->getSlugName(), 'is_disabled' => $entity->getDisabledStatus(), 'sort_order' => $entity->getSortOrder(), 'date_created' => $entity->getDateCreated()); return $aData; }