1 <?php
2
3 class ImportCatalogSiteConfig extends SiteConfigDecorator {
4
5 function () {
6 return array(
7 'db' => array(
8 'StartPage' => 'Int',
9 'SubSite' => 'Int',
10 'OldItemAction' => "Enum('hide, unpublish, delete')",
11 ),
12 'has_one' => array(
13 'BasePriceType' => 'ImportCatalog1C_PriceType',
14 'CostPriceType' => 'ImportCatalog1C_PriceType',
15 )
16 );
17 }
18
19 static $importer_class = 'ImportCatalog1C_Importer';
20
21 protected static $possible_start_pages = array('StartCatalog', 'Catalog', 'DocPage');
22
23 24 25 26 27
28 static function get_possible_start_pages() {
29 return self::$possible_start_pages;
30 }
31
32 33 34 35 36
37 static function set_possible_start_pages($pages) {
38 self::$possible_start_pages = $pages;
39 }
40
41 function updateCMSFields(& $fields) {
42 $tab = self::get_config_tab($fields, 'Import');
43
44 $tab->push(new DropdownField("StartPage", _t('ImportSiteConfig.StartPage', 'Start Page'), $this->getImportStartPageMap(), $this->owner->StartPage));
45 if (class_exists('SubSite')) {
46 $tab->push(new DropdownField("SubSite", _t('ImportSiteConfig.SubSite', 'Sub Site'), $this->getSubSiteMap(), $this->owner->SubSite));
47 }
48 $tab->push(new DropdownField('OldItemAction', _t('ImportSiteConfig.OldItemAction', 'Old Item Action'), $this->getOldItemActionMap(), $this->owner->OldItemAction));
49 if ($priceTypes = DataObject::get('ImportCatalog1C_PriceType')) {
50 $tab->push(new DropdownField('BasePriceTypeID', _t('ImportSiteConfig.BasePriceType', 'Base Price Type'), $priceTypes->map('ID', 'Title', 'не выбрано')));
51 $tab->push(new DropdownField('CostPriceTypeID', _t('ImportSiteConfig.CostPriceType', 'Cost Price Type'), $priceTypes->map('ID', 'Title', 'не выбрано')));
52 }
53 }
54
55 function getImportStartPageMap() {
56 $data = array();
57 $data[0] = _t('ImportSiteConfig.SiteRoot', 'Site Root');
58 foreach(self::get_possible_start_pages() as $pageType) {
59 $rs = DataObject::get($pageType);
60 if ($rs) {
61 foreach($rs as $entry) {
62 if ($entry->getAncestors()->Count() < 3) {
63 $str = '';
64 for($i = 1; $i <= ($entry->getAncestors()->Count()); $i++) {
65 $str .= '-';
66 }
67 $data[$entry->ID] = $str . $entry->MenuTitle;
68 }
69 }
70 }
71 }
72 return $data;
73 }
74
75 function getSubSiteMap() {
76 $data = array();
77 $data[0] = _t('ImportSiteConfig.SelectSubSite', 'Select Sub Site');
78 if (class_exists('SubSite')) {
79 $subsites = DataObject::get('SubSite');
80 if ($subsites) {
81 $data = $subsites->map('ID', 'Title', _t('ImportSiteConfig.SelectSubSite', 'Sub Site'));
82 }
83 }
84 return $data;
85 }
86
87 function getOldItemActionMap() {
88 $rs = array();
89 foreach($this->owner->dbObject('OldItemAction')->enumValues() as $mode)
90 $rs[$mode] = _t('ImportSiteConfig.OldItemAction_' . $mode, $mode);
91 return $rs;
92 }
93
94 function getLastProductCatalogDate() {
95 if ($log = Import1CLog::get_last_log(true)) {
96 return $log->ProductCatalogDate;
97 }
98 return false;
99 }
100
101 function requireDefaultRecords() {
102 if (!$Group = DataObject::get_one("Group", "`Group`.`Code` = 'EXCHANGE_1C'")) {
103 $group = new Group();
104 $group->Code = 'EXCHANGE_1C';
105 $group->Title = "Экспорт в 1С";
106 $group->write();
107
108 Permission::grant($group->ID, 'EXCHANGE_1C');
109 if (method_exists('DB', 'alteration_message'))
110 DB::alteration_message(_t('Registration.GROUPCREATED', 'Members group created'), "created");
111 }
112
113 }
114 }
[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.
-