htmlizer improvements

This commit is contained in:
yuri
2016-06-06 12:31:26 +03:00
parent 5bcdad2996
commit 2f97010b54
3 changed files with 43 additions and 5 deletions
+37 -4
View File
@@ -46,11 +46,19 @@ class Htmlizer
protected $config;
public function __construct(FileManager $fileManager, DateTime $dateTime, Number $number)
protected $acl;
public function __construct(FileManager $fileManager, DateTime $dateTime, Number $number, $acl = null)
{
$this->fileManager = $fileManager;
$this->dateTime = $dateTime;
$this->number = $number;
$this->acl = $acl;
}
protected function getAcl()
{
return $this->acl;
}
protected function formatNumber($value)
@@ -68,16 +76,22 @@ class Htmlizer
return $value;
}
protected function getDataFromEntity(Entity $entity)
protected function getDataFromEntity(Entity $entity, $notLinks = false)
{
$data = $entity->toArray();
$fieldDefs = $entity->getFields();
$fieldList = array_keys($fieldDefs);
$forbidenAttributeList = [];
if ($this->getAcl()) {
$forbidenAttributeList = $this->getAcl()->getScopeForbiddenAttributeList($entity->getEntityType(), 'read');
}
foreach ($fieldList as $field) {
if (in_array($field, $forbidenAttributeList)) continue;
$type = null;
if (!empty($fieldDefs[$field]['type'])) {
$type = $fieldDefs[$field]['type'];
@@ -123,6 +137,25 @@ class Htmlizer
}
}
if (!$notLinks) {
$relationDefs = $entity->getRelations();
foreach ($entity->getRelationList() as $relation) {
if (
!empty($relationDefs[$relation]['type'])
&&
($entity->getRelationType($relation) === 'belongsTo' || $entity->getRelationType($relation) === 'belongsToParent')
) {
$relatedEntity = $entity->get($relation);
if (!$relatedEntity) continue;
if ($this->getAcl()) {
if (!$this->getAcl()->check($relatedEntity, 'read')) continue;
}
$data[$relation] = $this->getDataFromEntity($relatedEntity, true);
}
}
}
return $data;
}
+5
View File
@@ -280,6 +280,11 @@ abstract class Entity implements IEntity
return array_keys($this->getAttributes());
}
public function getRelationList()
{
return array_keys($this->getRelations());
}
public function getValues()
{
return $this->toArray();
+1 -1
View File
@@ -88,7 +88,7 @@ class Pdf extends \Espo\Core\Services\Base
throw new Forbidden();
}
$htmlizer = new Htmlizer($this->getFileManager(), $this->getInjection('dateTime'), $this->getInjection('number'));
$htmlizer = new Htmlizer($this->getFileManager(), $this->getInjection('dateTime'), $this->getInjection('number'), $this->getAcl());
$pdf = new \Espo\Core\Pdf\Tcpdf();