N°2334 n:n relations : same fields displayed in EDIT and VIEW modes

Before we were only showing lnk fields in VIEW, and lnk+remote in EDIT (excluding some fields, see below).
Now by default (as this is customizable in VIEW mode) we have the same !

Rules to choose fields are moved from \UILinksWidget::__construct to :
  * \MetaModel::GetZListAttDefsFilteredForIndirectRemoteClass
  * \MetaModel::GetZListAttDefsFilteredForIndirectLinkClass
This commit is contained in:
Pierre Goiffon
2020-07-30 11:40:54 +02:00
parent 5d686d733f
commit b58a084de5
5 changed files with 160 additions and 40 deletions

View File

@@ -30,6 +30,9 @@ require_once('dbobjectiterator.php');
class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
{
public const LINK_ALIAS = 'Link';
public const REMOTE_ALIAS = 'Remote';
protected $sHostClass; // subclass of DBObject
protected $sAttCode; // xxxxxx_list
protected $sClass; // class of the links
@@ -786,11 +789,13 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
/**
* @param bool $bShowObsolete
*
* @return \DBObjectSet
* @return \DBObjectSet indirect relations will get `SELECT L,R ...` (l = lnk class, R = remote)
* @throws \CoreException
* @throws \CoreWarning
* @throws \MySQLException
* @throws \Exception
*
* @since 2.8.0 N°2334 returns both lnk and remote classes for indirect relations
*/
public function ToDBObjectSet($bShowObsolete = true)
{
@@ -802,7 +807,11 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
$sExtKeyToRemote = $oAttDef->GetExtKeyToRemote();
/** @var \AttributeExternalKey $oLinkingAttDef */
$oLinkingAttDef = MetaModel::GetAttributeDef($this->sClass, $sExtKeyToRemote);
// N°2334 add pointed class (SELECT L,R) to have all fields (lnk + remote) in display
// the pointed class is always present in the search, as generated by \AttributeLinkedSet::GetDefaultValue
$sTargetClass = $oLinkingAttDef->GetTargetClass();
$oRemoteClassSearch = new DBObjectSearch($sTargetClass);
if (!$bShowObsolete && MetaModel::IsObsoletable($sTargetClass))
{
$oNotObsolete = new BinaryExpression(
@@ -810,10 +819,12 @@ class ormLinkSet implements iDBObjectSetIterator, Iterator, SeekableIterator
'=',
new ScalarExpression(0)
);
$oNotObsoleteRemote = new DBObjectSearch($sTargetClass);
$oNotObsoleteRemote->AddConditionExpression($oNotObsolete);
$oLinkSearch->AddCondition_PointingTo($oNotObsoleteRemote, $sExtKeyToRemote);
$oRemoteClassSearch->AddConditionExpression($oNotObsolete);
}
$oLinkSearch->AddCondition_PointingTo($oRemoteClassSearch, $sExtKeyToRemote);
$oLinkSearch->RenameAlias($oLinkSearch->GetClassAlias(), self::LINK_ALIAS);
$oLinkSearch->RenameAlias($sTargetClass, self::REMOTE_ALIAS);
$oLinkSearch->SetSelectedClasses([self::LINK_ALIAS, self::REMOTE_ALIAS]);
}
$oLinkSet = new DBObjectSet($oLinkSearch);
$oLinkSet->SetShowObsoleteData($bShowObsolete);