Edit grading electronic plugin to send mail when generate certificate

- See BT#12404
- Rename function "register_user_certificate" to
"generateUserCertificate"
- Add option to send notification
pull/2487/head
jmontoyaa 8 years ago
parent 4175c9a22c
commit 92b8ac95f6
  1. 5
      main/cron/add_gradebook_certificates.php
  2. 2
      main/gradebook/gradebook_display_certificate.php
  3. 2
      main/gradebook/index.php
  4. 91
      main/gradebook/lib/be/category.class.php
  5. 16
      main/inc/lib/certificate.lib.php
  6. 2
      main/lp/lp_final_item.php
  7. 2
      main/lp/lp_view.php
  8. 10
      plugin/grading_electronic/generate.php

@ -14,7 +14,8 @@ require_once __DIR__.'/../inc/global.inc.php';
* Get all categories and users ids from gradebook
* @return array Categories and users ids
*/
function getAllCategoriesAndUsers() {
function getAllCategoriesAndUsers()
{
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
$jointable = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$joinStatement = ' JOIN '.$jointable.' ON '.$table.'.evaluation_id = '.$jointable.'.id';
@ -26,7 +27,7 @@ function getAllCategoriesAndUsers() {
if ($categoriesAndUsers = getAllCategoriesAndUsers()) {
foreach ($categoriesAndUsers as $categoryAndUser) {
Category::register_user_certificate(
Category::generateUserCertificate(
$categoryAndUser['category_id'],
$categoryAndUser['user_id']
);

@ -150,7 +150,7 @@ switch ($action) {
if ($userInfo['status'] == INVITEE) {
continue;
}
Category::register_user_certificate($cat_id, $userInfo['user_id']);
Category::generateUserCertificate($cat_id, $userInfo['user_id']);
}
}
break;

@ -755,7 +755,7 @@ if (!empty($selectCat)) {
if ($show_message == '') {
// Student
if (!api_is_allowed_to_edit() && !api_is_excluded_user_type()) {
$certificate = Category::register_user_certificate(
$certificate = Category::generateUserCertificate(
$selectCat,
$stud_id
);

@ -24,6 +24,9 @@ class Category implements GradebookItem
private $grade_model_id;
private $generateCertificates;
private $isRequirement;
private $courseDependency;
private $minimumToValidate;
public $studentList;
public $evaluations;
public $links;
@ -47,6 +50,8 @@ class Category implements GradebookItem
$this->grade_model_id = 0;
$this->generateCertificates = false;
$this->isRequirement = false;
$this->courseDependency = [];
$this->minimumToValidate = null;
}
/**
@ -248,6 +253,44 @@ class Category implements GradebookItem
$this->isRequirement = $isRequirement;
}
/**
* @param $value
*/
public function setCourseListDependency($value)
{
$result = [];
if (@unserialize($value) !== false) {
$result = unserialize($value);
}
$this->courseDependency = $result;
}
/**
* Course id list
* @return array
*/
public function getCourseListDependency()
{
return $this->courseDependency;
}
/**
* @param int $value
*/
public function setMinimumToValidate($value)
{
$this->minimumToValidate = $value;
}
/**
* @return null
*/
public function getMinimumToValidate()
{
return $this->minimumToValidate;
}
/**
* @return null|integer
*/
@ -324,8 +367,10 @@ class Category implements GradebookItem
*
* @return array
*/
public static function load_session_categories($id = null, $session_id = null)
{
public static function load_session_categories(
$id = null,
$session_id = null
) {
if (isset($id) && (int) $id === 0) {
$cats = array();
$cats[] = self::create_root_category();
@ -515,6 +560,9 @@ class Category implements GradebookItem
$cat->set_locked($data['locked']);
$cat->setGenerateCertificates($data['generate_certificates']);
$cat->setIsRequirement($data['is_requirement']);
$cat->setCourseListDependency(isset($data['depends']) ? $data['depends'] : []);
$cat->setMinimumToValidate(isset($data['minimum_to_validate']) ? $data['minimum_to_validate'] : null);
$categories[] = $cat;
}
@ -2070,16 +2118,17 @@ class Category implements GradebookItem
/**
* Generates a certificate for this user if everything matches
* @param int $category_id
* @param int $category_id gradebook id
* @param int $user_id
* @param bool $sendNotification
*
* @return bool|string
*/
public static function register_user_certificate($category_id, $user_id)
{
$courseId = api_get_course_int_id();
$courseCode = api_get_course_id();
$sessionId = api_get_session_id();
public static function generateUserCertificate(
$category_id,
$user_id,
$sendNotification = false
) {
// Generating the total score for a course
$cats_course = self::load(
$category_id,
@ -2087,13 +2136,22 @@ class Category implements GradebookItem
null,
null,
null,
$sessionId,
null,
false
);
/** @var Category $category */
$category = $cats_course[0];
if (empty($category)) {
return false;
}
$sessionId = $category->get_session_id();
$courseCode = $category->get_course_code();
$courseInfo = api_get_course_info($courseCode);
$courseId = $courseInfo['real_id'];
//@todo move these in a function
$sum_categories_weight_array = array();
if (isset($cats_course) && !empty($cats_course)) {
@ -2107,7 +2165,6 @@ class Category implements GradebookItem
}
}
$main_weight = $cats_course[0]->get_weight();
$cattotal = self::load($category_id);
$scoretotal = $cattotal[0]->calc_score($user_id);
@ -2115,9 +2172,6 @@ class Category implements GradebookItem
// file load this variable as a global
$scoredisplay = ScoreDisplay::instance();
$my_score_in_gradebook = $scoredisplay->display_score($scoretotal, SCORE_SIMPLE);
// A student always sees only the teacher's repartition
$scoretotal_display = $scoredisplay->display_score($scoretotal, SCORE_DIV_PERCENT);
$userFinishedCourse = self::userFinishedCourse(
$user_id,
$cats_course[0],
@ -2178,7 +2232,12 @@ class Category implements GradebookItem
$html = array();
if (!empty($my_certificate)) {
$certificate_obj = new Certificate($my_certificate['id']);
$certificate_obj = new Certificate(
$my_certificate['id'],
0,
$sendNotification
);
$fileWasGenerated = $certificate_obj->isHtmlFileGenerated();
if (!empty($fileWasGenerated)) {
@ -2233,7 +2292,7 @@ class Category implements GradebookItem
{
if (!empty($userList)) {
foreach ($userList as $userInfo) {
self::register_user_certificate($catId, $userInfo['user_id']);
self::generateUserCertificate($catId, $userInfo['user_id']);
}
}
}

@ -19,7 +19,7 @@ class Certificate extends Model
/**
* Certification data
*/
public $certificate_data = array();
public $certificate_data = [];
/**
* Student's certification path
@ -40,11 +40,15 @@ class Certificate extends Model
* Constructor
* @param int $certificate_id ID of the certificate.
* @param int $userId
* @param bool $sendNotification send message to student
*
* If no ID given, take user_id and try to generate one
*/
public function __construct($certificate_id = 0, $userId = 0)
{
public function __construct(
$certificate_id = 0,
$userId = 0,
$sendNotification = false
) {
$this->table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$this->user_id = !empty($userId) ? $userId : api_get_user_id();
@ -62,12 +66,12 @@ class Certificate extends Model
// To force certification generation
if ($this->force_certificate_generation) {
$this->generate();
$this->generate([], $sendNotification);
}
if (isset($this->certificate_data) && $this->certificate_data) {
if (empty($this->certificate_data['path_certificate'])) {
$this->generate();
$this->generate([], $sendNotification);
}
}
}
@ -150,7 +154,7 @@ class Certificate extends Model
* @param bool $sendNotification
* @return bool|int
*/
public function generate($params = array(), $sendNotification = false)
public function generate($params = [], $sendNotification = false)
{
// The user directory should be set
if (empty($this->certification_user_path) &&

@ -119,7 +119,7 @@ if ($accessGranted == false) {
if ($show_message == '') {
if (!api_is_allowed_to_edit() && !api_is_excluded_user_type()) {
$certificate = Category::register_user_certificate($categoryId, $userId);
$certificate = Category::generateUserCertificate($categoryId, $userId);
if (!empty($certificate['pdf_url']) || !empty($certificate['badge_link'])) {
if (is_array($certificate) && isset($certificate['pdf_url'])) {

@ -470,7 +470,7 @@ if ($_SESSION['oLP']->current == $_SESSION['oLP']->get_last()) {
$userScore = $gradebookLinks[0]->calc_score($user_id, 'best');
if ($userScore[0] >= $gradebookMinScore) {
Category::register_user_certificate($categories[0]->get_id(), $user_id);
Category::generateUserCertificate($categories[0]->get_id(), $user_id);
}
}
}

@ -70,10 +70,7 @@ try {
Criteria::expr()->eq('relationType', Session::STUDENT)
);
$subscriptions = $session
->getUsers()
->matching($criteria);
$subscriptions = $session->getUsers()->matching($criteria);
$students = [];
/** @var SessionRelUser $subscription */
@ -152,9 +149,10 @@ try {
continue;
}
Category::register_user_certificate(
Category::generateUserCertificate(
$gradebook->get_id(),
$student->getId()
$student->getId(),
true
);
}

Loading…
Cancel
Save