Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
urlmetadata.php
1<?php
2
4
9
26class UrlMetadataTable extends Entity\DataManager
27{
28 const TYPE_STATIC = 'S';
29 const TYPE_DYNAMIC = 'D';
30 const TYPE_TEMPORARY = 'T';
31 const TYPE_FILE = 'F';
32
38 public static function getTableName()
39 {
40 return 'b_urlpreview_metadata';
41 }
42
48 public static function getMap()
49 {
50 return array(
51 'ID' => new Entity\IntegerField('ID', array(
52 'primary' => true,
53 'autocomplete' => true,
54 )),
55 'URL' => new Entity\StringField('URL', array(
56 'required' => true,
57 )),
58 'TYPE' => new Entity\StringField('TYPE', array(
59 'required' => true,
60 )),
61 'TITLE' => new Entity\StringField('TITLE', [
62 'save_data_modification' => [Emoji::class, 'getSaveModificator'],
63 'fetch_data_modification' => [Emoji::class, 'getFetchModificator'],
64 ]),
65 'DESCRIPTION' => new Entity\TextField('DESCRIPTION', [
66 'save_data_modification' => [Emoji::class, 'getSaveModificator'],
67 'fetch_data_modification' => [Emoji::class, 'getFetchModificator'],
68 ]),
69 'IMAGE_ID' => new Entity\IntegerField('IMAGE_ID'),
70 'IMAGE' => new Entity\StringField('IMAGE'),
71 'EMBED' => new Entity\TextField('EMBED', [
72 'save_data_modification' => [Emoji::class, 'getSaveModificator'],
73 'fetch_data_modification' => [Emoji::class, 'getFetchModificator'],
74 ]),
75 'EXTRA' => new Entity\TextField('EXTRA', array(
76 'serialized' => true,
77 )),
78 'DATE_INSERT' => new Entity\DatetimeField('DATE_INSERT', array(
79 'default_value' => new Main\Type\DateTime(),
80 )),
81 'DATE_EXPIRE' => new Entity\DatetimeField('DATE_EXPIRE')
82 );
83 }
84
92 public static function getByUrl($url)
93 {
94 $parameters = [
95 'select' => ['*'],
96 'filter' => [
97 '=URL' => $url,
98 ],
99 'order' => [
100 'ID' => 'desc'
101 ],
102 'limit' => 1
103 ];
104
105 return static::getList($parameters)->fetch();
106 }
107
108 public static function onUpdate(Event $event)
109 {
110 $parameters = $event->getParameters();
111
112 if (!empty($parameters['fields']))
113 {
114 if (array_key_exists('IMAGE_ID', $parameters['fields']))
115 {
116 $currentValues = static::getList([
117 'select' => ['IMAGE_ID'],
118 'filter' => ['=ID' => $parameters['id']],
119 ])->fetch();
120
121 if ($currentValues['IMAGE_ID'] > 0 && $currentValues['IMAGE_ID'] != $parameters['fields']['IMAGE_ID'])
122 {
123 \CFile::Delete($currentValues['IMAGE_ID']);
124 }
125 }
126 }
127 }
128
129 public static function onDelete(Event $event)
130 {
131 $parameters = $event->getParameters();
132
133 $currentValues = static::getList([
134 'select' => ['IMAGE_ID'],
135 'filter' => ['=ID' => $parameters['id']],
136 ])->fetch();
137
138 if ($currentValues['IMAGE_ID'] > 0)
139 {
140 \CFile::Delete($currentValues['IMAGE_ID']);
141 }
142 }
143}