This repository has been archived by the owner on Jan 22, 2022. It is now read-only.
/
Tag.php
110 lines (96 loc) · 2.11 KB
/
Tag.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
<?php
namespace Mirasvit\Blog\Model;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\Context;
use Magento\Framework\Registry;
use Mirasvit\Blog\Api\Data\TagInterface;
class Tag extends AbstractModel implements IdentityInterface, UrlInterface, TagInterface
{
const CACHE_TAG = 'blog_tag';
/**
* @var Url
*/
protected $url;
/**
* @param Url $url
* @param Context $context
* @param Registry $registry
*/
public function __construct(
Url $url,
Context $context,
Registry $registry
) {
$this->url = $url;
parent::__construct($context, $registry);
}
/**
* Get identities.
* @return array
*/
public function getIdentities()
{
return [self::CACHE_TAG . '_' . $this->getId()];
}
/**
* {@inheritdoc}
*/
public function setName($value)
{
return $this->setData(self::NAME, $value);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getData(self::NAME);
}
/**
* {@inheritdoc}
*/
public function setUrlKey($value)
{
return $this->setData(self::URL_KEY, $value);
}
/**
* {@inheritdoc}
*/
public function getUrlKey()
{
return $this->getData(self::URL_KEY);
}
/**
* @param array $urlParams
*
* @return string
*/
public function getUrl($urlParams = [])
{
return $this->url->getTagUrl($this, $urlParams);
}
// /**
// * @param string $tag
// * @return $this
// */
// public function getOrCreate($tag)
// {
// $tag = trim($tag);
// $this->load($tag, 'name');
//
// if (!$this->getId()) {
// $this->setName($tag)
// ->save();
// }
//
// return $this;
// }
/**
* {@inheritdoc}
*/
protected function _construct()
{
$this->_init('Mirasvit\Blog\Model\ResourceModel\Tag');
}
}