Skip to content

Commit

Permalink
EL-1194/dates
Browse files Browse the repository at this point in the history
infotext bug fix
  • Loading branch information
stellargela authored and aczerzuh committed Dec 12, 2022
1 parent 2a35b36 commit 14e0e5d
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
71 changes: 71 additions & 0 deletions classes/dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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 the class for fetching the important dates in mod_questionnaire for a given module instance and a user.
*
* @package mod_questionnaire
* @copyright 2022 University of Vienna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

declare(strict_types=1);

namespace mod_questionnaire;

use core\activity_dates;

/**
* Class for fetching the important dates in mod_questionnaire for a given module instance and a user.
*
* @copyright 2022 University of Vienna
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dates extends activity_dates {

/**
* Returns a list of important dates in mod_questionnaire
*
* @return array
*/
protected function get_dates(): array {
global $DB;

$timeopen = $this->cm->customdata['opendate'] ?? null;
$timeclose = $this->cm->customdata['closedate'] ?? null;

$now = time();
$dates = [];

if ($timeopen) {
$openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened';
$dates[] = [
'label' => get_string($openlabelid, 'core_course'),
'timestamp' => (int) $timeopen,
];
}

if ($timeclose) {
$closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed';
$dates[] = [
'label' => get_string($closelabelid, 'core_course'),
'timestamp' => (int) $timeclose,
];
}

return $dates;
}
}
38 changes: 38 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1276,3 +1276,41 @@ function mod_questionnaire_coursemodule_edit_post_actions($data, $course) {

return $data;
}

/**
* Add a get_coursemodule_info function in case any questionnaire type wants to add 'extra' information
* for the course (see resource).
*
* Given a course_module object, this function returns any "extra" information that may be needed
* when printing this activity in a course listing. See get_array_of_activities() in course/lib.php.
*
* @param stdClass $coursemodule The coursemodule object (record).
* @return cached_cm_info An object on information that the courses
* will know about (most noticeably, an icon).
*/
function questionnaire_get_coursemodule_info($coursemodule) {
global $DB;

$dbparams = array('id'=>$coursemodule->instance);
if (! $questionnaire = $DB->get_record('questionnaire', $dbparams)) {
return false;
}

$result = new cached_cm_info();
$result->name = $questionnaire->name;

if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$result->content = format_module_intro('questionnaire', $questionnaire, $coursemodule->id, false);
}

// Populate some other values that can be used in calendar or on dashboard.
if ($questionnaire->opendate) {
$result->customdata['opendate'] = $questionnaire->opendate;
}
if ($questionnaire->closedate) {
$result->customdata['closedate'] = $questionnaire->closedate;
}

return $result;
}

0 comments on commit 14e0e5d

Please sign in to comment.