Extending workshop class constructor
Every action script in 99% starts with fetching course, course module, and module instance record. Workshop class will keep the reference to the course record in courserecord public member variable (do not confuse with course integer property).
This commit is contained in:
@@ -38,7 +38,7 @@ $PAGE->set_url('mod/workshop/allocation.php', array('cmid' => $cmid, 'method' =>
|
||||
$cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
|
||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||
$workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
$workshop = new workshop_api($workshop, $cm);
|
||||
$workshop = new workshop_api($workshop, $cm, $course);
|
||||
|
||||
require_login($course, false, $cm);
|
||||
$context = $PAGE->context;
|
||||
|
||||
@@ -333,6 +333,10 @@ class workshop_random_allocator implements workshop_allocator {
|
||||
* @return array array of (reviewerid => authorid) pairs
|
||||
*/
|
||||
protected function random_allocation($authors, $reviewers, $assessments, $numofreviews, $numper, &$o) {
|
||||
if (empty($authors) || empty($reviewers)) {
|
||||
// nothing to be done
|
||||
return array();
|
||||
}
|
||||
if (WORKSHOP_USERTYPE_AUTHOR == $numper) {
|
||||
// circles are authors, squares are reviewers
|
||||
$o[] = 'info::Trying to allocate ' . $numofreviews . ' review(s) per author'; // todo translate
|
||||
@@ -368,7 +372,7 @@ class workshop_random_allocator implements workshop_allocator {
|
||||
unset($squaregroupsworkload[0]); // [0] is not real group, it contains all users
|
||||
$o[] = 'debug::square workload = ' . json_encode($squareworkload);
|
||||
$o[] = 'debug::square group workload = ' . json_encode($squaregroupsworkload);
|
||||
$gmode = groups_get_activity_groupmode($this->workshop->cm);
|
||||
$gmode = groups_get_activity_groupmode($this->workshop->cm, $this->workshop->courserecord);
|
||||
if (SEPARATEGROUPS == $gmode) {
|
||||
// shuffle all groups but [0] which means "all users"
|
||||
$circlegroups = array_keys(array_diff_key($allcircles, array(0 => null)));
|
||||
|
||||
@@ -46,7 +46,8 @@ class workshop_random_allocator_form extends moodleform {
|
||||
|
||||
$mform->addElement('header', 'settings', get_string('allocationsettings', 'workshop'));
|
||||
|
||||
switch ($workshop->cm->groupmode) {
|
||||
$gmode = groups_get_activity_groupmode($workshop->cm, $workshop->courserecord);
|
||||
switch ($gmode) {
|
||||
case NOGROUPS:
|
||||
$grouplabel = get_string('groupsnone', 'group');
|
||||
break;
|
||||
|
||||
@@ -67,7 +67,7 @@ class workshop_allocation_random_test extends UnitTestCase {
|
||||
protected $allocator;
|
||||
|
||||
public function setUp() {
|
||||
$this->workshop = new workshop((object)array('id' => 42), new stdClass());
|
||||
$this->workshop = new workshop((object)array('id' => 42), new stdClass(), new stdClass());
|
||||
$this->allocator = new testable_workshop_random_allocator($this->workshop);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ if ($preview = optional_param('preview', 0, PARAM_INT)) {
|
||||
|
||||
require_login($course, false, $cm);
|
||||
|
||||
$workshop = new workshop_api($workshop, $cm);
|
||||
$workshop = new workshop_api($workshop, $cm, $course);
|
||||
|
||||
$context = $PAGE->context;
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ if (!$workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
|
||||
print_error('err_invalidworkshopid', 'workshop');
|
||||
}
|
||||
|
||||
$workshop = new workshop_api($workshop, $cm)l
|
||||
$workshop = new workshop_api($workshop, $cm, $course);
|
||||
|
||||
// where should the user be sent after closing the editing form
|
||||
$returnurl = "{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}";
|
||||
|
||||
+15
-7
@@ -50,25 +50,30 @@ define('WORKSHOP_COMPARISON_VERYHIGH', 4); /* f = 5.00 */
|
||||
/**
|
||||
* The base class of workshop instances
|
||||
*
|
||||
* It defines methods that are part of any activity module API and may be called by Moodle core.
|
||||
* The class just wraps the database record from the {workshop} table and adds some
|
||||
* methods that implement the compulsory activity module API.
|
||||
* For full-featured class see {@link workshop_api}.
|
||||
* For full-featured workshop class see {@link workshop_api}.
|
||||
*/
|
||||
class workshop {
|
||||
|
||||
/** course module record */
|
||||
/** @var object course module record */
|
||||
public $cm;
|
||||
|
||||
/** @var object course record */
|
||||
public $courserecord;
|
||||
|
||||
/**
|
||||
* Defines methods that are part of any activity module API and may be called by Moodle core
|
||||
*
|
||||
* Initializes the object using the data from DB. Makes deep copy of all $dbrecord properties.
|
||||
* Please do not confuse $this->course (integer property from the database record) and
|
||||
* $this->courserecord (object containing the whole course record).
|
||||
*
|
||||
* @param object $instance The instance data row from {workshop} table
|
||||
* @param object $cm Course module record
|
||||
* @param object $instance The instance data row from {workshop} table
|
||||
* @param object $cm Course module record
|
||||
* @param object $courserecord Course record
|
||||
*/
|
||||
public function __construct(stdClass $instance, stdClass $cm) {
|
||||
|
||||
public function __construct(stdClass $instance, stdClass $cm, stdClass $courserecord) {
|
||||
foreach ($instance as $key => $val) {
|
||||
if (is_object($val) || (is_array($val))) {
|
||||
// this should not happen if the $dbrecord is really just the record returned by $DB
|
||||
@@ -78,6 +83,7 @@ class workshop {
|
||||
}
|
||||
}
|
||||
$this->cm = $cm;
|
||||
$this->courserecord = $courserecord;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,6 +120,8 @@ function workshop_add_instance($data) {
|
||||
return workshop::add_instance($data);
|
||||
}
|
||||
|
||||
// TODO convert following functions into workshop methods
|
||||
|
||||
/**
|
||||
* Given an object containing all the necessary data,
|
||||
* (defined by the form in mod_form.php) this function
|
||||
|
||||
@@ -49,13 +49,13 @@ class workshop_api extends workshop {
|
||||
/**
|
||||
* Initialize the object using the data from DB
|
||||
*
|
||||
* @param object $instance The instance data row from {workshop} table
|
||||
* @param object $md Course module record
|
||||
*/
|
||||
public function __construct($instance, $cm) {
|
||||
|
||||
parent::__construct($instance, $cm);
|
||||
* @param object $instance The instance data row from {workshop} table
|
||||
* @param object $cm Course module record
|
||||
* @param object $courserecord Course record
|
||||
public function __construct($instance, $cm, $courserecord) {
|
||||
parent::__construct($instance, $cm, $courserecord);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fetches all users with the capability mod/workshop:submit in the current context
|
||||
@@ -103,6 +103,9 @@ class workshop_api extends workshop {
|
||||
|
||||
$authors = $this->get_peer_authors($musthavesubmission);
|
||||
$gauthors = array(); // grouped authors to be returned
|
||||
if (empty($authors)) {
|
||||
return $gauthors;
|
||||
}
|
||||
if ($this->cm->groupmembersonly) {
|
||||
// Available for group members only - the workshop is available only
|
||||
// to users assigned to groups within the selected grouping, or to
|
||||
@@ -174,6 +177,9 @@ class workshop_api extends workshop {
|
||||
|
||||
$reviewers = $this->get_peer_reviewers($musthavesubmission);
|
||||
$greviewers = array(); // grouped reviewers to be returned
|
||||
if (empty($reviewers)) {
|
||||
return $greviewers;
|
||||
}
|
||||
if ($this->cm->groupmembersonly) {
|
||||
// Available for group members only - the workshop is available only
|
||||
// to users assigned to groups within the selected grouping, or to
|
||||
|
||||
@@ -42,7 +42,7 @@ if ($id) {
|
||||
$cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
|
||||
}
|
||||
|
||||
$workshop = new workshop_api($workshop, $cm);
|
||||
$workshop = new workshop_api($workshop, $cm, $course);
|
||||
require_login($course, true, $cm);
|
||||
$context = $PAGE->context;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user