/
controller.php
84 lines (71 loc) · 2.13 KB
/
controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace Concrete\Attribute\Site;
use Concrete\Core\Attribute\FontAwesomeIconFormatter;
use Concrete\Core\Entity\Attribute\Value\Value\SiteValue;
use Concrete\Core\Attribute\Controller as CoreAttributeController;
class Controller extends CoreAttributeController
{
protected $searchIndexFieldDefinition = array('type' => 'integer', 'options' => array('default' => 0, 'notnull' => false));
public function getIconFormatter()
{
return new FontAwesomeIconFormatter('globe');
}
public function getAttributeValueClass()
{
return SiteValue::class;
}
public function getValue()
{
if ($this->attributeValue) {
$value = $this->attributeValue->getValueObject();
if ($value) {
/**
* @var $value SiteValue
*/
return $value->getSite();
}
}
}
public function form()
{
$siteID = null;
if (is_object($this->getValue())) {
$siteID = $this->getValue()->getSiteID();
}
$sites = array('' => t('** Select Site'));
foreach($this->app->make('site')->getList() as $site) {
$sites[$site->getSiteID()] = $site->getSiteName();
}
$form = $this->app->make('helper/form');
print $form->select($this->field('siteID'), $sites, $siteID);
}
public function getDisplayValue()
{
$site = $this->getValue();
if (is_object($site)) {
return $site->getSiteName();
}
}
public function createAttributeValue($site)
{
$av = new SiteValue();
$av->setSite($site);
return $av;
}
public function createAttributeValueFromRequest()
{
$data = $this->post();
$site = $this->app->make('site')->getByID($data['siteID']);
return $this->createAttributeValue($site);
}
public function getSearchIndexValue()
{
$value = $this->getAttributeValue();
if (is_object($value)) {
$value = $value->getValue();
if (is_object($value)) {
return $value->getSiteID();
}
}
}
}