31 private function convertToArray(Core\
Section\
Section $section): array
34 'NAME' => $section->getName(),
35 'ACTIVE' => $section->isActive() ? self::POSITIVE_ANSWER : self::NEGATIVE_ANSWER,
36 'DESCRIPTION' => $section->getDescription(),
37 'COLOR' => $section->getColor(),
38 'TEXT_COLOR' => $section->getTextColor(),
39 'SORT' => $section->getSort() ?? self::DEFAULT_SORT,
40 'CAL_TYPE' => $section->getType(),
41 'OWNER_ID' => !$section->getOwner() ?: $section->getOwner()->getId(),
43 'XML_ID' => $section->getXmlId(),
44 'EXTERNAL_ID' => $section->getExternalId(),
45 'GAPI_CALENDAR_ID' => $section->getGoogleId(),
46 'EXPORT' => $section->getExport(),
47 'CREATED_BY' => !$section->getCreator() ?: $section->getCreator()->getId(),
48 'PARENT_ID' => $section->getParentId(),
50 'DAV_EXCH_CAL' => $section->getDavExchangeCal(),
51 'DAV_EXCH_MOD' => $section->getDavExchangeMod(),
52 'CAL_DAV_CON' => $section->getCalDavConnectionId(),
53 'CAL_DAV_CAL' => $section->getCalDavCal(),
54 'CAL_DAV_MOD' => $section->getCalDavMod(),
55 'IS_EXCHANGE' => $section->isExchange() ? 1 : 0,
56 'SYNC_TOKEN' => $section->getSyncToken(),
57 'EXTERNAL_TYPE' => $section->getExternalType(),
58 'PAGE_TOKEN' => $section->getPageToken(),
73 if ($sectionData = SectionTable::query()
113 $arrayEntity = $this->prepareArrayEntityForDB($entity);
115 $result = SectionTable::add($arrayEntity);
117 if ($result->isSuccess())
119 $this->sendPushEdit($entity->getOwner()->getId(),
true);
120 $entity->setId((
int)$result->getId());
121 $entity->setXmlId($this->saveXmlId($result->getId(), $entity->getType()));
140 $arrayEntity = $this->prepareArrayEntityForDB($entity);
142 $result = SectionTable::update(
147 if ($result->isSuccess())
149 $this->sendPushEdit($entity->getOwner()->getId(),
false);
150 return $entity->setDateModified(
new Core\
Base\
Date());
161 return Core\Section\SectionMap::class;
175 protected function deleteEntity(Core\
Base\EntityInterface $entity, array $params = [
'softDelete' =>
true]): ?Core\
Base\EntityInterface
177 if (!empty($params[
'softDelete']))
179 $entity->setIsActive(
false);
185 if (CCalendarSect::Delete($entity->getId(),
false, $params))
204 return SectionTable::getList($params);
214 private function saveXmlId(
int $id,
string $type): string
216 $xmlId = md5($type.
'_'. $id.
'_'. Random::getString(8));
218 SectionTable::update($id, [
230 private function sendPushEdit(
int $userId,
bool $isNewSection): void
236 'newSection' => $isNewSection,
246 private function prepareArrayEntityForDB($entity): array
248 $arrayEntity = $this->convertToArray($entity);
249 if (!empty($arrayEntity[
'NAME']))
251 $arrayEntity[
'NAME'] = Emoji::encode($arrayEntity[
'NAME']);
262 return Core\Section\Section::class;