Skip to content

Commit

Permalink
MDL-24079 fixing recent regressions caused by api changes in tablelib…
Browse files Browse the repository at this point in the history
…; sorry I did not find the problem earlier
  • Loading branch information
skodak committed Sep 5, 2010
1 parent ee70439 commit 0f21a96
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 50 deletions.
10 changes: 6 additions & 4 deletions course/report/participation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@
$params['instanceid'] = $instanceid;
$params['timefrom'] = $timefrom;

if ($table->get_sql_where()) {
$sql .= ' AND '.$table->get_sql_where(); //initial bar
list($twhere, $tparams) = $table->get_sql_where();
if ($twhere) {
$sql .= ' AND '.$twhere; //initial bar
$params = array_merge($params, $tparams);
}

$sql .= " GROUP BY ra.userid, u.firstname, u.lastname, u.idnumber";
Expand All @@ -220,8 +222,8 @@

$totalcount = $DB->count_records_sql($countsql, $params);

if ($table->get_sql_where()) {
$matchcount = $DB->count_records_sql($countsql.' AND '.$table->get_sql_where(), $params);
if ($twhere) {
$matchcount = $DB->count_records_sql($countsql.' AND '.$twhere, $params);
} else {
$matchcount = $totalcount;
}
Expand Down
7 changes: 4 additions & 3 deletions mod/assignment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1261,11 +1261,12 @@ function display_submissions($message='') {
}
/// Construct the SQL

if ($where = $table->get_sql_where()) {
list($where, $params) = $table->get_sql_where();
if ($where) {
$where .= ' AND ';
}

if($filter == self::FILTER_SUBMITTED) {
if ($filter == self::FILTER_SUBMITTED) {
$where .= 's.timemodified > 0 AND ';
} else if($filter == self::FILTER_REQUIRE_GRADING) {
$where .= 's.timemarked < s.timemodified AND ';
Expand All @@ -1286,7 +1287,7 @@ function display_submissions($message='') {
AND s.assignment = '.$this->assignment->id.' '.
'WHERE '.$where.'u.id IN ('.implode(',',$users).') ';

$ausers = $DB->get_records_sql($select.$sql.$sort, null, $table->get_page_start(), $table->get_page_size());
$ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size());

$table->pagesize($perpage, count($users));

Expand Down
31 changes: 17 additions & 14 deletions mod/feedback/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedow
if ($filearea !== 'item') {
return false;
}

if ($item->feedback == $cm->instance) {
$filecontext = $context;
} else {
Expand All @@ -179,7 +179,7 @@ function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedow
return false;
}
}

$relativepath = implode('/', $args);
$fullpath = "/$context->id/mod_feedback/$filearea/$itemid/$relativepath";

Expand Down Expand Up @@ -805,42 +805,45 @@ function feedback_count_complete_users($cm, $group = false) {
* @uses FEEDBACK_ANONYMOUS_NO
* @param object $cm
* @param int $group single groupid
* @param string $where a sql where condition
* @param string $where a sql where condition (must end with " AND ")
* @param array parameters used in $where
* @param string $sort a table field
* @param int $startpage
* @param int $pagecount
* @return object the userrecords
*/
function feedback_get_complete_users($cm, $group = false, $where, $sort = '', $startpage = false, $pagecount = false) {
function feedback_get_complete_users($cm, $group = false, $where = '', array $params = NULL, $sort = '', $startpage = false, $pagecount = false) {
global $DB;

if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
print_error('badcontext');
}

$params = array(FEEDBACK_ANONYMOUS_NO, $cm->instance);
$params = (array)$params;

$params['anon'] = FEEDBACK_ANONYMOUS_NO;
$params['instance'] = $cm->instance;

$fromgroup = '';
$wheregroup = '';
if($group) {
if ($group) {
$fromgroup = ', {groups_members} g';
$wheregroup = ' AND g.groupid = ? AND g.userid = c.userid';
$params[] = $group;
$wheregroup = ' AND g.groupid = :group AND g.userid = c.userid';
$params['group'] = $group;
}

if($sort) {
if ($sort) {
$sortsql = ' ORDER BY '.$sort;
}else {
} else {
$sortsql = '';
}

$ufields = user_picture::fields('u');
$sql = 'SELECT DISTINCT '.$ufields.' FROM {user} u, {feedback_completed} c'.$fromgroup.'
WHERE '.$where.' anonymous_response = ? AND u.id = c.userid AND c.feedback = ?
$sql = 'SELECT DISTINCT '.$ufields.' FROM {user} u, {feedback_completed} c '.$fromgroup.'
WHERE '.$where.' anonymous_response = :anon AND u.id = c.userid AND c.feedback = :instance
'.$wheregroup.$sortsql;
;

if($startpage === false OR $pagecount === false) {
if ($startpage === false OR $pagecount === false) {
$startpage = false;
$pagecount = false;
}
Expand Down
8 changes: 3 additions & 5 deletions mod/feedback/show_entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@
$sort = '';
}

if($table->get_sql_where()) {
$where = $table->get_sql_where();
list($where, $params) = $table->get_sql_where();
if ($where) {
$where .= ' AND';
}else {
$where = '';
}

//get students in conjunction with groupmode
Expand All @@ -166,7 +164,7 @@
$pagecount = $table->get_page_size();
}

$students = feedback_get_complete_users($cm, $usedgroupid, $where, $sort, $startpage, $pagecount);
$students = feedback_get_complete_users($cm, $usedgroupid, $where, $params, $sort, $startpage, $pagecount);

$completedFeedbackCount = feedback_get_completeds_group_count($feedback, $mygroupid);
if($feedback->course == SITEID){
Expand Down
8 changes: 3 additions & 5 deletions mod/feedback/show_nonrespondents.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,9 @@
$sort = '';
}

if($table->get_sql_where()) {
$where = $table->get_sql_where();
list($where, $params) = $table->get_sql_where(); //TODO: weird, $where not used anywhere
if ($where) {
$where .= ' AND';
}else {
$where = '';
}

//get students in conjunction with groupmode
Expand All @@ -199,7 +197,7 @@
$pagecount = $table->get_page_size();
}

$students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount);
$students = feedback_get_incomplete_users($cm, $usedgroupid, $sort, $startpage, $pagecount); // TODO: $where and $params should be probably used here
//####### viewreports-start
//print the list of students
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
Expand Down
8 changes: 5 additions & 3 deletions mod/quiz/report/grading/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,14 @@ function view_question($quiz, $question, $totalattempts, $ungraded) {

list($select, $from, $where, $params) = $this->attempts_sql($quiz->id, true, $question->id);

if($table->get_sql_where()) { // forgot what this does
$where .= 'AND '.$table->get_sql_where();
list($twhere, $tparams) = $table->get_sql_where();
if ($twhere) {
$where .= ' AND '.$twhere; //initial bar
$params = array_merge($params, $tparams);
}

// sorting of the table
if($sort = $table->get_sql_sort()) {
if ($sort = $table->get_sql_sort()) {
$sort = 'ORDER BY '.$sort; // seems like I would need to have u. or qa. infront of the ORDER BY attribues... but seems to work..
} else {
// my default sort rule
Expand Down
17 changes: 10 additions & 7 deletions mod/scorm/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
$countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'','st.attempt').')) AS nbattempts, ';
$countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
$countsql .= $from.$where;
$params = array();
if (!$download) {
$sort = $table->get_sql_sort();
Expand All @@ -390,17 +391,19 @@

if (!$download) {
// Add extra limits due to initials bar
if($table->get_sql_where()) {
$where .= ' AND '.$table->get_sql_where();
list($twhere, $tparams) = $table->get_sql_where();
if ($twhere) {
$where .= ' AND '.$twhere; //initial bar
$params = array_merge($params, $tparams);
}

if (!empty($countsql)) {
$count = $DB->get_record_sql($countsql);
$totalinitials = $count->nbresults;
if ($table->get_sql_where()) {
$countsql .= ' AND '.$table->get_sql_where();
if ($twhere) {
$countsql .= ' AND '.$twhere;
}
$count = $DB->get_record_sql($countsql);
$count = $DB->get_record_sql($countsql, $params);
$total = $count->nbresults;
}

Expand All @@ -419,7 +422,7 @@

// Fetch the attempts
if (!$download) {
$attempts = $DB->get_records_sql($select.$from.$where.$sort, array(),
$attempts = $DB->get_records_sql($select.$from.$where.$sort, $params,
$table->get_page_start(), $table->get_page_size());
echo '<div id="scormtablecontainer">';
if ($candelete) {
Expand All @@ -436,7 +439,7 @@
}
$table->initialbars($totalinitials>20); // Build table rows
} else {
$attempts = $DB->get_records_sql($select.$from.$where.$sort);
$attempts = $DB->get_records_sql($select.$from.$where.$sort, $params);
}

if ($attempts) {
Expand Down
9 changes: 3 additions & 6 deletions tag/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,15 @@

$table->setup();

$params = array();

if ($table->get_sql_sort()) {
$sort = 'ORDER BY '. $table->get_sql_sort();
} else {
$sort = '';
}

if ($table->get_sql_where()) {
$where = 'WHERE '. $table->get_sql_where();
} else {
$where = '';
list($where, $params) = $table->get_sql_where();
if ($where) {
$where = 'WHERE '. $where;
}

$query = "
Expand Down
8 changes: 5 additions & 3 deletions user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

$page = optional_param('page', 0, PARAM_INT); // which page to show
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // how many per page
$mode = optional_param('mode', NULL); // use the MODE_ constants
$mode = optional_param('mode', NULL, PARAM_INT); // use the MODE_ constants
$accesssince = optional_param('accesssince',0,PARAM_INT); // filter by last access. -1 = never
$search = optional_param('search','',PARAM_RAW); // make sure it is processed with p() or s() when sending to output!
$roleid = optional_param('roleid', 0, PARAM_INT); // optional roleid, 0 means all enrolled users (or all on the frontpage)
Expand Down Expand Up @@ -424,8 +424,10 @@
$params['search3'] = "%$search%";
}

if ($table->get_sql_where()) {
$wheres[] = $table->get_sql_where();
list($twhere, $tparams) = $table->get_sql_where();
if ($twhere) {
$wheres[] = $twhere;
$params = array_merge($params, $tparams);
}

$from = implode("\n", $joins);
Expand Down

0 comments on commit 0f21a96

Please sign in to comment.