* * @param string $table The database table to be checked against. * @param string $select A fragment of SQL to be used in a where clause in the SQL call. * @param array $params array of sql parameters * @param string $fields A comma separated list of fields to be returned from the chosen table. * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; * IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); * MUST_EXIST means throw exception if no record or multiple records found * @return stdClass|false a fieldset object containing the first matching record, false or exception if error not found depending on mode * @throws dml_exception A DML specific exception is thrown for any errors. */ public function get_record_select($table, $select, ?array $params=null, $fields='*', $strictness=IGNORE_MISSING) { if ($select) { $select = "WHERE $select"; } try { return $this->get_record_sql("SELECT $fields FROM {" . $table . "} $select", $params, $strictness); } catch (dml_missing_record_exception $e) { // create new exception which will contain correct table name throw new dml_missing_record_exception($table, $e->sql, $e->params); } } /** * Get a single database record as an object using a SQL statement. * * The SQL statement should normally only return one record. * It is recommended to use get_records_sql() if more matches possible! * * @param string $sql The SQL string you wish to be executed, should normally only return one record. * @param array $params array of sql parameters * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; * IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); * MUST_EXIST means throw exception if no record or multiple records found * @return mixed a fieldset object containing the first matching record, false or exception if error not found depending on mode * @throws dml_exception A DML specific exception is thrown for any errors. */ public function get_record_sql($sql, ?array $params=null, $strictness=IGNORE_MISSING) { $strictness = (int)$strictness; // we support true/false for BC reasons too if ($strictness == IGNORE_MULTIPLE) {
return $menu; } /** * Get a single database record as an object where all the given conditions met. * * @param string $table The table to select from. * @param array $conditions optional array $fieldname=>requestedvalue with AND in between * @param string $fields A comma separated list of fields to be returned from the chosen table. * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; * IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); * MUST_EXIST means we will throw an exception if no record or multiple records found. * * @todo MDL-30407 MUST_EXIST option should not throw a dml_exception, it should throw a different exception as it's a requested check. * @return mixed a fieldset object containing the first matching record, false or exception if error not found depending on mode * @throws dml_exception A DML specific exception is thrown for any errors. */ public function get_record($table, array $conditions, $fields='*', $strictness=IGNORE_MISSING) { list($select, $params) = $this->where_clause($table, $conditions); return $this->get_record_select($table, $select, $params, $fields, $strictness); } /** * Get a single database record as an object which match a particular WHERE clause. * * @param string $table The database table to be checked against. * @param string $select A fragment of SQL to be used in a where clause in the SQL call. * @param array $params array of sql parameters * @param string $fields A comma separated list of fields to be returned from the chosen table. * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; * IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); * MUST_EXIST means throw exception if no record or multiple records found * @return stdClass|false a fieldset object containing the first matching record, false or exception if error not found depending on mode * @throws dml_exception A DML specific exception is thrown for any errors. */ public function get_record_select($table, $select, ?array $params=null, $fields='*', $strictness=IGNORE_MISSING) { if ($select) { $select = "WHERE $select"; } try {
public function get_course_context($strict = true) { return $this; } /** * Returns course context instance. * * @param int $courseid id from {course} table * @param int $strictness * @return course|false context instance */ public static function instance($courseid, $strictness = MUST_EXIST) { global $DB; if ($context = context::cache_get(self::LEVEL, $courseid)) { return $context; } if (!$record = $DB->get_record('context', array('contextlevel' => self::LEVEL, 'instanceid' => $courseid))) { if ($course = $DB->get_record('course', array('id' => $courseid), 'id,category', $strictness)) { if ($course->category) { $parentcontext = coursecat::instance($course->category); $record = context::insert_context_record(self::LEVEL, $course->id, $parentcontext->path); } else { $record = context::insert_context_record(self::LEVEL, $course->id, '/'.SYSCONTEXTID, 0); } } } if ($record) { $context = new course($record); context::cache_add($context); return $context; } return false; } /** * Create missing context instances at course context level
} } ?> </div> </div> <?php } ?> <div> <?php if (isset($data["trainers"]) && $data["trainers"]) { ?> <div class="col-md-12"> <div class="col-md-6"> <div class="h5"><?php echo format_text(get_string("trainer/s", "local_course")); ?> </div> </div> <div class="col-md-6"> <?php echo format_text($data["trainers"]); ?> </div> </div> <?php } else { $role = $DB->get_record('role', array('shortname' => 'teacher')); $context = context_course::instance($course->id); if ($role): $teachers = get_role_users($role->id, $context); if (!$teachers) { $role = $DB->get_record('role', array('shortname' => 'editingteacher')); $teachers = get_role_users($role->id, $context); } $fullname = ""; if ($teachers) : ?> <div class="col-md-12"> <div class="col-md-6"> <div class="h5"><?php echo format_text(get_string("trainer/s", "local_course")); ?> </div> </div> <div class="col-md-6"> <?php if (isset($data["trainers"]) && $data["trainers"]) { echo format_text($data["trainers"]); } else { $role = $DB->get_record('role', array('shortname' => 'teacher')); $context = context_course::instance($course->id);