113 lines
3.6 KiB
PHP
113 lines
3.6 KiB
PHP
<?php
|
|
// This file is part of the mycerts module for Moodle - http://moodle.org/
|
|
//
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
/**
|
|
* Provides functionality needed by mycerts activities.
|
|
*
|
|
* @package local_mycerts
|
|
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
namespace local_mycerts;
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
/**
|
|
* Class certificate.
|
|
*
|
|
* Helper functionality for certificates.
|
|
*
|
|
* @package local_mycerts
|
|
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2022 Kumi Systems e.U. <office@kumi.systems>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class certificate {
|
|
const CUSTOMCERT_PER_PAGE = 50;
|
|
|
|
/**
|
|
* Return the list of possible font sizes to use.
|
|
*/
|
|
public static function get_font_sizes() {
|
|
// Array to store the sizes.
|
|
$sizes = array();
|
|
|
|
for ($i = 1; $i <= 200; $i++) {
|
|
$sizes[$i] = $i;
|
|
}
|
|
|
|
return $sizes;
|
|
}
|
|
|
|
/**
|
|
* Get number of certificates for a user.
|
|
*
|
|
* @param int $userid
|
|
* @return int
|
|
*/
|
|
public static function get_number_of_certificates_for_user($userid) {
|
|
global $DB;
|
|
|
|
$sql = "SELECT COUNT(*)
|
|
FROM {htmlcert} c
|
|
INNER JOIN {htmlcert_issues} ci
|
|
ON c.id = ci.htmlcertid
|
|
WHERE ci.userid = :userid";
|
|
$htmlcerts = $DB->count_records_sql($sql, array('userid' => $userid));
|
|
$sql2 = "SELECT COUNT(*) FROM {customcert} c INNER JOIN {customcert_issues} ci ON c.id = ci.customcertid WHERE ci.userid = :userid";
|
|
$customcerts = $DB->count_records_sql($sql, array("userid" => $userid));
|
|
return $htmlcerts + $customcerts;
|
|
}
|
|
|
|
/**
|
|
* Gets the certificates for the user.
|
|
*
|
|
* @param int $userid
|
|
* @param int $limitfrom
|
|
* @param int $limitnum
|
|
* @param string $sort
|
|
* @return array
|
|
*/
|
|
public static function get_certificates_for_user($userid, $limitfrom, $limitnum, $sort = '') {
|
|
global $DB;
|
|
|
|
if (empty($sort)) {
|
|
$sort = 'ci.timecreated DESC';
|
|
}
|
|
|
|
$sql = "SELECT c.id, c.name, co.fullname as coursename, ci.code, ci.timecreated, 'htmlcert' as source
|
|
FROM {htmlcert} c
|
|
INNER JOIN {htmlcert_issues} ci
|
|
ON c.id = ci.htmlcertid
|
|
INNER JOIN {course} co
|
|
ON c.course = co.id
|
|
WHERE ci.userid = :userid
|
|
ORDER BY $sort";
|
|
$htmlcerts = $DB->get_records_sql($sql, array('userid' => $userid), $limitfrom, $limitnum);
|
|
$sql2 = "SELECT c.id, c.name, co.fullname as coursename, ci.code, ci.timecreated, 'customcert' as source
|
|
FROM {customcert} c
|
|
INNER JOIN {customcert_issues} ci
|
|
ON c.id = ci.customcertid
|
|
INNER JOIN {course} co
|
|
ON c.course = co.id
|
|
WHERE ci.userid = :userid
|
|
ORDER BY $sort";
|
|
$customcerts = $DB->get_records_sql($sql2, array('userid' => $userid), $limitfrom, $limitnum);
|
|
|
|
return $htmlcerts + $customcerts;
|
|
}
|
|
|
|
}
|