1 <?php
2
3 class CatalogRubricsHomepageWidget extends HomepageWidget {
4
5 static $many_many = array(
6 'Catalogs' => 'Catalog'
7 );
8
9 public $needObjects = array(
10 'Catalog' => 'Page'
11 );
12
13 static $catalog_sorting = null;
14
15
16 function getCMSFields() {
17 $fields = parent::getCMSFields();
18 $dom = new ManyManyComplexTableField(
19 $this,
20 'Catalogs',
21 'Catalog',
22 array(
23 'ID' => 'ID',
24 'Title' => 'Title',
25 )
26 );
27 $dom->setPermissions(array());
28 $fields->replaceField('Catalogs', $dom);
29
30 return $fields;
31 }
32
33 function hasContent() {
34 if ($this->Catalogs()->Count()) {
35 return true;
36 }
37 return false;
38 }
39
40 function ActiveCatalogs() {
41 if ($this->hasContent()) {
42 if(!self::$catalog_sorting){
43 return $this->Catalogs();
44 }else{
45 $tmp = new DataObjectSet();
46 foreach ($this->Catalogs() as $item) {
47 $tmp->push($item);
48 }
49 $tmp->sort(self::$catalog_sorting);
50 return $tmp;
51 }
52 }
53 return false;
54 }
55 }
56
57 class CatalogRubricsHomepageWidget_CatalogDecorator extends DataObjectDecorator {
58 function () {
59 return array(
60 'belongs_many_many' => array(
61 'Widgets' => 'CatalogRubricsHomepageWidget'
62 )
63 );
64 }
65
66 function updateCMSFields(& $fields) {
67 $dom = new ManyManyComplexTableField(
68 $this->owner,
69 'Widgets',
70 'CatalogRubricsHomepageWidget'
71 );
72 $dom->setPermissions(array());
73 $tab = $fields->findOrMakeTab('Root.Content.CatalogWidgets', 'Виджеты каталога на главной');
74 $tab->push($dom);
75 }
76 }
77
[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.
-