<?php
namespace Entity; abstract class Validator_PartnerContractAbstract extends \App\Entity\Utils\Extension_ValidateDefaultAbstract { protected function check_insert() { $fields = $this->entity->getFields(); $currentMessages = $this->entity->getMessages(); if ($fields['contractDate'] and $fields['expireDate']) { if ($fields['contractDate'] > $fields['expireDate']) { $currentMessages->addWarningCode('insert_invalidExpireDate'); } } if ($fields['fileName']){ if(!\Engine\Dir::create($this->entity->getFileStoragePath())){ $currentMessages->addErrorCode('insert_contractFilePathErr'); } } if (($fields['fileName'] and !$fields['fileContent']) or (!$fields['fileName'] and $fields['fileContent'])) { $currentMessages->addErrorCode('insert_fileIncorrect'); } if ($fields['fileName'] and $fields['fileName'] != \Engine\File::cleanName($fields['fileName'])) { $currentMessages->addWarningCode('insert_fileNameIncorrect'); } if ($fields['idResponsibleUser']) { $user = \Entity\User::select($fields['idResponsibleUser']); if (!$user->recordExists()) { $currentMessages->addErrorCode('insert_idResponsibleUserInvalid'); } elseif ($user->deleted) { $currentMessages->addWarningCode('insert_idResponsibleUserDeleted'); } } } protected function check_update() { $fields = $this->entity->getFields(); $currentMessages = $this->entity->getMessages(); $partnerRefColumnName = $this->entity->getPartnerRefColumnName(); if (array_key_exists($partnerRefColumnName, $fields)) { throw new \Exception("The field '{$partnerRefColumnName}' cannot be updated in the `".__CLASS__."` entity."); } if (array_key_exists('file', $fields)){ if(!\Engine\Dir::create($this->entity->getFileStoragePath())){ $currentMessages->addErrorCode('update_contractFilePathErr'); } } if (($fields['fileName'] and !$fields['fileContent']) or (!$fields['fileName'] and $fields['fileContent'])) { $currentMessages->addWarningCode('insert_fileIncorrect'); } if ($fields['fileName'] != \Engine\File::cleanName($fields['fileName'])) { $currentMessages->addWarningCode('insert_fileNameIncorrect'); } if ($fields['idResponsibleUser']) { $user = \Entity\User::select($fields['idResponsibleUser']); if (!$user->recordExists()) { $currentMessages->addErrorCode('insert_idResponsibleUserInvalid'); } elseif ($user->deleted) { $currentMessages->addWarningCode('insert_idResponsibleUserDeleted'); } } } }