Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-tool_lifecycle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-tool_lifecycle
Commits
67cdd305
Unverified
Commit
67cdd305
authored
8 years ago
by
Tobias Reischmann
Browse files
Options
Downloads
Patches
Plain Diff
Added email placeholder for courses
parent
37e1e6bf
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
step/email/lib.php
+46
-3
46 additions, 3 deletions
step/email/lib.php
with
46 additions
and
3 deletions
step/email/lib.php
+
46
−
3
View file @
67cdd305
...
@@ -107,7 +107,7 @@ class email extends libbase {
...
@@ -107,7 +107,7 @@ class email extends libbase {
array
(
'instanceid'
=>
$step
->
id
,
array
(
'instanceid'
=>
$step
->
id
,
'touser'
=>
$user
->
id
));
'touser'
=>
$user
->
id
));
$parsedsettings
=
$this
->
replace_placeholders
(
$settings
,
$user
,
$step
->
id
);
$parsedsettings
=
$this
->
replace_placeholders
(
$settings
,
$user
,
$step
->
id
,
$mailentries
);
$subject
=
$parsedsettings
[
'subject'
];
$subject
=
$parsedsettings
[
'subject'
];
$content
=
$parsedsettings
[
'content'
];
$content
=
$parsedsettings
[
'content'
];
...
@@ -129,29 +129,72 @@ class email extends libbase {
...
@@ -129,29 +129,72 @@ class email extends libbase {
* @param mixed $user user object
* @param mixed $user user object
* @return string[] array of mail text.
* @return string[] array of mail text.
*/
*/
private
function
replace_placeholders
(
$strings
,
$user
,
$stepid
)
{
private
function
replace_placeholders
(
$strings
,
$user
,
$stepid
,
$mailentries
)
{
global
$CFG
;
global
$CFG
;
$patterns
=
array
();
$patterns
=
array
();
$replacements
=
array
();
$replacements
=
array
();
// Replaces firstname of the user.
$patterns
[]
=
'##firstname##'
;
$patterns
[]
=
'##firstname##'
;
$replacements
[]
=
$user
->
firstname
;
$replacements
[]
=
$user
->
firstname
;
// Replaces lastname of the user.
$patterns
[]
=
'##lastname##'
;
$patterns
[]
=
'##lastname##'
;
$replacements
[]
=
$user
->
lastname
;
$replacements
[]
=
$user
->
lastname
;
// Replace link to interaction page.
$url
=
$CFG
->
wwwroot
.
'/'
.
$this
->
get_interaction_link
(
$stepid
)
->
out
();
$url
=
$CFG
->
wwwroot
.
'/'
.
$this
->
get_interaction_link
(
$stepid
)
->
out
();
$patterns
[]
=
'##link##'
;
$patterns
[]
=
'##link##'
;
$replacements
[]
=
$url
;
$replacements
[]
=
$url
;
// Replace html link to interaction page.
$patterns
[]
=
'##link-html##'
;
$patterns
[]
=
'##link-html##'
;
$replacements
[]
=
\html_writer
::
link
(
$url
,
$url
);
$replacements
[]
=
\html_writer
::
link
(
$url
,
$url
);
// Replace courses list.
$patterns
[]
=
'##courses##'
;
$coursesstring
=
''
;
$coursesstring
.
=
$this
->
parse_course
(
array_pop
(
$mailentries
)
->
courseid
);
foreach
(
$mailentries
as
$entry
)
{
$coursesstring
.
=
"
\n
"
.
$this
->
parse_course
(
$entry
->
courseid
);
}
$replacements
[]
=
$coursesstring
;
// Replace courses html.
$patterns
[]
=
'##courses-html##'
;
$coursestabledata
=
array
();
foreach
(
$mailentries
as
$entry
)
{
$coursestabledata
[
$entry
->
courseid
]
=
$this
->
parse_course_row_data
(
$entry
->
courseid
);
}
$coursestable
=
new
\html_table
();
$coursestable
->
data
=
$coursestabledata
;
$replacements
[]
=
\html_writer
::
table
(
$coursestable
);
return
str_ireplace
(
$patterns
,
$replacements
,
$strings
);
return
str_ireplace
(
$patterns
,
$replacements
,
$strings
);
}
}
/**
* Parses a course for the non html format.
* @param int $courseid id of the course
* @return string
*/
private
function
parse_course
(
$courseid
)
{
$course
=
get_course
(
$courseid
);
$result
=
$course
->
fullname
;
return
$result
;
}
/**
* Parses a course for the html format.
* @param int $courseid id of the course
* @return array column of a course
*/
private
function
parse_course_row_data
(
$courseid
)
{
$course
=
get_course
(
$courseid
);
return
array
(
$course
->
fullname
);
}
public
function
instance_settings
()
{
public
function
instance_settings
()
{
return
array
(
return
array
(
new
instance_setting
(
'responsetimeout'
,
PARAM_INT
),
new
instance_setting
(
'responsetimeout'
,
PARAM_INT
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment