<?php
 namespace Entity; class Validator_Trust extends \App\Entity\Utils\Extension_ValidateDefaultAbstract { protected function isAccessible_insert() { $currMessages = $this->entity->getMessages(); if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Partners/Trusts-insert')) { $currMessages->addWarningCode('noAccessToOption'); } } protected function check_insert() { $fields = $this->entity->getFields(); $currMessages = $this->entity->getMessages(); if ($fields['name']) { $trustObj = new \App\EntityList\Trusts(); $trustObj->setFilter('trusts.name', 'LIKE', $fields['name']); $trustObj->setFilter('trusts.type', 'LIKE', $fields['type']); $trustObj->setLimit(1); $trustArray = $trustObj->exportRecords(); if ($trustArray) { $currMessages->addWarningCode('insert_nameNotUnique', 'name'); } } } protected function isAccessible_update() { $currMessages = $this->entity->getMessages(); if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Partners/Trusts-update')) { $currMessages->addWarningCode('noAccessToOption'); } } protected function isAvailable_update() { $currentIdEntity = $this->entity->getId(); $currMessages = $this->entity->getMessages(); $trust = \Entity\Trust::selectForUpdate($currentIdEntity); if (!$trust->recordExists()) { $currMessages->addErrorCode('delete_trustIdInvalid'); } if ($trust->deleted) { $currMessages->addWarningCode('delete_trustDeleted'); } } protected function check_update() { $fields = $this->entity->getFields(); $currentIdEntity = $this->entity->getId(); $currMessages = $this->entity->getMessages(); $trust = \Entity\Trust::selectForUpdate($currentIdEntity); if ($fields['name']) { $trustObj = new \App\EntityList\Trusts(); $trustObj->setFilter('trusts.id', '!=', $currentIdEntity); $trustObj->setFilter('trusts.name', 'LIKE', $fields['name']); $trustObj->setFilter('trusts.type', 'LIKE', $trust->type); $trustObj->setLimit(1); $trustArray = $trustObj->exportRecords(); if ($trustArray) { $currMessages->addWarningCode('update_nameNotUnique', 'name'); } } } protected function isAccessible_delete() { if (!\App\UserAccess\CurrentUserAccessFast::getInstance()->hasAccessToOption('Modules/Partners/Trusts-delete')) { $this->entity->getMessages()->addWarningCode('noAccessToOption'); } } protected function isAvailable_delete() { $currentIdEntity=$this->entity->getId(); $currMessages=$this->entity->getMessages(); $trust = \Entity\Trust::selectForUpdate($currentIdEntity); if (!$trust->recordExists()) { $currMessages->addErrorCode('delete_trustIdInvalid'); } if ($trust->deleted) { $currMessages->addWarningCode('delete_trustDeleted'); } if ($trust->type == 'corporate') { $corporateObj = new \App\EntityList\Corporates(); $corporateObj->setFilter('corp.idTrust', '=', $currentIdEntity); $corporateObj->setLimit(1); $corporateArray = $corporateObj->exportRecords(); if ($corporateArray) { $currMessages->addWarningCode('delete_trustCantBeDeleted'); } } elseif ($trust->type == 'supplier') { $supplierObj = new \App\EntityList\Suppliers(); $supplierObj->setFilter('supp.idTrust', '=', $currentIdEntity); $supplierObj->setLimit(1); $supplierArray = $supplierObj->exportRecords(); if ($supplierArray) { $currMessages->addWarningCode('delete_trustCantBeDeleted'); } } } } 