1 <?php
2 3 4 5 6 7
8 class ConsultantWidget extends SidebarWidget {
9
10 static $db = array(
11 'ConsultantCount' => 'Int'
12 );
13
14 static $has_one = array(
15 'Holder' => 'OnlineConsultant'
16 );
17
18 static $defaults = array(
19 'ConsultantCount' => 2
20 );
21
22 public $needObjects = array(
23 'OnlineConsultant' => 'Page'
24 );
25
26 function getCMSFields() {
27 if (!$this->canCreate()) {
28 return $this->getFailCMSFields();
29 }
30 $fields = parent::getCMSFields();
31 $holders = DataObject::get('OnlineConsultant');
32 if ($holders) {
33 $holders = $holders->map();
34 } else {
35 $holders = array();
36 }
37 $fields->replaceField('HolderID', new DropdownField('HolderID', $this->fieldLabel('Holder'), $holders, "", null, _t('Widgets.All', 'All')));
38 return $fields;
39 }
40
41 function Consultants() {
42 if (class_exists('Consultant')) {
43 $holderID = $this->HolderID;
44 if (!$this->HolderID) {
45 $holderID = false;
46 }
47 $items = singleton('Consultant')->Widget($holderID);
48 if ($items) {
49 return $items->getRange(0, $this->ConsultantCount);
50 }
51 }
52 return false;
53 }
54
55 function hasContent() {
56 if ($this->Consultants()) {
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.
-