first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
<?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/>.
namespace mod_assign\output;
use templatable;
use renderable;
use moodle_url;
/**
* Output the actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class actionmenu implements templatable, renderable {
/** @var int The course module ID. */
private $cmid;
/**
* Constructor for this object.
*
* @param int $cmid The course module ID.
*/
public function __construct(int $cmid) {
$this->cmid = $cmid;
}
/**
* Data to be used for a template.
*
* @param \renderer_base $output renderer base output.
* @return array Data to be used for a template.
*/
public function export_for_template(\renderer_base $output): array {
$submissionlink = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'grading']);
$return = ['submissionlink' => $submissionlink->out(false)];
if (has_capability('mod/assign:grade', \context_module::instance($this->cmid))) {
$gradelink = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'grader']);
$return['gradelink'] = $gradelink->out(false);
}
return $return;
}
}
@@ -0,0 +1,87 @@
<?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/>.
/**
* This file contains the definition for the renderable assign header.
*
* @package mod_assign
* @copyright 2020 Matt Porritt <mattp@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
/**
* This file contains the definition for the renderable assign header.
*
* @package mod_assign
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assign_header implements \renderable {
/** @var \stdClass The assign record. */
public $assign;
/** @var mixed \context|null the context record. */
public $context;
/** @var bool $showintro Show or hide the intro. */
public $showintro;
/** @var int coursemoduleid The course module id. */
public $coursemoduleid;
/** @var string $subpage Optional subpage (extra level in the breadcrumbs). */
public $subpage;
/** @var string $preface Optional preface (text to show before the heading). */
public $preface;
/** @var string $postfix Optional postfix (text to show after the intro). */
public $postfix;
/** @var \moodle_url|null $subpageurl link for the sub page */
public $subpageurl;
/** @var bool $activity optional show activity text. */
public $activity;
/**
* Constructor
*
* @param \stdClass $assign The assign database record.
* @param \context|null $context The course module context.
* @param bool $showintro Show or hide the intro.
* @param int $coursemoduleid The course module id.
* @param string $subpage An optional sub page in the navigation.
* @param string $preface An optional preface to show before the heading.
* @param string $postfix An optional postfix to show after the intro.
* @param \moodle_url|null $subpageurl An optional sub page URL link for the subpage.
* @param bool $activity Optional show activity text if true.
*/
public function __construct(
\stdClass $assign,
$context,
$showintro,
$coursemoduleid,
$subpage = '',
$preface = '',
$postfix = '',
\moodle_url $subpageurl = null,
bool $activity = false
) {
$this->assign = $assign;
$this->context = $context;
$this->showintro = $showintro;
$this->coursemoduleid = $coursemoduleid;
$this->subpage = $subpage;
$this->preface = $preface;
$this->postfix = $postfix;
$this->subpageurl = $subpageurl;
$this->activity = $activity;
}
}
@@ -0,0 +1,204 @@
<?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/>.
/**
* This file contains the definition for the renderable assign submission status.
*
* @package mod_assign
* @copyright 2020 Matt Porritt <mattp@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
/**
* This file contains the definition for the renderable assign submission status.
*
* @package mod_assign
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assign_submission_status implements \renderable {
/** @var int STUDENT_VIEW */
const STUDENT_VIEW = 10;
/** @var int GRADER_VIEW */
const GRADER_VIEW = 20;
/** @var int allowsubmissionsfromdate */
public $allowsubmissionsfromdate = 0;
/** @var bool alwaysshowdescription */
public $alwaysshowdescription = false;
/** @var mixed the submission info (may be null or an integer) */
public $submission = null;
/** @var boolean teamsubmissionenabled - true or false */
public $teamsubmissionenabled = false;
/** @var \stdClass teamsubmission the team submission info (may be null) */
public $teamsubmission = null;
/** @var mixed submissiongroup the submission group info (may be null) */
public $submissiongroup = null;
/** @var array submissiongroupmemberswhoneedtosubmit list of users who still need to submit */
public $submissiongroupmemberswhoneedtosubmit = array();
/** @var bool submissionsenabled */
public $submissionsenabled = false;
/** @var bool locked */
public $locked = false;
/** @var bool graded */
public $graded = false;
/** @var int duedate */
public $duedate = 0;
/** @var int cutoffdate */
public $cutoffdate = 0;
/** @var array submissionplugins - the list of submission plugins */
public $submissionplugins = array();
/** @var string returnaction */
public $returnaction = '';
/** @var string returnparams */
public $returnparams = array();
/** @var int courseid */
public $courseid = 0;
/** @var int coursemoduleid */
public $coursemoduleid = 0;
/** @var int the view (STUDENT_VIEW OR GRADER_VIEW) */
public $view = self::STUDENT_VIEW;
/** @var bool canviewfullnames */
public $canviewfullnames = false;
/** @var bool canedit */
public $canedit = false;
/** @var bool cansubmit */
public $cansubmit = false;
/** @var int extensionduedate */
public $extensionduedate = 0;
/** @var \context context */
public $context = 0;
/** @var bool blindmarking - Should we hide student identities from graders? */
public $blindmarking = false;
/** @var string gradingcontrollerpreview */
public $gradingcontrollerpreview = '';
/** @var string attemptreopenmethod */
public $attemptreopenmethod = 'none';
/** @var int maxattempts */
public $maxattempts = -1;
/** @var string gradingstatus */
public $gradingstatus = '';
/** @var bool preventsubmissionnotingroup */
public $preventsubmissionnotingroup = 0;
/** @var array usergroups */
public $usergroups = array();
/** @var int The time limit for the assignment */
public $timelimit = 0;
/** @var bool */
public $caneditowner;
/**
* Constructor
*
* @param int $allowsubmissionsfromdate
* @param bool $alwaysshowdescription
* @param mixed $submission
* @param bool $teamsubmissionenabled
* @param \stdClass $teamsubmission
* @param mixed $submissiongroup
* @param array $submissiongroupmemberswhoneedtosubmit
* @param bool $submissionsenabled
* @param bool $locked
* @param bool $graded
* @param int $duedate
* @param int $cutoffdate
* @param array $submissionplugins
* @param string $returnaction
* @param array $returnparams
* @param int $coursemoduleid
* @param int $courseid
* @param string $view
* @param bool $canedit
* @param bool $cansubmit
* @param bool $canviewfullnames
* @param int $extensionduedate Any extension to the due date granted for this user.
* @param \context $context Any extension to the due date granted for this user.
* @param bool $blindmarking Should we hide student identities from graders?
* @param string $gradingcontrollerpreview
* @param string $attemptreopenmethod The method of reopening student attempts.
* @param int $maxattempts How many attempts can a student make?
* @param string $gradingstatus The submission status (ie. Graded, Not Released etc).
* @param bool $preventsubmissionnotingroup Prevent submission if user is not in a group.
* @param array $usergroups Array containing all groups the user is assigned to.
* @param int $timelimit The time limit for the assignment.
*/
public function __construct(
$allowsubmissionsfromdate,
$alwaysshowdescription,
$submission,
$teamsubmissionenabled,
$teamsubmission,
$submissiongroup,
$submissiongroupmemberswhoneedtosubmit,
$submissionsenabled,
$locked,
$graded,
$duedate,
$cutoffdate,
$submissionplugins,
$returnaction,
$returnparams,
$coursemoduleid,
$courseid,
$view,
$canedit,
$cansubmit,
$canviewfullnames,
$extensionduedate,
$context,
$blindmarking,
$gradingcontrollerpreview,
$attemptreopenmethod,
$maxattempts,
$gradingstatus,
$preventsubmissionnotingroup,
$usergroups,
$timelimit
) {
$this->allowsubmissionsfromdate = $allowsubmissionsfromdate;
$this->alwaysshowdescription = $alwaysshowdescription;
$this->submission = $submission;
$this->teamsubmissionenabled = $teamsubmissionenabled;
$this->teamsubmission = $teamsubmission;
$this->submissiongroup = $submissiongroup;
$this->submissiongroupmemberswhoneedtosubmit = $submissiongroupmemberswhoneedtosubmit;
$this->submissionsenabled = $submissionsenabled;
$this->locked = $locked;
$this->graded = $graded;
$this->duedate = $duedate;
$this->cutoffdate = $cutoffdate;
$this->submissionplugins = $submissionplugins;
$this->returnaction = $returnaction;
$this->returnparams = $returnparams;
$this->coursemoduleid = $coursemoduleid;
$this->courseid = $courseid;
$this->view = $view;
$this->canedit = $canedit;
$this->cansubmit = $cansubmit;
$this->canviewfullnames = $canviewfullnames;
$this->extensionduedate = $extensionduedate;
$this->context = $context;
$this->blindmarking = $blindmarking;
$this->gradingcontrollerpreview = $gradingcontrollerpreview;
$this->attemptreopenmethod = $attemptreopenmethod;
$this->maxattempts = $maxattempts;
$this->gradingstatus = $gradingstatus;
$this->preventsubmissionnotingroup = $preventsubmissionnotingroup;
$this->usergroups = $usergroups;
$this->timelimit = $timelimit;
}
}
@@ -0,0 +1,77 @@
<?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/>.
/**
* Output the grading actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
use templatable;
use renderable;
use moodle_url;
/**
* Output the grading actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_actionmenu implements templatable, renderable {
/** @var int Course module ID. */
protected $cmid;
/** @var bool If any submission plugins are enabled. */
protected $submissionpluginenabled;
/** @var int The number of submissions made. */
protected $submissioncount;
/**
* Constructor for this object.
*
* @param int $cmid Course module ID.
* @param bool $submissionpluginenabled If any submission plugins are enabled.
* @param int $submissioncount The number of submissions made.
*/
public function __construct(int $cmid, bool $submissionpluginenabled = false, int $submissioncount = 0) {
$this->cmid = $cmid;
$this->submissionpluginenabled = $submissionpluginenabled;
$this->submissioncount = $submissioncount;
}
/**
* Data to render in a template.
*
* @param \renderer_base $output renderer base output.
* @return array Data to render.
*/
public function export_for_template(\renderer_base $output): array {
$downloadall = '';
if ($this->submissionpluginenabled && $this->submissioncount) {
$downloadall = (new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'downloadall']))->out(false);
}
return [
'downloadall' => $downloadall
];
}
}
+181
View File
@@ -0,0 +1,181 @@
<?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/>.
/**
* Renderable that initialises the grading "app".
*
* @package mod_assign
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
defined('MOODLE_INTERNAL') || die();
use renderer_base;
use renderable;
use templatable;
use stdClass;
/**
* Grading app renderable.
*
* @package mod_assign
* @since Moodle 3.1
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_app implements templatable, renderable {
/**
* @var $userid - The initial user id.
*/
public $userid = 0;
/**
* @var $groupid - The initial group id.
*/
public $groupid = 0;
/**
* @var $assignment - The assignment instance.
*/
public $assignment = null;
/**
* @var array - List of user records with extra fields.
*/
public $participants = [];
/**
* Constructor for this renderable.
*
* @param int $userid The user we will open the grading app too.
* @param int $groupid If groups are enabled this is the current course group.
* @param \assign $assignment The assignment class
*/
public function __construct($userid, $groupid, $assignment) {
$this->userid = $userid;
$this->groupid = $groupid;
$this->assignment = $assignment;
$this->participants = $assignment->list_participants_with_filter_status_and_group($groupid);
if (!$this->userid && count($this->participants)) {
$this->userid = reset($this->participants)->id;
}
}
/**
* Export this class data as a flat list for rendering in a template.
*
* @param renderer_base $output The current page renderer.
* @return stdClass - Flat list of exported data.
*/
public function export_for_template(renderer_base $output) {
global $CFG, $USER;
$export = new stdClass();
$export->userid = $this->userid;
$export->assignmentid = $this->assignment->get_instance()->id;
$export->cmid = $this->assignment->get_course_module()->id;
$export->contextid = $this->assignment->get_context()->id;
$export->groupid = $this->groupid;
$export->name = $this->assignment->get_context()->get_context_name(true, false, false);
$export->courseid = $this->assignment->get_course()->id;
$export->participants = array();
$export->filters = $this->assignment->get_filters();
$export->markingworkflowfilters = $this->assignment->get_marking_workflow_filters(true);
$export->hasmarkingworkflow = count($export->markingworkflowfilters) > 0;
$export->markingallocationfilters = $this->assignment->get_marking_allocation_filters(true);
$export->hasmarkingallocation = count($export->markingallocationfilters) > 0;
$num = 1;
foreach ($this->participants as $idx => $record) {
$user = new stdClass();
$user->id = $record->id;
$user->fullname = fullname($record);
$user->requiregrading = $record->requiregrading;
$user->grantedextension = $record->grantedextension;
$user->submitted = $record->submitted;
if (!empty($record->groupid)) {
$user->groupid = $record->groupid;
$user->groupname = $record->groupname;
}
if ($record->id == $this->userid) {
$export->index = $num;
$user->current = true;
}
$export->participants[] = $user;
$num++;
}
$feedbackplugins = $this->assignment->get_feedback_plugins();
$showreview = false;
foreach ($feedbackplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible()) {
if ($plugin->supports_review_panel()) {
$showreview = true;
}
}
}
$export->actiongrading = 'grading';
$export->viewgrading = get_string('viewgrading', 'mod_assign');
$export->showreview = $showreview;
$time = time();
$export->count = count($export->participants);
$export->coursename = $this->assignment->get_course_context()->get_context_name(true, false, false);
$export->caneditsettings = has_capability('mod/assign:addinstance', $this->assignment->get_context());
$export->duedate = $this->assignment->get_instance()->duedate;
$export->duedatestr = userdate($this->assignment->get_instance()->duedate);
// Time remaining.
$due = '';
if ($export->duedate - $time <= 0) {
$due = get_string('assignmentisdue', 'assign');
} else {
$due = get_string('timeremainingcolon', 'assign', format_time($export->duedate - $time));
}
$export->timeremainingstr = $due;
if ($export->duedate < $time) {
$export->cutoffdate = $this->assignment->get_instance()->cutoffdate;
$cutoffdate = $export->cutoffdate;
if ($cutoffdate) {
if ($cutoffdate > $time) {
$late = get_string('latesubmissionsaccepted', 'assign', userdate($export->cutoffdate));
} else {
$late = get_string('nomoresubmissionsaccepted', 'assign');
}
$export->cutoffdatestr = $late;
}
}
$export->defaultsendnotifications = $this->assignment->get_instance()->sendstudentnotifications;
$export->rarrow = $output->rarrow();
$export->larrow = $output->larrow();
// List of identity fields to display (the user info will not contain any fields the user cannot view anyway).
// TODO Does not support custom user profile fields (MDL-70456).
$export->showuseridentity = implode(',', \core_user\fields::get_identity_fields(null, false));
$export->currentuserid = $USER->id;
$helpicon = new \help_icon('sendstudentnotifications', 'assign');
$export->helpicon = $helpicon->export_for_template($output);
return $export;
}
}
@@ -0,0 +1,161 @@
<?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/>.
/**
* Output the override actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
use core_availability\info_module;
use moodle_url;
use templatable;
use renderable;
use url_select;
use single_button;
/**
* Output the override actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class override_actionmenu implements templatable, renderable {
/** @var moodle_url The current url for this page. */
protected $currenturl;
/** @var \cm_info course module information */
protected $cm;
/** @var bool Can all groups be accessed */
protected $canaccessallgroups;
/** @var array Groups related to this activity */
protected $groups;
/**
* Constructor for this action menu.
*
* @param moodle_url $currenturl The current url for this page.
* @param \cm_info $cm course module information.
*/
public function __construct(moodle_url $currenturl, \cm_info $cm) {
$this->currenturl = $currenturl;
$this->cm = $cm;
$groupmode = groups_get_activity_groupmode($this->cm);
$this->canaccessallgroups = ($groupmode === NOGROUPS) ||
has_capability('moodle/site:accessallgroups', $this->cm->context);
$this->groups = $this->canaccessallgroups ? groups_get_all_groups($this->cm->course) :
groups_get_activity_allowed_groups($this->cm);
}
/**
* Create a select menu for overrides.
*
* @return url_select A url select object.
*/
protected function get_select_menu(): url_select {
$userlink = new moodle_url('/mod/assign/overrides.php', ['cmid' => $this->cm->id, 'mode' => 'user']);
$grouplink = new moodle_url('/mod/assign/overrides.php', ['cmid' => $this->cm->id, 'mode' => 'group']);
$menu = [
$userlink->out(false) => get_string('useroverrides', 'mod_assign'),
$grouplink->out(false) => get_string('groupoverrides', 'mod_assign'),
];
return new url_select($menu, $this->currenturl->out(false), null, 'mod_assign_override_select');
}
/**
* Whether to show groups or not. Assignments can be have group overrides if there are groups available in the course.
* There is no restriction related to the assignment group setting.
*
* @return bool
*/
protected function show_groups(): bool {
if ($this->canaccessallgroups) {
$groups = groups_get_all_groups($this->cm->course);
} else {
$groups = groups_get_activity_allowed_groups($this->cm);
}
return !(empty($groups));
}
/**
* Whether to enable/disable user override button or not.
*
* @return bool
*/
protected function show_useroverride(): bool {
global $DB;
$users = [];
$context = $this->cm->context;
if ($this->canaccessallgroups) {
$users = get_enrolled_users($context, '', 0, 'u.id');
} else if ($this->groups) {
$enrolledjoin = get_enrolled_join($context, 'u.id');
list($ingroupsql, $ingroupparams) = $DB->get_in_or_equal(array_keys($this->groups), SQL_PARAMS_NAMED);
$params = $enrolledjoin->params + $ingroupparams;
$sql = "SELECT u.id
FROM {user} u
JOIN {groups_members} gm ON gm.userid = u.id
{$enrolledjoin->joins}
WHERE gm.groupid $ingroupsql
AND {$enrolledjoin->wheres}";
$users = $DB->get_records_sql($sql, $params);
}
$info = new info_module($this->cm);
$users = $info->filter_user_list($users);
return !empty($users);
}
/**
* Data to be used in a template.
*
* @param \renderer_base $output renderer base output.
* @return array The data to be used in a template.
*/
public function export_for_template(\renderer_base $output): array {
$type = $this->currenturl->get_param('mode');
if ($type == 'user') {
$text = get_string('addnewuseroverride', 'mod_assign');
} else {
$text = get_string('addnewgroupoverride', 'mod_assign');
}
$action = ($type == 'user') ? 'adduser' : 'addgroup';
$params = ['cmid' => $this->currenturl->get_param('cmid'), 'action' => $action];
$url = new moodle_url('/mod/assign/overrideedit.php', $params);
$options = [];
if ($action == 'addgroup' && !$this->show_groups()) {
$options = ['disabled' => 'true'];
} else if ($action === 'adduser' && !$this->show_useroverride()) {
$options = ['disabled' => 'true'];
}
$overridebutton = new single_button($url, $text, 'post', single_button::BUTTON_PRIMARY, $options);
$urlselect = $this->get_select_menu();
return [
'addoverride' => $overridebutton->export_for_template($output),
'urlselect' => $urlselect->export_for_template($output)
];
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,82 @@
<?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/>.
/**
* Represents the timer panel.
*
* @package mod_assign
* @copyright 2020 Ilya Tregubov <ilyatregubov@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
use renderable;
use renderer_base;
use stdClass;
use templatable;
/**
* Represents the timer panel.
*
* @package mod_assign
* @copyright 2020 Ilya Tregubov <ilyatregubov@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class timelimit_panel implements templatable, renderable {
/** @var \stdClass assign submission attempt.*/
protected $submission;
/** @var object assign object.*/
protected $assign;
/**
* Constructor.
*
* @param \stdClass $submission assign submission.
* @param \stdClass $assign assign object.
*/
public function __construct(\stdClass $submission, \stdClass $assign) {
$this->submission = $submission;
$this->assign = $assign;
}
/**
* Render timer.
*
* @param renderer_base $output The current page renderer.
* @return stdClass - Flat list of exported data.
*/
public function export_for_template(renderer_base $output): stdClass {
return (object)['timerstartvalue' => $this->end_time() - time()];
}
/**
* Compute end time for this assign attempt.
*
* @return int the time when assign attempt is due.
*/
private function end_time(): int {
$timedue = $this->submission->timestarted + $this->assign->timelimit;
if ($this->assign->duedate) {
return min($timedue, $this->assign->duedate);
}
if ($this->assign->cutoffdate) {
return min($timedue, $this->assign->cutoffdate);
}
return $timedue;
}
}
@@ -0,0 +1,174 @@
<?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/>.
/**
* Output the user submission actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_assign\output;
use templatable;
use renderable;
use moodle_url;
use help_icon;
use single_button;
use stdClass;
/**
* Output the user submission actionbar for this activity.
*
* @package mod_assign
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_submission_actionmenu implements templatable, renderable {
/** @var int The course module ID. */
protected $cmid;
/** @var bool Whether to show the submit button. */
protected $showsubmit;
/** @var bool Whether to show the edit button. */
protected $showedit;
/** @var stdClass A submission for this activity. */
protected $submission;
/** @var stdClass A team submission for this activity. */
protected $teamsubmission;
/** @var int The time limit for the submission. 0 = no time limit. */
protected $timelimit;
/**
* Constructor for this object.
*
* @param int $cmid The course module ID.
* @param bool $showsubmit Whether to show the submit button.
* @param bool $showedit Whether to show the edit button.
* @param stdClass|null $submission A submission for this activity.
* @param stdClass|null $teamsubmission A team submission for this activity.
* @param int $timelimit The time limit for completing this activity.
*/
public function __construct(int $cmid, bool $showsubmit, bool $showedit, stdClass $submission = null,
stdClass $teamsubmission = null, int $timelimit = 0) {
$this->cmid = $cmid;
$this->showsubmit = $showsubmit;
$this->showedit = $showedit;
$this->submission = $submission;
$this->teamsubmission = $teamsubmission;
$this->timelimit = $timelimit;
}
/**
* Get the submission status.
*
* @return string The status of the submission.
*/
protected function get_current_status(): string {
if (!is_null($this->teamsubmission) && isset($this->teamsubmission->status)) {
return $this->teamsubmission->status;
} else if (!empty((array)$this->submission)) {
return $this->submission->status;
} else {
return ASSIGN_SUBMISSION_STATUS_NEW;
}
}
/**
* Export the submission buttons for the page.
*
* @param \renderer_base $output renderer base output.
* @return array The data to be rendered.
*/
public function export_for_template(\renderer_base $output): array {
$data = ['edit' => false, 'submit' => false, 'remove' => false, 'previoussubmission' => false];
if ($this->showedit) {
$url = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'editsubmission']);
$button = new single_button($url, get_string('editsubmission', 'mod_assign'), 'get');
$data['edit'] = [
'button' => $button->export_for_template($output),
];
$status = $this->get_current_status();
if ($status !== ASSIGN_SUBMISSION_STATUS_NEW && $status !== ASSIGN_SUBMISSION_STATUS_REOPENED) {
$url = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'removesubmissionconfirm']);
$button = new single_button($url, get_string('removesubmission', 'mod_assign'), 'get');
$data['remove'] = ['button' => $button->export_for_template($output)];
}
if ($status === ASSIGN_SUBMISSION_STATUS_REOPENED) {
$params = ['id' => $this->cmid, 'action' => 'editprevioussubmission', 'sesskey' => sesskey()];
$url = new moodle_url('/mod/assign/view.php', $params);
$button = new single_button($url, get_string('addnewattemptfromprevious', 'mod_assign'), 'get');
$help = new help_icon('addnewattemptfromprevious', 'mod_assign');
$data['previoussubmission'] = [
'button' => $button->export_for_template($output),
'help' => $help->export_for_template($output)
];
$url = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'editsubmission']);
$newattemptbutton = new single_button(
$url,
get_string('addnewattempt', 'mod_assign'),
'get',
single_button::BUTTON_PRIMARY
);
$newattempthelp = new help_icon('addnewattempt', 'mod_assign');
$data['edit']['button'] = $newattemptbutton->export_for_template($output);
$data['edit']['help'] = $newattempthelp->export_for_template($output);
}
if ($status === ASSIGN_SUBMISSION_STATUS_NEW) {
$timelimitenabled = get_config('assign', 'enabletimelimit');
if ($timelimitenabled && $this->timelimit && empty($this->submission->timestarted)) {
$confirmation = new \confirm_action(
get_string('confirmstart', 'assign', format_time($this->timelimit)),
null,
get_string('beginassignment', 'assign')
);
$urlparams = array('id' => $this->cmid, 'action' => 'editsubmission');
$beginbutton = new \action_link(
new moodle_url('/mod/assign/view.php', $urlparams),
get_string('beginassignment', 'assign'),
$confirmation,
['class' => 'btn btn-primary']
);
$data['edit']['button'] = $beginbutton->export_for_template($output);
$data['edit']['begin'] = true;
$data['edit']['help'] = '';
} else {
$newattemptbutton = new single_button(
$url,
get_string('addsubmission', 'mod_assign'),
'get',
single_button::BUTTON_PRIMARY
);
$data['edit']['button'] = $newattemptbutton->export_for_template($output);
$data['edit']['help'] = '';
}
}
}
if ($this->showsubmit) {
$url = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'submit']);
$button = new single_button($url, get_string('submitassignment', 'mod_assign'), 'get', single_button::BUTTON_PRIMARY);
$help = new help_icon('submitassignment', 'mod_assign');
$data['submit'] = [
'button' => $button->export_for_template($output),
'help' => $help->export_for_template($output)
];
}
return $data;
}
}