Skip to content
Snippets Groups Projects
Commit 04c3c719 authored by Laurent's avatar Laurent
Browse files

dev #46812 library rewrite url: fix profil validation

parent 67efd067
Branches
Tags
3 merge requests!181847973 ckeditor dialog focus problem,!1817Dev#46812 contractuel url personnalisee pour les fiches bibliotheques chambery,!1812Dev#46812 contractuel url personnalisee pour les fiches bibliotheques chambery
......@@ -55,30 +55,30 @@ class ZendAfi_Validate_ProfilRewriteUrl extends Zend_Validate_Abstract {
if (!$this->checkPageWithSameUrlAsAPageWithoutRewriteUrl($profil))
return false;
if (!$this->checkOtherModelsUrl($profil))
return false;
if (!$this->checkOtherModelsUrl($profil))
return false;
return true;
}
return true;
}
protected function checkOtherModelsUrl($profil) {
$validator = new ZendAfi_Validate_RewriteUrl();
if ($validator->isValid($profil))
return true;
protected function checkOtherModelsUrl($profil) {
$validator = new ZendAfi_Validate_RewriteUrl(['Class_Profil']);
if ($validator->isValid($profil))
return true;
foreach($validator->getMessages() as $key => $message) {
$this->_errors[]= $key;
$this->_messages[$key] = $message;
}
foreach($validator->getMessages() as $key => $message) {
$this->_errors[]= $key;
$this->_messages[$key] = $message;
}
return false;
}
return false;
}
protected function checkProfilWithSameUrlAsAnotherProfil($profil) {
if ($profil->hasParentProfil())
return true;
protected function checkProfilWithSameUrlAsAnotherProfil($profil) {
if ($profil->hasParentProfil())
return true;
$others = Class_Profil::findAllBy(['rewrite_url' => $profil->getRewriteUrl(),
'parent_id' => null]);
......
......@@ -21,6 +21,9 @@
class ZendAfi_Validate_RewriteUrl extends Zend_Validate_Abstract {
use Trait_Translator;
protected
$_exclude_models = [];
const
INVALID_URL = 'invalidURL',
URL_ALREADY_EXISTS_IN_ANOTHER_MODEL = 'urlAlreadyExistsInAModel';
......@@ -32,6 +35,11 @@ class ZendAfi_Validate_RewriteUrl extends Zend_Validate_Abstract {
];
public function __construct($exclude_models = []) {
$this->_exclude_models = $exclude_models;
}
public function isValid($model) {
$url = trim($model->getRewriteUrl());
$this->_setValue($url);
......@@ -44,10 +52,24 @@ class ZendAfi_Validate_RewriteUrl extends Zend_Validate_Abstract {
return false;
}
return
$this->isValidForClass('Class_Bib', $model, $this->_('bibliothèque'))
&&
$this->isValidForClass('Class_Profil', $model, $this->_('profil'));
$valid = true;
foreach($this->_modelsWithRewrite() as $classname => $label)
$valid = $valid && $this->isValidForClass($classname,
$model,
$label);
return $valid;
}
protected function _modelsWithRewrite() {
$models = [
'Class_Bib' => $this->_('bibliothèque'),
'Class_Profil' => $this->_('profil') ];
return array_diff_key($models,
array_combine($this->_exclude_models,
$this->_exclude_models));
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment