<?php
 namespace Entity; class Validator_ActivityDomain extends \App\Entity\Utils\Extension_ValidateDefaultAbstract { protected function check_insert() { $fields = $this->entity->getFields(); $currMessages = $this->entity->getMessages(); if ($fields['idCategory']) { $categ = \Entity\ActivityDomainCategory::selectForUpdate($fields['idCategory']); if (!$categ->recordExists()){ $currMessages->addErrorCode('insert_invalidCategSelected'); } elseif ($categ->deleted) { $currMessages->addWarningCode('insert_selectedCategDeleted'); } } if ($fields['name'] && $fields['idCategory']) { $activityDomainObj = new \App\EntityList\ActivityDomains(); $activityDomainObj->setFilter('ad.name', 'LIKE', $fields['name']); $activityDomainObj->setFilter('ad.idCategory', '=', $fields['idCategory']); $activityDomainObj->setLimit(1); $activityDomainArray = $activityDomainObj->exportRecords(); if ($activityDomainArray) { $currMessages->addWarningCode('insert_domainNotUnique', 'name'); } } } protected function isAvailable_update() { $currentIdEntity = $this->entity->getId(); $currMessages = $this->entity->getMessages(); $activityDomain = \Entity\ActivityDomain::selectForUpdate($currentIdEntity); if (!$activityDomain->recordExists()) { $currMessages->addErrorCode('update_invalidId'); } elseif ($activityDomain->deleted) { $currMessages->addWarningCode('update_actDomDeleted'); } } protected function check_update() { $fields = $this->entity->getFields(); $currentIdEntity = $this->entity->getId(); $currMessages = $this->entity->getMessages(); $ad = \Entity\ActivityDomain::selectForUpdate($currentIdEntity); if ($fields['name']) { $activityDomainObj = new \App\EntityList\ActivityDomains(); $activityDomainObj->setFilter('ad.id', '!=', $currentIdEntity); $activityDomainObj->setFilter('ad.name', 'LIKE', $fields['name']); $activityDomainObj->setFilter('ad.idCategory', '=', $ad->idCategory); $activityDomainObj->setLimit(1); $activityDomainArray = $activityDomainObj->exportRecords(); if ($activityDomainArray) { $currMessages->addWarningCode('update_domainNotUnique', 'name'); } } } protected function isAvailable_delete() { $currentIdEntity = $this->entity->getId(); $currMessages = $this->entity->getMessages(); $activityDomain = \Entity\ActivityDomain::selectForUpdate($currentIdEntity); if (!$activityDomain->recordExists()) { $currMessages->addErrorCode('delete_activityDomainIdInvalid'); } elseif ($activityDomain->deleted) { $currMessages->addWarningCode('delete_activityDomainDeleted'); } } } 