/** * Makes SQL for the text labels for the course nodes. * * @static * @param block_ajax_marking_query $query */ protected function alter_query(block_ajax_marking_query $query) { // Same order as the super query will need them. Prefixed so we will have it as the // first column for the GROUP BY. $query->add_from(array('join' => 'INNER JOIN', 'table' => 'course_modules', 'on' => 'course_modules.id = countwrapperquery.id')); $query->add_select(array('table' => 'course_modules', 'column' => 'id', 'alias' => 'coursemoduleid')); // The javascript needs this for styling. $query->add_select(array('table' => 'countwrapperquery', 'column' => 'modulename')); // This will add the stuff that joins to the various module tables and gets the right names. $moduleclasses = block_ajax_marking_get_module_classes(); $introcoalesce = array(); $namecoalesce = array(); $orderbycoalesce = array(); foreach ($moduleclasses as $moduleclass) { $moduletablename = $moduleclass->get_module_name(); $query->add_from(array('join' => 'LEFT JOIN', 'table' => $moduletablename, 'on' => "(course_modules.instance = " . $moduletablename . ".id\n AND course_modules.module = '" . $moduleclass->get_module_id() . "')")); $namecoalesce[$moduletablename] = 'name'; $introcoalesce[$moduletablename] = 'intro'; $orderbycoalesce[$moduletablename] = $moduletablename . '.name'; } $query->add_select(array('table' => 'course_modules', 'column' => 'id', 'alias' => 'coursemoduleid')); $query->add_select(array('table' => $namecoalesce, 'function' => 'COALESCE', 'column' => 'name', 'alias' => 'name')); $query->add_select(array('table' => $introcoalesce, 'function' => 'COALESCE', 'column' => 'intro', 'alias' => 'tooltip')); $query->add_orderby('COALESCE(' . implode(', ', $orderbycoalesce) . ') ASC'); // This will add the stuff that will show us the name of the actual module instance. // We use the same stuff for both config and marking trees, but the config tree doesn't need // the stuff to pull through submission counts. // TODO separate counts. // This allows us to have separate decorators, but may obfuscate what's happening a bit. // Code is not duplicated, though. }
/** * Applies the filter needed for course nodes or their descendants * * @param block_ajax_marking_query $query * @SuppressWarnings(PHPMD.UnusedPrivateMethod) Dynamic method names don't register */ protected function alter_query(block_ajax_marking_query $query) { // This is for the displayquery when we are making course nodes. $query->add_from(array('table' => 'course', 'alias' => 'course', 'on' => 'countwrapperquery.id = course.id')); $query->add_select(array('table' => 'course', 'column' => 'shortname', 'alias' => 'name')); $query->add_select(array('table' => 'course', 'column' => 'fullname', 'alias' => 'tooltip')); $query->add_orderby('course.shortname ASC'); }
/** * Makes a bunch of user nodes by grouping quiz submissions by the user id. The grouping is * automatic, but the text labels for the nodes are specified here. * * @static * @param block_ajax_marking_query $query */ protected function alter_query(block_ajax_marking_query $query) { $query->add_select(array('table' => 'countwrapperquery', 'column' => 'timestamp', 'alias' => 'tooltip')); $query->add_select(array('table' => 'usertable', 'column' => 'firstname')); $query->add_select(array('table' => 'usertable', 'column' => 'lastname')); $query->add_from(array('join' => 'INNER JOIN', 'table' => 'user', 'alias' => 'usertable', 'on' => 'usertable.id = countwrapperquery.id')); // This is only needed to add the right callback function. $query->add_select(array('column' => "'quiz'", 'alias' => 'modulename')); }
/** * Applies the filter needed for course nodes or their descendants * * @param block_ajax_marking_query $query */ protected function alter_query(block_ajax_marking_query $query) { // This is for the displayquery when we are making course nodes. $query->add_from(array('join' => 'LEFT JOIN', 'table' => 'groups', 'on' => 'countwrapperquery.id = groups.id')); // We may get a load of people in no group. $query->add_select(array('function' => 'COALESCE', 'table' => array('groups' => 'name', get_string('notingroup', 'block_ajax_marking')), 'alias' => 'name')); $query->add_select(array('function' => 'COALESCE', 'table' => array('groups' => 'description', get_string('notingroupdescription', 'block_ajax_marking')), 'alias' => 'tooltip')); $query->add_orderby("COALESCE(groups.name, '" . get_string('notingroup', 'block_ajax_marking') . "') ASC"); }
/** * Makes a set of question nodes by grouping submissions by questionid. * * @static * @param block_ajax_marking_query $query */ protected function alter_query(block_ajax_marking_query $query) { // Outer bit to get display name. $query->add_from(array('join' => 'INNER JOIN', 'table' => 'question', 'on' => 'question.id = countwrapperquery.id')); $query->add_select(array('table' => 'question', 'column' => 'name')); $query->add_select(array('table' => 'question', 'column' => 'questiontext', 'alias' => 'tooltip')); // This is only needed to add the right callback function. $query->add_select(array('column' => "'quiz'", 'alias' => 'modulename')); $query->add_orderby("question.name ASC"); }
/** * Applies the filter needed for course nodes or their descendants * * @param block_ajax_marking_query $query * @SuppressWarnings(PHPMD.UnusedPrivateMethod) Dynamic method names don't register */ protected function alter_query(block_ajax_marking_query $query) { // What do we need for the nodes? $table = array('join' => 'INNER JOIN', 'table' => 'cohort', 'on' => 'countwrapperquery.id = cohort.id'); $query->add_from($table); $conditions = array('table' => 'cohort', 'column' => 'name'); $query->add_select($conditions); $conditions = array('table' => 'cohort', 'column' => 'description'); $query->add_select($conditions); $query->add_orderby('cohort.name ASC'); }
/** * Makes user nodes for the assign modules by grouping them and then adding in the right * text to describe them. * * @static * @param block_ajax_marking_query $query */ protected function alter_query(block_ajax_marking_query $query) { $conditions = array('table' => 'countwrapperquery', 'column' => 'timestamp', 'alias' => 'tooltip'); $query->add_select($conditions); $conditions = array('table' => 'usertable', 'column' => 'firstname'); $query->add_select($conditions); $conditions = array('table' => 'usertable', 'column' => 'lastname'); $query->add_select($conditions); $table = array('table' => 'user', 'alias' => 'usertable', 'on' => 'usertable.id = countwrapperquery.id'); $query->add_from($table); }
/** * Makes user nodes for the assignment modules by grouping them and then adding in the right * text to describe them. * * @static * @param block_ajax_marking_query $query */ protected function alter_query(block_ajax_marking_query $query) { $conditions = array('table' => 'countwrapperquery', 'column' => 'timestamp', 'alias' => 'tooltip'); $query->add_select($conditions); // Need this to make the popup show properly because some assignment code shows or // not depending on this flag to tell if it's in a pop-up e.g. the revert to draft // button for advanced upload. $conditions = array('column' => "'single'", 'alias' => 'mode'); $query->add_select($conditions); $conditions = array('table' => 'usertable', 'column' => 'firstname'); $query->add_select($conditions); $conditions = array('table' => 'usertable', 'column' => 'lastname'); $query->add_select($conditions); $table = array('table' => 'user', 'alias' => 'usertable', 'on' => 'usertable.id = countwrapperquery.id'); $query->add_from($table); }
/** * 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 * @return mixed|void */ protected function alter_query(block_ajax_marking_query $query) { // Apply WHERE clause. $conditions = array('table' => 'question', 'column' => 'id', 'alias' => 'questionid'); // TODO needs applying to just the quiz one. $query->add_select($conditions); }
/** * Adds SQL to construct a set of discussion nodes. * * @param block_ajax_marking_query $query * @return mixed|void */ protected function alter_query(block_ajax_marking_query $query) { // We join like this because we can't put extra stuff into the UNION ALL bit // unless all modules have it and this is unique to forums. $query->add_from(array('table' => 'forum_posts', 'on' => 'moduleunion.subid = post.id', 'alias' => 'post')); $query->add_from(array('table' => 'forum_discussions', 'on' => 'discussion.id = post.discussion', 'alias' => 'discussion')); $query->add_select(array('table' => 'discussion', 'column' => 'id'), true); }
/** * Adds SQL to construct a set of discussion nodes. * * @static * @param block_ajax_marking_query $query */ protected function alter_query(block_ajax_marking_query $query) { // This will be derived form the coursemodule id, but how to get it cleanly? // The query will know, but not easy to get it out. Might have been prefixed. // TODO pass this properly somehow. $coursemoduleid = required_param('coursemoduleid', PARAM_INT); // Normal forum needs discussion title as label, participant usernames as // description eachuser needs username as title and discussion subject as // description. if (block_ajax_marking_forum::forum_is_eachuser($coursemoduleid)) { $query->add_select(array('table' => 'firstpost', 'column' => 'subject', 'alias' => 'description')); } else { $query->add_select(array('table' => 'firstpost', 'column' => 'subject', 'alias' => 'label')); // TODO need a SELECT bit to get all userids of people in the discussion // instead. $query->add_select(array('table' => 'firstpost', 'column' => 'message', 'alias' => 'tooltip')); } $query->add_from(array('join' => 'INNER JOIN', 'table' => 'forum_discussions', 'alias' => 'outerdiscussions', 'on' => 'countwrapperquery.id = outerdiscussions.id')); $query->add_from(array('join' => 'INNER JOIN', 'table' => 'forum_posts', 'alias' => 'firstpost', 'on' => 'firstpost.id = outerdiscussions.firstpost')); $query->add_orderby("timestamp ASC"); }
/** * Applies the filter needed for course nodes or their descendants * * @param block_ajax_marking_query $query * @SuppressWarnings(PHPMD.UnusedPrivateMethod) Dynamic method names don't register */ protected function alter_query(block_ajax_marking_query $query) { global $USER; // This is for the displayquery when we are making course nodes. $query->add_from(array('table' => 'course', 'alias' => 'course', 'on' => 'course_modules.course = course.id')); $query->add_select(array('table' => 'course', 'column' => 'id', 'alias' => 'courseid', 'distinct' => true)); $query->add_select(array('table' => 'course', 'column' => 'shortname', 'alias' => 'name')); $query->add_select(array('table' => 'course', 'column' => 'fullname', 'alias' => 'tooltip')); // We need the config settings too, if there are any. // TODO this should be in the config filter. $query->add_from(array('join' => 'LEFT JOIN', 'table' => 'block_ajax_marking', 'alias' => 'settings', 'on' => "settings.instanceid = course.id\n AND settings.tablename = 'course'\n AND settings.userid = :settingsuserid")); $query->add_param('settingsuserid', $USER->id); $query->add_select(array('table' => 'settings', 'column' => 'display')); $query->add_select(array('table' => 'settings', 'column' => 'groupsdisplay')); $query->add_select(array('table' => 'settings', 'column' => 'id', 'alias' => 'settingsid')); $query->add_orderby('course.shortname ASC'); }
/** * @param block_ajax_marking_query $query * @return void */ protected function alter_query(block_ajax_marking_query $query) { // This will add the select, which will get a zero as the groupid if we don't have a group membership at all. $query->add_select(array('column' => block_ajax_marking_get_countwrapper_groupid_sql(), 'alias' => 'id')); }
/** * This will change the query so that it does whatever this decorator is supposed to do. * * @param block_ajax_marking_query $query * @return void */ protected function alter_query(block_ajax_marking_query $query) { $select = array('table' => 'moduleunion', 'column' => 'course', 'alias' => 'id'); $query->add_select($select, true); }
/** * Makes user nodes for the assignment modules by grouping them and then adding in the right * text to describe them. * * @static * @param block_ajax_marking_query $query * @return void */ protected function alter_query(block_ajax_marking_query $query) { // Make the count be grouped by user id. $conditions = array('table' => 'moduleunion', 'column' => 'userid', 'alias' => 'id'); $query->add_select($conditions, true); }
/** * @param block_ajax_marking_query $query * @return void */ protected function alter_query(block_ajax_marking_query $query) { $conditions = array('table' => 'cohort', 'column' => 'id'); $query->add_select($conditions); }
/** * Config nodes need some stuff to be returned from the config tables so we can have settings * adjusted based on existing values. * * @param block_ajax_marking_query $query * @param string $nextnodefilter * @return void */ private static function attach_config_settings(block_ajax_marking_query $query, $nextnodefilter) { $nodesthatneedconfigsettings = array('courseid', 'coursemoduleid'); if (!in_array($nextnodefilter, $nodesthatneedconfigsettings)) { return; } // The inner query joins to the config tables already for the WHERE clauses, so we // make use of them to get the settings for those nodes that are not filtered out. $countwrapper = $query->get_subquery('countwrapperquery'); switch ($nextnodefilter) { // This is for the ordinary nodes. We need to work out what to request for the next node // so groupsdisplay has to be sent through. Also for the config context menu to work. // COALESCE is no good here as we need the actual settings, so we work out that stuff // in JavaScript. case 'courseid': $countwrapper->add_select(array('table' => 'courseconfig', 'column' => 'display')); $countwrapper->add_select(array('table' => 'courseconfig', 'column' => 'groupsdisplay')); break; case 'coursemoduleid': // The inner query joins to the config tables already for the WHERE clauses, so we // make use of them to get the settings for those nodes that are not filtered out. $countwrapper = $query->get_subquery('countwrapperquery'); $countwrapper->add_select(array('table' => 'cmconfig', 'column' => 'display')); $countwrapper->add_select(array('table' => 'cmconfig', 'column' => 'groupsdisplay')); break; } // The outer query (we need one because we have to do a join between the numeric // fields that can be fed into a GROUP BY and the text fields that we display) pulls // through the display fields, which were sent through from the middle query using the // stuff above. $query->add_select(array('table' => 'countwrapperquery', 'column' => 'display')); $query->add_select(array('table' => 'countwrapperquery', 'column' => 'groupsdisplay')); }
/** * 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 * @return mixed|void */ protected function alter_query(block_ajax_marking_query $query) { $query->add_select(array('table' => 'moduleunion', 'column' => 'questionid', 'alias' => 'id')); }