/
Template.php
140 lines (119 loc) · 2.87 KB
/
Template.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
namespace Concrete\Core\Entity\Board;
use Concrete\Core\Board\Template\Driver\DriverInterface;
use Concrete\Core\Board\Template\Driver\Manager;
use Concrete\Core\Entity\PackageTrait;
use Concrete\Core\Support\Facade\Facade;
use HtmlObject\Image;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(
* name="BoardTemplates"
* )
*/
class Template implements \JsonSerializable
{
use PackageTrait;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $icon = '';
/**
* @ORM\Column(type="string")
*/
protected $name = '';
/**
* @ORM\Column(type="string")
*/
protected $handle = '';
public function getId(): ?int
{
return $this->id;
}
public function getHandle(): string
{
return $this->handle;
}
/**
* @return $this
*/
public function setHandle(string $handle): self
{
$this->handle = $handle;
return $this;
}
public function getIcon(): string
{
return $this->icon;
}
/**
* @return $this
*/
public function setIcon(string $icon): self
{
$this->icon = $icon;
return $this;
}
public function getName(): string
{
return $this->name;
}
public function getDisplayName(): string
{
return tc('BoardTemplateName', $this->getName());
}
/**
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @param bool $asTag
*
* @return \HtmlObject\Image|string|null
*/
public function getTemplateIconImage(bool $asTag = true)
{
if ($this->getIcon()) {
$image = ASSETS_URL_IMAGES . '/icons/board_templates/' . $this->getIcon();
if ($asTag) {
$image = new Image($image);
}
return $image;
}
}
public function getDriver() : DriverInterface
{
$app = Facade::getFacadeApplication();
$manager = $app->make(Manager::class);
return $manager->driver($this->getHandle());
}
public function export(\SimpleXMLElement $node): void
{
$template = $node->addChild('template');
$template->addAttribute('handle', $this->getHandle());
$template->addAttribute('name', h($this->getName()));
$template->addAttribute('icon', h($this->getIcon()));
$template->addAttribute('package', $this->getPackageHandle());
}
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return [
'name' => $this->getName(),
'id' => $this->getId(),
'icon' => $this->getIcon(),
'slots' => $this->getDriver()->getTotalSlots(),
];
}
}