src/Model/DataObject/Community.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Model\DataObject;
  3. use Pimcore\Model\DataObject\DemiDistrict;
  4. use Pimcore\Model\DataObject\DemiFilterObject;
  5. use Pimcore\Model\DataObject\DemiTown;
  6. use Pimcore\Model\DataObject\Region;
  7. use Pimcore\Model\WebsiteSetting;
  8. class Community extends \Pimcore\Model\DataObject\Community
  9. {
  10.     public function getRegion(): ?Region {
  11.         $parent $this->getParent();
  12.         if($parent instanceof Region) {
  13.             return $parent;
  14.         }
  15.         $mainRegion WebsiteSetting::getByName('mainRegion');
  16.         if($mainRegion && $mainRegion->getData() instanceof Region) {
  17.             return $mainRegion->getData();
  18.         }
  19.         return null;
  20.     }
  21.     public function getDemiTownOrDistrict(): null|DemiTown|DemiDistrict
  22.     {
  23.         $filterObject $this->getDemiFilterObject();
  24.         if($filterObject instanceof DemiFilterObject) {
  25.             $filterElements $filterObject->getFilterElements();
  26.             if(!empty($filterElements)) {
  27.                 foreach ($filterElements as $filterElement) {
  28.                     if ($filterElement instanceof  DemiTown) {
  29.                         return $filterElement;
  30.                     }
  31.                     if($filterElement instanceof DemiDistrict) {
  32.                         return $filterElement;
  33.                     }
  34.                 }
  35.             }
  36.         }
  37.         return null;
  38.     }
  39. }