ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCourseMailTemplateMemberContext.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Mail/classes/class.ilMailTemplateContext.php';
5
13{
14 const ID = 'crs_context_member_manual';
15
17 protected static $periodInfoByObjIdCache = [];
18
22 public function getId() : string
23 {
24 return self::ID;
25 }
26
30 public function getTitle() : string
31 {
32 global $DIC;
33
34 $lng = $DIC['lng'];
35
36 $lng->loadLanguageModule('crs');
37
38 return $lng->txt('crs_mail_context_member_title');
39 }
40
44 public function getDescription() : string
45 {
46 global $DIC;
47
48 $lng = $DIC['lng'];
49
50 $lng->loadLanguageModule('crs');
51
52 return $lng->txt('crs_mail_context_member_info');
53 }
54
59 public function getSpecificPlaceholders() : array
60 {
64 global $DIC;
65
66 $lng = $DIC['lng'];
67
68 $lng->loadLanguageModule('crs');
69
70 $placeholders = array();
71
72 $placeholders['crs_title'] = array(
73 'placeholder' => 'COURSE_TITLE',
74 'label' => $lng->txt('crs_title')
75 );
76
77 $placeholders['crs_period_start'] = array(
78 'placeholder' => 'COURSE_PERIOD_START',
79 'label' => $lng->txt('crs_period_start_mail_placeholder')
80 );
81
82 $placeholders['crs_period_end'] = array(
83 'placeholder' => 'COURSE_PERIOD_END',
84 'label' => $lng->txt('crs_period_end_mail_placeholder')
85 );
86
87 $placeholders['crs_link'] = array(
88 'placeholder' => 'COURSE_LINK',
89 'label' => $lng->txt('crs_mail_permanent_link')
90 );
91
92
93 return $placeholders;
94 }
95
100 private function getCachedPeriodByObjId(int $objId)
101 {
102 if (!array_key_exists($objId, self::$periodInfoByObjIdCache)) {
103 self::$periodInfoByObjIdCache[$objId] = ilObjCourseAccess::lookupPeriodInfo($objId);
104 }
105
106 return self::$periodInfoByObjIdCache[$objId];
107 }
108
112 public function resolveSpecificPlaceholder(
113 string $placeholder_id,
114 array $context_parameters,
115 ilObjUser $recipient = null,
116 bool $html_markup = false
117 ) : string {
121 global $DIC;
122
123 $ilObjDataCache = $DIC['ilObjDataCache'];
124
125 if ('crs_title' == $placeholder_id) {
126 return $ilObjDataCache->lookupTitle($ilObjDataCache->lookupObjId($context_parameters['ref_id']));
127 } else {
128 if ('crs_link' == $placeholder_id) {
129 require_once './Services/Link/classes/class.ilLink.php';
130 return ilLink::_getLink($context_parameters['ref_id'], 'crs');
131 } elseif ('crs_period_start' == $placeholder_id) {
132 $periodInfo = $this->getCachedPeriodByObjId((int) $ilObjDataCache->lookupObjId($context_parameters['ref_id']));
133 if ($periodInfo) {
134 $useRelativeDates = ilDatePresentation::useRelativeDates();
136 $formattedDate = ilDatePresentation::formatDate($periodInfo['crs_end']);
138
139 return $formattedDate;
140 }
141
142 return '';
143 } elseif ('crs_period_end' == $placeholder_id) {
144 $periodInfo = $this->getCachedPeriodByObjId((int) $ilObjDataCache->lookupObjId($context_parameters['ref_id']));
145 if ($periodInfo) {
146 $useRelativeDates = ilDatePresentation::useRelativeDates();
148 $formattedDate = ilDatePresentation::formatDate($periodInfo['crs_end']);
150
151 return $formattedDate;
152 }
153
154 return '';
155 }
156 }
157
158 return '';
159 }
160}
An exception for terminatinating execution or to throw for unit testing.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
Class ilMailTemplateContext.
getSpecificPlaceholders()
Return an array of placeholders.
resolveSpecificPlaceholder(string $placeholder_id, array $context_parameters, ilObjUser $recipient=null, bool $html_markup=false)
static lookupPeriodInfo($a_obj_id)
Lookup course period info.
global $DIC
Definition: goto.php:24
$lng
$objId
Definition: xapitoken.php:39