. /** * Privacy Fetch Result Set. * * @package core_privacy * @copyright 2018 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace core_privacy\local\request; defined('MOODLE_INTERNAL') || die(); /** * Privacy Fetch Result Set. * * @copyright 2018 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class contextlist extends contextlist_base { /** * Add a set of contexts from SQL. * * The SQL should only return a list of context IDs. * * @param string $sql The SQL which will fetch the list of * context IDs * @param array $params The set of SQL parameters * @return $this */ public function add_from_sql(string $sql, array $params) : contextlist { global $DB; $fields = \context_helper::get_preload_record_columns_sql('ctx'); $wrapper = "SELECT {$fields} FROM {context} ctx WHERE id IN ({$sql})"; $contexts = $DB->get_recordset_sql($wrapper, $params); $contextids = []; foreach ($contexts as $context) { $contextids[] = $context->ctxid; \context_helper::preload_from_record($context); } $this->set_contextids(array_merge($this->get_contextids(), $contextids)); return $this; } /** * Sets the component for this contextlist. * * @param string $component the frankenstyle component name. */ public function set_component($component) { parent::set_component($component); } }