Skip to content

Commit

Permalink
Fix sql queries with variable replacements.
Browse files Browse the repository at this point in the history
  • Loading branch information
srobotta committed Oct 23, 2024
1 parent a0f8937 commit 3879f39
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ public static function is_ready($verbalfeedbackid) {
*/
public static function get_instance_by_itemid($itemid) {
global $DB;
[$vftable, $cattable, $crittable] = [tables::INSTANCE_TABLE, tables::INSTANCE_CATEGORY_TABLE, tables::INSTANCE_CRITERION_TABLE];
$id = (int)$itemid;
static $instances = [];
if (isset($instances[$id])) {
return $instances[$id];
}
$instances[$id] = $DB->get_record_sql("
SELECT vf.* FROM {{$vftable} vf
INNER JOIN {{$cattable}} cat ON cat.instanceid = vf.id
INNER JOIN {{$crittable}} crit ON crit.categoryid = cat.id
WHERE crit.id = ?",
$instances[$id] = $DB->get_record_sql(sprintf('
SELECT vf.* FROM {%s} vf
INNER JOIN {%s} cat ON cat.instanceid = vf.id
INNER JOIN {%s} crit ON crit.categoryid = cat.id
WHERE crit.id = ?',
tables::INSTANCE_TABLE, tables::INSTANCE_CATEGORY_TABLE, tables::INSTANCE_CRITERION_TABLE),
[$id], IGNORE_MISSING);
return $instances[$id];
}
Expand All @@ -137,16 +137,16 @@ public static function get_instance_by_itemid($itemid) {
*/
public static function get_instance_by_categoryid($categoryid) {
global $DB;
[$vftable, $cattable] = [tables::INSTANCE_TABLE, tables::INSTANCE_CATEGORY_TABLE];
$id = (int)$categoryid;
static $instances = [];
if (isset($instances[$id])) {
return $instances[$id];
}
$instances[$id] = $DB->get_record_sql("
SELECT vf.* FROM {{$vftable}} vf
INNER JOIN {{$cattable}} cat ON cat.instanceid = vf.id
WHERE cat.id = ?",
$instances[$id] = $DB->get_record_sql(sprintf('
SELECT vf.* FROM {%s} vf
INNER JOIN {%s} cat ON cat.instanceid = vf.id
WHERE cat.id = ?',
tables::INSTANCE_TABLE, tables::INSTANCE_CATEGORY_TABLE),
[$id], IGNORE_MISSING);
return $instances[$id];
}
Expand Down

0 comments on commit 3879f39

Please sign in to comment.