Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
UrlItem.php
1<?php
2
4
5use Bitrix\Im\Model\EO_LinkUrl;
8use Bitrix\Im\V2\Common\MigrationStatusCheckerTrait;
14
15class UrlItem extends BaseLinkItem
16{
17 use MigrationStatusCheckerTrait;
18
19 protected static string $migrationOptionName = 'im_link_url_migration';
20
21 protected string $url;
22
26 public function __construct($source = null)
27 {
28 $this->initByDefault();
29
30 if (!empty($source))
31 {
32 $this->load($source);
33 }
34 }
35
36 public static function getRestEntityName(): string
37 {
38 return 'link';
39 }
40
41 public static function getEntityClassName(): string
42 {
43 return Entity\Url\UrlItem::class;
44 }
45
46 public function save(): Result
47 {
48 if (!static::isMigrationFinished())
49 {
50 return new Result();
51 }
52
53 $result = parent::save();
54 LinkUrlIndexTable::indexInBackground();
55
56 return $result;
57 }
58
59 public function delete(): Result
60 {
61 LinkUrlIndexTable::delete($this->getPrimaryId());
62
63 return parent::delete();
64 }
65
66 public static function getDataClass(): string
67 {
68 return LinkUrlTable::class;
69 }
70
71 protected static function getEntityIdFieldName(): string
72 {
73 return 'PREVIEW_URL_ID';
74 }
75
76 protected static function mirrorDataEntityFields(): array
77 {
78 $additionalFields = [
79 'URL' => [
80 'field' => 'url',
81 'set' => 'setUrl',
82 'get' => 'getUrl',
83 ]
84 ];
85
86 return array_merge(parent::mirrorDataEntityFields(), $additionalFields);
87 }
88
89 //region Setters & getters
90
94 public function getEntity(): \Bitrix\Im\V2\Entity\Url\UrlItem
95 {
96 return $this->entity;
97 }
98
103 public function setEntity(RestEntity $entity): self
104 {
105 if (!($entity instanceof \Bitrix\Im\V2\Entity\Url\UrlItem))
106 {
107 throw new ArgumentTypeException(get_class($entity));
108 }
109 $this->setUrl($entity->getUrl());
110
111 return parent::setEntity($entity);
112 }
113
114 public function getUrl(): string
115 {
116 return $this->url;
117 }
118
119 public function setUrl(string $url): self
120 {
121 $this->url = $url;
122 return $this;
123 }
124
125 //endregion
126}