<?php
 namespace Entity; class Validator_ActivityDomainCategory extends \App\Entity\Utils\Extension_ValidateDefaultAbstract { protected function check_insert() { $fields = $this->entity->getFields(); $currMessages = $this->entity->getMessages(); if ($fields['name']) { $domainCategoryObj = new \App\EntityList\ActivityDomainCategories(); $domainCategoryObj->setFilter('adc.name', 'LIKE', $fields['name']); $domainCategoryObj->setLimit(1); $domainCategoryArray = $domainCategoryObj->exportRecords(); if ($domainCategoryArray) { $currMessages->addWarningCode('insert_categoryNotUnique', 'name'); } } } protected function isAvailable_update() { $currentIdEntity = $this->entity->getId(); $currMessages = $this->entity->getMessages(); $category = \Entity\ActivityDomainCategory::selectForUpdate($currentIdEntity); if (!$category->recordExists()) { $currMessages->addErrorCode('update_invalidId'); } elseif ($category->deleted) { $currMessages->addWarningCode('update_catDeleted'); } } protected function check_update() { $fields = $this->entity->getFields(); $currentIdEntity = $this->entity->getId(); $currMessages = $this->entity->getMessages(); if ($fields['name']) { $activityDomainCategoryObj = new \App\EntityList\ActivityDomainCategories(); $activityDomainCategoryObj->setFilter('adc.id', '!=', $currentIdEntity); $activityDomainCategoryObj->setFilter('adc.name', 'LIKE', $fields['name']); $activityDomainCategoryObj->setLimit(1); $activityDomainCategoryArray = $activityDomainCategoryObj->exportRecords(); if ($activityDomainCategoryArray) { $currMessages->addWarningCode('update_categoryNotUnique', 'name'); } } } protected function isAvailable_delete() { $currentIdEntity = $this->entity->getId(); $currMessages = $this->entity->getMessages(); $cat = \Entity\ActivityDomainCategory::selectForUpdate($currentIdEntity); if (!$cat->recordExists()) { $currMessages->addErrorCode('delete_invalidId'); } elseif ($cat->deleted) { $currMessages->addWarningCode('delete_catDeleted'); } $domListObj = new \App\EntityList\ActivityDomains(); $domListObj->setColumn('name'); $domListObj->setFilter('idCategory', '=', $currentIdEntity); $domListObj->setLimit(1); if ($domListObj->exportRecords()) { $currMessages->addWarningCode('delete_catHasDomains'); } } } 