Skip to content
Code-Schnipsel Gruppen Projekte
Address.php 3,71 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?php
    
    /**
     * This file contains QUI\ERP\Address
     */
    
    namespace QUI\ERP;
    
    use QUI;
    
    use QUI\Interfaces\Users\User as QUIUserInterface;
    
    Henning Leutz's avatar
    Henning Leutz committed
    use function dirname;
    use function is_numeric;
    
    
    /**
     * Class Address
     *
     * @package QUI\ERP
     */
    class Address extends QUI\Users\Address
    {
        /**
         * Address constructor.
         *
    
         * @param array|null $data
    
    Henning Leutz's avatar
    Henning Leutz committed
         * @param QUIUserInterface|null $User
    
        public function __construct(?array $data = [], null | QUI\Interfaces\Users\User $User = null)
    
            if (!$data) {
                $data = [];
            }
    
    
    
            if (isset($data['id'])) {
                $this->id = (int)$data['id'];
            }
    
    Henning Leutz's avatar
    Henning Leutz committed
    
            if (isset($data['uuid'])) {
                $this->uuid = $data['uuid'];
            }
    
    
        /**
         * Return the address as HTML display
         *
         * @param array $options - options ['mail' => true, 'tel' => true]
         * @return string - HTML <address>
         */
    
        public function getDisplay(array $options = []): string
    
    Henning Leutz's avatar
    Henning Leutz committed
            $Engine = QUI::getTemplateManager()->getEngine(true);
    
            $contactPerson = '';
    
            if ($this->User && $this->User->isCompany()) {
    
                $isCompany = $this->User->isCompany();
            }
    
    
            if (!empty($this->getAttribute('contactPerson'))) {
                $contactPerson = $this->getAttribute('contactPerson');
    
            } elseif ($this->User) {
                $ContactPersonAddress = CustomerUtils::getInstance()->getContactPersonAddress($this->User);
    
                if ($ContactPersonAddress) {
                    $contactPerson = $ContactPersonAddress->getName();
                }
    
            }
    
            if ((bool)Defaults::conf('general', 'contactPersonOnAddress') === false) {
                $contactPerson = '';
            }
    
    
    Henning Leutz's avatar
    Henning Leutz committed
            if (is_numeric($contactPerson)) {
    
                $contactPerson = '';
            }
    
    
            $salutation = $this->emptyStringCheck($this->getAttribute('salutation'));
    
            $street_no = $this->emptyStringCheck($this->getAttribute('street_no'));
            $zip = $this->emptyStringCheck($this->getAttribute('zip'));
            $city = $this->emptyStringCheck($this->getAttribute('city'));
            $country = $this->emptyStringCheck($this->getAttribute('country'));
            $suffix = $this->emptyStringCheck($this->getAttribute('suffix'));
    
    
            $firstname = $this->getAttribute('firstname');
    
            $lastname = $this->getAttribute('lastname');
    
    
            if (empty($firstname) && $this->User) {
                $firstname = $this->User->getAttribute('firstname');
            }
    
            if (empty($lastname) && $this->User) {
                $lastname = $this->User->getAttribute('lastname');
            }
    
    
            $Engine->assign([
    
                'User' => $this->User,
                'Address' => $this,
    
                'Countries' => new QUI\Countries\Manager(),
    
                'options' => $options,
    
                'isCompany' => $isCompany,
                'salutation' => $salutation,
                'firstname' => $this->emptyStringCheck($firstname),
                'lastname' => $this->emptyStringCheck($lastname),
                'street_no' => $street_no,
                'zip' => $zip,
                'city' => $city,
                'country' => $country,
    
                'contactPerson' => $this->emptyStringCheck($contactPerson),
    
    Henning Leutz's avatar
    Henning Leutz committed
            return $Engine->fetch(dirname(__FILE__) . '/Address.html');
    
        public function save(?QUIUserInterface $PermissionUser = null): void
    
        /**
         * @param $value
         * @return string
         */
        protected function emptyStringCheck($value): string
        {
            if (empty($value)) {
                return '';
            }
    
            return $value;
        }