/
controller.php
102 lines (89 loc) · 2.82 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace Concrete\Attribute\UserSelector;
use Concrete\Core\Attribute\Controller as AttributeTypeController;
use Concrete\Core\Attribute\FontAwesomeIconFormatter;
use Concrete\Core\Entity\Attribute\Value\Value\NumberValue;
use Concrete\Core\User\User;
use Concrete\Core\User\UserInfo;
class Controller extends AttributeTypeController
{
protected $searchIndexFieldDefinition = [
'type' => 'integer',
'options' => ['default' => 0, 'notnull' => false],
];
public function getIconFormatter()
{
return new FontAwesomeIconFormatter('user');
}
public function getAttributeValueClass()
{
return NumberValue::class;
}
public function form()
{
$value = null;
if (is_object($this->attributeValue)) {
$value = $this->getAttributeValue()->getValue();
}
if (!$value) {
if ($this->request->query->has($this->attributeKey->getAttributeKeyHandle())) {
$value = $this->createAttributeValue((int) $this->request->query->get($this->attributeKey->getAttributeKeyHandle()));
}
}
$this->set('value', $value);
$this->set('user_selector', $this->app->make('helper/form/user_selector'));
}
public function getDisplayValue()
{
$uID = $this->getAttributeValue()->getValue();
$ui = UserInfo::getByID($uID);
if (is_object($ui)) {
return '<a href="'.$ui->getUserPublicProfileUrl().'">'.$ui->getUserName().'</a>';
}
}
public function getPlainTextValue()
{
$uID = $this->getAttributeValue()->getValue();
$user = User::getByUserID($uID);
if (is_object($user)) {
return $user->getUserName();
}
}
public function createAttributeValue($value)
{
$av = new NumberValue();
if ($value instanceof User) {
$value = $value->getUserID();
}
$av->setValue($value);
return $av;
}
public function getSearchIndexValue()
{
return $this->attributeValue->getValue();
}
public function createAttributeValueFromRequest()
{
$data = $this->post();
if (isset($data['value'])) {
return $this->createAttributeValue((int) $data['value']);
}
}
public function importValue(\SimpleXMLElement $akv)
{
if (isset($akv->value)) {
$user = User::getByUserID($akv->value);
if (is_object($user)) {
return $user->getUserID();
}
}
}
public function exportValue(\SimpleXMLElement $akn)
{
if (is_object($this->attributeValue)) {
$uID = $this->getAttributeValue()->getValue();
$user = User::getByUserID($uID);
$avn = $akn->addChild('value', $user->getUserID());
}
}
}