Skip to content

Commit

Permalink
Customfield placeholder improved.
Browse files Browse the repository at this point in the history
- PLS-740, PLS-739
  • Loading branch information
raja-lmsace committed Apr 24, 2024
1 parent b19b0a7 commit 8042c24
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 8 additions & 6 deletions classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ class helper {
* @return array Updated subject and message body content.
*/
public static function update_emailvars($templatetext, $subject, $course, $user, $mod, $sender, $conditionvars=[]) {
global $DB, $CFG;
global $DB, $CFG, $USER;

// Include placholders handler and user profile library.
require_once($CFG->dirroot.'/mod/pulse/lib/vars.php');
require_once($CFG->dirroot.'/user/profile/lib.php');

// Load user profile field data.
$newuser = (object) ['id' => $user->id];
$newuser = (object) ['id' => !empty($user->id) ? $user->id : $USER->id];
profile_load_data($newuser);
// Make the profile custom field data to separate element of the user object.
$newuserkeys = array_map(function($value) {
Expand Down Expand Up @@ -99,10 +99,12 @@ public static function update_emailvars($templatetext, $subject, $course, $user,

if (\mod_pulse\automation\helper::create()->timemanagement_installed()) {
$userenrolments = ltool_timemanagement_get_course_user_enrollment($course->id, $user->id);
$record = $DB->get_record('ltool_timemanagement_modules', ['cmid' => $mod->id ?? 0]);
if ($record) {
$dates = ltool_timemanagement_cal_coursemodule_managedates($record, $userenrolments[0]['timestart']);
$duedate = isset($dates['duedate']) ? userdate($dates['duedate']) : '';
if (!empty($userenrolments)) {
$record = $DB->get_record('ltool_timemanagement_modules', ['cmid' => $mod->id ?? 0]);
if ($record) {
$dates = ltool_timemanagement_cal_coursemodule_managedates($record, $userenrolments[0]['timestart']);
$duedate = isset($dates['duedate']) ? userdate($dates['duedate']) : '';
}
}
}
$mod->duedate = $duedate ?? '';
Expand Down
11 changes: 8 additions & 3 deletions lib/vars.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ class pulse_email_vars {
* @return void
*/
public function __construct($user, $course, $sender, $pulse, $condition=null) {
global $CFG;
global $CFG, $USER;

$newuser = !empty($user->id) ? $user : $USER;
self::convert_varstime_format($user);
$this->user =& $user;
$this->user =& $newuser;

$this->sender =& $sender;
$wwwroot = $CFG->wwwroot;
Expand Down Expand Up @@ -538,7 +539,11 @@ public static function course_fields() {
'groupmode', 'groupmodeforce', 'defaultgroupingid', 'lang', 'calendartype', 'theme', 'timecreated',
'timemodified', 'enablecompletion',
];
$records = $DB->get_records('customfield_field', [], '', 'shortname');

$sql = "SELECT cf.shortname FROM {customfield_field} cf
JOIN {customfield_category} cc ON cc.id = cf.categoryid
WHERE cc.component = :component";
$records = $DB->get_records_sql($sql, ['component' => 'core_course']);

$customfields = array_map(function($value) {
return 'customfield_'.$value;
Expand Down

0 comments on commit 8042c24

Please sign in to comment.