Skip to content

Commit

Permalink
add 'Icon' (%I) and 'Event Preset Title' (%E) options to 'Title Templ…
Browse files Browse the repository at this point in the history
…ate' - #539 and #548
  • Loading branch information
SergeyMosin committed Oct 8, 2024
1 parent 4abc743 commit ff361d4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
10 changes: 8 additions & 2 deletions lib/Backend/BCSabreImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,11 @@ function setAttendee($userId, $calId, $uri, $info)

$parts = $this->utils->makeAppointmentParts(
$userId, $tza[BackendUtils::TMPL_TZ_DATA],
(new \DateTime('now', new \DateTimeZone('UTC')))->format(self::TIME_FORMAT));
(new \DateTime('now', new \DateTimeZone('UTC')))->format(self::TIME_FORMAT),
isset($td[$info['tmpl_day']][$info['tmpl_idx']]['title'])
? '_' . $td[$info['tmpl_day']][$info['tmpl_idx']]['title']
: ''
);
if (isset($parts['err'])) {
$this->logErr($parts['err'] . " - template mode");
return 3;
Expand Down Expand Up @@ -1076,7 +1080,9 @@ function setAttendee($userId, $calId, $uri, $info)
/** @noinspection PhpUnhandledExceptionInspection */
$parts = $this->utils->makeAppointmentParts(
$userId, $tzi,
(new \DateTime('now', new \DateTimeZone('UTC')))->format(self::TIME_FORMAT));
(new \DateTime('now', new \DateTimeZone('UTC')))->format(self::TIME_FORMAT),
isset($evt->SUMMARY) ? '_' . $evt->SUMMARY->getValue() : ''
);
if (isset($parts['err'])) {
$this->logErr($parts['err'] . " - calId: " . $srcId . ", uri: " . $srcUri);
return 4;
Expand Down
40 changes: 34 additions & 6 deletions lib/Backend/BackendUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ class BackendUtils
public const PAGE_ENABLED = "enabled";
public const PAGE_LABEL = "label";

private const STATE_PENDING = 1;
private const STATE_CONFIRMED = 2;

private array|null $settings = null;
private ApptDocProp|null $apptDoc = null;

Expand Down Expand Up @@ -295,7 +298,15 @@ function dataSetAttendee(string $data, array $info, string $userId, string $uri)
$title = $t;
}
}
$evt->SUMMARY->setValue("" . $this->makeEvtTitle($userId, $info['name'], $info['_page_id'], $this->getAttendee($evt)->getValue()));

$evt->SUMMARY->setValue($this->makeEvtTitle(
self::STATE_PENDING,
$userId,
$info['name'],
$info['_page_id'],
$this->getAttendee($evt)->getValue(),
$title
));

$dsr = $info['name'] . "\n" . (empty($info['phone']) ? "" : ($info['phone'] . "\n")) . $info['email'] . $info['_more_data'];

Expand Down Expand Up @@ -517,8 +528,10 @@ function dataConfirmAttendee(string $data, string $userId, string $pageId): arra
return [null, null, ""];
}

$presetTitle = "";
if (isset($evt->{ApptDocProp::PROP_NAME})) {
$apptDoc = $this->getApptDoc($evt);
$presetTitle = $apptDoc->title;

$dts = $this->getDateTimeString(
$evt->DTSTART->getDateTime(),
Expand Down Expand Up @@ -551,7 +564,14 @@ function dataConfirmAttendee(string $data, string $userId, string $pageId): arra
if (!isset($evt->SUMMARY)) {
$evt->add('SUMMARY');
} // ???
$evt->SUMMARY->setValue("✔️ " . $this->makeEvtTitle($userId, $attendeeName, $pageId, $this->getAttendee($evt)->getValue()));
$evt->SUMMARY->setValue($this->makeEvtTitle(
self::STATE_CONFIRMED,
$userId,
$attendeeName,
$pageId,
$this->getAttendee($evt)->getValue(),
$presetTitle
));

//Talk link
if (isset($evt->{ApptDocProp::PROP_NAME})) {
Expand Down Expand Up @@ -2186,8 +2206,10 @@ function removeSubscriptionSync(string $subscriptionId): void
}
}

private function makeEvtTitle(string $userId, string $attendeeName, string $pageId, string $av): string
private function makeEvtTitle(int $state, string $userId, string $attendeeName, string $pageId, string $av, string $presetTitle): string
{
$icon = $state === self::STATE_PENDING ? "" : "✔️";

$settings = $this->getUserSettings();
if (isset($settings[self::CLS_TITLE_TEMPLATE]) && !empty($settings[self::CLS_TITLE_TEMPLATE])) {

Expand All @@ -2201,14 +2223,20 @@ private function makeEvtTitle(string $userId, string $attendeeName, string $page
$tkn = strtoupper(substr(str_replace(' ', '', $attendeeName), 0, 3)) .
strtoupper(substr(str_replace(['+', '/', '='], '', base64_encode(sha1($attendeeName . $av . $userId, true))), 0, 8));

// %I = Icon ("✔️")
// %N = Attendee Name
// %O = Organization Name
// %P = Page Tag
// %T = Mask Token
return str_replace(["%N", "%O", "%P", "%T"],
[$attendeeName, $settings[self::ORG_NAME], $pageTag, $tkn], $tmpl);
// %E = Event Preset Title
if ($state === self::STATE_PENDING && !str_contains($tmpl, "%I")) {
// for pending appointments we must have the "⌛" icon
$tmpl = "%I " . $tmpl;
}
return str_replace(["%I", "%N", "%O", "%P", "%T", "%E"],
[$icon, $attendeeName, $settings[self::ORG_NAME], $pageTag, $tkn, ltrim($presetTitle, '_')], $tmpl);
} else {
return $attendeeName;
return $icon . ' ' . $attendeeName;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/components/settings-v2/SectionAdvanced.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ const syncOptions = [
<ComboInput
class="ps-vert-spacing"
prop-name="titleTemplate"
placeholder="%N"
placeholder="%I %N"
:label="t('appointments', 'Event Title Template')"
:store="settingsStore">
<template #help>
{{ t('appointments', "Following template tokens can be used to customize Appointment's Title:") }}<br>
<strong>%I</strong> - {{ t('appointments', 'Icon') }} (✔️)<br>
<strong>%N</strong> - {{ t('appointments', 'Attendee name') }}<br>
<strong>%O</strong> - {{ t('appointments', 'Organization Name') }}<br>
<strong>%P</strong> - {{ t('appointments', 'Page Tag') }}<br>
<strong>%T</strong> - {{ t('appointments', 'Mask Token (first three letters of name + semi-random token)') }}<br><br>
<strong>%T</strong> - {{ t('appointments', 'Mask Token (first three letters of name + semi-random token)') }}<br>
<strong>%E</strong> - {{ t('appointments', 'Event Preset Title') }}<br><br>
{{ t('appointments', 'For example template like {tokens} will set new appointments title to something like John Smith (Good Org)', {tokens: '%N (%O)'}) }}
</template>
</ComboInput>
Expand Down

0 comments on commit ff361d4

Please sign in to comment.