Aligned SQL to conform to Moodle standards

This commit is contained in:
Mark Nelson 2015-03-11 01:22:44 -07:00
parent 8a55c96dab
commit 6821122c30
6 changed files with 44 additions and 47 deletions

View file

@ -99,12 +99,12 @@ class restore_customcert_activity_task extends restore_activity_task {
// Get the customcert elements.
$sql = "SELECT e.*
FROM {customcert_elements} e
INNER JOIN {customcert_pages} p
ON e.pageid = p.id
INNER JOIN {customcert} c
ON p.customcertid = c.id
WHERE c.id = :customcertid";
FROM {customcert_elements} e
INNER JOIN {customcert_pages} p
ON e.pageid = p.id
INNER JOIN {customcert} c
ON p.customcertid = c.id
WHERE c.id = :customcertid";
if ($elements = $DB->get_records_sql($sql, array('customcertid' => $this->get_activityid()))) {
// Go through the elements for the certificate.
foreach ($elements as $e) {

View file

@ -110,9 +110,9 @@ class customcert_element_date extends customcert_element_base {
} else if ($dateitem == CUSTOMCERT_DATE_COMPLETION) {
// Get the enrolment end date.
$sql = "SELECT MAX(c.timecompleted) as timecompleted
FROM {course_completions} c
WHERE c.userid = :userid
AND c.course = :courseid";
FROM {course_completions} c
WHERE c.userid = :userid
AND c.course = :courseid";
if ($timecompleted = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $COURSE->id))) {
if (!empty($timecompleted->timecompleted)) {
$date = $timecompleted->timecompleted;

View file

@ -212,8 +212,8 @@ abstract class customcert_element_base {
$sequence = 1;
// Check if there already elements that exist, if so, overwrite value.
$sql = "SELECT MAX(sequence) as maxsequence
FROM {customcert_elements}
WHERE pageid = :id";
FROM {customcert_elements}
WHERE pageid = :id";
// Get the current max sequence on this page and add 1 to get the new sequence.
if ($maxseq = $DB->get_record_sql($sql, array('id' => $pageid))) {
$sequence = $maxseq->maxsequence + 1;

12
lib.php
View file

@ -90,10 +90,10 @@ function customcert_delete_instance($id) {
// Delete the elements.
$sql = "SELECT e.*
FROM {customcert_elements} e
INNER JOIN {customcert_pages} p
ON e.pageid = p.id
WHERE p.customcertid = :customcertid";
FROM {customcert_elements} e
INNER JOIN {customcert_pages} p
ON e.pageid = p.id
WHERE p.customcertid = :customcertid";
if ($elements = $DB->get_records_sql($sql, array('customcertid' => $id))) {
foreach ($elements as $element) {
// Get an instance of the element class.
@ -137,8 +137,8 @@ function customcert_reset_userdata($data) {
if (!empty($data->reset_customcert)) {
$sql = "SELECT cert.id
FROM {customcert} cert
WHERE cert.course = :courseid";
FROM {customcert} cert
WHERE cert.course = :courseid";
$DB->delete_records_select('customcert_issues', "customcertid IN ($sql)", array('courseid' => $data->courseid));
$status[] = array('component' => $componentstr, 'item' => get_string('customcertremoved', 'customcert'), 'error' => false);
}

View file

@ -44,10 +44,10 @@ require_capability('mod/customcert:manage', $context);
if ($confirm) {
// First, remove all the existing elements and pages.
$sql = "SELECT e.*
FROM {customcert_elements} e
INNER JOIN {customcert_pages} p
ON e.pageid = p.id
WHERE p.customcertid = :customcertid";
FROM {customcert_elements} e
INNER JOIN {customcert_pages} p
ON e.pageid = p.id
WHERE p.customcertid = :customcertid";
if ($elements = $DB->get_records_sql($sql, array('customcertid' => $customcert->id))) {
foreach ($elements as $element) {
// Get an instance of the element class.

View file

@ -252,8 +252,8 @@ function customcert_add_page($data) {
$pagenumber = 1;
// Get the max page number.
$sql = "SELECT MAX(pagenumber) as maxpage
FROM {customcert_pages} cp
WHERE cp.customcertid = :customcertid";
FROM {customcert_pages} cp
WHERE cp.customcertid = :customcertid";
if ($maxpage = $DB->get_record_sql($sql, array('customcertid' => $data->id))) {
$pagenumber = $maxpage->maxpage + 1;
}
@ -301,11 +301,10 @@ function customcert_delete_page($pageid) {
// Now we want to decrease the page number values of
// the pages that are greater than the page we deleted.
$sql = "UPDATE {customcert_pages}
SET pagenumber = pagenumber - 1
WHERE customcertid = :customcertid
AND pagenumber > :pagenumber";
$DB->execute($sql, array('customcertid' => $page->customcertid,
'pagenumber' => $page->pagenumber));
SET pagenumber = pagenumber - 1
WHERE customcertid = :customcertid
AND pagenumber > :pagenumber";
$DB->execute($sql, array('customcertid' => $page->customcertid, 'pagenumber' => $page->pagenumber));
}
/**
@ -407,17 +406,15 @@ function customcert_get_issues($customcertid, $groupmode, $cm, $page, $perpage)
$allparams = $conditionsparams + array('customcertid' => $customcertid);
// Return the issues.
return $DB->get_records_sql("SELECT u.*, ci.code, ci.timecreated
FROM {user} u
INNER JOIN {customcert_issues} ci
ON u.id = ci.userid
WHERE u.deleted = 0
AND ci.customcertid = :customcertid
$conditionssql
ORDER BY " . $DB->sql_fullname(),
$allparams,
$page * $perpage,
$perpage);
$sql = "SELECT u.*, ci.code, ci.timecreated
FROM {user} u
INNER JOIN {customcert_issues} ci
ON u.id = ci.userid
WHERE u.deleted = 0
AND ci.customcertid = :customcertid
$conditionssql
ORDER BY " . $DB->sql_fullname();
return $DB->get_records_sql($sql, $allparams, $page * $perpage, $perpage);
}
/**
@ -438,14 +435,14 @@ function customcert_get_number_of_issues($customcertid, $cm, $groupmode) {
$allparams = $conditionsparams + array('customcertid' => $customcertid);
// Return the number of issues.
return $DB->count_records_sql("SELECT COUNT(u.id) as count
FROM {user} u
INNER JOIN {customcert_issues} ci
ON u.id = ci.userid
WHERE u.deleted = 0
AND ci.customcertid = :customcertid
$conditionssql",
$allparams);
$sql = "SELECT COUNT(u.id) as count
FROM {user} u
INNER JOIN {customcert_issues} ci
ON u.id = ci.userid
WHERE u.deleted = 0
AND ci.customcertid = :customcertid
$conditionssql";
return $DB->count_records_sql($sql, $allparams);
}
/**