Project.class.php 4.09 KB
<?php

namespace SH\Entities;


class Project extends \Cpeople\Classes\Block\Object
{
    use \Sh\Traits\FunctionName;
    use \Cpeople\Traits\MapConnection;

    static $thumbParams = array('width' => 911, 'height' => 566, 'type' => 'put_out');
    static $thumbParamsSmall = array('width' => 607, 'height' => 381, 'type' => 'put_out');

    function getText()
    {
        return $this->{'~PREVIEW_TEXT'};
    }

    function getSquare()
    {
        return $this->getPropValue('SQUARE');
    }

    function getFloorCount()
    {
        return $this->getPropValue('FLOOR_COUNT');
    }

    function getBedroomCount()
    {
        return $this->getPropValue('BEDROOM_COUNT');
    }

    function getPreviewGallery($isSmall = false)
    {
        $result = array();
        $thumbParams = $isSmall ? self::$thumbParamsSmall : self::$thumbParams;

        if($this->hasPreviewImage()) {
            $result[] = $this->getPreivewImageUrl();
//            $result[] = $this->getPreviewImageThumb($thumbParams);
        }

        if($images = $this->getImages('IMAGES_PROJECT')) {
            foreach($images as $image) {
                $result[] = $image->getUrl($thumbParams);
//                $result[] = $image->getThumbUrl($thumbParams);
            }
        }

        return $result;
    }

    function getPreviewImage($isSmall = false)
    {
        if($this->hasPreviewImage()) {
//            if($isSmall) {
//                return $this->getPreviewImageThumb(self::$thumbParamsSmall);
//            } else {
                return $this->getPreivewImageUrl();
//            }
//            $thumbParams = $isSmall ? self::$thumbParamsSmall : self::$thumbParams;
//            return $this->getPreviewImageThumb($thumbParams);
        }

        return false;
    }

    function getIcon()
    {
        $sectionXmlId = $this->getPropXMLValue('PROJECT_SECTION');
        return '/img/svg/'. ($sectionXmlId == 'house'
            ? 'house'
            : ($sectionXmlId == 'bathhouse' ? 'bath_house' : 'other')) .'.svg';
    }

    static function getTypeBreadcrumbData()
    {
        return array(
            'house' => array('Дома из клееного бруса', '/projects/doma-iz-kleenogo-brusa/'),
            'bathhouse' => array('Бани из клееного бруса', '/projects/bani-iz-kleenogo-brusa/'),
            'misc' => array('Малые архитектурные формы и другие постройки', '/projects/raznye-proekty/')
        );
    }

    static function getTypeBreadcrumbNameByCode($code)
    {
        return false;
        $data = self::getTypeBreadcrumbData();
        foreach($data as $row) {
            if(strpos($row[1], $code) !== false) {
                return $row[0];
            }
        }
    }

    function getTypeBreadcrumb()
    {
        $sectionXmlId = $this->getPropXMLValue('PROJECT_SECTION');
        $data = self::getTypeBreadcrumbData();
        return $data[$sectionXmlId];
    }

    function getRegion()
    {
        return $this->getPropValue('REGION');
    }

    function hasDetail()
    {
        return (bool) $this->DETAIL_TEXT;
    }

    function getZoom()
    {
        return 9;
//        $val = $this->hasProp('MAP_ZOOM') ? (int) $this->getPropValue('MAP_ZOOM') : false;
//        return $val ? $val : 15;
    }

    function getImgAlt($photoNumber = false) {
        if(empty($this->imgAltBegin)) {
            $this->imgAltBegin = 'Проект деревянного дома из клееного бруса ' . strip_tags($this->{'NAME'});
            if($val = $this->getSquare()) {
                $this->imgAltBegin .= ', площадь ' . $val . ' м2';
            }
            if($val = $this->getFloorCount()) {
                $this->imgAltBegin .= ', ' . num_to_string($val, 'этаж', 'этажа', 'этажей');
            }
            if($val = $this->getBedroomCount()) {
                $this->imgAltBegin .= ', ' . num_to_string($val, 'спальня', 'спальни', 'спален');
            }
        }

        $result = $this->imgAltBegin;
        if($photoNumber) $result .= ', фото ' . $photoNumber;

        return $result;
    }
}