mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°803 - Allow display & edition of attributes on n:n relations on Portal
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
namespace Combodo\iTop\Form\Field;
|
||||
|
||||
use Closure;
|
||||
use Dict;
|
||||
use ormLinkSet;
|
||||
|
||||
/**
|
||||
* Description of LinkedSetField
|
||||
@@ -35,10 +37,12 @@ class LinkedSetField extends Field
|
||||
/** @var bool DEFAULT_DISPLAY_OPENED */
|
||||
const DEFAULT_DISPLAY_OPENED = false;
|
||||
/** @var bool DEFAULT_DISPLAY_LIMITED_ACCESS_ITEMS */
|
||||
const DEFAULT_DISPLAY_LIMITED_ACCESS_ITEMS = false;
|
||||
|
||||
const DEFAULT_DISPLAY_LIMITED_ACCESS_ITEMS = false;
|
||||
|
||||
/** @var string $sTargetClass */
|
||||
protected $sTargetClass;
|
||||
/** @var string $sLinkedClass */
|
||||
protected $sLinkedClass;
|
||||
/** @var string $sExtKeyToRemote */
|
||||
protected $sExtKeyToRemote;
|
||||
/** @var bool $bIndirect */
|
||||
@@ -51,6 +55,8 @@ class LinkedSetField extends Field
|
||||
protected $aLimitedAccessItemIDs;
|
||||
/** @var array $aAttributesToDisplay */
|
||||
protected $aAttributesToDisplay;
|
||||
/** @var array $aLnkAttributesToDisplay */
|
||||
protected $aLnkAttributesToDisplay;
|
||||
/** @var string $sSearchEndpoint */
|
||||
protected $sSearchEndpoint;
|
||||
/** @var string $sInformationEndpoint */
|
||||
@@ -68,6 +74,7 @@ class LinkedSetField extends Field
|
||||
$this->bDisplayLimitedAccessItems = static::DEFAULT_DISPLAY_LIMITED_ACCESS_ITEMS;
|
||||
$this->aLimitedAccessItemIDs = array();
|
||||
$this->aAttributesToDisplay = array();
|
||||
$this->aLnkAttributesToDisplay = array();
|
||||
$this->sSearchEndpoint = null;
|
||||
$this->sInformationEndpoint = null;
|
||||
|
||||
@@ -96,6 +103,31 @@ class LinkedSetField extends Field
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @since 3.1
|
||||
*
|
||||
*/
|
||||
public function GetLinkedClass()
|
||||
{
|
||||
return $this->sLinkedClass;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 3.1
|
||||
*
|
||||
* @param string $sLinkedClass
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLinkedClass(string $sLinkedClass)
|
||||
{
|
||||
$this->sLinkedClass = $sLinkedClass;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
@@ -237,6 +269,35 @@ class LinkedSetField extends Field
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash array of attributes to be displayed in the linkedset in the form $sAttCode => $sAttLabel
|
||||
*
|
||||
* @since 3.1
|
||||
*
|
||||
* @param boolean $bAttCodesOnly If set to true, will return only the attcodes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetLnkAttributesToDisplay(bool $bAttCodesOnly = false)
|
||||
{
|
||||
return ($bAttCodesOnly) ? array_keys($this->aLnkAttributesToDisplay) : $this->aLnkAttributesToDisplay;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 3.1
|
||||
*
|
||||
* @param array $aAttributesToDisplay
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLnkAttributesToDisplay(array $aAttributesToDisplay)
|
||||
{
|
||||
$this->aLnkAttributesToDisplay = $aAttributesToDisplay;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
@@ -288,4 +349,30 @@ class LinkedSetField extends Field
|
||||
{
|
||||
return in_array($iItemID, $this->aLimitedAccessItemIDs, false);
|
||||
}
|
||||
|
||||
/** @inheritdoc @since 3.1 */
|
||||
public function Validate()
|
||||
{
|
||||
$bValid = parent::Validate();
|
||||
|
||||
/** @var ormLinkSet $oSet */
|
||||
$oSet = $this->GetCurrentValue();
|
||||
|
||||
/** @var \DBObject $oItem */
|
||||
foreach ($oSet as $oItem) {
|
||||
list($bRes, $aIssues) = $oItem->CheckToWrite();
|
||||
if ($bRes === false) {
|
||||
foreach ($aIssues as $sIssue) {
|
||||
$sItem = $oItem->Get('friendlyname') != '' ? $oItem->Get('friendlyname') : Dict::S('UI:Links:NewItem');
|
||||
$this->AddErrorMessage('<b>'.$sItem.' : </b>'.$sIssue);
|
||||
}
|
||||
$bValid = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$oSet->Rewind();
|
||||
|
||||
return $bValid;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user