htmlizer loop through collection
This commit is contained in:
@@ -75,6 +75,11 @@ class Htmlizer
|
||||
return $this->entityManager;
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
protected function format($value)
|
||||
{
|
||||
if (is_float($value)) {
|
||||
@@ -101,6 +106,15 @@ class Htmlizer
|
||||
$forbidenAttributeList = $this->getAcl()->getScopeForbiddenAttributeList($entity->getEntityType(), 'read');
|
||||
}
|
||||
|
||||
$relationList = $entity->getRelationList();
|
||||
|
||||
foreach ($relationList as $relation) {
|
||||
if (!$entity->hasLinkMultipleField($relation)) continue;
|
||||
|
||||
$collection = $entity->getLinkMultipleCollection($relation);
|
||||
$data[$relation] = $collection;
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if ($value instanceof \Espo\ORM\EntityCollection) {
|
||||
$skipAttributeList[] = $key;
|
||||
|
||||
@@ -33,12 +33,22 @@ class Entity extends \Espo\ORM\Entity
|
||||
{
|
||||
public function hasLinkMultipleField($field)
|
||||
{
|
||||
return $this->hasAttribute($field . 'Ids');
|
||||
return
|
||||
$this->hasRelation($field) &&
|
||||
$this->getAttributeParam($field . 'Ids', 'isLinkMultipleIdList');
|
||||
}
|
||||
|
||||
public function hasLinkField($field)
|
||||
{
|
||||
return $this->hasAttribute($field . 'Id');
|
||||
return $this->hasAttribute($field . 'Id') && $this->hasRelation($field);
|
||||
}
|
||||
|
||||
public function hasLinkParentField($field)
|
||||
{
|
||||
return
|
||||
$this->hasAttributeType($field . 'Type') == 'foreignType' &&
|
||||
$this->hasAttribute($field . 'Id') &&
|
||||
$this->hasRelation($field);
|
||||
}
|
||||
|
||||
public function loadParentNameField($field)
|
||||
@@ -64,15 +74,28 @@ class Entity extends \Espo\ORM\Entity
|
||||
}
|
||||
}
|
||||
|
||||
public function loadLinkMultipleField($field, $columns = null)
|
||||
public function getLinkMultipleCollection($field)
|
||||
{
|
||||
if (!$this->hasRelation($field) || !$this->hasAttribute($field . 'Ids')) return;
|
||||
if (!$this->hasLinkMultipleField($field)) return;
|
||||
|
||||
$defs = array();
|
||||
if (!empty($columns)) {
|
||||
$defs['additionalColumns'] = $columns;
|
||||
$defs = $this->getRelationSelectParams($field);
|
||||
|
||||
$columnAttribute = $field . 'Columns';
|
||||
if ($this->hasAttribute($columnAttribute) && $this->getAttributeParam($columnAttribute, 'columns')) {
|
||||
$defs['additionalColumns'] = $this->getAttributeParam($columnAttribute, 'columns');
|
||||
}
|
||||
|
||||
$collection = $this->get($field, $defs);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
protected function getRelationSelectParams($link)
|
||||
{
|
||||
$field = $link;
|
||||
|
||||
$defs = [];
|
||||
|
||||
$idsAttribute = $field . 'Ids';
|
||||
|
||||
$foreignEntityType = $this->getRelationParam($field, 'entity');
|
||||
@@ -103,6 +126,19 @@ class Entity extends \Espo\ORM\Entity
|
||||
}
|
||||
}
|
||||
|
||||
return $defs;
|
||||
}
|
||||
|
||||
public function loadLinkMultipleField($field, $columns = null)
|
||||
{
|
||||
if (!$this->hasRelation($field) || !$this->hasAttribute($field . 'Ids')) return;
|
||||
|
||||
$defs = $this->getRelationSelectParams($field);
|
||||
|
||||
if (!empty($columns)) {
|
||||
$defs['additionalColumns'] = $columns;
|
||||
}
|
||||
|
||||
$defs['select'] = ['id', 'name'];
|
||||
|
||||
$hasType = false;
|
||||
@@ -136,6 +172,8 @@ class Entity extends \Espo\ORM\Entity
|
||||
}
|
||||
}
|
||||
|
||||
$idsAttribute = $field . 'Ids';
|
||||
|
||||
$this->set($idsAttribute, $ids);
|
||||
if (!$this->isNew() && !$this->hasFetched($idsAttribute)) {
|
||||
$this->setFetched($idsAttribute, $ids);
|
||||
@@ -301,4 +339,3 @@ class Entity extends \Espo\ORM\Entity
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ class LinkMultiple extends Base
|
||||
$data[$entityName]['fields'][$fieldName . 'Columns'] = [
|
||||
'type' => 'jsonObject',
|
||||
'notStorable' => true,
|
||||
'columns' => $columns
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ abstract class Entity implements IEntity
|
||||
}
|
||||
}
|
||||
|
||||
public function get($name, $params = array())
|
||||
public function get($name, $params = [])
|
||||
{
|
||||
if ($name == 'id') {
|
||||
return $this->id;
|
||||
|
||||
Reference in New Issue
Block a user