1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
section.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Core\Mappers;
4
5use Bitrix\Calendar\Core\Builders\SectionBuilderFromDataManager;
6use Bitrix\Calendar\Core;
7use Bitrix\Calendar\Integration\Pull\PushCommand;
8use Bitrix\Calendar\Internals\EO_Section;
9use Bitrix\Calendar\Internals\SectionTable;
10use Bitrix\Calendar\Util;
11use Bitrix\Main\ArgumentException;
12use Bitrix\Main\ObjectPropertyException;
13use Bitrix\Main\ORM\Query\Result;
14use Bitrix\Main\Security\Random;
15use Bitrix\Main\SystemException;
16use Bitrix\Main\Text\Emoji;
17use Bitrix\Main\Type\DateTime;
18use CCalendarSect;
19use Exception;
20
21class Section extends Mapper implements BaseMapperInterface
22{
23 public const SECTION_TYPE_LOCAL = 'local';
24
25 public const DEFAULT_SORT = 100;
26
32 private function convertToArray(Core\Section\Section $section): array
33 {
34 return [
35 'NAME' => $section->getName(),
36 'ACTIVE' => $section->isActive() ? self::POSITIVE_ANSWER : self::NEGATIVE_ANSWER,
37 'DESCRIPTION' => $section->getDescription(),
38 'COLOR' => $section->getColor(),
39 'TEXT_COLOR' => $section->getTextColor(),
40 'SORT' => $section->getSort() ?? self::DEFAULT_SORT,
41 'CAL_TYPE' => $section->getType(),
42 'OWNER_ID' => !$section->getOwner() ?: $section->getOwner()->getId(),
43 'TIMESTAMP_X' => new DateTime,
44 'XML_ID' => $section->getXmlId(),
45 'EXTERNAL_ID' => $section->getExternalId(),
46 'GAPI_CALENDAR_ID' => $section->getGoogleId(),
47 'EXPORT' => $section->getExport(),
48 'CREATED_BY' => !$section->getCreator() ?: $section->getCreator()->getId(),
49 'PARENT_ID' => $section->getParentId(),
50 'DATE_CREATE' => new DateTime,
51 'DAV_EXCH_CAL' => $section->getDavExchangeCal(),
52 'DAV_EXCH_MOD' => $section->getDavExchangeMod(),
53 'CAL_DAV_CON' => $section->getCalDavConnectionId(),
54 'CAL_DAV_CAL' => $section->getCalDavCal(),
55 'CAL_DAV_MOD' => $section->getCalDavMod(),
56 'IS_EXCHANGE' => $section->isExchange() ? 1 : 0,
57 'SYNC_TOKEN' => $section->getSyncToken(),
58 'EXTERNAL_TYPE' => $section->getExternalType(),
59 'PAGE_TOKEN' => $section->getPageToken(),
60 ];
61 }
62
72 protected function getOneEntityByFilter(array $filter): ?object
73 {
74 $sectionData = SectionTable::query()
75 ->setFilter($filter)
76 ->setSelect(['*'])
77 ->fetchObject()
78 ;
79
80 if ($sectionData)
81 {
82 return $this->convertToObject($sectionData);
83 }
84
85 return null;
86 }
87
93 protected function convertToObject($objectEO): Core\Base\EntityInterface
94 {
95 return (new SectionBuilderFromDataManager($objectEO))->build();
96 }
97
101 protected function getEntityName(): string
102 {
103 return 'section';
104 }
105
116 {
117 $arrayEntity = $this->prepareArrayEntityForDB($entity);
118
119 $result = SectionTable::add($arrayEntity);
120
121 if ($result->isSuccess())
122 {
123 $this->sendPushEdit($entity->getOwner()->getId(), true);
124 $entity->setId((int)$result->getId());
125 $entity->setXmlId($this->saveXmlId($result->getId(), $entity->getType()));
126
127 return $entity;
128 }
129
130 throw new Core\Base\BaseException('Error of create section');
131 }
132
143 {
144 $arrayEntity = $this->prepareArrayEntityForDB($entity);
145
146 $result = SectionTable::update(
147 $entity->getId(),
148 $arrayEntity
149 );
150
151 if ($result->isSuccess())
152 {
153 $this->sendPushEdit($entity->getOwner()->getId(), false);
154 return $entity->setDateModified(new Core\Base\Date());
155 }
156
157 throw new Core\Base\BaseException('Error of update section');
158 }
159
163 protected function getMapClass(): string
164 {
165 return Core\Section\SectionMap::class;
166 }
167
179 protected function deleteEntity(Core\Base\EntityInterface $entity, array $params = ['softDelete' => true]): ?Core\Base\EntityInterface
180 {
181 if (!empty($params['softDelete']))
182 {
183 $entity->setIsActive(false);
184
185 return $this->updateEntity($entity, $params);
186 }
187
188 // TODO: change it to SectionTable::delete() after implementation all logic
189 if (CCalendarSect::Delete($entity->getId(), false, $params))
190 {
191 return null;
192 }
193
194 throw new Core\Base\BaseException('Error of delete section');
195 }
196
207 {
208 return SectionTable::getList($params);
209 }
210
218 private function saveXmlId(int $id, string $type): string
219 {
220 $xmlId = md5($type. '_'. $id. '_'. Random::getString(8));
221
222 SectionTable::update($id, [
223 'XML_ID' => $xmlId
224 ]);
225
226 return $xmlId;
227 }
228
234 private function sendPushEdit(int $userId, bool $isNewSection): void
235 {
237 PushCommand::EditSection,
238 $userId,
239 [
240 'newSection' => $isNewSection,
241 ],
242 );
243 }
244
250 private function prepareArrayEntityForDB($entity): array
251 {
252 $arrayEntity = $this->convertToArray($entity);
253 if (!empty($arrayEntity['NAME']))
254 {
255 $arrayEntity['NAME'] = Emoji::encode($arrayEntity['NAME']);
256 }
257
258 return $arrayEntity;
259 }
260
264 protected function getEntityClass(): string
265 {
266 return Core\Section\Section::class;
267 }
268}
$type
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
convertToObject($objectEO)
Определения section.php:93
updateEntity($entity, array $params=[])
Определения section.php:142
const SECTION_TYPE_LOCAL
Определения section.php:23
getOneEntityByFilter(array $filter)
Определения section.php:72
deleteEntity(Core\Base\EntityInterface $entity, array $params=['softDelete'=> true])
Определения section.php:179
createEntity($entity, array $params=[])
Определения section.php:115
getDataManagerResult(array $params)
Определения section.php:206
static addPullEvent(PushCommand $command, int $userId, array $params=[])
Определения util.php:385
Определения date.php:9
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$entity
$filter
Определения iblock_catalog_list.php:54
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799