<?php
 namespace Entity; class Validator_UserProfile extends \App\Entity\Utils\Extension_ValidateDefaultAbstract { protected function check_insert() { $fields = $this->entity->getFields(); $currentMessages = $this->entity->getMessages(); if ($fields['name']) { $userProfileObj = new \App\EntityList\UserProfiles(); $userProfileObj->setFilter('userProfile.name', 'LIKE', $fields['name']); $userProfileObj->setLimit(1); $userProfileArray = $userProfileObj->exportRecords(); if ($userProfileArray) { $currentMessages->addWarningCode('insert_nameNotUnique'); } } } protected function isAvailable_update() { $currentEntityId = $this->entity->getId(); $currentMessages = $this->entity->getMessages(); $userProfile = UserProfile::selectForUpdate($currentEntityId); if (!$userProfile->recordExists()) { $currentMessages->addErrorCode('update_invalidId'); } elseif ($userProfile->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('name', $fields)) { $userProfileObj = new \App\EntityList\UserProfiles(); $userProfileObj->setFilter('userProfile.name', 'LIKE', $fields['name']); $userProfileObj->setFilter('userProfile.id', '!=', $currentEntityId); $userProfileObj->setLimit(1); $userProfileArray = $userProfileObj->exportRecords(); if ($userProfileArray) { $currentMessages->addWarningCode('update_nameNotUnique'); } } } protected function isAvailable_delete() { $currentEntityId = $this->entity->getId(); $currentMessages = $this->entity->getMessages(); $userProfile = UserProfile::selectForUpdate($currentEntityId); if (!$userProfile->recordExists()) { $currentMessages->addErrorCode('delete_idInvalid'); } elseif ($userProfile->deleted) { $currentMessages->addWarningCode('delete_deleted'); } $userObj = new \App\EntityList\Users(); $userObj->setFilter('user.idUsersAccessProfile', 'LIKE', $currentEntityId); $userObj->setLimit(1); $userArray = $userObj->exportRecords(); if ($userArray) { $currentMessages->addWarningCode('delete_profHasUsers'); } } } 