<?php
namespace Entity; class Validator_TaskOperationType extends \App\Entity\Utils\Extension_ValidateDefaultAbstract { protected function check_insert() { $fields = $this->entity->getFields(); $currentMessages = $this->entity->getMessages(); if ($fields['description']) { $taskOperationTypesObj = new \App\EntityList\TaskOperationTypes(); $taskOperationTypesObj->setFilter('taskOperationTypes.description', 'LIKE', $fields['description']); $taskOperationTypesArray = $taskOperationTypesObj->exportRecords(); if ($taskOperationTypesArray) { $currentMessages->addWarningCode('descriptionNotUnique'); } } } protected function isAvailable_update() { $currentEntityId = $this->entity->getId(); $currentMessages = $this->entity->getMessages(); $taskOperationType = \Entity\TaskOperationType::selectForUpdate($currentEntityId); if(!$taskOperationType->recordExists()) { $currentMessages->addErrorCode('update_invalidId'); } elseif ($taskOperationType->deleted) { $currentMessages->addWarningCode('update_deleted'); } } protected function check_update() { $fields = $this->entity->getFields(); $currentEntityId = $this->entity->getId(); $currentMessages = $this->entity->getMessages(); if (array_key_exists('description', $fields)) { $taskOperationTypeObj = new \App\EntityList\TaskOperationTypes(); $taskOperationTypeObj->setFilter('taskOperationTypes.description', 'LIKE', $fields['description']); $taskOperationTypeObj->setFilter('taskOperationTypes.id', '!=', $currentEntityId); $taskOperationTypeArray = $taskOperationTypeObj->exportRecords(); if ($taskOperationTypeArray) { $currentMessages->addWarningCode('descriptionNotUnique'); } } } protected function isAvailable_delete() { $currentEntityId = $this->entity->getId(); $currentMessages = $this->entity->getMessages(); $taskOperationType = \Entity\TaskOperationType::selectForUpdate($currentEntityId); if (!$taskOperationType->recordExists()) { $currentMessages->addErrorCode('delete_idInvalid'); } elseif ($taskOperationType->deleted) { $currentMessages->addWarningCode('delete_deleted'); } } }