1 <?php
2 3 4 5 6 7 8
9 class extends SidebarWidget {
10
11 static $db = array(
12 'CityID' => 'Varchar(255)'
13 );
14
15 static $cities = array(
16 'russia/kareliya/petrozavodsk' => 'Петрозаводск',
17 'russia/kareliya/belomorskiy-rayon/belomorsk' => 'Беломорск',
18 'russia/kareliya/pudozhskiy-rayon/pudozh' => 'Пудож',
19 );
20
21 static function set_cities($cities) {
22 self::$cities = $cities;
23 }
24
25 public $needObjects = array(
26 'PageInformerWeather' => 'Class'
27 );
28
29 function getCMSFields() {
30 if (!$this->canCreate()) {
31 return $this->getFailCMSFields();
32 }
33 $fields = parent::getCMSFields();
34 $fields->addFieldToTab('Root.Main', new DropdownField('CityID', $this->fieldLabel('CityID'), self::$cities));
35 return $fields;
36 }
37
38 function Title() {
39 return ($this->Title) ? $this->Title : $this->i18n_singular_name();
40 }
41
42 function CMSTitle() {
43 return $this->Title();
44 }
45
46 function Weather() {
47 if ($this->CityID) {
48
49 $weather = singleton('PageInformerWeather')->WeatherInfo(2, $this->CityID);
50 return $weather;
51 }
52 return false;
53 }
54
55 function hasContent() {
56 if ($this->Weather()) {
57 return true;
58 }
59 return false;
60 }
61 }
62
63
[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.
-