コード例 #1
0
 /**
  * This will add a groupid to each of the submissions coming out of the moduleunion. This means getting
  * all the group memberships for this course and choosing the maximum groupid. We can't count more than
  * once when students are in two groups, so we need to do it like this. It's a greatest-n-per-group
  * problem, solved with the classic left-join approach.
  *
  * @param block_ajax_marking_query $query
  * @return void
  */
 protected function alter_query(block_ajax_marking_query $query)
 {
     list($maxquery, $maxparams) = block_ajax_marking_group_max_subquery();
     list($memberquery, $memberparams) = block_ajax_marking_group_members_subquery();
     list($visibilitysubquery, $visibilityparams) = block_ajax_marking_group_visibility_subquery();
     // We need to join to groups members to see if there are any memberships at all (in which case
     // we use the highest visible id if there is one), or 0 if there are no memberships at all.
     $table = array('join' => 'LEFT JOIN', 'table' => $memberquery, 'on' => 'membergroupquery.userid = moduleunion.userid
                  AND membergroupquery.coursemoduleid = moduleunion.coursemoduleid', 'alias' => 'membergroupquery', 'subquery' => true);
     $query->add_from($table);
     $query->add_params($memberparams);
     // To make sure it's the highest visible one, we use this subquery as a greatest-n-per-group thing.
     $table = array('join' => 'LEFT JOIN', 'table' => $maxquery, 'on' => 'membergroupquery.userid = maxgroupquery.userid
                  AND membergroupquery.coursemoduleid = maxgroupquery.coursemoduleid
                  AND maxgroupquery.groupid > membergroupquery.groupid', 'alias' => 'maxgroupquery', 'subquery' => true);
     $query->add_from($table);
     $query->add_params($maxparams);
     // We join only if the group id is larger, then specify that it must be null. This means that
     // the membergroupquery group id will be the largest available.
     $query->add_where(array('type' => 'AND', 'condition' => 'maxgroupquery.groupid IS NULL'));
     // Make sure it's not hidden. We want to know if there are people with no group, compared to a group that
     // is hidden, so the aim is to get a null group id if there are no memberships by left joining, then
     // hide that null row if the settings for group id 0 say so.
     $table = array('join' => 'LEFT JOIN', 'table' => $visibilitysubquery, 'on' => '(membervisibilityquery.groupid = membergroupquery.groupid OR
                   (membervisibilityquery.groupid = 0 AND membergroupquery.groupid IS NULL))
                  AND membervisibilityquery.coursemoduleid = membergroupquery.coursemoduleid', 'alias' => 'membervisibilityquery', 'subquery' => true);
     $query->add_from($table);
     $query->add_params($visibilityparams);
     $query->add_where(array('type' => 'AND', 'condition' => 'membervisibilityquery.coursemoduleid IS NULL'));
 }
コード例 #2
0
 /**
  * @param block_ajax_marking_query $query
  * @param int|string $userid
  */
 protected function alter_query(block_ajax_marking_query $query, $userid)
 {
     // Applies if users are not the final nodes.
     $clause = array('type' => 'AND', 'condition' => 'quiz_attempts.userid = :quizuseridfilterancestor');
     $query->add_where($clause);
     $query->add_param('quizuseridfilterancestor', $userid);
 }
コード例 #3
0
    /**
     * Returns an SQL snippet that will tell us whether a student is directly enrolled in this
     * course
     *
     * @param block_ajax_marking_query $query
     * @param array $filters So we can filter by cohortid if we need to
     * @return array The join and where strings, with params. (Where starts with 'AND)
     */
    private static function apply_sql_enrolled_students(block_ajax_marking_query $query, array $filters)
    {
        global $DB, $CFG, $USER;
        $nextnodefilter = block_ajax_marking_get_nextnodefilter_from_params($filters);
        // Hide users added by plugins which are now disabled.
        if (isset($filters['cohortid']) || $nextnodefilter == 'cohortid') {
            // We need to specify only people enrolled via a cohort.
            $enabledsql = " = 'cohort'";
        } else {
            if ($CFG->enrol_plugins_enabled) {
                // Returns list of english names of enrolment plugins.
                $plugins = explode(',', $CFG->enrol_plugins_enabled);
                list($enabledsql, $params) = $DB->get_in_or_equal($plugins, SQL_PARAMS_NAMED, 'enrol001');
                $query->add_params($params);
            } else {
                // No enabled enrolment plugins.
                $enabledsql = ' = :sqlenrollednever';
                $query->add_param('sqlenrollednever', -1);
            }
        }
        $sql = <<<SQL
                SELECT NULL
                  FROM {enrol} enrol
            INNER JOIN {user_enrolments} user_enrolments
                    ON user_enrolments.enrolid = enrol.id
                 WHERE enrol.enrol {$enabledsql}
                   AND enrol.courseid = moduleunion.course
                   AND user_enrolments.userid != :enrolcurrentuser
                   AND user_enrolments.userid = moduleunion.userid
SQL;
        $query->add_where(array('type' => 'AND', 'condition' => "EXISTS ({$sql})"));
        $query->add_param('enrolcurrentuser', $USER->id, false);
    }
コード例 #4
0
 /**
  * Not sure we'll ever need this, but just in case...
  *
  * @static
  * @param block_ajax_marking_query $query
  * @param int $userid
  */
 public function alter_query(block_ajax_marking_query $query, $userid)
 {
     $clause = array('type' => 'AND', 'condition' => 'sub.userid = :assignmentuseridfilteruserid');
     $query->add_where($clause);
     $query->add_param('assignmentuseridfilteruserid', $userid);
 }
コード例 #5
0
 /**
  * This is for when a courseid node is an ancestor of the node that has been
  * selected, so we just do a where.
  *
  * @param block_ajax_marking_query $query
  * @param int|string $cohortid
  * @return void
  */
 protected function alter_query(block_ajax_marking_query $query, $cohortid)
 {
     $clause = array('type' => 'AND', 'condition' => 'cohort.id = :cohortidfiltercohortid');
     $query->add_where($clause);
     $query->add_param('cohortidfiltercohortid', $cohortid);
 }
コード例 #6
0
 /**
  * Adds SQL for when there is a discussion node as an ancestor of the current nodes.
  *
  * @static
  * @param block_ajax_marking_query $query
  * @param int $discussionid
  */
 protected function alter_query(block_ajax_marking_query $query, $discussionid)
 {
     $clause = array('type' => 'AND', 'condition' => 'discussion.id = :discussionidfilterdiscussionid');
     $query->add_where($clause);
     $query->add_param('discussionidfilterdiscussionid', $discussionid);
 }
コード例 #7
0
 /**
  * This is for when a courseid node is an ancestor of the node that has been
  * selected, so we just do a where.
  *
  * @param block_ajax_marking_query $query
  * @param int $courseid
  */
 protected function alter_query(block_ajax_marking_query $query, $courseid)
 {
     $conditions = array('type' => 'AND', 'condition' => 'moduleunion.course = :courseidancestorcourseid');
     $query->add_where($conditions);
     $query->add_param('courseidancestorcourseid', $courseid);
 }
コード例 #8
0
 /**
  * Used when there is an ancestor node representing a coursemodule.
  *
  * @static
  * @param block_ajax_marking_query $query
  * @param int|string $groupid
  * @return void
  */
 protected function alter_query(block_ajax_marking_query $query, $groupid)
 {
     $conditions = array('type' => 'AND', 'condition' => block_ajax_marking_get_countwrapper_groupid_sql() . ' = :groupid');
     $query->add_where($conditions);
     $query->add_param('groupid', $groupid);
 }
コード例 #9
0
 /**
  * Adds SQL to a dynamic query for when there is a question node as an ancestor of the current
  * nodes.
  *
  * @static
  * @param block_ajax_marking_query $query
  * @param int $questionid
  */
 protected function alter_query(block_ajax_marking_query $query, $questionid)
 {
     $clause = array('type' => 'AND', 'condition' => 'moduleunion.questionid = :quizfilterquestionidancestor');
     $query->add_where($clause);
     $query->add_param('quizfilterquestionidancestor', $questionid);
 }