/
AssociationColumn.php
62 lines (52 loc) · 1.56 KB
/
AssociationColumn.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
<?php
namespace Concrete\Core\Express\Search\Column;
use Concrete\Core\Entity\Express\Association;
use Concrete\Core\Search\Column\Column;
use Concrete\Core\Search\Result\Result;
class AssociationColumn extends Column
{
protected $association = false;
protected $associationID;
public function __construct(Association $association)
{
$this->association = $association;
$this->associationID = $association->getId();
}
public function getColumnKey()
{
return 'association_' . $this->association->getId();
}
public function getColumnName()
{
return $this->association->getTargetEntity()->getName();
}
public function getAssociation()
{
return $this->association;
}
public function getColumnValue($obj)
{
if (is_object($this->association)) {
$entryAssociation = $obj->getEntryAssociation($this->association);
if ($entryAssociation) {
$entries = [];
foreach($entryAssociation->getSelectedEntries() as $entry) {
$entries[] = $entry->getLabel();
}
return implode('<br/>', $entries);
}
}
}
public function __sleep()
{
return ['associationID'];
}
/**
* Initialize the instance once it has been deserialized.
*/
public function __wakeup()
{
$em = \Database::connection()->getEntityManager();
$this->association = $em->find('Concrete\Core\Entity\Express\Association', $this->associationID);
}
}