1: <?php
2:
3: namespace Charcoal\Cms;
4:
5: use Exception;
6:
7: // From 'charcoal-translator'
8: use Charcoal\Translator\Translation;
9:
10: // From 'charcoal-cms'
11: use Charcoal\Object\CategoryInterface;
12: use Charcoal\Object\CategoryTrait;
13: use Charcoal\Object\Content;
14:
15: /**
16: * CMS Tag
17: */
18: class Tag extends Content implements
19: CategoryInterface
20: {
21: use CategoryTrait;
22:
23: /**
24: * The tag's name.
25: *
26: * @var Translation|string|null
27: */
28: protected $name;
29:
30: /**
31: * The tag's color.
32: *
33: * @var string
34: */
35: protected $color;
36:
37: /**
38: * @param array $data The object's data options.
39: */
40: public function __construct(array $data = null)
41: {
42: parent::__construct($data);
43:
44: $this->setData($this->defaultData());
45: }
46:
47: // ==========================================================================
48: // Functions
49: // ==========================================================================
50:
51: /**
52: * @throws Exception If function is called.
53: * @return void
54: */
55: public function loadCategoryItems()
56: {
57: throw new Exception('Cannot use loadCategoryItems');
58: }
59:
60: // ==========================================================================
61: // GETTERS
62: // ==========================================================================
63:
64: /**
65: * The tag's name.
66: *
67: * @return Translation|string|null
68: */
69: public function name()
70: {
71: return $this->name;
72: }
73:
74: /**
75: * The tag's color.
76: *
77: * @return mixed
78: */
79: public function color()
80: {
81: return $this->color;
82: }
83:
84: // ==========================================================================
85: // SETTERS
86: // ==========================================================================
87:
88: /**
89: * @param mixed $name The name of the tag.
90: * @return self
91: */
92: public function setName($name)
93: {
94: $this->name = $this->translator()->translation($name);
95: return $this;
96: }
97:
98: /**
99: * @param string $color The color in HEX format as a string.
100: * @return self
101: */
102: public function setColor($color)
103: {
104: $this->color = $color;
105: return $this;
106: }
107: }
108: