Add "sendNotification" parameter when generating certificates BT#12982

- Minor format code
- Replace name of add_skill_to_user to camelCase
- Fix course code when entering certificates/index.php page
pull/2487/head
jmontoyaa 8 years ago
parent 6042afd466
commit 1b5a9ae1e2
  1. 49
      main/gradebook/gradebook_display_certificate.php
  2. 2
      main/gradebook/lib/be/category.class.php
  3. 38
      main/inc/lib/certificate.lib.php
  4. 10
      main/inc/lib/skill.lib.php

@ -78,20 +78,13 @@ if ($filter === 'true') {
$content = '';
$tags = [
'((course_title))',
'((user_first_name))',
'((user_last_name))',
'((author_first_name))',
'((author_last_name))',
'((score))',
'((portal_name))'
];
$tags = Certificate::notificationTags();
switch ($action) {
case 'send_notifications':
$currentUserInfo = api_get_user_info();
$originalMessage = isset($_POST['message']) ? $_POST['message'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
$subject = get_lang('NotificationCertificateSubject');
if (!empty($originalMessage)) {
foreach ($certificate_list as $index => $value) {
$userInfo = api_get_user_info($value['user_id']);
@ -103,42 +96,14 @@ switch ($action) {
$cat_id
);
$subject = get_lang('NotificationCertificateSubject');
foreach ($list as $valueCertificate) {
$replace = [
$courseInfo['title'],
$userInfo['firstname'],
$userInfo['lastname'],
$currentUserInfo['firstname'],
$currentUserInfo['lastname'],
$valueCertificate['score_certificate'],
api_get_setting('Institution')
];
$message = str_replace($tags, $replace, $originalMessage);
MessageManager::send_message(
$userInfo['id'],
Certificate::sendNotification(
$subject,
$message,
[],
[],
0,
0,
0,
0,
$currentUserInfo['id']
$userInfo,
$courseInfo,
$valueCertificate
);
$plugin = new AppPlugin();
$smsPlugin = $plugin->getSMSPluginLibrary();
if ($smsPlugin) {
$additionalParameters = array(
'smsType' => SmsPlugin::CERTIFICATE_NOTIFICATION,
'userId' => $userInfo['id'],
'direct_message' => $message
);
$smsPlugin->send($additionalParameters);
}
}
}
Display::addFlash(Display::return_message(get_lang('Sent')));

@ -2136,7 +2136,7 @@ class Category implements GradebookItem
if ($skillToolEnabled) {
$skill = new Skill();
$skill->add_skill_to_user(
$skill->addSkillToUser(
$user_id,
$category_id,
$courseId,

@ -147,9 +147,10 @@ class Certificate extends Model
* Generates an HTML Certificate and fills the path_certificate field in the DB
*
* @param array $params
* @param bool $sendNotification
* @return bool|int
*/
public function generate($params = array())
public function generate($params = array(), $sendNotification = false)
{
// The user directory should be set
if (empty($this->certification_user_path) &&
@ -167,12 +168,12 @@ class Certificate extends Model
if (isset($my_category[0]) &&
$my_category[0]->is_certificate_available($this->user_id)
) {
$courseId = api_get_course_int_id();
$courseInfo = api_get_course_info();
$sessionId = api_get_session_id();
$courseInfo = api_get_course_info($my_category[0]->get_course_code());
$courseId = $courseInfo['real_id'];
$sessionId = $my_category[0]->get_session_id();
$skill = new Skill();
$skill->add_skill_to_user(
$skill->addSkillToUser(
$this->user_id,
$this->certificate_data['cat_id'],
$courseId,
@ -245,19 +246,20 @@ class Certificate extends Model
$qr_code_filename
);
$subject = get_lang('NotificationCertificateSubject');
$message = nl2br(get_lang('NotificationCertificateTemplate'));
$score = $this->certificate_data['score_certificate'];
Certificate::sendNotification(
$subject,
$message,
api_get_user_info($this->user_id),
$courseInfo,
[
'score_certificate' => $score
]
);
if ($sendNotification) {
$subject = get_lang('NotificationCertificateSubject');
$message = nl2br(get_lang('NotificationCertificateTemplate'));
$score = $this->certificate_data['score_certificate'];
Certificate::sendNotification(
$subject,
$message,
api_get_user_info($this->user_id),
$courseInfo,
[
'score_certificate' => $score
]
);
}
}
}
}

@ -852,10 +852,14 @@ class Skill extends Model
* @param int $courseId
* @param int $sessionId
*/
public function add_skill_to_user($user_id, $gradebook_id, $courseId = 0, $sessionId = 0)
{
public function addSkillToUser(
$user_id,
$gradebook_id,
$courseId = 0,
$sessionId = 0
) {
$skill_gradebook = new SkillRelGradebook();
$skill_rel_user = new SkillRelUser();
$skill_rel_user = new SkillRelUser();
$skill_gradebooks = $skill_gradebook->get_all(
array('where' => array('gradebook_id = ?' => $gradebook_id))

Loading…
Cancel
Save