mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°3216 - Refactor form files to be part of the autoloader
This commit is contained in:
81
sources/Form/Field/BlobField.php
Normal file
81
sources/Form/Field/BlobField.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use utils;
|
||||
use Dict;
|
||||
|
||||
/**
|
||||
* Description of BlobField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class BlobField extends Field
|
||||
{
|
||||
protected $sDownloadUrl;
|
||||
protected $sDisplayUrl;
|
||||
|
||||
public function GetDownloadUrl()
|
||||
{
|
||||
return $this->sDownloadUrl;
|
||||
}
|
||||
|
||||
public function GetDisplayUrl()
|
||||
{
|
||||
return $this->sDisplayUrl;
|
||||
}
|
||||
|
||||
public function SetDownloadUrl($sDownloadUrl)
|
||||
{
|
||||
$this->sDownloadUrl = $sDownloadUrl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function SetDisplayUrl($sDisplayUrl)
|
||||
{
|
||||
$this->sDisplayUrl = $sDisplayUrl;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetCurrentValue()
|
||||
{
|
||||
return $this->currentValue->GetFileName();
|
||||
}
|
||||
|
||||
public function GetDisplayValue()
|
||||
{
|
||||
if ($this->currentValue->IsEmpty())
|
||||
{
|
||||
$sValue = Dict::S('Portal:File:None');
|
||||
}
|
||||
else
|
||||
{
|
||||
$sFilename = $this->currentValue->GetFileName();
|
||||
$iSize = utils::BytesToFriendlyFormat(strlen($this->currentValue->GetData()));
|
||||
$sOpenLink = $this->GetDisplayUrl();
|
||||
$sDownloadLink = $this->GetDownloadUrl();
|
||||
|
||||
$sValue = Dict::Format('Portal:File:DisplayInfo+', $sFilename, $iSize, $sOpenLink, $sDownloadLink);
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
}
|
||||
62
sources/Form/Field/CaseLogField.php
Normal file
62
sources/Form/Field/CaseLogField.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of CaseLogField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @since iTop 2.3.0
|
||||
*/
|
||||
class CaseLogField extends TextAreaField
|
||||
{
|
||||
protected $aEntries;
|
||||
|
||||
/**
|
||||
* @param bool $bMustChange
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMustChange($bMustChange)
|
||||
{
|
||||
$this->SetMandatory($bMustChange);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetEntries()
|
||||
{
|
||||
return $this->aEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $aEntries
|
||||
* @return \Combodo\iTop\Form\Field\TextAreaField
|
||||
*/
|
||||
public function SetEntries($aEntries)
|
||||
{
|
||||
$this->aEntries = $aEntries;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
31
sources/Form/Field/CheckboxField.php
Normal file
31
sources/Form/Field/CheckboxField.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of CheckboxField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class CheckboxField extends MultipleChoicesField
|
||||
{
|
||||
const DEFAULT_MULTIPLE_VALUES_ENABLED = true;
|
||||
|
||||
}
|
||||
28
sources/Form/Field/DateField.php
Normal file
28
sources/Form/Field/DateField.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of StringField
|
||||
*/
|
||||
class DateField extends StringField
|
||||
{
|
||||
|
||||
}
|
||||
110
sources/Form/Field/DateTimeField.php
Normal file
110
sources/Form/Field/DateTimeField.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* A field for Dates and Date & Times, supporting custom formats
|
||||
*/
|
||||
class DateTimeField extends StringField
|
||||
{
|
||||
protected $sJSDateTimeFormat;
|
||||
protected $sPHPDateTimeFormat;
|
||||
protected $bDateOnly;
|
||||
|
||||
/**
|
||||
* Overloaded constructor
|
||||
*
|
||||
* @param string $sId
|
||||
* @param \Closure $onFinalizeCallback (Used in the $oForm->AddField($sId, ..., function() use ($oManager, $oForm, '...') { ... } ); )
|
||||
*/
|
||||
public function __construct($sId, Closure $onFinalizeCallback = null)
|
||||
{
|
||||
parent::__construct($sId, $onFinalizeCallback);
|
||||
$this->bDateOnly = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PHP format string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetPHPDateTimeFormat()
|
||||
{
|
||||
return $this->sPHPDateTimeFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sPHPDateTimeFormat
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Field\DateTimeField
|
||||
*/
|
||||
public function SetPHPDateTimeFormat($sPHPDateTimeFormat)
|
||||
{
|
||||
$this->sPHPDateTimeFormat = $sPHPDateTimeFormat;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetJSDateTimeFormat()
|
||||
{
|
||||
return $this->sJSDateTimeFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sJSDateTimeFormat
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Field\DateTimeField
|
||||
*/
|
||||
public function SetJSDateTimeFormat($sJSDateTimeFormat)
|
||||
{
|
||||
$this->sJSDateTimeFormat = $sJSDateTimeFormat;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the DateOnly flag
|
||||
*
|
||||
* @param boolean $bDateOnly
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Field\DateTimeField
|
||||
*/
|
||||
public function SetDateOnly($bDateOnly)
|
||||
{
|
||||
$this->bDateOnly = $bDateOnly;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsDateOnly()
|
||||
{
|
||||
return $this->bDateOnly;
|
||||
}
|
||||
|
||||
}
|
||||
41
sources/Form/Field/DurationField.php
Normal file
41
sources/Form/Field/DurationField.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Str;
|
||||
use AttributeDuration;
|
||||
|
||||
/**
|
||||
* Description of StringField
|
||||
*/
|
||||
class DurationField extends Field
|
||||
{
|
||||
|
||||
/**
|
||||
* Note: This is inspired by AttributeDuration::GetAsHTML()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetDisplayValue()
|
||||
{
|
||||
return Str::pure2html(AttributeDuration::FormatDuration($this->currentValue));
|
||||
}
|
||||
|
||||
}
|
||||
45
sources/Form/Field/EmailField.php
Normal file
45
sources/Form/Field/EmailField.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Str;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Description of EmailField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class EmailField extends StringField
|
||||
{
|
||||
public function GetDisplayValue()
|
||||
{
|
||||
$sLabel = Str::pure2html($this->currentValue);
|
||||
if (strlen($sLabel) > 128)
|
||||
{
|
||||
// Truncate the length to 128 characters, by removing the middle
|
||||
$sLabel = substr($sLabel, 0, 100).'.....'.substr($sLabel, -20);
|
||||
}
|
||||
|
||||
$sUrlDecorationClass = utils::GetConfig()->Get('email_decoration_class');
|
||||
|
||||
return "<a class=\"mailto\" href=\"mailto:$this->currentValue\"><span class=\"form_field_decoration text_decoration $sUrlDecorationClass\"></span>$sLabel</a>";
|
||||
}
|
||||
}
|
||||
517
sources/Form/Field/Field.php
Normal file
517
sources/Form/Field/Field.php
Normal file
@@ -0,0 +1,517 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2019 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Closure;
|
||||
use Combodo\iTop\Form\Validator\Validator;
|
||||
use Combodo\iTop\Form\Validator\MandatoryValidator;
|
||||
|
||||
/**
|
||||
* Description of Field
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @since iTop 2.3.0
|
||||
*/
|
||||
abstract class Field
|
||||
{
|
||||
const ENUM_DISPLAY_MODE_COSY = 'cosy'; // Label above value
|
||||
const ENUM_DISPLAY_MODE_COMPACT = 'compact'; // Label and value side by side
|
||||
const ENUM_DISPLAY_MODE_DENSE = 'dense'; // Label and value side by side, closely
|
||||
|
||||
const DEFAULT_LABEL = '';
|
||||
const DEFAULT_METADATA = array();
|
||||
const DEFAULT_HIDDEN = false;
|
||||
const DEFAULT_READ_ONLY = false;
|
||||
const DEFAULT_MANDATORY = false;
|
||||
const DEFAULT_DISPLAY_MODE = self::ENUM_DISPLAY_MODE_COSY;
|
||||
const DEFAULT_VALID = true;
|
||||
|
||||
protected $sId;
|
||||
protected $sGlobalId;
|
||||
protected $sFormPath;
|
||||
protected $sLabel;
|
||||
protected $aMetadata;
|
||||
protected $bHidden;
|
||||
protected $bReadOnly;
|
||||
protected $bMandatory;
|
||||
protected $sDisplayMode;
|
||||
protected $aValidators;
|
||||
protected $bValid;
|
||||
protected $aErrorMessages;
|
||||
protected $currentValue;
|
||||
protected $onFinalizeCallback;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param string $sId
|
||||
* @param Closure $onFinalizeCallback (Used in the $oForm->AddField($sId, ..., function() use ($oManager, $oForm, '...') { ... } ); )
|
||||
*/
|
||||
public function __construct($sId, Closure $onFinalizeCallback = null)
|
||||
{
|
||||
$this->sId = $sId;
|
||||
// No space in such an id, that could be used as a DOM node id
|
||||
$this->sGlobalId = 'field_' . str_replace(' ', '_', $sId) . '_' . uniqid();
|
||||
$this->sLabel = static::DEFAULT_LABEL;
|
||||
$this->aMetadata = static::DEFAULT_METADATA;
|
||||
$this->bHidden = static::DEFAULT_HIDDEN;
|
||||
$this->bReadOnly = static::DEFAULT_READ_ONLY;
|
||||
$this->bMandatory = static::DEFAULT_MANDATORY;
|
||||
$this->sDisplayMode = static::DEFAULT_DISPLAY_MODE;
|
||||
$this->aValidators = array();
|
||||
$this->bValid = static::DEFAULT_VALID;
|
||||
$this->aErrorMessages = array();
|
||||
$this->onFinalizeCallback = $onFinalizeCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field id within its container form
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetId()
|
||||
{
|
||||
return $this->sId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a unique field id within the top level form
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetGlobalId()
|
||||
{
|
||||
return $this->sGlobalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the container form
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetFormPath()
|
||||
{
|
||||
return $this->sFormPath;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetLabel()
|
||||
{
|
||||
return $this->sLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of $sName => $sValue metadata.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function GetMetadata()
|
||||
{
|
||||
return $this->aMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function GetHidden()
|
||||
{
|
||||
return $this->bHidden;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function GetReadOnly()
|
||||
{
|
||||
return $this->bReadOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This not implemented yet! Just a pre-conception for CaseLogField
|
||||
*
|
||||
* @todo Implement
|
||||
* @return boolean
|
||||
*/
|
||||
public function GetMustChange()
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function GetMandatory()
|
||||
{
|
||||
return $this->bMandatory;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetDisplayMode()
|
||||
{
|
||||
return $this->sDisplayMode;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetValidators()
|
||||
{
|
||||
return $this->aValidators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current validation state of the field (true|false).
|
||||
* It DOESN'T make the validation, see Validate() instead.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function GetValid()
|
||||
{
|
||||
return $this->bValid;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetErrorMessages()
|
||||
{
|
||||
return $this->aErrorMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function GetCurrentValue()
|
||||
{
|
||||
return $this->currentValue;
|
||||
}
|
||||
|
||||
|
||||
public function GetDisplayValue()
|
||||
{
|
||||
return $this->currentValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the field formpath
|
||||
* Usually Called by the form when adding the field
|
||||
*
|
||||
* @param string $sFormPath
|
||||
* @return $this
|
||||
*/
|
||||
public function SetFormPath($sFormPath)
|
||||
{
|
||||
$this->sFormPath = $sFormPath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sLabel
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLabel($sLabel)
|
||||
{
|
||||
$this->sLabel = $sLabel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Must be an array of $sName => $sValue metadata.
|
||||
*
|
||||
* @param array $aMetadata
|
||||
*
|
||||
* @return $this
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function SetMetadata($aMetadata)
|
||||
{
|
||||
$this->aMetadata = $aMetadata;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $bHidden
|
||||
* @return $this
|
||||
*/
|
||||
public function SetHidden($bHidden)
|
||||
{
|
||||
$this->bHidden = $bHidden;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $bReadOnly
|
||||
* @return $this
|
||||
*/
|
||||
public function SetReadOnly($bReadOnly)
|
||||
{
|
||||
$this->bReadOnly = $bReadOnly;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the field is mandatory or not.
|
||||
* Setting the value will automatically add/remove a MandatoryValidator to the Field
|
||||
*
|
||||
* @param boolean $bMandatory
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMandatory($bMandatory)
|
||||
{
|
||||
// Before changing the property, we check if it was already mandatory. If not, we had the mandatory validator
|
||||
if ($bMandatory && !$this->bMandatory)
|
||||
{
|
||||
$this->AddValidator(new MandatoryValidator());
|
||||
}
|
||||
|
||||
if (!$bMandatory)
|
||||
{
|
||||
foreach ($this->aValidators as $iKey => $oValue)
|
||||
{
|
||||
if ($oValue::Getname() === MandatoryValidator::GetName())
|
||||
{
|
||||
unset($this->aValidators[$iKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->bMandatory = $bMandatory;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the field is must change or not.
|
||||
* Note: This not implemented yet! Just a pre-conception for CaseLogField
|
||||
*
|
||||
* @todo Implement
|
||||
* @param boolean $bMustChange
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMustChange($bMustChange)
|
||||
{
|
||||
// TODO.
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sDisplayMode
|
||||
* @return $this
|
||||
*/
|
||||
public function SetDisplayMode($sDisplayMode)
|
||||
{
|
||||
$this->sDisplayMode = $sDisplayMode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $aValidators
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValidators($aValidators)
|
||||
{
|
||||
$this->aValidators = $aValidators;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note : Function is protected as bValid should not be set from outside
|
||||
*
|
||||
* @param boolean $bValid
|
||||
* @return $this
|
||||
*/
|
||||
protected function SetValid($bValid)
|
||||
{
|
||||
$this->bValid = $bValid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note : Function is protected as aErrorMessages should not be set from outside
|
||||
*
|
||||
* @param array $aErrorMessages
|
||||
* @return $this
|
||||
*/
|
||||
protected function SetErrorMessages($aErrorMessages)
|
||||
{
|
||||
$this->aErrorMessages = $aErrorMessages;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mixed $currentValue
|
||||
* @return $this
|
||||
*/
|
||||
public function SetCurrentValue($currentValue)
|
||||
{
|
||||
$this->currentValue = $currentValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Closure $onFinalizeCallback
|
||||
* @return $this
|
||||
*/
|
||||
public function SetOnFinalizeCallback(Closure $onFinalizeCallback)
|
||||
{
|
||||
$this->onFinalizeCallback = $onFinalizeCallback;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a metadata to the field. If the metadata $sName already exists, it will be overwritten.
|
||||
*
|
||||
* @param string $sName
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return $this;
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function AddMetadata($sName, $sValue)
|
||||
{
|
||||
$this->aMetadata[$sName] = $sValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Combodo\iTop\Form\Validator\Validator $oValidator
|
||||
* @return $this
|
||||
*/
|
||||
public function AddValidator(Validator $oValidator)
|
||||
{
|
||||
$this->aValidators[] = $oValidator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Combodo\iTop\Form\Validator\Validator $oValidator
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveValidator(Validator $oValidator)
|
||||
{
|
||||
foreach ($this->aValidators as $iKey => $oValue)
|
||||
{
|
||||
if ($oValue === $oValidator)
|
||||
{
|
||||
unset($this->aValidators[$iKey]);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note : Function is protected as aErrorMessages should not be add from outside
|
||||
*
|
||||
* @param string $sErrorMessage
|
||||
* @return $this
|
||||
*/
|
||||
protected function AddErrorMessage($sErrorMessage)
|
||||
{
|
||||
$this->aErrorMessages[] = $sErrorMessage;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note : Function is protected as aErrorMessages should not be set from outside
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function EmptyErrorMessages()
|
||||
{
|
||||
$this->aErrorMessages = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the field is editable. Meaning that it is not editable nor hidden.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function IsEditable()
|
||||
{
|
||||
return (!$this->bReadOnly && !$this->bHidden);
|
||||
}
|
||||
|
||||
public function OnCancel()
|
||||
{
|
||||
// Overload when needed
|
||||
}
|
||||
|
||||
public function OnFinalize()
|
||||
{
|
||||
if ($this->onFinalizeCallback !== null)
|
||||
{
|
||||
// Note : We MUST have a temp variable to call the Closure. otherwise it won't work when the Closure is a class member
|
||||
$callback = $this->onFinalizeCallback;
|
||||
$callback($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the validators to see if the field's current value is valid.
|
||||
* Then sets $bValid and $aErrorMessages.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function Validate()
|
||||
{
|
||||
$this->SetValid(true);
|
||||
$this->EmptyErrorMessages();
|
||||
|
||||
$bEmpty = ( ($this->GetCurrentValue() === null) || ($this->GetCurrentValue() === '') );
|
||||
|
||||
if (!$bEmpty || $this->GetMandatory())
|
||||
{
|
||||
foreach ($this->GetValidators() as $oValidator)
|
||||
{
|
||||
if (!preg_match($oValidator->GetRegExp(true), $this->GetCurrentValue()))
|
||||
{
|
||||
$this->SetValid(false);
|
||||
$this->AddErrorMessage($oValidator->GetErrorMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->GetValid();
|
||||
}
|
||||
}
|
||||
156
sources/Form/Field/FileUploadField.php
Normal file
156
sources/Form/Field/FileUploadField.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* Description of FileUploadField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class FileUploadField extends Field
|
||||
{
|
||||
/** @var bool DEFAULT_ALLOW_DELETE */
|
||||
const DEFAULT_ALLOW_DELETE = true;
|
||||
|
||||
/** @var string|null $sTransactionId */
|
||||
protected $sTransactionId;
|
||||
/** @var \DBObject|null $oObject */
|
||||
protected $oObject;
|
||||
/** @var string|null $sUploadEndpoint */
|
||||
protected $sUploadEndpoint;
|
||||
/** @var string|null $sDownloadEndpoint */
|
||||
protected $sDownloadEndpoint;
|
||||
/** @var bool $bAllowDelete */
|
||||
protected $bAllowDelete;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct($sId, Closure $onFinalizeCallback = null)
|
||||
{
|
||||
$this->sTransactionId = null;
|
||||
$this->oObject = null;
|
||||
$this->sUploadEndpoint = null;
|
||||
$this->sDownloadEndpoint = null;
|
||||
$this->bAllowDelete = static::DEFAULT_ALLOW_DELETE;
|
||||
|
||||
parent::__construct($sId, $onFinalizeCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the transaction id for the field.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetTransactionId()
|
||||
{
|
||||
return $this->sTransactionId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sTransactionId
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTransactionId($sTransactionId)
|
||||
{
|
||||
$this->sTransactionId = $sTransactionId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DBObject|null
|
||||
*/
|
||||
public function GetObject()
|
||||
{
|
||||
return $this->oObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $oObject
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetObject($oObject)
|
||||
{
|
||||
$this->oObject = $oObject;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function GetUploadEndpoint()
|
||||
{
|
||||
return $this->sUploadEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sUploadEndpoint
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetUploadEndpoint($sUploadEndpoint)
|
||||
{
|
||||
$this->sUploadEndpoint = $sUploadEndpoint;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function GetDownloadEndpoint()
|
||||
{
|
||||
return $this->sDownloadEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sDownloadEndpoint
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetDownloadEndpoint($sDownloadEndpoint)
|
||||
{
|
||||
$this->sDownloadEndpoint = $sDownloadEndpoint;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function GetAllowDelete()
|
||||
{
|
||||
return $this->bAllowDelete;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bAllowDelete
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetAllowDelete($bAllowDelete)
|
||||
{
|
||||
$this->bAllowDelete = (boolean) $bAllowDelete;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
30
sources/Form/Field/HiddenField.php
Normal file
30
sources/Form/Field/HiddenField.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of HiddenField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class HiddenField extends TextField
|
||||
{
|
||||
const DEFAULT_HIDDEN = true;
|
||||
}
|
||||
51
sources/Form/Field/ImageField.php
Normal file
51
sources/Form/Field/ImageField.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use utils;
|
||||
use Dict;
|
||||
|
||||
/**
|
||||
* Description of ImageField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class ImageField extends BlobField
|
||||
{
|
||||
public function GetDisplayValue()
|
||||
{
|
||||
if ($this->currentValue->IsEmpty())
|
||||
{
|
||||
$sValue = Dict::S('Portal:File:None');
|
||||
}
|
||||
else
|
||||
{
|
||||
$sFilename = $this->currentValue->GetFileName();
|
||||
$iSize = utils::BytesToFriendlyFormat(strlen($this->currentValue->GetData()));
|
||||
$sOpenLink = $this->GetDisplayUrl();
|
||||
$sDownloadLink = $this->GetDownloadUrl();
|
||||
|
||||
$sValue = Dict::Format('Portal:File:DisplayInfo+', $sFilename, $iSize, $sOpenLink, $sDownloadLink);
|
||||
}
|
||||
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
}
|
||||
30
sources/Form/Field/LabelField.php
Normal file
30
sources/Form/Field/LabelField.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of LabelField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class LabelField extends TextField
|
||||
{
|
||||
|
||||
}
|
||||
291
sources/Form/Field/LinkedSetField.php
Normal file
291
sources/Form/Field/LinkedSetField.php
Normal file
@@ -0,0 +1,291 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2019 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* Description of LinkedSetField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class LinkedSetField extends Field
|
||||
{
|
||||
/** @var bool DEFAULT_INDIRECT */
|
||||
const DEFAULT_INDIRECT = false;
|
||||
/** @var bool DEFAULT_DISPLAY_OPENED */
|
||||
const DEFAULT_DISPLAY_OPENED = false;
|
||||
/** @var bool DEFAULT_DISPLAY_LIMITED_ACCESS_ITEMS */
|
||||
const DEFAULT_DISPLAY_LIMITED_ACCESS_ITEMS = false;
|
||||
|
||||
/** @var string $sTargetClass */
|
||||
protected $sTargetClass;
|
||||
/** @var string $sExtKeyToRemote */
|
||||
protected $sExtKeyToRemote;
|
||||
/** @var bool $bIndirect */
|
||||
protected $bIndirect;
|
||||
/** @var bool $bDisplayOpened */
|
||||
protected $bDisplayOpened;
|
||||
/** @var bool $bDisplayLimitedAccessItems */
|
||||
protected $bDisplayLimitedAccessItems;
|
||||
/** @var array $aLimitedAccessItemIDs IDs of the items that are not visible or cannot be edited */
|
||||
protected $aLimitedAccessItemIDs;
|
||||
/** @var array $aAttributesToDisplay */
|
||||
protected $aAttributesToDisplay;
|
||||
/** @var string $sSearchEndpoint */
|
||||
protected $sSearchEndpoint;
|
||||
/** @var string $sInformationEndpoint */
|
||||
protected $sInformationEndpoint;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct($sId, Closure $onFinalizeCallback = null)
|
||||
{
|
||||
$this->sTargetClass = null;
|
||||
$this->sExtKeyToRemote = null;
|
||||
$this->bIndirect = static::DEFAULT_INDIRECT;
|
||||
$this->bDisplayOpened = static::DEFAULT_DISPLAY_OPENED;
|
||||
$this->bDisplayLimitedAccessItems = static::DEFAULT_DISPLAY_LIMITED_ACCESS_ITEMS;
|
||||
$this->aLimitedAccessItemIDs = array();
|
||||
$this->aAttributesToDisplay = array();
|
||||
$this->sSearchEndpoint = null;
|
||||
$this->sInformationEndpoint = null;
|
||||
|
||||
parent::__construct($sId, $onFinalizeCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetTargetClass()
|
||||
{
|
||||
return $this->sTargetClass;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sTargetClass
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetTargetClass($sTargetClass)
|
||||
{
|
||||
$this->sTargetClass = $sTargetClass;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetExtKeyToRemote()
|
||||
{
|
||||
return $this->sExtKeyToRemote;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sExtKeyToRemote
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetExtKeyToRemote($sExtKeyToRemote)
|
||||
{
|
||||
$this->sExtKeyToRemote = $sExtKeyToRemote;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function IsIndirect()
|
||||
{
|
||||
return $this->bIndirect;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $bIndirect
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetIndirect($bIndirect)
|
||||
{
|
||||
$this->bIndirect = $bIndirect;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the field should be displayed opened on initialization
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function GetDisplayOpened()
|
||||
{
|
||||
return $this->bDisplayOpened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the field should be displayed opened on initialization
|
||||
*
|
||||
* @param $bDisplayOpened
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetDisplayOpened($bDisplayOpened)
|
||||
{
|
||||
$this->bDisplayOpened = $bDisplayOpened;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the field should display limited access items
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function GetDisplayLimitedAccessItems()
|
||||
{
|
||||
return $this->bDisplayLimitedAccessItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the field should display limited access items
|
||||
*
|
||||
* @param boolean $bDisplayLimitedAccessItems
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetDisplayLimitedAccessItems($bDisplayLimitedAccessItems)
|
||||
{
|
||||
$this->bDisplayLimitedAccessItems = $bDisplayLimitedAccessItems;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns IDs of the linked items with a limited access (not visible or not editable)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetLimitedAccessItemIDs()
|
||||
{
|
||||
return $this->aLimitedAccessItemIDs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the IDs of items with a limited access (not visible ot no editable)
|
||||
*
|
||||
* @param array $aLimitedAccessItemIDs
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLimitedAccessItemIDs($aLimitedAccessItemIDs)
|
||||
{
|
||||
$this->aLimitedAccessItemIDs = $aLimitedAccessItemIDs;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash array of attributes to be displayed in the linkedset in the form $sAttCode => $sAttLabel
|
||||
*
|
||||
* @param boolean $bAttCodesOnly If set to true, will return only the attcodes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetAttributesToDisplay($bAttCodesOnly = false)
|
||||
{
|
||||
return ($bAttCodesOnly) ? array_keys($this->aAttributesToDisplay) : $this->aAttributesToDisplay;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $aAttributesToDisplay
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetAttributesToDisplay(array $aAttributesToDisplay)
|
||||
{
|
||||
$this->aAttributesToDisplay = $aAttributesToDisplay;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function GetSearchEndpoint()
|
||||
{
|
||||
return $this->sSearchEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSearchEndpoint
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetSearchEndpoint($sSearchEndpoint)
|
||||
{
|
||||
$this->sSearchEndpoint = $sSearchEndpoint;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function GetInformationEndpoint()
|
||||
{
|
||||
return $this->sInformationEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sInformationEndpoint
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetInformationEndpoint($sInformationEndpoint)
|
||||
{
|
||||
$this->sInformationEndpoint = $sInformationEndpoint;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the remote object with $iItemID ID has limited access
|
||||
*
|
||||
* @param int $iItemID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function IsLimitedAccessItem($iItemID)
|
||||
{
|
||||
return in_array($iItemID, $this->aLimitedAccessItemIDs, false);
|
||||
}
|
||||
}
|
||||
236
sources/Form/Field/MultipleChoicesField.php
Normal file
236
sources/Form/Field/MultipleChoicesField.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* Description of MultipleChoicesField
|
||||
*
|
||||
* Choices = Set of items that can be picked
|
||||
* Values = Items that have been picked
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @since 2.3.0
|
||||
*/
|
||||
abstract class MultipleChoicesField extends Field
|
||||
{
|
||||
/** @var bool DEFAULT_MULTIPLE_VALUES_ENABLED */
|
||||
const DEFAULT_MULTIPLE_VALUES_ENABLED = false;
|
||||
|
||||
/** @var bool $bMultipleValuesEnabled */
|
||||
protected $bMultipleValuesEnabled;
|
||||
/** @var array $aChoices */
|
||||
protected $aChoices;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct($sId, Closure $onFinalizeCallback = null)
|
||||
{
|
||||
parent::__construct($sId, $onFinalizeCallback);
|
||||
$this->bMultipleValuesEnabled = static::DEFAULT_MULTIPLE_VALUES_ENABLED;
|
||||
$this->aChoices = array();
|
||||
$this->currentValue = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetCurrentValue()
|
||||
{
|
||||
$value = null;
|
||||
if (!empty($this->currentValue))
|
||||
{
|
||||
if ($this->bMultipleValuesEnabled)
|
||||
{
|
||||
$value = $this->currentValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
reset($this->currentValue);
|
||||
$value = current($this->currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current value for the MultipleChoicesField.
|
||||
*
|
||||
* @param mixed $currentValue Can be either an array of values (in case of multiple values) or just a simple value
|
||||
* @return $this
|
||||
*/
|
||||
public function SetCurrentValue($currentValue)
|
||||
{
|
||||
if (is_array($currentValue))
|
||||
{
|
||||
$this->currentValue = $currentValue;
|
||||
}
|
||||
elseif (is_null($currentValue))
|
||||
{
|
||||
$this->currentValue = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->currentValue = array($currentValue);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function GetMultipleValuesEnabled()
|
||||
{
|
||||
return $this->bMultipleValuesEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bMultipleValuesEnabled
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMultipleValuesEnabled($bMultipleValuesEnabled)
|
||||
{
|
||||
$this->bMultipleValuesEnabled = $bMultipleValuesEnabled;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aValues
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetValues($aValues)
|
||||
{
|
||||
$this->currentValue = $aValues;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddValue($value)
|
||||
{
|
||||
$this->currentValue = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveValue($value)
|
||||
{
|
||||
if (array_key_exists($value, $this->currentValue))
|
||||
{
|
||||
unset($this->currentValue[$value]);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function IsAmongValues($value)
|
||||
{
|
||||
return in_array($value, $this->currentValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetChoices()
|
||||
{
|
||||
return $this->aChoices;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aChoices
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetChoices($aChoices)
|
||||
{
|
||||
$this->aChoices = $aChoices;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sId
|
||||
* @param null $choice
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function AddChoice($sId, $choice = null)
|
||||
{
|
||||
if ($choice === null)
|
||||
{
|
||||
$choice = $sId;
|
||||
}
|
||||
$this->aChoices[$sId] = $choice;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sId
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function RemoveChoice($sId)
|
||||
{
|
||||
if (in_array($sId, $this->aChoices))
|
||||
{
|
||||
unset($this->aChoices[$sId]);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function Validate()
|
||||
{
|
||||
$this->SetValid(true);
|
||||
$this->EmptyErrorMessages();
|
||||
|
||||
foreach ($this->GetValidators() as $oValidator)
|
||||
{
|
||||
foreach ($this->currentValue as $value)
|
||||
{
|
||||
if (!preg_match($oValidator->GetRegExp(true), $value))
|
||||
{
|
||||
$this->SetValid(false);
|
||||
$this->AddErrorMessage($oValidator->GetErrorMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->GetValid();
|
||||
}
|
||||
|
||||
}
|
||||
31
sources/Form/Field/MultipleSelectField.php
Normal file
31
sources/Form/Field/MultipleSelectField.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of MultipleSelectField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class MultipleSelectField extends SelectField
|
||||
{
|
||||
const DEFAULT_MULTIPLE_VALUES_ENABLED = true;
|
||||
|
||||
}
|
||||
30
sources/Form/Field/PasswordField.php
Normal file
30
sources/Form/Field/PasswordField.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of PasswordField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class PasswordField extends TextField
|
||||
{
|
||||
|
||||
}
|
||||
45
sources/Form/Field/PhoneField.php
Normal file
45
sources/Form/Field/PhoneField.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Str;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* Description of PhoneField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class PhoneField extends StringField
|
||||
{
|
||||
public function GetDisplayValue()
|
||||
{
|
||||
$sLabel = Str::pure2html($this->currentValue);
|
||||
if (strlen($sLabel) > 128)
|
||||
{
|
||||
// Truncate the length to 128 characters, by removing the middle
|
||||
$sLabel = substr($sLabel, 0, 100).'.....'.substr($sLabel, -20);
|
||||
}
|
||||
|
||||
$sUrlDecorationClass = utils::GetConfig()->Get('phone_number_decoration_class');
|
||||
|
||||
return "<a class=\"tel\" href=\"tel:$this->currentValue\"><span class=\"form_field_decoration text_decoration $sUrlDecorationClass\"></span>$sLabel</a>";
|
||||
}
|
||||
}
|
||||
31
sources/Form/Field/RadioField.php
Normal file
31
sources/Form/Field/RadioField.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of RadioField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class RadioField extends MultipleChoicesField
|
||||
{
|
||||
const DEFAULT_MULTIPLE_VALUES_ENABLED = false;
|
||||
|
||||
}
|
||||
104
sources/Form/Field/SelectField.php
Normal file
104
sources/Form/Field/SelectField.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Closure;
|
||||
use Dict;
|
||||
|
||||
/**
|
||||
* Description of SelectField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class SelectField extends MultipleChoicesField
|
||||
{
|
||||
// Overloaded constants
|
||||
const DEFAULT_MULTIPLE_VALUES_ENABLED = false;
|
||||
|
||||
/** @var string DEFAULT_NULL_CHOICE_LABEL */
|
||||
const DEFAULT_NULL_CHOICE_LABEL = 'UI:SelectOne';
|
||||
/** @var bool DEFAULT_STARTS_WITH_NULL_CHOICE */
|
||||
const DEFAULT_STARTS_WITH_NULL_CHOICE = true;
|
||||
|
||||
/** @var bool $bStartsWithNullChoice */
|
||||
protected $bStartsWithNullChoice;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct($sId, Closure $onFinalizeCallback = null)
|
||||
{
|
||||
parent::__construct($sId, $onFinalizeCallback);
|
||||
$this->bStartsWithNullChoice = static::DEFAULT_STARTS_WITH_NULL_CHOICE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the select starts with a dummy choice before its choices.
|
||||
* This can be useful when you want to force the user to explicitly select a choice.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function GetStartsWithNullChoice()
|
||||
{
|
||||
return $this->bStartsWithNullChoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bStartsWithNullChoice
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetStartsWithNullChoice($bStartsWithNullChoice)
|
||||
{
|
||||
$this->bStartsWithNullChoice = $bStartsWithNullChoice;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field choices with null choice first
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetChoices()
|
||||
{
|
||||
$aChoices = parent::GetChoices();
|
||||
if ($this->bStartsWithNullChoice && !array_key_exists(null, $aChoices))
|
||||
{
|
||||
$aChoices = array(null => Dict::S(static::DEFAULT_NULL_CHOICE_LABEL)) + $aChoices;
|
||||
}
|
||||
|
||||
return $aChoices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloads the method to prevent changing this property.
|
||||
*
|
||||
* @param boolean $bMultipleValuesEnabled
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMultipleValuesEnabled($bMultipleValuesEnabled)
|
||||
{
|
||||
// We don't allow changing this value
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
238
sources/Form/Field/SelectObjectField.php
Normal file
238
sources/Form/Field/SelectObjectField.php
Normal file
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2019 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use BinaryExpression;
|
||||
use Closure;
|
||||
use Combodo\iTop\Form\Validator\NotEmptyExtKeyValidator;
|
||||
use DBObjectSet;
|
||||
use DBSearch;
|
||||
use FieldExpression;
|
||||
use ScalarExpression;
|
||||
|
||||
/**
|
||||
* Description of SelectObjectField
|
||||
*
|
||||
* @author Romain Quetiez <romain.quetiez@combodo.com>
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class SelectObjectField extends Field
|
||||
{
|
||||
/** @var int CONTROL_SELECT */
|
||||
const CONTROL_SELECT = 1;
|
||||
/** @var int CONTROL_RADIO_VERTICAL */
|
||||
const CONTROL_RADIO_VERTICAL = 2;
|
||||
|
||||
/** @var \DBSearch $oSearch */
|
||||
protected $oSearch;
|
||||
/** @var int $iMaximumComboLength */
|
||||
protected $iMaximumComboLength;
|
||||
/** @var int $iMinAutoCompleteChars */
|
||||
protected $iMinAutoCompleteChars;
|
||||
/** @var bool $bHierarchical */
|
||||
protected $bHierarchical;
|
||||
/** @var int $iControlType */
|
||||
protected $iControlType;
|
||||
/** @var string $sSearchEndpoint */
|
||||
protected $sSearchEndpoint;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct($sId, Closure $onFinalizeCallback = null)
|
||||
{
|
||||
parent::__construct($sId, $onFinalizeCallback);
|
||||
$this->oSearch = null;
|
||||
$this->iMaximumComboLength = null;
|
||||
$this->iMinAutoCompleteChars = 3;
|
||||
$this->bHierarchical = false;
|
||||
$this->iControlType = self::CONTROL_SELECT;
|
||||
$this->sSearchEndpoint = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DBSearch $oSearch
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetSearch(DBSearch $oSearch)
|
||||
{
|
||||
$this->oSearch = $oSearch;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iMaximumComboLength
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMaximumComboLength($iMaximumComboLength)
|
||||
{
|
||||
$this->iMaximumComboLength = $iMaximumComboLength;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iMinAutoCompleteChars
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetMinAutoCompleteChars($iMinAutoCompleteChars)
|
||||
{
|
||||
$this->iMinAutoCompleteChars = $iMinAutoCompleteChars;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bHierarchical
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetHierarchical($bHierarchical)
|
||||
{
|
||||
$this->bHierarchical = $bHierarchical;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $iControlType
|
||||
*/
|
||||
public function SetControlType($iControlType)
|
||||
{
|
||||
$this->iControlType = $iControlType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSearchEndpoint
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetSearchEndpoint($sSearchEndpoint)
|
||||
{
|
||||
$this->sSearchEndpoint = $sSearchEndpoint;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function SetMandatory($bMandatory)
|
||||
{
|
||||
// Before changing the property, we check if it was already mandatory. If not, we had the mandatory validator
|
||||
if ($bMandatory && !$this->bMandatory)
|
||||
{
|
||||
$this->AddValidator(new NotEmptyExtKeyValidator());
|
||||
}
|
||||
|
||||
if (!$bMandatory)
|
||||
{
|
||||
foreach ($this->aValidators as $iKey => $oValue)
|
||||
{
|
||||
if ($oValue::Getname() === NotEmptyExtKeyValidator::GetName())
|
||||
{
|
||||
unset($this->aValidators[$iKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->bMandatory = $bMandatory;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DBSearch
|
||||
*/
|
||||
public function GetSearch()
|
||||
{
|
||||
return $this->oSearch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function GetMaximumComboLength()
|
||||
{
|
||||
return $this->iMaximumComboLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function GetMinAutoCompleteChars()
|
||||
{
|
||||
return $this->iMinAutoCompleteChars;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function GetHierarchical()
|
||||
{
|
||||
return $this->bHierarchical;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function GetControlType()
|
||||
{
|
||||
return $this->iControlType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function GetSearchEndpoint()
|
||||
{
|
||||
return $this->sSearchEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets current value if not among allowed ones.
|
||||
* By default, reset is done ONLY when the field is not read-only.
|
||||
*
|
||||
* @param boolean $bAlways Set to true to verify even when the field is read-only.
|
||||
*
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function VerifyCurrentValue($bAlways = false)
|
||||
{
|
||||
if (!$this->GetReadOnly() || $bAlways)
|
||||
{
|
||||
$oValuesScope = $this->GetSearch()->DeepClone();
|
||||
$oBinaryExp = new BinaryExpression(new FieldExpression('id', $oValuesScope->GetClassAlias()), '=',
|
||||
new ScalarExpression($this->currentValue));
|
||||
$oValuesScope->AddConditionExpression($oBinaryExp);
|
||||
$oValuesSet = new DBObjectSet($oValuesScope);
|
||||
|
||||
if ($oValuesSet->Count() === 0)
|
||||
{
|
||||
$this->currentValue = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
30
sources/Form/Field/SetField.php
Normal file
30
sources/Form/Field/SetField.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of SetField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class SetField extends Field
|
||||
{
|
||||
|
||||
}
|
||||
25
sources/Form/Field/StringField.php
Normal file
25
sources/Form/Field/StringField.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
class StringField extends TextField
|
||||
{
|
||||
|
||||
}
|
||||
194
sources/Form/Field/SubFormField.php
Normal file
194
sources/Form/Field/SubFormField.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use \Closure;
|
||||
use \Combodo\iTop\Form\Form;
|
||||
|
||||
/**
|
||||
* Description of SubFormField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class SubFormField extends Field
|
||||
{
|
||||
protected $oForm;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param string $sId
|
||||
* @param \Closure $onFinalizeCallback
|
||||
*/
|
||||
public function __construct($sId, Closure $onFinalizeCallback = null)
|
||||
{
|
||||
$this->oForm = new Form('subform_' . $sId);
|
||||
parent::__construct($sId, $onFinalizeCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
public function GetForm()
|
||||
{
|
||||
return $this->oForm;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Combodo\iTop\Form\Form $oForm
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Field\SubFormField
|
||||
*/
|
||||
public function SetForm(Form $oForm)
|
||||
{
|
||||
$this->oForm = $oForm;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the validators to see if the field's current value is valid.
|
||||
* Then sets $bValid and $aErrorMessages.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function Validate()
|
||||
{
|
||||
return $this->oForm->Validate();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function GetValid()
|
||||
{
|
||||
return $this->oForm->GetValid();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetErrorMessages()
|
||||
{
|
||||
$aRet = array();
|
||||
foreach ($this->oForm->GetErrorMessages() as $sSubFieldId => $aSubFieldMessages)
|
||||
{
|
||||
$aRet[] = $sSubFieldId.': '.implode(', ', $aSubFieldMessages);
|
||||
}
|
||||
return $aRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetCurrentValue()
|
||||
{
|
||||
return $this->oForm->GetCurrentValues();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $value
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Field\SubFormField
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function SetCurrentValue($value)
|
||||
{
|
||||
$this->oForm->SetCurrentValues($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mandatory flag on all the fields on the form
|
||||
*
|
||||
* @param boolean $bMandatory
|
||||
*/
|
||||
public function SetMandatory($bMandatory)
|
||||
{
|
||||
foreach ($this->oForm->GetFields() as $oField)
|
||||
{
|
||||
$oField->SetMandatory($bMandatory);
|
||||
}
|
||||
parent::SetMandatory($bMandatory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the read-only flag on all the fields on the form
|
||||
*
|
||||
* @param boolean $bReadOnly
|
||||
*/
|
||||
public function SetReadOnly($bReadOnly)
|
||||
{
|
||||
foreach ($this->oForm->GetFields() as $oField)
|
||||
{
|
||||
$oField->SetReadOnly($bReadOnly);
|
||||
$oField->SetMandatory(false);
|
||||
}
|
||||
parent::SetReadOnly($bReadOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hidden flag on all the fields on the form
|
||||
*
|
||||
* @param boolean $bHidden
|
||||
*/
|
||||
public function SetHidden($bHidden)
|
||||
{
|
||||
foreach ($this->oForm->GetFields() as $oField)
|
||||
{
|
||||
$oField->SetHidden($bHidden);
|
||||
}
|
||||
parent::SetHidden($bHidden);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sFormPath
|
||||
* @return Form|null
|
||||
*/
|
||||
public function FindSubForm($sFormPath)
|
||||
{
|
||||
return $this->oForm->FindSubForm($sFormPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function OnFinalize()
|
||||
{
|
||||
$sFormId = 'subform_' . $this->sId;
|
||||
if ($this->sFormPath !== null)
|
||||
{
|
||||
$sFormId = $this->sFormPath . '-' . $sFormId;
|
||||
}
|
||||
$this->oForm->SetId($sFormId);
|
||||
|
||||
// Calling first the field callback,
|
||||
// Then only calling finalize on the subform's fields
|
||||
parent::OnFinalize();
|
||||
$this->oForm->Finalize();
|
||||
}
|
||||
|
||||
}
|
||||
30
sources/Form/Field/TagSetField.php
Normal file
30
sources/Form/Field/TagSetField.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of TagSetField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class TagSetField extends Field
|
||||
{
|
||||
|
||||
}
|
||||
128
sources/Form/Field/TextAreaField.php
Normal file
128
sources/Form/Field/TextAreaField.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Closure;
|
||||
use DBObject;
|
||||
use InlineImage;
|
||||
use AttributeText;
|
||||
|
||||
/**
|
||||
* Description of TextAreaField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
* @package \Combodo\iTop\Form\Field
|
||||
* @since 2.3.0
|
||||
*/
|
||||
class TextAreaField extends TextField
|
||||
{
|
||||
const ENUM_FORMAT_TEXT = 'text';
|
||||
const ENUM_FORMAT_HTML = 'html';
|
||||
const DEFAULT_FORMAT = 'html';
|
||||
|
||||
protected $sFormat;
|
||||
protected $oObject;
|
||||
protected $sTransactionId;
|
||||
|
||||
public function __construct($sId, Closure $onFinalizeCallback = null, DBObject $oObject = null)
|
||||
{
|
||||
parent::__construct($sId, $onFinalizeCallback);
|
||||
$this->sFormat = static::DEFAULT_FORMAT;
|
||||
$this->oObject = $oObject;
|
||||
$this->sTransactionId = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetFormat()
|
||||
{
|
||||
return $this->sFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sFormat
|
||||
* @return \Combodo\iTop\Form\Field\TextAreaField
|
||||
*/
|
||||
public function SetFormat($sFormat)
|
||||
{
|
||||
$this->sFormat = $sFormat;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return DBObject
|
||||
*/
|
||||
public function GetObject()
|
||||
{
|
||||
return $this->oObject;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param DBObject $oObject
|
||||
* @return \Combodo\iTop\Form\Field\TextAreaField
|
||||
*/
|
||||
public function SetObject(DBObject $oObject)
|
||||
{
|
||||
$this->oObject = $oObject;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the transaction id for the field. This is usally used/setted when using a html format that allows upload of files/images
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetTransactionId()
|
||||
{
|
||||
return $this->sTransactionId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sTransactionId
|
||||
* @return \Combodo\iTop\Form\Field\TextAreaField
|
||||
*/
|
||||
public function SetTransactionId($sTransactionId)
|
||||
{
|
||||
$this->sTransactionId = $sTransactionId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetDisplayValue()
|
||||
{
|
||||
if ($this->GetFormat() == TextAreaField::ENUM_FORMAT_TEXT)
|
||||
{
|
||||
$sValue = \Str::pure2html($this->GetCurrentValue());
|
||||
$sValue = AttributeText::RenderWikiHtml($sValue);
|
||||
return "<div>".str_replace("\n", "<br>\n", $sValue).'</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sValue = AttributeText::RenderWikiHtml($this->GetCurrentValue(), true /* wiki only */);
|
||||
return "<div class=\"HTML\">".InlineImage::FixUrls($sValue).'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
30
sources/Form/Field/TextField.php
Normal file
30
sources/Form/Field/TextField.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
/**
|
||||
* Description of TextField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
abstract class TextField extends Field
|
||||
{
|
||||
|
||||
}
|
||||
67
sources/Form/Field/UrlField.php
Normal file
67
sources/Form/Field/UrlField.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Str;
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* Description of UrlField
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class UrlField extends StringField
|
||||
{
|
||||
const DEFAULT_TARGET = '_blank';
|
||||
|
||||
protected $sTarget;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param string $sId
|
||||
* @param \Closure $onFinalizeCallback (Used in the $oForm->AddField($sId, ..., function() use ($oManager, $oForm, '...') { ... } ); )
|
||||
*/
|
||||
public function __construct($sId, Closure $onFinalizeCallback = null)
|
||||
{
|
||||
parent::__construct($sId, $onFinalizeCallback);
|
||||
|
||||
$this->sTarget = static::DEFAULT_TARGET;
|
||||
}
|
||||
|
||||
public function SetTarget($sTarget)
|
||||
{
|
||||
$this->sTarget = $sTarget;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetDisplayValue()
|
||||
{
|
||||
$sLabel = Str::pure2html($this->currentValue);
|
||||
if (strlen($sLabel) > 128)
|
||||
{
|
||||
// Truncate the length to 128 characters, by removing the middle
|
||||
$sLabel = substr($sLabel, 0, 100).'.....'.substr($sLabel, -20);
|
||||
}
|
||||
|
||||
return "<a target=\"$this->sTarget\" href=\"$this->currentValue\">$sLabel</a>";
|
||||
}
|
||||
}
|
||||
584
sources/Form/Form.php
Normal file
584
sources/Form/Form.php
Normal file
@@ -0,0 +1,584 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form;
|
||||
|
||||
use \Exception;
|
||||
use \Dict;
|
||||
use \Combodo\iTop\Form\Field\Field;
|
||||
use \Combodo\iTop\Form\Field\CaseLogField;
|
||||
use \Combodo\iTop\Form\Field\SubFormField;
|
||||
|
||||
/**
|
||||
* Description of Form
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class Form
|
||||
{
|
||||
protected $sId;
|
||||
protected $sTransactionId;
|
||||
protected $aFields;
|
||||
protected $aDependencies;
|
||||
protected $bValid;
|
||||
protected $aErrorMessages;
|
||||
protected $iEditableFieldCount;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param string $sId
|
||||
*/
|
||||
public function __construct($sId)
|
||||
{
|
||||
$this->sId = $sId;
|
||||
$this->sTransactionId = null;
|
||||
$this->aFields = array();
|
||||
$this->aDependencies = array();
|
||||
$this->bValid = true;
|
||||
$this->aErrorMessages = array();
|
||||
$this->iEditableFieldCount = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetId()
|
||||
{
|
||||
return $this->sId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sId
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
public function SetId($sId)
|
||||
{
|
||||
// Setting id for the form itself
|
||||
$this->sId = $sId;
|
||||
// Then setting formpath to its fields
|
||||
foreach ($this->aFields as $oField)
|
||||
{
|
||||
$oField->SetFormPath($sId);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetTransactionId()
|
||||
{
|
||||
return $this->sTransactionId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sTransactionId
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
public function SetTransactionId($sTransactionId)
|
||||
{
|
||||
$this->sTransactionId = $sTransactionId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetFields()
|
||||
{
|
||||
return $this->aFields;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetDependencies()
|
||||
{
|
||||
return $this->aDependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash array of "Field id" => "Field value"
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetCurrentValues()
|
||||
{
|
||||
$aValues = array();
|
||||
foreach ($this->aFields as $sId => $oField)
|
||||
{
|
||||
$aValues[$sId] = $oField->GetCurrentValue();
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $aValues Must be a hash array of "Field id" => "Field value"
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function SetCurrentValues($aValues)
|
||||
{
|
||||
foreach ($aValues as $sId => $value)
|
||||
{
|
||||
$oField = $this->GetField($sId);
|
||||
$oField->SetCurrentValue($value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current validation state of the form (true|false).
|
||||
* It DOESN'T make the validation, see Validate() instead.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function GetValid()
|
||||
{
|
||||
return $this->bValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note : Function is protected as bValid should not be set from outside
|
||||
*
|
||||
* @param boolean $bValid
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
protected function SetValid($bValid)
|
||||
{
|
||||
$this->bValid = $bValid;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetErrorMessages()
|
||||
{
|
||||
return $this->aErrorMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note : Function is protected as aErrorMessages should not be set from outside
|
||||
*
|
||||
* @param array $aErrorMessages
|
||||
* @param string $sFieldId
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
protected function SetErrorMessages($aErrorMessages, $sFieldId = null)
|
||||
{
|
||||
if ($sFieldId === null)
|
||||
{
|
||||
$this->aErrorMessages = $aErrorMessages;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->aErrorMessages[$sFieldId] = $aErrorMessages;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* If $sFieldId is not set, the $sErrorMessage will be added to the general form messages
|
||||
*
|
||||
* Note : Function is protected as aErrorMessages should not be add from outside
|
||||
*
|
||||
* @param string $sErrorMessage
|
||||
* @param string $sFieldId
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
protected function AddErrorMessage($sErrorMessage, $sFieldId = '_main')
|
||||
{
|
||||
if (!isset($this->aErrorMessages[$sFieldId]))
|
||||
{
|
||||
$this->aErrorMessages[$sFieldId] = array();
|
||||
}
|
||||
$this->aErrorMessages[$sFieldId][] = $sErrorMessage;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note : Function is protected as aErrorMessages should not be set from outside
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
protected function EmptyErrorMessages()
|
||||
{
|
||||
$this->aErrorMessages = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sId
|
||||
* @return \Combodo\iTop\Form\Field\Field
|
||||
* @throws Exception
|
||||
*/
|
||||
public function GetField($sId)
|
||||
{
|
||||
if (!array_key_exists($sId, $this->aFields))
|
||||
{
|
||||
throw new Exception('Field with ID "' . $sId . '" was not found in the Form of ID "' . $this->sId . '".');
|
||||
}
|
||||
return $this->aFields[$sId];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sId
|
||||
* @return boolean
|
||||
*/
|
||||
public function HasField($sId)
|
||||
{
|
||||
return array_key_exists($sId, $this->aFields);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Combodo\iTop\Form\Field\Field $oField
|
||||
* @param array $aDependsOnIds
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
public function AddField(Field $oField, $aDependsOnIds = array())
|
||||
{
|
||||
$oField->SetFormPath($this->sId);
|
||||
$this->aFields[$oField->GetId()] = $oField;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sId
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
public function RemoveField($sId)
|
||||
{
|
||||
if (array_key_exists($sId, $this->aFields))
|
||||
{
|
||||
unset($this->aFields[$sId]);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a array (list) of the fields ordered by their dependencies.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetOrderedFields()
|
||||
{
|
||||
// TODO : Do this so it flatten the array
|
||||
return $this->aFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of field ids the $sFieldId depends on.
|
||||
*
|
||||
* @param string $sFieldId
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function GetFieldDependencies($sFieldId)
|
||||
{
|
||||
if (!array_key_exists($sFieldId, $this->aDependencies))
|
||||
{
|
||||
throw new Exception('Field with ID "' . $sFieldId . '" had no dependancies declared in the Form.');
|
||||
}
|
||||
return $this->aDependencies[$sFieldId];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sFieldId
|
||||
* @param array $aDependsOnIds
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
public function AddFieldDependencies($sFieldId, array $aDependsOnIds)
|
||||
{
|
||||
foreach ($aDependsOnIds as $sDependsOnId)
|
||||
{
|
||||
$this->AddFieldDependency($sFieldId, $sDependsOnId);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sFieldId
|
||||
* @param string $sDependsOnId
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
public function AddFieldDependency($sFieldId, $sDependsOnId)
|
||||
{
|
||||
if (!array_key_exists($sFieldId, $this->aDependencies))
|
||||
{
|
||||
$this->aDependencies[$sFieldId] = array();
|
||||
}
|
||||
$this->aDependencies[$sFieldId][] = $sDependsOnId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash array of the fields impacts on other fields. Key being the field that impacts the fields stored in the value as a regular array
|
||||
* (It kind of reversed the dependencies array)
|
||||
*
|
||||
* eg :
|
||||
* - 'service' => array('subservice', 'template')
|
||||
* - 'subservice' => array()
|
||||
* - ...
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetFieldsImpacts()
|
||||
{
|
||||
$aRes = array();
|
||||
|
||||
foreach ($this->aDependencies as $sImpactedFieldId => $aDependentFieldsIds)
|
||||
{
|
||||
foreach ($aDependentFieldsIds as $sDependentFieldId)
|
||||
{
|
||||
if (!array_key_exists($sDependentFieldId, $aRes))
|
||||
{
|
||||
$aRes[$sDependentFieldId] = array();
|
||||
}
|
||||
$aRes[$sDependentFieldId][] = $sImpactedFieldId;
|
||||
}
|
||||
}
|
||||
|
||||
return $aRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of editable fields in this form.
|
||||
*
|
||||
* @param bool $bForce
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function GetEditableFieldCount($bForce = false)
|
||||
{
|
||||
// Count is usally done by the Finalize function but it can be done there if Finalize hasn't been called yet or if we choose to force it.
|
||||
if (($this->iEditableFieldCount === null) || ($bForce === true))
|
||||
{
|
||||
$this->iEditableFieldCount = 0;
|
||||
foreach ($this->aFields as $oField)
|
||||
{
|
||||
if ($oField->IsEditable())
|
||||
{
|
||||
$this->iEditableFieldCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->iEditableFieldCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the form has at least one editable field
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function HasEditableFields()
|
||||
{
|
||||
return ($this->GetEditableFieldCount() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the form has at least one editable field
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function HasVisibleFields()
|
||||
{
|
||||
$bRet = false;
|
||||
foreach ($this->aFields as $oField)
|
||||
{
|
||||
if (!$oField->GetHidden())
|
||||
{
|
||||
$bRet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $bRet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the form to a read only state by setting read only to true on all its fields
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
public function MakeReadOnly()
|
||||
{
|
||||
foreach ($this->GetFields() as $oField)
|
||||
{
|
||||
$oField->SetReadOnly(true);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sFormPath
|
||||
* @return Form|null
|
||||
*/
|
||||
public function FindSubForm($sFormPath)
|
||||
{
|
||||
$ret = null;
|
||||
if ($sFormPath == $this->sId)
|
||||
{
|
||||
$ret = $this;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($this->aFields as $oField)
|
||||
{
|
||||
if ($oField instanceof SubFormField)
|
||||
{
|
||||
$ret = $oField->FindSubForm($sFormPath);
|
||||
if ($ret !== null) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets CaseLog fields value in the form and its sub-forms
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
public function ResetCaseLogFields()
|
||||
{
|
||||
foreach($this->GetFields() as $oField)
|
||||
{
|
||||
if($oField instanceof CaseLogField)
|
||||
{
|
||||
$oField->SetCurrentValue(null);
|
||||
}
|
||||
elseif($oField instanceof SubFormField)
|
||||
{
|
||||
$oField->GetForm()->ResetCaseLogFields();
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalizes each field, following the dependencies so that a field can compute its value or other properties,
|
||||
* depending on other fields
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function Finalize()
|
||||
{
|
||||
$aFieldList = array(); // Fields ordered by dependence
|
||||
// Clone the dependency data : $aDependencies will be truncated as the fields are added to the list
|
||||
$aDependencies = $this->aDependencies;
|
||||
$bMadeProgress = true; // Safety net in case of circular references
|
||||
|
||||
foreach ($aDependencies as $sImpactedBy => $aSomeFields)
|
||||
{
|
||||
foreach ($aSomeFields as $i => $sSomeId)
|
||||
{
|
||||
if (!array_key_exists($sSomeId, $this->aFields))
|
||||
{
|
||||
throw new Exception('Unmet dependency : Field ' . $sImpactedBy . ' expecting field ' . $sSomeId . ' which is not in the Form');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ($bMadeProgress && count($aFieldList) < count($this->aFields))
|
||||
{
|
||||
$bMadeProgress = false;
|
||||
foreach ($this->aFields as $sId => $oField)
|
||||
{
|
||||
if (array_key_exists($sId, $aFieldList))
|
||||
continue;
|
||||
if (isset($aDependencies[$sId]) && count($aDependencies[$sId]) > 0) continue;
|
||||
// Add the field at the end of the list
|
||||
$aFieldList[$sId] = $oField;
|
||||
$bMadeProgress = true;
|
||||
|
||||
// Track that this dependency has been solved
|
||||
foreach ($aDependencies as $sImpactedBy => $aSomeFields)
|
||||
{
|
||||
foreach ($aSomeFields as $i => $sSomeId)
|
||||
{
|
||||
if ($sSomeId == $sId)
|
||||
{
|
||||
unset($aDependencies[$sImpactedBy][$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$bMadeProgress)
|
||||
{
|
||||
throw new Exception('Unmet dependencies (might be a circular reference) : ' . implode(', ', array_keys($aDependencies)));
|
||||
}
|
||||
foreach ($aFieldList as $sId => $oField)
|
||||
{
|
||||
$oField->OnFinalize();
|
||||
if ($oField->IsEditable())
|
||||
{
|
||||
$this->iEditableFieldCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the form and return if it's valid or not
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function Validate()
|
||||
{
|
||||
$this->SetValid(true);
|
||||
$this->EmptyErrorMessages();
|
||||
|
||||
foreach ($this->aFields as $oField)
|
||||
{
|
||||
if (!$oField->Validate())
|
||||
{
|
||||
$this->SetValid(false);
|
||||
foreach ($oField->GetErrorMessages() as $sErrorMessage)
|
||||
{
|
||||
$this->AddErrorMessage(Dict::S($sErrorMessage), $oField->Getid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->GetValid();
|
||||
}
|
||||
|
||||
}
|
||||
173
sources/Form/FormManager.php
Normal file
173
sources/Form/FormManager.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Form;
|
||||
|
||||
use Combodo\iTop\Renderer\FormRenderer;
|
||||
|
||||
/**
|
||||
* Description of formmanager
|
||||
*
|
||||
* @package Combodo\iTop\Form
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
abstract class FormManager
|
||||
{
|
||||
/** @var \Combodo\iTop\Form\Form $oForm */
|
||||
protected $oForm;
|
||||
/** @var \Combodo\iTop\Renderer\FormRenderer $oRenderer */
|
||||
protected $oRenderer;
|
||||
|
||||
/**
|
||||
* Creates an instance of \Combodo\iTop\Form\FormManager from JSON data that must contain at least :
|
||||
* - formrenderer_class : The class of the FormRenderer to use in the FormManager
|
||||
* - formrenderer_endpoint : The endpoint of the renderer
|
||||
*
|
||||
* @param string $sJson
|
||||
* @return $this
|
||||
*/
|
||||
static function FromJSON($sJson)
|
||||
{
|
||||
// Overload in child class when needed
|
||||
if (is_array($sJson))
|
||||
{
|
||||
$aJson = $sJson;
|
||||
}
|
||||
else
|
||||
{
|
||||
$aJson = json_decode($sJson, true);
|
||||
}
|
||||
|
||||
$oFormManager = new static();
|
||||
|
||||
$sFormRendererClass = $aJson['formrenderer_class'];
|
||||
/** @var \Combodo\iTop\Renderer\FormRenderer $oFormRenderer */
|
||||
$oFormRenderer = new $sFormRendererClass();
|
||||
$oFormRenderer->SetEndpoint($aJson['formrenderer_endpoint']);
|
||||
$oFormManager->SetRenderer($oFormRenderer);
|
||||
|
||||
$oFormManager->SetForm(new Form($aJson['id']));
|
||||
$oFormManager->GetForm()->SetTransactionId($aJson['transaction_id']);
|
||||
$oFormManager->GetRenderer()->SetForm($oFormManager->GetForm());
|
||||
|
||||
return $oFormManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* FormManager constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Overload in child class when needed
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Combodo\iTop\Form\Form
|
||||
*/
|
||||
public function GetForm()
|
||||
{
|
||||
return $this->oForm;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Combodo\iTop\Form\Form $oForm
|
||||
* @return $this
|
||||
*/
|
||||
public function SetForm(Form $oForm)
|
||||
{
|
||||
$this->oForm = $oForm;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Combodo\iTop\Renderer\FormRenderer
|
||||
*/
|
||||
public function GetRenderer()
|
||||
{
|
||||
return $this->oRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Combodo\iTop\Renderer\FormRenderer $oRenderer
|
||||
* @return $this
|
||||
*/
|
||||
public function SetRenderer(FormRenderer $oRenderer)
|
||||
{
|
||||
$this->oRenderer = $oRenderer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetClass()
|
||||
{
|
||||
return get_class($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a JSON string from the current object including :
|
||||
* - id : Id of the current Form
|
||||
* - formmanager_class
|
||||
* - formrenderer_class
|
||||
* - formrenderer_endpoint
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function ToJSON()
|
||||
{
|
||||
// Overload in child class when needed
|
||||
return array(
|
||||
'id' => $this->oForm->GetId(),
|
||||
'transaction_id' => $this->oForm->GetTransactionId(),
|
||||
'formmanager_class' => $this->GetClass(),
|
||||
'formrenderer_class' => get_class($this->GetRenderer()),
|
||||
'formrenderer_endpoint' => $this->GetRenderer()->GetEndpoint()
|
||||
);
|
||||
}
|
||||
|
||||
abstract public function Build();
|
||||
|
||||
/**
|
||||
* @param array|null $aArgs
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function OnUpdate($aArgs = null);
|
||||
|
||||
/**
|
||||
* @param array|null $aArgs
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function OnSubmit($aArgs = null);
|
||||
|
||||
/**
|
||||
* @param array|null $aArgs
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function OnCancel($aArgs = null);
|
||||
}
|
||||
33
sources/Form/Validator/IntegerValidator.php
Normal file
33
sources/Form/Validator/IntegerValidator.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Validator;
|
||||
|
||||
/**
|
||||
* Description of IntegerValidator
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class IntegerValidator extends Validator
|
||||
{
|
||||
const VALIDATOR_NAME = 'integer';
|
||||
const DEFAULT_REGEXP = '^[0-9]+$';
|
||||
const DEFAULT_ERROR_MESSAGE = 'Core:Validator:MustBeInteger';
|
||||
|
||||
}
|
||||
35
sources/Form/Validator/MandatoryValidator.php
Normal file
35
sources/Form/Validator/MandatoryValidator.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Validator;
|
||||
|
||||
/**
|
||||
* Description of MandatoryValidator
|
||||
*
|
||||
* MandatoryValidator is different than NotEmptyValidator as it doesn't apply to text input only
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class MandatoryValidator extends Validator
|
||||
{
|
||||
const VALIDATOR_NAME = 'mandatory';
|
||||
const DEFAULT_REGEXP = '.*\S.*';
|
||||
const DEFAULT_ERROR_MESSAGE = 'Core:Validator:Mandatory';
|
||||
|
||||
}
|
||||
33
sources/Form/Validator/NotEmptyExtKeyValidator.php
Normal file
33
sources/Form/Validator/NotEmptyExtKeyValidator.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Validator;
|
||||
|
||||
/**
|
||||
* Description of NotEmptyExtKeyValidator
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class NotEmptyExtKeyValidator extends Validator
|
||||
{
|
||||
const VALIDATOR_NAME = 'notemptyextkey';
|
||||
const DEFAULT_REGEXP = '^[0-9]*[1-9][0-9]*$';
|
||||
const DEFAULT_ERROR_MESSAGE = 'Core:Validator:MustSelectOne';
|
||||
|
||||
}
|
||||
117
sources/Form/Validator/Validator.php
Normal file
117
sources/Form/Validator/Validator.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
// Copyright (C) 2010-2018 Combodo SARL
|
||||
//
|
||||
// This file is part of iTop.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// iTop is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
namespace Combodo\iTop\Form\Validator;
|
||||
|
||||
/**
|
||||
* Description of Validator
|
||||
*
|
||||
* @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
|
||||
*/
|
||||
class Validator
|
||||
{
|
||||
const VALIDATOR_NAME = 'expression';
|
||||
const DEFAULT_REGEXP = '';
|
||||
const DEFAULT_ERROR_MESSAGE = 'Core:Validator:Default';
|
||||
|
||||
protected $sRegExp;
|
||||
protected $sErrorMessage;
|
||||
|
||||
public static function GetName()
|
||||
{
|
||||
return static::VALIDATOR_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sRegExp
|
||||
* @param string $sErrorMessage
|
||||
*/
|
||||
public function __construct($sRegExp = null, $sErrorMessage = null)
|
||||
{
|
||||
$this->sRegExp = ($sRegExp === null) ? static::DEFAULT_REGEXP : $sRegExp;
|
||||
$this->sErrorMessage = ($sErrorMessage === null) ? static::DEFAULT_ERROR_MESSAGE : $sErrorMessage;
|
||||
$this->ComputeConstraints();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
public function GetErrorMessage()
|
||||
{
|
||||
return $this->sErrorMessage;
|
||||
}
|
||||
|
||||
public function SetRegExp($sRegExp)
|
||||
{
|
||||
$this->sRegExp = $sRegExp;
|
||||
$this->ComputeConstraints();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function SetErrorMessage($sErrorMessage)
|
||||
{
|
||||
$this->sErrorMessage = $sErrorMessage;
|
||||
$this->ComputeConstraints();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the regular expression and error message when changing constraints on the validator.
|
||||
* Should be called in the validator's setters.
|
||||
*/
|
||||
public function ComputeConstraints()
|
||||
{
|
||||
$this->ComputeRegularExpression();
|
||||
$this->ComputeErrorMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the regular expression when changing constraints on the validator.
|
||||
*/
|
||||
public function ComputeRegularExpression()
|
||||
{
|
||||
// Overload when necessary
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the error message when changing constraints on the validator.
|
||||
*/
|
||||
public function ComputeErrorMessage()
|
||||
{
|
||||
// Overload when necessary
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user