forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
319 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
<?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/>. | ||
|
||
/** | ||
* Table log for displaying logs. | ||
* | ||
* @package report_log | ||
* @copyright 2014 Rajesh Taneja <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die; | ||
global $CFG; | ||
require_once($CFG->libdir . '/tablelib.php'); | ||
/** | ||
* Table log class for displaying logs. | ||
* | ||
* @package report_log | ||
* @copyright 2014 Rajesh Taneja <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class djarran extends table_sql { | ||
|
||
protected $cm; | ||
protected $context; | ||
public $download; | ||
protected $isdownload; | ||
public $hasinactive; | ||
|
||
/** | ||
* Constructor | ||
* @param int $uniqueid all tables have to have a unique id, this is used | ||
* as a key when storing table properties like sort order in the session. | ||
*/ | ||
function __construct($uniqueid, $mode, $cm, $context, $isdownload = null) { | ||
|
||
parent::__construct($uniqueid); | ||
|
||
$this->cm = $cm; | ||
$this->context = $context; | ||
$this->isdownload = $isdownload; | ||
|
||
$canedit = true; | ||
|
||
$columns = []; | ||
|
||
|
||
if ($isdownload) { | ||
$columns[] = $mode == 'group' ? 'groupid' : 'userid'; | ||
} | ||
|
||
if ($mode == 'group') { | ||
$columns[] = 'name'; | ||
} else { | ||
$columns[] = 'firstname'; | ||
} | ||
|
||
// Define the list of columns to show. | ||
array_push($columns, 'timeopen', 'timeclose', 'timelimit', 'attempts', 'password'); | ||
|
||
if (!$isdownload) { | ||
$columns[] = 'actions'; | ||
} | ||
|
||
// $columns = array('username', 'password', 'firstname', 'lastname'); | ||
$this->define_columns($columns); | ||
|
||
$headers = []; | ||
|
||
if ($isdownload) { | ||
$headers[] = $mode == 'group' ? 'Group ID' : 'User ID'; | ||
} | ||
|
||
if ($mode == 'group') { | ||
$headers[] = 'Group'; | ||
} else { | ||
$headers[] = 'User'; | ||
} | ||
|
||
// Define the titles of columns to show in header. | ||
array_push($headers, 'Quiz opens', 'Quiz closes', 'Time limit', 'Attempts', 'Password'); | ||
|
||
if (!$isdownload) { | ||
$headers[] = 'Actions'; | ||
} | ||
|
||
// $headers = array('Username', 'Password', 'First name', 'Last name'); | ||
$this->define_headers($headers); | ||
|
||
$this->collapsible(false); | ||
$this->sortable(false); | ||
$this->pageable(true); | ||
$this->pagesize = 20; | ||
} | ||
|
||
// public function format_row($row) { | ||
// print_r($row); | ||
// $rowclass = ''; | ||
// | ||
// if (true) { | ||
// $rowclass = 'dimmed_text'; | ||
// } | ||
// | ||
// return parent::format_row($row, $rowclass); | ||
// } | ||
|
||
function get_row_class($row) { | ||
if (!$this->is_active($row)) { | ||
return 'dimmed_text'; | ||
} | ||
} | ||
|
||
function is_active($override): bool { | ||
|
||
$active = true; | ||
if (!has_capability('mod/quiz:attempt', $this->context, $override->userid)) { | ||
// User not allowed to take the quiz. | ||
$active = false; | ||
$this->hasinactive = true; | ||
} else if (!\core_availability\info_module::is_user_visible($this->cm, $override->userid)) { | ||
// User cannot access the module. | ||
$active = false; | ||
$this->hasinactive = true; | ||
} | ||
|
||
return $active; | ||
} | ||
|
||
public function is_downloadable($downloadable = null) { | ||
return true; | ||
} | ||
|
||
public function col_firstname($override) { | ||
|
||
$active = $this->is_active($override); | ||
|
||
$userurl = new moodle_url('/user/view.php', []); | ||
$extranamebit = $active ? '' : '*'; | ||
|
||
return html_writer::link(new moodle_url($userurl, ['id' => $override->userid]), | ||
fullname($override) . $extranamebit); } | ||
|
||
public function col_name($override) { | ||
$groupurl = new moodle_url('/group/overview.php', ['id' => $this->cm->course]); | ||
$active = true; | ||
$extranamebit = $active ? '' : '*'; | ||
|
||
$override->rowclasses[] = 'dimmed_text'; | ||
|
||
return html_writer::link(new moodle_url($groupurl, ['group' => $override->groupid]), | ||
format_string($override->name, true, ['context' => $this->context]) . $extranamebit); | ||
} | ||
|
||
public function col_actions($override) { | ||
global $OUTPUT; | ||
|
||
// print_r($override); | ||
$overridedeleteurl = new moodle_url('/mod/quiz/overridedelete.php'); | ||
$overrideediturl = new moodle_url('/mod/quiz/overrideedit.php'); | ||
|
||
if (true) { | ||
$actiondiv = html_writer::start_div('actions'); | ||
|
||
// Edit button. | ||
$editurlstr = $overrideediturl->out(true, ['id' => $override->id]); | ||
$editbutton = html_writer::link($editurlstr, $OUTPUT->pix_icon('t/edit', get_string('edit')), | ||
// array('class' => 'btn btn-primary', 'title' => get_string('edit'))); | ||
array('title' => get_string('edit'))); | ||
$actiondiv .= $editbutton; | ||
|
||
// Duplicate button. | ||
$copyurlstr = $overrideediturl->out(true, | ||
['id' => $override->id, 'action' => 'duplicate']); | ||
$copybutton = html_writer::link($copyurlstr, $OUTPUT->pix_icon('t/copy', get_string('copy')), | ||
// array('class' => 'btn btn-secondary', 'title' => get_string('copy'))); | ||
array('title' => get_string('copy'))); | ||
$actiondiv .= $copybutton; | ||
|
||
// Delete button. | ||
$deleteurlstr = $overridedeleteurl->out(true, | ||
['id' => $override->id, 'sesskey' => sesskey()]); | ||
$deletebutton = html_writer::link($deleteurlstr, $OUTPUT->pix_icon('t/delete', get_string('delete')), | ||
array('title' => get_string('delete'))); | ||
$actiondiv .= $deletebutton; | ||
|
||
$actiondiv .= html_writer::end_div(); | ||
|
||
return $actiondiv; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
|
||
/** | ||
* This function is called for each data row to allow processing of the | ||
* username value. | ||
* | ||
* @param object $values Contains object with all the values of record. | ||
* @return $string Return username with link to profile or username only | ||
* when downloading. | ||
*/ | ||
// function col_quiz($values) { | ||
// // If the data is being downloaded than we don't want to show HTML. | ||
// if ($this->is_downloading()) { | ||
// return $values->quiz; | ||
// } else { | ||
// return $values->quiz; | ||
// } | ||
// } | ||
|
||
/** | ||
* This function is called for each data row to allow processing of | ||
* columns which do not have a *_cols function. | ||
* @return string return processed value. Return NULL if no change has | ||
* been made. | ||
*/ | ||
function other_cols($colname, $value) { | ||
// For security reasons we don't want to show the password hash. | ||
if ($colname == 'password' && !$this->isdownload) { | ||
return !empty($value->password) ? | ||
get_string('enabled', 'quiz') : get_string('none', 'quiz'); | ||
} | ||
|
||
if ($colname == 'timeopen') { | ||
|
||
if ($this->isdownload) { | ||
return date('Y-m-d H:i', $value->timeopen); | ||
} | ||
|
||
return $value->timeopen > 0 ? userdate($value->timeopen) : get_string('noopen', 'quiz'); | ||
} | ||
if ($colname == 'timeclose') { | ||
if ($this->isdownload) { | ||
return date('Y-m-d H:i', $value->timeclose); | ||
} | ||
return $value->timeclose > 0 ? userdate($value->timeclose) : get_string('noopen', 'quiz'); | ||
} | ||
|
||
if ($colname == 'timelimit') { | ||
return $values[] = $value->timelimit > 0 ? | ||
format_time($value->timelimit) : get_string('none', 'quiz'); | ||
} | ||
|
||
if ($colname == 'attempts') { | ||
return $values[] = $value->attempts > 0 && isset($value->attempts) ? | ||
$value->attempts : 'Unlimited'; | ||
} | ||
} | ||
} |
Oops, something went wrong.