mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Merge branch 'support/3.2' into develop
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
@@ -11,12 +12,12 @@ namespace Combodo\iTop\Form\Validator;
|
||||
*/
|
||||
abstract class AbstractRegexpValidator extends AbstractValidator
|
||||
{
|
||||
public const VALIDATOR_NAME = 'abstract_regexp';
|
||||
public const VALIDATOR_NAME = 'abstract_regexp';
|
||||
|
||||
/** @var string Override in children classes to set regexp to use for validation */
|
||||
public const DEFAULT_REGEXP = '';
|
||||
/** @var string Override in children classes to set regexp to use for validation */
|
||||
public const DEFAULT_REGEXP = '';
|
||||
|
||||
protected string $sRegExp;
|
||||
protected string $sRegExp;
|
||||
|
||||
public function __construct(?string $sErrorMessage = null)
|
||||
{
|
||||
@@ -36,21 +37,21 @@ abstract class AbstractRegexpValidator extends AbstractValidator
|
||||
return [$this->sErrorMessage];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the regular expression of the validator.
|
||||
*
|
||||
* @param boolean $bWithSlashes If true, surrounds $sRegExp with '/'. Used with preg_match & co
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetRegExp($bWithSlashes = false)
|
||||
{
|
||||
if ($bWithSlashes) {
|
||||
$sRet = '/'.str_replace('/', '\\/', $this->sRegExp).'/';
|
||||
} else {
|
||||
$sRet = $this->sRegExp;
|
||||
}
|
||||
/**
|
||||
* Returns the regular expression of the validator.
|
||||
*
|
||||
* @param boolean $bWithSlashes If true, surrounds $sRegExp with '/'. Used with preg_match & co
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetRegExp($bWithSlashes = false)
|
||||
{
|
||||
if ($bWithSlashes) {
|
||||
$sRet = '/'.str_replace('/', '\\/', $this->sRegExp).'/';
|
||||
} else {
|
||||
$sRet = $this->sRegExp;
|
||||
}
|
||||
|
||||
return $sRet;
|
||||
}
|
||||
}
|
||||
return $sRet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
@@ -24,8 +25,7 @@ abstract class AbstractValidator
|
||||
{
|
||||
if (false === utils::IsNullOrEmptyString($sErrorMessage)) {
|
||||
$this->sErrorMessage = $sErrorMessage;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->sErrorMessage = static::DEFAULT_ERROR_MESSAGE;
|
||||
}
|
||||
}
|
||||
@@ -56,4 +56,4 @@ abstract class AbstractValidator
|
||||
{
|
||||
return $this->sErrorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
@@ -19,4 +20,4 @@ class CustomRegexpValidator extends AbstractRegexpValidator
|
||||
|
||||
$this->sRegExp = $sRegExp; // must be done after parent constructor call !
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
@@ -30,45 +30,45 @@ use utils;
|
||||
*/
|
||||
class LinkedSetValidator extends AbstractRegexpValidator
|
||||
{
|
||||
public const VALIDATOR_NAME = 'linkedset_validator';
|
||||
private $aAttributesToDisplayCodes;
|
||||
public const VALIDATOR_NAME = 'linkedset_validator';
|
||||
private $aAttributesToDisplayCodes;
|
||||
|
||||
public function __construct($aAttributesToDisplayCodes)
|
||||
{
|
||||
$this->aAttributesToDisplayCodes = $aAttributesToDisplayCodes;
|
||||
public function __construct($aAttributesToDisplayCodes)
|
||||
{
|
||||
$this->aAttributesToDisplayCodes = $aAttributesToDisplayCodes;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function Validate($value): array
|
||||
{
|
||||
$aErrorMessages = [];
|
||||
public function Validate($value): array
|
||||
{
|
||||
$aErrorMessages = [];
|
||||
|
||||
/** @var ormLinkSet $oSet */
|
||||
$oSet = $value;
|
||||
/** @var ormLinkSet $oSet */
|
||||
$oSet = $value;
|
||||
|
||||
// validate each links...
|
||||
/** @var \DBObject $oItem */
|
||||
foreach ($oSet as $oItem) {
|
||||
$aChanges = $oItem->ListChanges();
|
||||
foreach ($aChanges as $sAttCode => $AttValue) {
|
||||
if (!in_array($sAttCode, $this->aAttributesToDisplayCodes)) {
|
||||
continue;
|
||||
}
|
||||
$res = $oItem->CheckValue($sAttCode);
|
||||
if ($res !== true) {
|
||||
$sAttLabel = $oItem->GetLabel($sAttCode);
|
||||
$sItem = utils::IsNullOrEmptyString($oItem->Get('friendlyname'))
|
||||
? Dict::S('UI:Links:NewItem')
|
||||
: $oItem->Get('friendlyname');
|
||||
$sIssue = Dict::Format('Core:CheckValueError', $sAttLabel, $sAttCode, $res);
|
||||
$aErrorMessages[] = '<b>' . $sItem . ' : </b>' . $sIssue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// validate each links...
|
||||
/** @var \DBObject $oItem */
|
||||
foreach ($oSet as $oItem) {
|
||||
$aChanges = $oItem->ListChanges();
|
||||
foreach ($aChanges as $sAttCode => $AttValue) {
|
||||
if (!in_array($sAttCode, $this->aAttributesToDisplayCodes)) {
|
||||
continue;
|
||||
}
|
||||
$res = $oItem->CheckValue($sAttCode);
|
||||
if ($res !== true) {
|
||||
$sAttLabel = $oItem->GetLabel($sAttCode);
|
||||
$sItem = utils::IsNullOrEmptyString($oItem->Get('friendlyname'))
|
||||
? Dict::S('UI:Links:NewItem')
|
||||
: $oItem->Get('friendlyname');
|
||||
$sIssue = Dict::Format('Core:CheckValueError', $sAttLabel, $sAttCode, $res);
|
||||
$aErrorMessages[] = '<b>'.$sItem.' : </b>'.$sIssue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$oSet->Rewind();
|
||||
$oSet->Rewind();
|
||||
|
||||
return $aErrorMessages;
|
||||
}
|
||||
return $aErrorMessages;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
@@ -10,50 +11,50 @@ use utils;
|
||||
|
||||
class MultipleChoicesValidator extends AbstractValidator
|
||||
{
|
||||
public const VALIDATOR_NAME = 'multiple_choices_validator';
|
||||
public const VALIDATOR_NAME = 'multiple_choices_validator';
|
||||
|
||||
/** @var array List of possible choices */
|
||||
private array $aChoices;
|
||||
/** @var array List of possible choices */
|
||||
private array $aChoices;
|
||||
|
||||
public function __construct(array $aChoices)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->aChoices = $aChoices;
|
||||
}
|
||||
public function __construct(array $aChoices)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->aChoices = $aChoices;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value Warning can either be an array (if multiple values are allowed in the field) or a primitive : {@see \Combodo\iTop\Form\Field\MultipleChoicesField::GetCurrentValue()}
|
||||
*
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function Validate($value): array
|
||||
{
|
||||
$aErrorMessages = [];
|
||||
if (false === is_array($value)) {
|
||||
$this->CheckValueAgainstChoices($value, $aErrorMessages);
|
||||
/**
|
||||
* @param mixed $value Warning can either be an array (if multiple values are allowed in the field) or a primitive : {@see \Combodo\iTop\Form\Field\MultipleChoicesField::GetCurrentValue()}
|
||||
*
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function Validate($value): array
|
||||
{
|
||||
$aErrorMessages = [];
|
||||
if (false === is_array($value)) {
|
||||
$this->CheckValueAgainstChoices($value, $aErrorMessages);
|
||||
|
||||
return $aErrorMessages;
|
||||
}
|
||||
return $aErrorMessages;
|
||||
}
|
||||
|
||||
if (count($value) === 0) {
|
||||
return [];
|
||||
}
|
||||
if (count($value) === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
foreach ($value as $sCode => $valueItem) {
|
||||
if (utils::IsNullOrEmptyString($valueItem)) {
|
||||
continue;
|
||||
}
|
||||
$this->CheckValueAgainstChoices($valueItem, $aErrorMessages);
|
||||
}
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
foreach ($value as $sCode => $valueItem) {
|
||||
if (utils::IsNullOrEmptyString($valueItem)) {
|
||||
continue;
|
||||
}
|
||||
$this->CheckValueAgainstChoices($valueItem, $aErrorMessages);
|
||||
}
|
||||
|
||||
return $aErrorMessages;
|
||||
}
|
||||
return $aErrorMessages;
|
||||
}
|
||||
|
||||
private function CheckValueAgainstChoices(string $sValue, array &$aErrorMessages): void
|
||||
{
|
||||
if (false === array_key_exists($sValue, $this->aChoices)) {
|
||||
$aErrorMessages[] = "Value ({$sValue}) is not part of the field possible values list";
|
||||
}
|
||||
}
|
||||
}
|
||||
private function CheckValueAgainstChoices(string $sValue, array &$aErrorMessages): void
|
||||
{
|
||||
if (false === array_key_exists($sValue, $this->aChoices)) {
|
||||
$aErrorMessages[] = "Value ({$sValue}) is not part of the field possible values list";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// iTop is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
@@ -12,34 +13,34 @@ use utils;
|
||||
|
||||
class SelectObjectValidator extends AbstractValidator
|
||||
{
|
||||
public const VALIDATOR_NAME = 'select_object_validator';
|
||||
public const VALIDATOR_NAME = 'select_object_validator';
|
||||
|
||||
/** @var \DBSearch $oSearch */
|
||||
private $oSearch;
|
||||
/** @var \DBSearch $oSearch */
|
||||
private $oSearch;
|
||||
|
||||
public function __construct(DBSearch $oSearch)
|
||||
{
|
||||
parent::__construct();
|
||||
public function __construct(DBSearch $oSearch)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->oSearch = $oSearch;
|
||||
}
|
||||
$this->oSearch = $oSearch;
|
||||
}
|
||||
|
||||
public function Validate($value): array
|
||||
{
|
||||
if (utils::IsNullOrEmptyString($value)) {
|
||||
return [];
|
||||
}
|
||||
if (($value === 0) || ($value === '0')) {
|
||||
return [];
|
||||
}
|
||||
public function Validate($value): array
|
||||
{
|
||||
if (utils::IsNullOrEmptyString($value)) {
|
||||
return [];
|
||||
}
|
||||
if (($value === 0) || ($value === '0')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$oSetForExistingCurrentValue = FieldHelper::GetObjectsSetFromSearchAndCurrentValueId($this->oSearch, $value);
|
||||
$iObjectsCount = $oSetForExistingCurrentValue->CountWithLimit(1);
|
||||
$oSetForExistingCurrentValue = FieldHelper::GetObjectsSetFromSearchAndCurrentValueId($this->oSearch, $value);
|
||||
$iObjectsCount = $oSetForExistingCurrentValue->CountWithLimit(1);
|
||||
|
||||
if ($iObjectsCount === 0) {
|
||||
return ["Value $value does not match the corresponding filter set"];
|
||||
}
|
||||
if ($iObjectsCount === 0) {
|
||||
return ["Value $value does not match the corresponding filter set"];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user