#51 Added ability to verify certificates
This commit is contained in:
parent
7e6fa8103f
commit
ca08fe954a
11 changed files with 409 additions and 2 deletions
52
classes/output/renderer.php
Normal file
52
classes/output/renderer.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
// This file is part of 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/>.
|
||||
|
||||
/**
|
||||
* Contains renderer class.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_customcert\output;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use plugin_renderer_base;
|
||||
|
||||
/**
|
||||
* Renderer class.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Renders the verify certificate results.
|
||||
*
|
||||
* Defer to template.
|
||||
*
|
||||
* @param \mod_customcert\output\verify_certificate_results $page
|
||||
* @return string html for the page
|
||||
*/
|
||||
public function render_verify_certificate_results(verify_certificate_results $page) {
|
||||
$data = $page->export_for_template($this);
|
||||
return parent::render_from_template('mod_customcert/verify_certificate_results', $data);
|
||||
}
|
||||
}
|
90
classes/output/verify_certificate_result.php
Normal file
90
classes/output/verify_certificate_result.php
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
// This file is part of 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/>.
|
||||
|
||||
/**
|
||||
* Contains class used to prepare a verification result for display.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_customcert\output;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use renderable;
|
||||
use templatable;
|
||||
|
||||
/**
|
||||
* Class to prepare a verification result for display.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class verify_certificate_result implements templatable, renderable {
|
||||
|
||||
/**
|
||||
* @var string The URL to the user's profile.
|
||||
*/
|
||||
public $userprofileurl;
|
||||
|
||||
/**
|
||||
* @var string The user's fullname.
|
||||
*/
|
||||
public $userfullname;
|
||||
|
||||
/**
|
||||
* @var string The URL to the course page.
|
||||
*/
|
||||
public $courseurl;
|
||||
|
||||
/**
|
||||
* @var string The course's fullname.
|
||||
*/
|
||||
public $coursefullname;
|
||||
|
||||
/**
|
||||
* @var string The certificate's name.
|
||||
*/
|
||||
public $certificatename;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \stdClass $result
|
||||
*/
|
||||
public function __construct($result) {
|
||||
$this->userprofileurl = new \moodle_url('/user/view.php', array('id' => $result->userid,
|
||||
'course' => $result->courseid));
|
||||
$this->userfullname = fullname($result);
|
||||
$this->courseurl = new \moodle_url('/course/view.php', array('id' => $result->courseid));
|
||||
$this->coursefullname = $result->coursefullname;
|
||||
$this->certificatename = $result->certificatename;
|
||||
}
|
||||
|
||||
public function export_for_template(\renderer_base $output) {
|
||||
$result = new \stdClass();
|
||||
$result->userprofileurl = $this->userprofileurl;
|
||||
$result->userfullname = $this->userfullname;
|
||||
$result->coursefullname = $this->coursefullname;
|
||||
$result->courseurl = $this->courseurl;
|
||||
$result->certificatename = $this->certificatename;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
83
classes/output/verify_certificate_results.php
Normal file
83
classes/output/verify_certificate_results.php
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
// This file is part of 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/>.
|
||||
|
||||
/**
|
||||
* Contains class used to prepare verification results for display.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_customcert\output;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use renderable;
|
||||
use templatable;
|
||||
|
||||
/**
|
||||
* Class to prepare verification results for display.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class verify_certificate_results implements templatable, renderable {
|
||||
|
||||
/**
|
||||
* @var bool Was the code successfully verified?
|
||||
*/
|
||||
public $success;
|
||||
|
||||
/**
|
||||
* @var string The message to display.
|
||||
*/
|
||||
public $message;
|
||||
|
||||
/**
|
||||
* @var array The certificates issued with the matching code.
|
||||
*/
|
||||
public $issues;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \stdClass $result
|
||||
*/
|
||||
public function __construct($result) {
|
||||
$this->success = $result->success;
|
||||
if ($this->success) {
|
||||
$this->message = get_string('verified', 'customcert');
|
||||
} else {
|
||||
$this->message = get_string('notverified', 'customcert');
|
||||
}
|
||||
$this->issues = $result->issues;
|
||||
}
|
||||
|
||||
public function export_for_template(\renderer_base $output) {
|
||||
$result = new \stdClass();
|
||||
$result->success = $this->success;
|
||||
$result->message = $this->message;
|
||||
$result->issues = array();
|
||||
foreach ($this->issues as $issue) {
|
||||
$resultissue = new verify_certificate_result($issue);
|
||||
$result->issues[] = $resultissue->export_for_template($output);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue