]> git.mjollnir.org Git - moodle.git/commitdiff
Extending workshop class constructor
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:47:43 +0000 (17:47 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:47:43 +0000 (17:47 +0000)
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).

mod/workshop/allocation.php
mod/workshop/allocation/random/allocator.php
mod/workshop/allocation/random/settings_form.php
mod/workshop/allocation/random/simpletest/testallocator.php
mod/workshop/assessment.php
mod/workshop/editform.php
mod/workshop/lib.php
mod/workshop/locallib.php
mod/workshop/view.php

index 049948c10ea2757b81b5fdfb2e0a604ef552870a..b1954a56d9f12de3b5d6faf801c857983657db81 100644 (file)
@@ -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;
index 1d9209b457e36d8ec2c2bc64e269db9984b277d1..fb0fcfbc25aadbc4a2f0c621724ce1e70a13986d 100644 (file)
@@ -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)));
index 2e7930f58dfa2b6b99dfc6f48764ab98f958140b..7299343f888eeb8d000c4db24cc391ce0d3be227 100644 (file)
@@ -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;
index 63e6a48e19f633a21a6e30884d6e85ddcef6e3f6..c08f7b1f0b091c7984d5aea782ea35e3f7e668ca 100644 (file)
@@ -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);
     }
 
index 7968eec80f02de816eaed91fb79ceddc743ec221..639fc8f2174bf24e606fb6f58bcf600f40556b5b 100644 (file)
@@ -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;
 
index eabdbe9ade4a1d896ced4cbc5f9b249aa60003ca..976b074c4db4c37d1326253378ec474051a0dd04 100644 (file)
@@ -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}";
index 3b719c258b2927928b8f40aec598dca7bdd2fae3..9c8d0ebd0b34153c1b3dbb5e127400477d484a4b 100644 (file)
@@ -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
index bdc3b1e69e01a17195c117e66eae92628c2ecee9..e4dbec8e504be951eee23d31aefe225fa7b85acb 100644 (file)
@@ -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
index 027cdeaff261969a7c54b8841c6f5016fcc0f9ce..be43882fa871bd439ae807fd0b01388eefa87315 100644 (file)
@@ -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;