- // User to be checked is always the same (usually null, get it form first element)
- $firstcap = reset($this->requiredcapabilities);
- $userid = isset($firstcap['user']) ? $firstcap['user'] : null;
- // Extract caps to check, this saves us a bunch of iterations
- $requiredcaps = array();
- foreach ($this->requiredcapabilities as $cap) {
- $requiredcaps[] = $cap['capability'];
- }
- // Iterate while we have records and haven't reached $this->maxresults.
- while ($totalcourses > $offs and $this->totalcount < $this->maxresults) {
- $resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz);
+ if ($totalcourses > 0) {
+ // User to be checked is always the same (usually null, get it from first element).
+ $firstcap = reset($this->requiredcapabilities);
+ $userid = isset($firstcap['user']) ? $firstcap['user'] : null;
+ // Extract caps to check, this saves us a bunch of iterations.
+ $requiredcaps = array();
+ foreach ($this->requiredcapabilities as $cap) {
+ $requiredcaps[] = $cap['capability'];
+ }
+ // Iterate while we have records and haven't reached $this->maxresults.
+ $resultset = $DB->get_recordset_sql($sql, $params);