Minor - format code

pull/2487/head
jmontoyaa 7 years ago
parent 6f765924ae
commit 2b9e651285
  1. 108
      main/inc/lib/certificate.lib.php
  2. 35
      plugin/buycourses/src/service_process.php

@ -30,11 +30,10 @@ class Certificate extends Model
public $qr_file = null;
public $user_id;
/* If true every time we enter to the certificate URL
we would generate a new certificate (good thing because we can edit the
certificate and all users will have the latest certificate bad because we
load the certificate everytime*/
/** If true every time we enter to the certificate URL
* we would generate a new certificate (good thing because we can edit the
* certificate and all users will have the latest certificate bad because we
* load the certificate every time */
public $force_certificate_generation = true;
/**
@ -169,6 +168,7 @@ class Certificate extends Model
$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();
$skill = new Skill();
@ -192,6 +192,7 @@ class Certificate extends Model
if ($my_category[0]->get_id() == strval(intval($this->certificate_data['cat_id']))) {
$name = $this->certificate_data['path_certificate'];
$myPathCertificate = $this->certification_user_path.basename($name);
if (file_exists($myPathCertificate) &&
!empty($name) &&
!is_dir($myPathCertificate) &&
@ -203,7 +204,7 @@ class Certificate extends Model
// Creating new name
$name = md5($this->user_id.$this->certificate_data['cat_id']).'.html';
$myPathCertificate = $this->certification_user_path.$name;
$path_certificate = '/'.$name;
$path_certificate = '/'.$name;
// Getting QR filename
$file_info = pathinfo($path_certificate);
@ -239,7 +240,24 @@ class Certificate extends Model
$text = $this->parse_certificate_variables(
$new_content_html['variables']
);
$this->generateQRImage($text, $qr_code_filename);
$this->generateQRImage(
$text,
$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
]
);
}
}
}
@ -254,6 +272,82 @@ class Certificate extends Model
return false;
}
/**
* @return array
*/
public static function notificationTags()
{
$tags = [
'((course_title))',
'((user_first_name))',
'((user_last_name))',
'((author_first_name))',
'((author_last_name))',
'((score))',
'((portal_name))'
];
return $tags;
}
/**
* @param string $subject
* @param string $message
* @param array $userInfo
* @param array $courseInfo
* @param array $certificateInfo
*
* @return bool
*/
public static function sendNotification(
$subject,
$message,
$userInfo,
$courseInfo,
$certificateInfo
) {
if (empty($userInfo) || empty($courseInfo)) {
return false;
}
$currentUserInfo = api_get_user_info();
$replace = [
$courseInfo['title'],
$userInfo['firstname'],
$userInfo['lastname'],
$currentUserInfo['firstname'],
$currentUserInfo['lastname'],
$certificateInfo['score_certificate'],
api_get_setting('Institution')
];
$message = str_replace(self::notificationTags(), $replace, $message);
MessageManager::send_message(
$userInfo['id'],
$subject,
$message,
[],
[],
0,
0,
0,
0,
$currentUserInfo['id']
);
$plugin = new AppPlugin();
$smsPlugin = $plugin->getSMSPluginLibrary();
if ($smsPlugin) {
$additionalParameters = array(
'smsType' => SmsPlugin::CERTIFICATE_NOTIFICATION,
'userId' => $userInfo['id'],
'direct_message' => $message
);
$smsPlugin->send($additionalParameters);
}
}
/**
* update user info about certificate
* @param int $cat_id category id

@ -1,15 +1,15 @@
<?php
/* For license terms, see /license.txt */
use Chamilo\UserBundle\Entity\User;
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
use Chamilo\CoreBundle\Entity\Session;
/**
* Process payments for the Buy Courses plugin
* @package chamilo.plugin.buycourses
*/
use Chamilo\UserBundle\Entity\User,
Chamilo\CoreBundle\Entity\SessionRelCourseRelUser,
Chamilo\CoreBundle\Entity\Session;
$cidReset = true;
require_once '../config.php';
@ -79,7 +79,6 @@ if ($form->validate()) {
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_process_confirm.php');
}
exit;
}
@ -98,7 +97,10 @@ if (!$culqiEnabled) {
}
$form->addHtml(
Display::return_message($plugin->get_lang('PleaseSelectThePaymentMethodBeforeConfirmYourOrder'), 'info')
Display::return_message(
$plugin->get_lang('PleaseSelectThePaymentMethodBeforeConfirmYourOrder'),
'info'
)
);
$form->addRadio('payment_type', null, $paymentTypesOptions);
$form->addHtml(
@ -113,8 +115,11 @@ $selectOptions = [
if ($typeUser) {
$users = $em->getRepository('ChamiloUserBundle:User')->findAll();
$selectOptions[$userInfo['user_id']] = api_get_person_name($userInfo['firstname'], $userInfo['lastname'])
.' ('.get_lang('Myself').')';
$selectOptions[$userInfo['user_id']] = api_get_person_name(
$userInfo['firstname'],
$userInfo['lastname']
).' ('.get_lang('Myself').')';
if (!empty($users)) {
/** @var User $user */
foreach ($users as $user) {
@ -134,7 +139,12 @@ if ($typeUser) {
$selectOptions[$course->getCourse()->getId()] = $course->getCourse()->getTitle();
}
if (!$checker) {
$form->addHtml(Display::return_message($plugin->get_lang('YouNeedToBeRegisteredInAtLeastOneCourse'), 'error'));
$form->addHtml(
Display::return_message(
$plugin->get_lang('YouNeedToBeRegisteredInAtLeastOneCourse'),
'error'
)
);
}
$form->addSelect('info_select', get_lang('Course'), $selectOptions);
} elseif ($typeSession) {
@ -215,7 +225,12 @@ if ($typeUser) {
$selectOptions = $selectOptions + $courseLpList + $sessionLpList;
if (!$checker) {
$form->addHtml(Display::return_message($plugin->get_lang('YourCoursesNeedAtLeastOneLearningPath'), 'error'));
$form->addHtml(
Display::return_message(
$plugin->get_lang('YourCoursesNeedAtLeastOneLearningPath'),
'error'
)
);
}
$form->addSelect('info_select', get_lang('LearningPath'), $selectOptions);
}

Loading…
Cancel
Save