Source of file EmailReminderReplacerClassBase.php
Size: 3,549 Bytes - Last Modified: 2021-12-23T10:41:35+00:00
/var/www/docs.ssmods.com/process/src/src/Api/EmailReminderReplacerClassBase.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 | <?php namespace SunnySideUp\EmailReminder\Api; use SilverStripe\Control\Director; use SilverStripe\ORM\DataObject; use SilverStripe\View\ViewableData; use SunnySideUp\EmailReminder\Email\EmailReminderMailer; use SunnySideUp\EmailReminder\Interfaces\EmailReminderReplacerClassInterface; class EmailReminderReplacerClassBase extends ViewableData implements EmailReminderReplacerClassInterface { protected $replaceArray = [ '[PASSWORD_REMINDER_LINK]' => [ 'Title' => 'Password reminder page', 'Method' => 'PasswordReminderLink', ], '[LOGIN_LINK]' => [ 'Title' => 'Login Page', 'Method' => 'LoginLink', ], '[DAYS]' => [ 'Title' => 'Replaces with the number of days, as set', 'Method' => 'Days', ], '[BEFORE_OR_AFTER]' => [ 'Title' => 'Replaces with before or after expiry date, as set', 'Method' => 'BeforeOrAfter', ], ]; /** * @return array */ public function getReplaceArray() { return $this->replaceArray; } /** * @param EmailReminderMailer $reminder * @param DataObject $record */ public function replace($reminder, $record, string $str): string { foreach ($this->replaceArray as $searchString => $moreInfoArray) { $method = $moreInfoArray['Method']; $str = $this->{$method}($reminder, $record, $searchString, $str); } return $str; } /** * @param bool $asHTML * * @return array|string */ public function replaceHelpList(?bool $asHTML = false) { $newArray = []; foreach ($this->replaceArray as $searchString => $moreInfoArray) { $newArray[$searchString] = $moreInfoArray['Title']; } if ($asHTML) { $html = ' <ul class="replace-help-list">'; foreach ($newArray as $searchString => $title) { $html .= ' <li><strong>' . $searchString . ':</strong> <span>' . $title . '</span></li>'; } $html .= ' </ul>'; return $html; } return $newArray; } /** * @param EmailReminderMailer $reminder * @param DataObject $record */ protected function PasswordReminderLink($reminder, $record, string $searchString, string $str): string { $replace = Director::absoluteURL('Security/lostpassword'); return str_replace($searchString, $replace, $str); } /** * @param EmailReminderMailer $reminder * @param DataObject $record */ protected function LoginLink($reminder, $record, string $searchString, string $str): string { $replace = Director::absoluteURL('Security/login'); return str_replace($searchString, $replace, $str); } /** * @param EmailReminderMailer $reminder * @param DataObject $record */ protected function Days($reminder, $record, string $searchString, string $str): string { $replace = $reminder->Days; return str_replace($searchString, $replace, $str); } /** * @param EmailReminderMailer $reminder * @param DataObject $record */ protected function BeforeOrAfter($reminder, $record, string $searchString, string $str): string { $replace = $reminder->BeforeAfter; return str_replace($searchString, $replace, $str); } } |