<?php
namespace App\Model;
use App\Helpers\PageObjectRelationHelper;
class Sector extends \Pimcore\Model\DataObject\Sector
{
/**
* @return \Pimcore\Model\Document\Page|null
*/
public function page()
{
return (new PageObjectRelationHelper())->getSectorPageFromSectorObject($this);
}
public function renderThumbnail($thumbnail = "default", $options = [])
{
$image = $this->getVisuals()?->getItems()[0] ?? null;
return $image?->getImage()?->getThumbnail($thumbnail)->getHtml($options);
}
public function projects()
{
$def = $this->getClass()->getFieldDefinition("projects");
$refKey = $def->getOwnerFieldName();
$refId = $def->getOwnerClassId();
$nonOwnerRelations = $this->getRelationData($refKey, false, $refId);
#yoinked: https://pimcore.com/docs/pimcore/10.2/Development_Documentation/Objects/Object_Classes/Data_Types/Reverse_Object_Relation_Type.html
foreach ($nonOwnerRelations as $relation){
$projects[] = Project::getById($relation['id']);
}
return $projects ?? false;
}
}