This commit is contained in:
Molkobain
2019-08-13 17:25:04 +02:00
parent 384641e274
commit e3995a130f
4 changed files with 267 additions and 96 deletions

View File

@@ -1,20 +1,21 @@
<?php
// Copyright (C) 2010-2017 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/>
/**
* 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
*/
require_once('dbobjectiterator.php');
@@ -107,6 +108,10 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
}
}
/**
* @return \DBObjectSearch
* @throws \CoreException
*/
public function GetFilter()
{
return clone $this->oOriginalSet->GetFilter();
@@ -115,9 +120,10 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
/**
* Specify the subset of attributes to load (for each class of objects) before performing the SQL query for retrieving the rows from the DB
*
* @param hash $aAttToLoad Format: alias => array of attribute_codes
* @param array $aAttToLoad Format: alias => array of attribute_codes
*
* @return void
* @throws \CoreException
*/
public function OptimizeColumnLoad($aAttToLoad)
{
@@ -182,6 +188,11 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
}
}
/**
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
*/
protected function LoadOriginalIds()
{
if ($this->aOriginalObjects === null)
@@ -217,7 +228,12 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
/**
* Note: After calling this method, the set cursor will be at the end of the set. You might want to rewind it.
*
* @return array
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
* @throws \Exception
*/
protected function GetArrayOfIndex()
{
@@ -289,6 +305,9 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
* The total number of objects in the collection
*
* @return int
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
*/
public function Count()
{
@@ -300,7 +319,8 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
/**
* Position the cursor to the given 0-based position
*
* @param $iPosition
* @param int $iPosition
*
* @throws Exception
* @internal param int $iRow
*/
@@ -324,6 +344,9 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
* Fetch the object at the current position in the collection and move the cursor to the next position.
*
* @return DBObject|null The fetched object or null when at the end
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
*/
public function Fetch()
{
@@ -340,8 +363,14 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
/**
* Return the current element
*
* @link http://php.net/manual/en/iterator.current.php
* @return mixed Can return any type.
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
*/
public function current()
{
@@ -371,8 +400,12 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
/**
* Move forward to next element
*
* @link http://php.net/manual/en/iterator.next.php
* @return void Any returned value is ignored.
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
*/
public function next()
{
@@ -411,9 +444,13 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
/**
* Checks if current position is valid
*
* @link http://php.net/manual/en/iterator.valid.php
* @return boolean The return value will be casted to boolean and then evaluated.
* Returns true on success or false on failure.
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
*/
public function valid()
{
@@ -426,8 +463,12 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
/**
* Rewind the Iterator to the first element
*
* @link http://php.net/manual/en/iterator.rewind.php
* @return void Any returned value is ignored.
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \MySQLException
*/
public function rewind()
{
@@ -439,6 +480,9 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
reset($this->aModified);
}
/**
* @return bool
*/
public function HasDelta()
{
return $this->bHasDelta;
@@ -446,7 +490,9 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
/**
* This method has been designed specifically for AttributeLinkedSet:Equals and as such it assumes that the passed argument is a clone of this.
* @param ormLinkSet $oFellow
*
* @param \ormLinkSet $oFellow
*
* @return bool|null
* @throws Exception
*/
@@ -473,6 +519,12 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
return $bRet;
}
/**
* @param \iDBObjectSetIterator $oFellow
*
* @throws \CoreException
* @throws \Exception
*/
public function UpdateFromCompleteList(iDBObjectSetIterator $oFellow)
{
if ($oFellow === $this)
@@ -511,7 +563,7 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
$this->aPreserved = ($this->aOriginalObjects === null) ? array() : $this->aOriginalObjects;
$this->bHasDelta = false;
/** @var AttributeLinkedSet $oAttDef */
/** @var \AttributeLinkedSet|\AttributeLinkedSetIndirect $oAttDef */
$oAttDef = MetaModel::GetAttributeDef($this->sHostClass, $this->sAttCode);
$sExtKeyToMe = $oAttDef->GetExtKeyToMe();
$sAdditionalKey = null;
@@ -520,6 +572,7 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
$sAdditionalKey = $oAttDef->GetExtKeyToRemote();
}
// Compare both collections by iterating the whole sets, order them, a build a fingerprint based on meaningful data (what make the difference)
/** @var \DBObject $oLink */
$oComparator = new DBObjectSetComparator($this, $oFellow, array($sExtKeyToMe), $sAdditionalKey);
$aChanges = $oComparator->GetDifferences();
foreach ($aChanges['added'] as $oLink)
@@ -562,10 +615,21 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
/**
* @param DBObject $oHostObject
*
* @throws \ArchivedObjectException
* @throws \CoreCannotSaveObjectException
* @throws \CoreException
* @throws \CoreUnexpectedValue
* @throws \CoreWarning
* @throws \DeleteException
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
* @throws \OQLException
* @throws \Exception
*/
public function DBWrite(DBObject $oHostObject)
{
/** @var AttributeLinkedSet $oAttDef */
/** @var \AttributeLinkedSet|\AttributeLinkedSetIndirect $oAttDef */
$oAttDef = MetaModel::GetAttributeDef(get_class($oHostObject), $this->sAttCode);
$sExtKeyToMe = $oAttDef->GetExtKeyToMe();
$sExtKeyToRemote = $oAttDef->IsIndirect() ? $oAttDef->GetExtKeyToRemote() : 'n/a';
@@ -718,13 +782,24 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
$oMtx->Unlock();
}
/**
* @param bool $bShowObsolete
*
* @return \DBObjectSet
* @throws \CoreException
* @throws \CoreWarning
* @throws \MySQLException
* @throws \Exception
*/
public function ToDBObjectSet($bShowObsolete = true)
{
/** @var \AttributeLinkedSet|\AttributeLinkedSetIndirect $oAttDef */
$oAttDef = MetaModel::GetAttributeDef($this->sHostClass, $this->sAttCode);
$oLinkSearch = $this->GetFilter();
if ($oAttDef->IsIndirect())
{
$sExtKeyToRemote = $oAttDef->GetExtKeyToRemote();
/** @var \AttributeExternalKey $oLinkingAttDef */
$oLinkingAttDef = MetaModel::GetAttributeDef($this->sClass, $sExtKeyToRemote);
$sTargetClass = $oLinkingAttDef->GetTargetClass();
if (!$bShowObsolete && MetaModel::IsObsoletable($sTargetClass))
@@ -745,6 +820,7 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
{
$oLinkSet->AddObjectArray($this->aAdded);
}
return $oLinkSet;
}
}

View File

@@ -1,45 +1,61 @@
<?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/>
/**
* 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
{
const DEFAULT_INDIRECT = false;
const DEFAULT_DISPLAY_OPENED = false;
/** @var bool DEFAULT_INDIRECT */
const DEFAULT_INDIRECT = false;
/** @var bool DEFAULT_DISPLAY_OPENED */
const DEFAULT_DISPLAY_OPENED = false;
/** @var string $sTargetClass */
protected $sTargetClass;
/** @var string $sExtKeyToRemote */
protected $sExtKeyToRemote;
/** @var bool $bIndirect */
protected $bIndirect;
protected $bDisplayOpened;
/** @var bool $bDisplayOpened */
protected $bDisplayOpened;
/** @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;
public function __construct($sId, \Closure $onFinalizeCallback = null)
/**
* @inheritDoc
*/
public function __construct($sId, Closure $onFinalizeCallback = null)
{
$this->sTargetClass = null;
$this->sExtKeyToRemote = null;
@@ -65,11 +81,13 @@ class LinkedSetField extends Field
/**
*
* @param string $sTargetClass
* @return \Combodo\iTop\Form\Field\LinkedSetField
*
* @return $this
*/
public function SetTargetClass($sTargetClass)
{
$this->sTargetClass = $sTargetClass;
return $this;
}
@@ -85,11 +103,13 @@ class LinkedSetField extends Field
/**
*
* @param string $sExtKeyToRemote
* @return \Combodo\iTop\Form\Field\LinkedSetField
*
* @return $this
*/
public function SetExtKeyToRemote($sExtKeyToRemote)
{
$this->sExtKeyToRemote = $sExtKeyToRemote;
return $this;
}
@@ -105,35 +125,39 @@ class LinkedSetField extends Field
/**
*
* @param boolean $bIndirect
* @return \Combodo\iTop\Form\Field\LinkedSetField
*
* @return $this
*/
public function SetIndirect($bIndirect)
{
$this->bIndirect = $bIndirect;
return $this;
}
/**
* Returns if the field should be displayed opened on initialization
*
* @return boolean
*/
/**
* Returns if the field should be displayed opened on initialization
*
* @return boolean
*/
public function GetDisplayOpened()
{
return $this->bDisplayOpened;
}
{
return $this->bDisplayOpened;
}
/**
* Sets if the field should be displayed opened on initialization
*
* @param $bDisplayOpened
* @return \Combodo\iTop\Form\Field\LinkedSetField
*/
public function SetDisplayOpened($bDisplayOpened)
{
$this->bDisplayOpened = $bDisplayOpened;
return $this;
}
/**
* Sets if the field should be displayed opened on initialization
*
* @param $bDisplayOpened
*
* @return $this
*/
public function SetDisplayOpened($bDisplayOpened)
{
$this->bDisplayOpened = $bDisplayOpened;
return $this;
}
/**
* Returns IDs of the linked items with a limited access (not visible or not editable)
@@ -163,7 +187,7 @@ class LinkedSetField extends Field
* 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)
@@ -174,34 +198,53 @@ class LinkedSetField extends Field
/**
*
* @param array $aAttributesToDisplay
*
* @return \Combodo\iTop\Form\Field\LinkedSetField
*
* @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;
}

View File

@@ -1,21 +1,22 @@
<?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/>
/**
* 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;
@@ -31,19 +32,31 @@ use ScalarExpression;
* Description of SelectObjectField
*
* @author Romain Quetiez <romain.quetiez@combodo.com>
* @since 2.3.0
*/
class SelectObjectField extends Field
{
protected $oSearch;
protected $iMaximumComboLength;
protected $iMinAutoCompleteChars;
protected $bHierarchical;
protected $iControlType;
protected $sSearchEndpoint;
/** @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);
@@ -55,6 +68,11 @@ class SelectObjectField extends Field
$this->sSearchEndpoint = null;
}
/**
* @param \DBSearch $oSearch
*
* @return $this
*/
public function SetSearch(DBSearch $oSearch)
{
$this->oSearch = $oSearch;
@@ -62,6 +80,11 @@ class SelectObjectField extends Field
return $this;
}
/**
* @param int $iMaximumComboLength
*
* @return $this
*/
public function SetMaximumComboLength($iMaximumComboLength)
{
$this->iMaximumComboLength = $iMaximumComboLength;
@@ -69,6 +92,11 @@ class SelectObjectField extends Field
return $this;
}
/**
* @param int $iMinAutoCompleteChars
*
* @return $this
*/
public function SetMinAutoCompleteChars($iMinAutoCompleteChars)
{
$this->iMinAutoCompleteChars = $iMinAutoCompleteChars;
@@ -76,6 +104,11 @@ class SelectObjectField extends Field
return $this;
}
/**
* @param bool $bHierarchical
*
* @return $this
*/
public function SetHierarchical($bHierarchical)
{
$this->bHierarchical = $bHierarchical;
@@ -83,11 +116,19 @@ class SelectObjectField extends Field
return $this;
}
/**
* @param int $iControlType
*/
public function SetControlType($iControlType)
{
$this->iControlType = $iControlType;
}
/**
* @param string $sSearchEndpoint
*
* @return $this
*/
public function SetSearchEndpoint($sSearchEndpoint)
{
$this->sSearchEndpoint = $sSearchEndpoint;
@@ -96,12 +137,7 @@ class SelectObjectField extends Field
}
/**
* Sets if the field is mandatory or not.
* Setting the value will automatically add/remove a MandatoryValidator to the Field
*
* @param boolean $bMandatory
*
* @return \Combodo\iTop\Form\Field\Field
* @inheritDoc
*/
public function SetMandatory($bMandatory)
{
@@ -135,33 +171,48 @@ class SelectObjectField extends Field
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 is not among allowed ones.
* 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.

View File

@@ -591,6 +591,7 @@ JS
$oAttDef = MetaModel::GetAttributeDef($this->oField->GetTargetClass(), $sAttCode);
if ($oAttDef->IsExternalKey())
{
/** @var \AttributeExternalKey $oAttDef */
$aAttProperties['value'] = $oRemoteItem->Get($sAttCode . '_friendlyname');
// Checking if user can access object's external key