Version: current

     1 <?php
     2 /**
     3  * Скрипт формирования дефолтных параметров и фильтров
     4  *
     5  *
     6  * @package building_company
     7  * @author menedem
     8  *
     9  */
    10 class HouseCatalogGenerateProductParamsTask extends BuildTask {
    11
    12     protected $title = "Generate House Catalog Params";
    13
    14     protected $description = "Generate params and filters needed for house catalog";
    15
    16     static $params = array(
    17         'Square' => array('Type' => 'number', 'ShowInList' => 1, 'ShowInView' => 1, 'Sort' => 1),
    18         'Width' => array('Type' => 'number', 'ShowInList' => 1, 'ShowInView' => 1, 'Sort' => 2),
    19         'Length' => array('Type' => 'number', 'ShowInList' => 1, 'ShowInView' => 1, 'Sort' => 3),
    20         'Floor' => array('Type' => 'number', 'ShowInList' => 1, 'ShowInView' => 1, 'Sort' => 4),
    21         //'Latitude' => array('Type' => 'number', 'ShowInList' => 0, 'ShowInView' => 1, 'Sort' => 5),
    22         //'Longitude' => array('Type' => 'number', 'ShowInList' => 0, 'ShowInView' => 1, 'Sort' => 6),
    23     );
    24
    25     static $filters = array(
    26         'Price' => array('Type' => 'slider', 'Important' => 1, 'Sort' => 1, 'Unit' => '₽'),
    27         'Square' => array('Type' => 'slider', 'Important' => 1, 'Sort' => 2, 'Unit' => 'кв.м.'),
    28         'Width' => array('Type' => 'slider', 'Important' => 0, 'Sort' => 3, 'Unit' => 'м.'),
    29         'Length' => array('Type' => 'slider', 'Important' => 0, 'Sort' => 4, 'Unit' => 'м.'),
    30         'Floor' => array('Type' => 'list', 'Important' => 0, 'Sort' => 5),
    31     );
    32
    33     /**
    34      * Список параметров каталога недвижимости по умолчанию
    35      *
    36      *
    37      * @return array
    38      */
    39     static function get_required_params() {
    40         return self::$params;
    41     }
    42
    43      /**
    44      * Список фильтров каталога недвижимости по умолчанию
    45      *
    46      *
    47      * @return array
    48      */
    49     static function get_required_filters() {
    50         return self::$filters;
    51     }
    52
    53     function run($request) {
    54
    55         // импортируем параметры
    56         if ($params = self::get_required_params()) {
    57             foreach($params as $name=>$properties) {
    58                 $paramData = DataObject::get_one('ProductParam', "ParentCatalogID = 0 AND TechTitle = '". Convert::raw2sql($name) . "'");
    59                 if (!$paramData) {
    60                     $paramData = new ProductParam();
    61                     $paramData->TechTitle = Convert::raw2sql($name);
    62                 }
    63                 $paramData->ParentCatalogID = 0;
    64                 $paramData->ShowDefault = 1; // добавляем в настройки сайта, с ShowDefault = 1
    65                 $paramData->Title = _t("HouseCatalog.ParamTitle_{$name}");
    66                 $paramData->Type = $properties['Type'];
    67                 $paramData->ShowInList = (isset($properties['ShowInList'])) ? $properties['ShowInList'] : 0;
    68                 $paramData->ShowInView = (isset($properties['ShowInView'])) ? $properties['ShowInView'] : 0;
    69                 $paramData->Sort = (isset($properties['Sort'])) ? $properties['Sort'] : 0;
    70                 $paramData->write();
    71             }
    72         }
    73
    74         // импортируем фильтры
    75         if ($filters = self::get_required_filters()) {
    76             foreach($filters as $name=>$properties) {
    77                 $filterData = DataObject::get_one('CatalogFilter', "ParentCatalogID = 0 AND TechTitle = '". Convert::raw2sql($name) . "'");
    78                 if (!$filterData) {
    79                     $filterData = new CatalogFilter();
    80                     $filterData->TechTitle = Convert::raw2sql($name);
    81                 }
    82                 $filterData->FilterField = Convert::raw2sql($name);
    83                 $filterData->ParentCatalogID = 0;
    84                 $filterData->ShowDefault = 1; // добавляем в настройки сайта, с ShowDefault = 1
    85                 $filterData->Title = _t("HouseCatalog.FilterTitle_{$name}");
    86                 $filterData->Type = $properties['Type'];
    87                 $filterData->Important = (isset($properties['Important'])) ? $properties['Important'] : 0;
    88                 $filterData->Sort = (isset($properties['Sort'])) ? $properties['Sort'] : 0;
    89                 if (isset($properties['Unit'])) {
    90                     $filterData->Unit = $properties['Unit'];
    91                 }
    92                 $filterData->write();
    93             }
    94         }
    95     }
    96 }
    97

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -