Commit f5d9267a authored by Matt Porritt's avatar Matt Porritt Committed by Cameron Ball
Browse files

MDL-69696 mod_assign: Class refactoring - rendering

Refactor rendering classes to be more PSR compliant.

Move renderer to output class folder and initial
splitting of classes in renderable.php into individual
class files. To make it easier to refactor assign UI
functionality in the future.
parent 1cb6f330
<?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;
/**
* 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.
*/
public function __construct(
\stdClass $assign,
$context,
$showintro,
$coursemoduleid,
$subpage = '',
$preface = '',
$postfix = '',
\moodle_url $subpageurl = null
) {
$this->assign = $assign;
$this->context = $context;
$this->showintro = $showintro;
$this->coursemoduleid = $coursemoduleid;
$this->subpage = $subpage;
$this->preface = $preface;
$this->postfix = $postfix;
$this->subpageurl = $subpageurl;
}
}
<?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();
/**
* 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.
*/
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
) {
$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 diff is collapsed.
<?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 mappings for classes that have been renamed.
*
* @package mod_assign
* @copyright 2021 Catalyst IT Australia Pty Ltd
* @author Cameron Ball <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$renamedclasses = [
// Since Moodle 4.0.
'assign_header' => 'mod_assign\output\assign_header',
'assign_submission_status' => 'mod_assign\output\assign_submission_status'
];
......@@ -25,6 +25,8 @@
defined('MOODLE_INTERNAL') || die();
use mod_assign\output\assign_header;
/**
* library class for importing feedback files from a zip
*
......
......@@ -25,6 +25,8 @@
defined('MOODLE_INTERNAL') || die();
use \mod_assign\output\assign_header;
// File areas for file feedback assignment.
define('ASSIGNFEEDBACK_FILE_FILEAREA', 'feedback_files');
define('ASSIGNFEEDBACK_FILE_BATCH_FILEAREA', 'feedback_files_batch');
......
......@@ -25,6 +25,8 @@
defined('MOODLE_INTERNAL') || die();
use \mod_assign\output\assign_header;
require_once($CFG->dirroot.'/grade/grading/lib.php');
/**
......
......@@ -92,6 +92,8 @@ require_once($CFG->dirroot . '/mod/assign/gradingtable.php');
require_once($CFG->libdir . '/portfolio/caller.php');
use \mod_assign\output\grading_app;
use \mod_assign\output\assign_header;
use \mod_assign\output\assign_submission_status;
/**
* Standard base class for mod_assign (assignment types).
......
......@@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use \mod_assign\output\assign_submission_status;
defined('MOODLE_INTERNAL') || die();
/**
......@@ -271,7 +273,7 @@ class assign_submission_plugin_submission implements renderable {
*/
class assign_feedback_status implements renderable {
/** @var stding $gradefordisplay the student grade rendered into a format suitable for display */
/** @var string $gradefordisplay the student grade rendered into a format suitable for display */
public $gradefordisplay = '';
/** @var mixed the graded date (may be null) */
public $gradeddate = 0;
......@@ -323,176 +325,6 @@ class assign_feedback_status implements renderable {
}
}
/**
* Renderable 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 stdClass the submission info (may be null) */
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 stdClass 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();
/**
* Constructor
*
* @param int $allowsubmissionsfromdate
* @param bool $alwaysshowdescription
* @param stdClass $submission
* @param bool $teamsubmissionenabled
* @param stdClass $teamsubmission
* @param int $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
*/
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) {
$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;
}
}
/**
* Renderable submission status
* @package mod_assign
......@@ -650,59 +482,6 @@ class assign_attempt_history_chooser implements renderable, templatable {
}
}
/**
* Renderable 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 = null;
/** @var mixed context|null the context record */
public $context = null;
/** @var bool $showintro - show or hide the intro */
public $showintro = false;
/** @var int coursemoduleid - The course module id */
public $coursemoduleid = 0;
/** @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 $subpageurl link for the subpage */
public $subpageurl = null;
/**
* Constructor
*
* @param stdClass $assign - the assign database record
* @param mixed $context context|null 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
*/
public function __construct(stdClass $assign,
$context,
$showintro,
$coursemoduleid,
$subpage='',
$preface='',
$postfix='',
moodle_url $subpageurl = null) {
$this->assign = $assign;
$this->context = $context;
$this->showintro = $showintro;
$this->coursemoduleid = $coursemoduleid;
$this->subpage = $subpage;
$this->preface = $preface;
$this->postfix = $postfix;
$this->subpageurl = $subpageurl;
}
}
/**
* Renderable header related to an individual subplugin
* @package mod_assign
......
This diff is collapsed.
......@@ -4308,7 +4308,7 @@ Anchor link 2:<a title=\"bananas\" href=\"../logo-240x60.gif\">Link text</a>
$_GET['group'] = $activegroup->id;
/** @var assign $assign */
$header = new assign_header(
$header = new \mod_assign\output\assign_header(
$assign->get_instance(),
$assign->get_context(),
false,
......