#207 No need to use a table/list when displaying only one issue

This commit is contained in:
Mark Nelson 2018-07-09 23:45:19 +08:00
parent 47f1102545
commit f3cff401b5
3 changed files with 24 additions and 38 deletions

View file

@ -60,7 +60,11 @@ class mobile {
$certificate->introformat, $context->id, 'mod_customcert', 'intro');
// Get any issues this person may have.
$issues = $DB->get_records('customcert_issues', ['userid' => $USER->id, 'customcertid' => $certificate->id]);
$issue = false;
if ($issues = $DB->get_records('customcert_issues', ['userid' => $USER->id, 'customcertid' => $certificate->id],
'timecreated DESC')) {
$issue = reset($issues);
}
$candownload = true;
$canmanage = has_capability('mod/customcert:manage', $context);
@ -101,8 +105,7 @@ class mobile {
$data = [
'certificate' => $certificate,
'cmid' => $cm->id,
'hasissues' => !empty($issues),
'issues' => array_values($issues),
'issue' => $issue,
'showgroups' => !empty($groups),
'groups' => array_values($groups),
'canmanage' => $canmanage,

View file

@ -50,12 +50,9 @@
"requiredtime": "60"
},
"cmid": "25",
"hasissues": "true",
"issues": [
{
"timecreated": "1528370177"
}
],
"issue": {
"timecreated": "1528370177"
},
"showgroups": "true",
"groups": [
{
@ -84,20 +81,15 @@
{{=<% %>=}}
<div>
<core-course-module-description description="<% certificate.intro %>" component="mod_customcert" componentId="<% cmid %>"></core-course-module-description>
<%#hasissues%>
<%#issue%>
<%^canmanage%>
<ion-list>
<ion-list-header class="text-center">
{{ 'plugin.mod_customcert.receiveddate' | translate }}
</ion-list-header>
<%#issues%>
<ion-item class="text-center">
{{ <% timecreated %> | coreToLocaleString }}
</ion-item>
<%/issues%>
</ion-list>
<ion-item>
{{ 'plugin.mod_customcert.receiveddate' | translate }}
<br />
<div class="timerewarded">{{ <% timecreated %> | coreToLocaleString }}</div>
</ion-item>
<%/canmanage%>
<%/hasissues%>
<%/issue%>
<%#candownload%>
<ion-item>
<button ion-button block core-course-download-module-main-file moduleId="<% cmid %>" courseId="<% certificate.course %>" component="mod_customcert" [files]="[{fileurl: '<% fileurl %>', timemodified: '<% currenttimestamp %>'}]">

View file

@ -124,35 +124,26 @@ if (!$downloadown && !$downloadissue) {
}
// If the current user has been issued a customcert generate HTML to display the details.
$issuelist = '';
$issuehtml = '';
$issues = $DB->get_records('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id));
if ($issues && !$canmanage) {
$table = new html_table();
$table->class = 'generaltable';
$table->head = array(get_string('receiveddate', 'customcert'));
$table->align = array('left');
$table->attributes = array('style' => 'width:20%; margin:auto');
foreach ($issues as $issue) {
$row = array();
$row[] = userdate($issue->timecreated);
$table->data[$issue->id] = $row;
}
$issuelist = html_writer::table($table) . "<br />";
// Get the most recent issue (there should only be one).
$issue = reset($issues);
$issuestring = get_string('receiveddate', 'customcert') . ': ' . userdate($issue->timecreated);
$issuehtml = $OUTPUT->box($issuestring);
}
// Create the button to download the customcert.
$linkname = get_string('getcustomcert', 'customcert');
$link = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id, 'downloadown' => true));
$downloadbutton = new single_button($link, $linkname);
$downloadbutton = html_writer::tag('div', $OUTPUT->render($downloadbutton), array('style' => 'text-align:center'));
$downloadbutton = new single_button($link, $linkname, 'post', true);
$downloadbutton = $OUTPUT->render($downloadbutton);
// Output all the page data.
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($customcert->name));
echo $intro;
echo $issuelist;
echo $issuehtml;
echo $downloadbutton;
if (isset($reporttable)) {
echo $OUTPUT->heading(get_string('listofissues', 'customcert'), 3);