public function delete($id) { $merchantAuthenticated = Module::getRepository('Merchant')->findOneBy(array('apiPublicKey' => Module::getApiPublicKey())); if ($merchantAuthenticated && !empty($merchantAuthenticated->getApiPrivateKey())) { $existingUser = Module::getRepository('User')->findOneBy(array('integrationMerchant' => Module::getRepository('IntegrationMerchant')->findOneBy(array('apiPublicKey' => $id)))); $user = false; $integration_merchant = false; $address = false; if ($existingUser) { $iMId = $existingUser->getIntegrationMerchant()->getId(); $aId = $existingUser->getAddress()->getId(); $user = Module::removeEntity('User', $existingUser->getDocument(), 'document'); $address = Module::removeEntity('Address', $aId); $integration_merchant = Module::removeEntity('IntegrationMerchant', $iMId); } return new JsonModel(array(array('success' => $user && $address && $integration_merchant))); } return new JsonModel(array(array('success' => false))); }
/** * Remover uma Entidade existente * * @param string $nameEntity * @param string $idValue * @param string $idCode * @return boolean */ public function removeEntity($nameEntity, $idValue, $idCode = 'id') { return Module::removeEntity($nameEntity, $idValue, $idCode); }
public function delete($id) { $existingUser = Module::getRepository('User')->findOneBy(array('merchant' => Module::getRepository('Merchant')->findOneBy(array('apiPrivateKey' => $id, 'apiPublicKey' => Module::getApiPublicKey())))); $user = false; $merchant = false; $address = false; if ($existingUser) { $mId = $existingUser->getMerchant()->getId(); $aId = $existingUser->getAddress()->getId(); $user = Module::removeEntity('User', $existingUser->getDocument(), 'document'); $address = Module::removeEntity('Address', $aId); $merchant = Module::removeEntity('Merchant', $mId); } return new JsonModel(array(array('success' => $user && $address && $merchant))); }
public function delete($id) { $existingUser = Module::getRepository('User')->findOneBy(array('integrationMerchant' => Module::getRepository('IntegrationMerchant')->findOneBy(array('merchant' => Module::getRepository('Merchant')->findOneBy(array('apiPublicKey' => Module::getApiPublicKey())))))); if ($existingUser) { if (!empty($existingUser->getMerchant()->getApiPrivateKey())) { $existingUser = Module::getRepository('User')->findOneBy(array('integrationMerchant' => Module::getRepository('IntegrationMerchant')->findOneBy(array('merchant' => Module::getRepository('Merchant')->findOneBy(array('apiPublicKey' => $id)))))); } else { $this->controller->getResponse()->setStatusCode(401); throw new \Exception('Request Not Authorized'); } } else { $existingUser = Module::getRepository('User')->findOneBy(array('integrationMerchant' => Module::getRepository('IntegrationMerchant')->findOneBy(array('merchant' => Module::getRepository('Merchant')->findOneBy(array('apiPrivateKey' => $id, 'apiPublicKey' => Module::getApiPublicKey())))))); } $user = false; $merchant = false; $address = false; if ($existingUser) { $mId = $existingUser->getMerchant()->getId(); $aId = $existingUser->getAddress()->getId(); $user = Module::removeEntity('User', $existingUser->getDocument(), 'document'); $address = Module::removeEntity('Address', $aId); $merchant = Module::removeEntity('Merchant', $mId); } return new JsonModel(array(array('success' => $user && $address && $merchant))); }