<?php
namespace Entity; class Validator_AgencyCreditCard extends \App\Entity\Utils\Extension_ValidateDefaultAbstract { protected function isAccessible_insert() { $currentMessages = $this->entity->getMessages(); if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Admin/AgencyCreditCards-insert')) { $currentMessages->addWarningCode('noAccessToOption'); } } protected function check_insert() { $fields = $this->entity->getFields(); $currentMessages = $this->entity->getMessages(); if ($fields['name']) { $agencyCC = new \App\EntityList\AgencyCreditCards(); $agencyCC->setCustomFilter('agencyCreditCards.name = ?', [$fields['name']]); $agencyCC->setLimit(1); $agencyCCArray = $agencyCC->exportRecords(); if ($agencyCCArray) { $currentMessages->addWarningCode('insert_notUniqueName'); } } } protected function isAccessible_update() { $currentMessages = $this->entity->getMessages(); if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Admin/AgencyCreditCards-update')) { $currentMessages->addWarningCode('noAccessToOption'); } } protected function isAvailable_update() { $currentMessages = $this->entity->getMessages(); $currentEntityId = $this->entity->getId(); $agencyCC = \Entity\AgencyCreditCard::selectForUpdate($currentEntityId); if (!$agencyCC->recordExists()) { $currentMessages->addErrorCode("update_invalidId"); } elseif ($agencyCC->deleted) { $currentMessages->addWarningCode("update_deletedId"); } } protected function check_update() { $fields = $this->entity->getFields(); $currentMessages = $this->entity->getMessages(); $currentEntityId = $this->entity->getId(); if ($fields['name']) { $agencyCC = new \App\EntityList\AgencyCreditCards(); $agencyCC->setFilter('agencyCreditCards.id', '!=', $currentEntityId); $agencyCC->setCustomFilter('agencyCreditCards.name = ?', [$fields['name']]); $agencyCC->setLimit(1); $agencyCCArray = $agencyCC->exportRecords(); if ($agencyCCArray) { $currentMessages->addWarningCode('update_notUniqueName'); } } } protected function isAccessible_delete() { $currentMessages = $this->entity->getMessages(); if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Admin/AgencyCreditCards-delete')) { $currentMessages->addWarningCode('noAccessToOption'); } } protected function isAvailable_delete() { $currentEntityId = $this->entity->getId(); $currentMessages = $this->entity->getMessages(); $agencyCC = \Entity\AgencyCreditCard::selectForUpdate($currentEntityId); if (!$agencyCC->recordExists()) { $currentMessages->addErrorCode("delete_invalidId"); } elseif ($agencyCC->deleted) { $currentMessages->addWarningCode("delete_deletedId"); } } }