MDL-37806 Add new workshop class method to return pending assessments
authorDavid Mudrák <david@moodle.com>
Thu, 31 Jan 2013 17:13:26 +0000 (18:13 +0100)
committerDavid Mudrák <david@moodle.com>
Thu, 31 Jan 2013 17:21:50 +0000 (18:21 +0100)
This is a simple wrapper around workshop::get_assessments_by_reviewer()
that filters assigned assessments and returns just those that were not
graded by the reviewer yet.

mod/workshop/locallib.php

index a534f4c..3d77819 100644 (file)
@@ -1169,6 +1169,37 @@ class workshop {
         return $DB->get_records_sql($sql, $params);
     }
 
+    /**
+     * Get allocated assessments not graded yet by the given reviewer
+     *
+     * @see self::get_assessments_by_reviewer()
+     * @param int $reviewerid the reviewer id
+     * @param null|int|array $exclude optional assessment id (or list of them) to be excluded
+     * @return array
+     */
+    public function get_pending_assessments_by_reviewer($reviewerid, $exclude = null) {
+
+        $assessments = $this->get_assessments_by_reviewer($reviewerid);
+
+        foreach ($assessments as $id => $assessment) {
+            if (!is_null($assessment->grade)) {
+                unset($assessments[$id]);
+                continue;
+            }
+            if (!empty($exclude)) {
+                if (is_array($exclude) and in_array($id, $exclude)) {
+                    unset($assessments[$id]);
+                    continue;
+                } else if ($id == $exclude) {
+                    unset($assessments[$id]);
+                    continue;
+                }
+            }
+        }
+
+        return $assessments;
+    }
+
     /**
      * Allocate a submission to a user for review
      *