Skip to content

Commit

Permalink
Format the sql
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusgreen committed Oct 8, 2024
1 parent 73d7137 commit 6306132
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions import_examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ protected function definition() {
*/
public function get_question_category($courseshortname) {
global $DB;
/* parent=0 means where you have multiple categories it is at the top */
$sql = 'Select qcat.id id, c.id courseid,c.shortname,ctx.id contextid from {course} c
join {context} ctx on ctx.instanceid=c.id
join {question_categories} qcat on qcat.contextid=ctx.id
and ctx.contextlevel=50 and qcat.parent=0 and c.shortname =?';
$category = $DB->get_records_sql($sql, array($courseshortname));
/* parent=0 means where you have multiple categories it is at the top 50 is CONTEXT_COURSE*/
$sql = 'SELECT qcat.id id, c.id courseid,c.shortname,ctx.id contextid FROM {course} c
JOIN {context} ctx on ctx.instanceid=c.id
JOIN {question_categories} qcat on qcat.contextid=ctx.id
AND ctx.contextlevel=50 AND qcat.parent=0 AND c.shortname =?';
$category = $DB->get_records_sql($sql, [$courseshortname]);
$category = array_shift($category);
return $category;
}
Expand All @@ -87,17 +87,17 @@ public function get_question_category($courseshortname) {
* @param array $data
* @return boolean
*/
public function validation($fromform, $data) {
$errors = array();
public function validation($fromform, $data): array|bool {
$errors = [];
global $DB;
$sql = 'select id from {course} where shortname =?';
$sql = 'SELECT id FROM {course} WHERE shortname =?';
$this->course = $DB->get_records_sql($sql, array($fromform['courseshortname']));
$this->course = array_shift($this->course);
if ($this->course == null) {
$errors['courseshortname'] = get_string('coursenotfound', 'qtype_gapfill');
} else {
$this->questioncategory = $this->get_question_category($fromform['courseshortname']);
if (count($this->questioncategory) == 0) {
if ($this->questioncategory->id == 0) {
$url = new moodle_url('/question/edit.php?courseid=' . $this->course->id);
$errors['courseshortname'] = get_string('questioncatnotfound', 'qtype_gapfill', $url->out());
}
Expand Down

0 comments on commit 6306132

Please sign in to comment.