2013-03-14 01:19:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// This file is part of the customcert 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/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The date elements core interaction API.
|
|
|
|
*
|
2013-06-12 08:23:08 +00:00
|
|
|
* @package customcertelements_date
|
2013-03-14 01:19:08 +00:00
|
|
|
* @copyright Mark Nelson <markn@moodle.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2013-04-10 09:17:19 +00:00
|
|
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
2013-03-14 01:19:08 +00:00
|
|
|
|
|
|
|
require_once($CFG->dirroot . '/mod/customcert/elements/element.class.php');
|
2013-06-06 10:59:08 +00:00
|
|
|
require_once($CFG->dirroot . '/mod/customcert/elements/grade/lib.php');
|
2013-03-14 01:19:08 +00:00
|
|
|
|
2013-06-12 08:23:08 +00:00
|
|
|
class customcert_elements_date extends customcert_elements_base {
|
2013-03-14 01:19:08 +00:00
|
|
|
|
|
|
|
/**
|
2013-06-06 10:59:08 +00:00
|
|
|
* Constructor.
|
2013-03-14 01:19:08 +00:00
|
|
|
*
|
2013-06-06 10:59:08 +00:00
|
|
|
* @param stdClass $element the element data
|
2013-03-14 01:19:08 +00:00
|
|
|
*/
|
2013-06-06 10:59:08 +00:00
|
|
|
function __construct($element) {
|
|
|
|
parent::__construct($element);
|
|
|
|
|
|
|
|
// Set the item and format for this element.
|
2013-03-14 01:19:08 +00:00
|
|
|
$dateitem = '';
|
|
|
|
$dateformat = '';
|
|
|
|
|
|
|
|
if (!empty($this->element->data)) {
|
|
|
|
$dateinfo = json_decode($this->element->data);
|
|
|
|
$dateitem = $dateinfo->dateitem;
|
|
|
|
$dateformat = $dateinfo->dateformat;
|
|
|
|
}
|
|
|
|
|
2013-06-06 10:59:08 +00:00
|
|
|
$this->element->dateitem = $dateitem;
|
|
|
|
$this->element->dateformat = $dateformat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function renders the form elements when adding a customcert element.
|
|
|
|
*
|
|
|
|
* @param stdClass $mform the edit_form instance.
|
|
|
|
*/
|
|
|
|
public function render_form_elements($mform) {
|
2013-04-24 09:47:36 +00:00
|
|
|
// Get the possible date options.
|
|
|
|
$dateoptions = array();
|
|
|
|
$dateoptions['1'] = get_string('issueddate', 'certificate');
|
|
|
|
$dateoptions['2'] = get_string('completiondate', 'certificate');
|
2013-06-12 08:23:08 +00:00
|
|
|
$dateoptions = $dateoptions + customcert_elements_grade::get_grade_items();
|
2013-03-14 01:19:08 +00:00
|
|
|
|
2013-06-12 08:23:08 +00:00
|
|
|
$mform->addElement('select', 'dateitem', get_string('dateitem', 'customcertelements_date'), $dateoptions);
|
|
|
|
$mform->addHelpButton('dateitem', 'dateitem', 'customcertelements_date');
|
2013-06-05 09:32:12 +00:00
|
|
|
|
2013-06-12 08:23:08 +00:00
|
|
|
$mform->addElement('select', 'dateformat', get_string('dateformat', 'customcertelements_date'), self::get_date_formats());
|
|
|
|
$mform->addHelpButton('dateformat', 'dateformat', 'customcertelements_date');
|
2013-06-05 09:32:12 +00:00
|
|
|
|
|
|
|
parent::render_form_elements($mform);
|
2013-03-14 01:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This will handle how form data will be saved into the data column in the
|
2013-04-24 09:47:36 +00:00
|
|
|
* customcert_elements table.
|
2013-03-14 01:19:08 +00:00
|
|
|
*
|
|
|
|
* @param stdClass $data the form data.
|
|
|
|
* @return string the json encoded array
|
|
|
|
*/
|
|
|
|
public function save_unique_data($data) {
|
|
|
|
// Array of data we will be storing in the database.
|
|
|
|
$arrtostore = array(
|
2013-06-06 10:59:08 +00:00
|
|
|
'dateitem' => $data->dateitem,
|
|
|
|
'dateformat' => $data->dateformat
|
2013-03-14 01:19:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Encode these variables before saving into the DB.
|
|
|
|
return json_encode($arrtostore);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-10 09:53:56 +00:00
|
|
|
* Handles rendering the element on the pdf.
|
2013-03-14 01:19:08 +00:00
|
|
|
*
|
2013-04-24 09:47:36 +00:00
|
|
|
* @param stdClass $pdf the pdf object
|
2013-03-14 01:19:08 +00:00
|
|
|
*/
|
2013-06-05 08:42:18 +00:00
|
|
|
public function render($pdf) {
|
2013-03-14 01:19:08 +00:00
|
|
|
// TO DO.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to return all the date formats.
|
|
|
|
*
|
|
|
|
* @return array the list of date formats
|
|
|
|
*/
|
2013-04-24 09:47:36 +00:00
|
|
|
public static function get_date_formats() {
|
2013-03-14 01:19:08 +00:00
|
|
|
$dateformats = array();
|
|
|
|
$dateformats[] = 'January 1, 2000';
|
|
|
|
$dateformats[] = 'January 1st, 2000';
|
|
|
|
$dateformats[] = '1 January 2000';
|
|
|
|
$dateformats[] = 'January 2000';
|
|
|
|
$dateformats[] = get_string('userdateformat', 'certificate');
|
|
|
|
|
|
|
|
return $dateformats;
|
|
|
|
}
|
|
|
|
}
|