$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;
* @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
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)));
$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;
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);
}
require_login($course, false, $cm);
-$workshop = new workshop_api($workshop, $cm);
+$workshop = new workshop_api($workshop, $cm, $course);
$context = $PAGE->context;
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}";
/**
* 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
}
}
$this->cm = $cm;
+ $this->courserecord = $courserecord;
}
/**
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
/**
* 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
$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
$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
$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;