예제 #1
0
/**
 * We have to do greatest-n-per-group to get the highest group id that's not specified as hidden by the user.
 * This involves repeating the same SQL twice because MySQL doesn't support CTEs.
 *
 * This function provides the base query which shows us all of the group members attached to their coursemodules. We can
 * then do a left join to block_ajax_marking_group_max_subquery() to make sure there's no higher group id that's visible
 * but whereas that has the visibility query within it, this doesn't because we want to use the possible null value
 * as an indicator that the user is not in any group.
 */
function block_ajax_marking_group_members_subquery()
{
    global $DB;
    // Params need new names every time.
    static $counter = 1;
    $counter++;
    $courses = block_ajax_marking_get_my_teacher_courses();
    list($coursessql, $coursesparams) = $DB->get_in_or_equal(array_keys($courses), SQL_PARAMS_NAMED, "gmember_{$counter}_courses");
    // This only shows people who have group memberships, so we need to say if there isn't one or not in the outer
    // query. For this reason, this query will return all group memberships, plus whether they ought to be displayed.
    // The outer query can then do a left join.
    $sql = <<<SQL

             /* Start member query */

        SELECT gmember_members{$counter}.userid,
               gmember_groups{$counter}.id AS groupid,
               gmember_course_modules{$counter}.id AS coursemoduleid
          FROM {groups_members} gmember_members{$counter}
    INNER JOIN {groups} gmember_groups{$counter}
            ON gmember_groups{$counter}.id = gmember_members{$counter}.groupid
    INNER JOIN {course_modules} gmember_course_modules{$counter}
            ON gmember_course_modules{$counter}.course = gmember_groups{$counter}.courseid
            /* Limit the size of the subquery for performance */
         WHERE gmember_groups{$counter}.courseid {$coursessql}

         /* End member query */
SQL;
    return array($sql, $coursesparams);
}
 /**
  * Makes sure we only get stuff for the courses this user is a teacher in
  *
  * @param block_ajax_marking_query $query
  * @param string $coursecolumn
  * @return void
  */
 private static function apply_sql_owncourses(block_ajax_marking_query $query, $coursecolumn = '')
 {
     global $DB;
     $courses = block_ajax_marking_get_my_teacher_courses();
     $courseids = array_keys($courses);
     if ($courseids) {
         list($sql, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED, 'courseid0000');
         $query->add_where(array('type' => 'AND', 'condition' => $coursecolumn . ' ' . $sql));
         $query->add_params($params);
     }
 }
 /**
  * Standard get content function returns $this->content containing the block HTML etc
  *
  * @return bool|\stdClass
  */
 public function get_content()
 {
     global $CFG, $PAGE;
     if (!isloggedin()) {
         // Save all the DB stuff for the non-logged in front page.
         return false;
     }
     $modclasses = block_ajax_marking_get_module_classes();
     // If the user has switched role, we want to hide the block if the role would not normally
     // see the block. Normally, we don't check at this level so that we can have overrides
     // at module level.
     if (!empty($PAGE->course->id) && is_role_switched($PAGE->course->id)) {
         $canseeblock = false;
         foreach ($modclasses as $mod) {
             if (has_capability($mod->get_capability(), $PAGE->context)) {
                 $canseeblock = true;
             }
             if (!$canseeblock) {
                 return false;
             }
         }
     }
     if ($this->content !== null) {
         return $this->content;
     }
     require_once $CFG->dirroot . '/blocks/ajax_marking/lib.php';
     $courses = block_ajax_marking_get_my_teacher_courses();
     if (count($courses) > 0) {
         // Grading permissions exist in at least one course, so display.
         $this->content = new stdClass();
         // Start building content output.
         $this->content->footer = '';
         $this->content->text = '<div id="block_ajax_marking">';
         // Add a style to hide the HTML list and prevent flicker.
         $this->content->text .= $this->anti_flicker_js();
         // Add the basic HTML for the rest of the stuff to fit into.
         $divs = '
             <div id="block_ajax_marking_hidden">
                 <div id="dynamicicons">';
         $divs .= $this->get_dynamic_icons_html();
         $divs .= '
                 </div>
             </div>
             <div id="treetabs"></div>
             <div id="block_ajax_marking_error"></div>';
         $this->content->text .= $divs;
         // Don't warn about javascript if the screenreader option is set - it was deliberate.
         $noscript = '<noscript>
                          <p>' . get_string('nojavascript', 'block_ajax_marking') . '</p>
                      </noscript>';
         $this->content->text .= $noscript;
         $this->content->text .= ' <div class="block_ajax_marking_spacer"></div>' . '</div>';
         // End of #block_ajax_marking container.
         // Set things going.
         $PAGE->requires->js_init_call('M.block_ajax_marking.initialise', array(), true, $this->js_module());
         // We need to append all of the plugin specific javascript. This file will be
         // requested as part of a separate http request after the PHP has all been finished
         // with, so we do this cheaply to keep overheads low by not using setup.php and
         // having the js in static functions.
         foreach (array_keys($modclasses) as $modname) {
             $filename = '/blocks/ajax_marking/modules/' . $modname . '/' . $modname . '.js';
             if (file_exists($CFG->dirroot . $filename)) {
                 $PAGE->requires->js($filename);
             }
         }
     } else {
         // No grading permissions in any courses - don't display the block (student). Exception.
         // for when the block is just installed and the user can edit. Might look broken
         // otherwise.
         if (has_capability('moodle/course:manageactivities', $PAGE->context)) {
             $this->content = new stdClass();
             $this->content->text .= get_string('nogradedassessments', 'block_ajax_marking');
         } else {
             // This will stop the other functions like has_content() from running all the way
             // through this again.
             $this->content = false;
         }
     }
     return $this->content;
 }