@param  Context $original_context
@param  Context $new_context

@return array<int, string>
352416
public static function getNewOrUpdatedVarIds(Context $original_context, Context $new_context)
    {
        $redefined_var_ids = [];

        foreach ($new_context->vars_in_scope as $var_id => $context_type) {
            if (!isset($original_context->vars_in_scope[$var_id])
                || !$original_context->vars_in_scope[$var_id]->equals($context_type)
            ) {
                $redefined_var_ids[] = $var_id;
            }
        }

        return $redefined_var_ids;
    }
544888
protected function processInsert($row, $context)
    {
        if ($row instanceof InsertFromSelect) {
            return $this->processInsertFromSelect($row, $context);
        }

        $newRow = [];
        foreach ($row as $column => $value) {
            $column = $this->processColumnName($column, $context);
            $newRow[$column] = $this->processValueOrSubQuery($value, $context);
        }

        return $newRow;
    }
549713
public function contexts()
    {
        if (is_null($this->contextRequests)) {
            $this->contextRequests = new ContextRequests($this->client);
        }

        return $this->contextRequests;
    }
1182364
public function getUpgrades($context = null) {
        if (! $context) {
                $context = $this->getContext();
            }

        if (isset($this->_upgradeStack[$context])) {
            return $this->_upgradeStack[$context];
        }
        return array();
    }
123962
final protected static function get_context_structure() {
        return array(
            'contextid' => new external_value(PARAM_INT, 'The context id', VALUE_OPTIONAL),
            'contextlevel' => new external_value(PARAM_ALPHA, 'The context level', VALUE_OPTIONAL),
            'instanceid' => new external_value(PARAM_INT, 'The Instance id', VALUE_OPTIONAL),
        );
    }
703239
protected function getTranslation($domain, $context, $original)
    {
        return isset($this->dictionary[$domain][$context][$original])
             ? $this->dictionary[$domain][$context][$original]
             : false;
    }
1278821
public function getContext()
    {
        $context = [
            'log_cmd_insert'    => [$this, 'onInsert'],
            'log_cmd_delete'    => [$this, 'onDelete'],
            'log_cmd_update'    => [$this, 'onUpdate'],
            'log_insert'        => [$this, 'onInsert'],
            'log_delete'        => [$this, 'onDelete'],
            'log_update'        => [$this, 'onUpdate'],
            'log_batchinsert'   => [$this, 'onBatchInsert'],
            'log_write_batch'   => [$this, 'onBatchInsert'],
            'log_query'         => [$this, 'onQuery']
        ];
        return $context;
    }
1318631
public function load(LoadingContext $context) : array
    {
        $rows      = $context->query($this->select)->getRows();
        $data      = [];

        foreach ($this->columnIndexMap as $columnName => $index) {
            foreach ($rows as $key => $row) {
                $data[$key][$index] = $row->getColumn($columnName);
            }
        }

        foreach ($this->relationsToLoad as $index => list($relation, $parentTable, $parentColumnMap)) {
            /** @var Table $parentTable */
            if ($relation instanceof IToOneRelation) {
                $map       = new ParentChildMap($parentTable->getPrimaryKeyColumnName());
                $rowKeyMap = new \SplObjectStorage();

                foreach ($rows as  $key => $row) {
                    $mappedColumnData = [];
                    $originalColumnData = $row->getColumnData();

                    foreach($parentColumnMap as $original => $mapped) {
                        $mappedColumnData[$mapped] = $originalColumnData[$original];
                    }

                    $mappedRow = new Row($parentTable, $mappedColumnData);

                    $map->add($mappedRow, null);
                    $rowKeyMap[$mappedRow] = $key;
                }

                $relation->load($context, $map);

                foreach ($map->getItems() as $item) {
                    $data[$rowKeyMap[$item->getParent()]][$index] = $item->getChild();
                }
            } elseif ($relation instanceof IToManyRelation) {
                $map = new ParentChildrenMap($parentTable->getPrimaryKeyColumnName());
                $rowKeyMap = new \SplObjectStorage();

                foreach ($rows as $key => $row) {
                    $mappedColumnData = [];
                    $originalColumnData = $row->getColumnData();

                    foreach($parentColumnMap as $original => $mapped) {
                        $mappedColumnData[$mapped] = $originalColumnData[$original];
                    }

                    $mappedRow = new Row($parentTable, $mappedColumnData);

                    $map->add($mappedRow, []);
                    $rowKeyMap[$mappedRow] = $key;
                }

                $relation->load($context, $map);

                foreach ($map->getItems() as $item) {
                    $data[$rowKeyMap[$item->getParent()]][$index] = $relation->buildCollection($item->getChildren());
                }
            }
        }

        return $data;
    }
124633
public static function create_from_expiry_info(\context $context, expiry_info $info, bool $save = true) : expired_context {
        $record = (object) [
            'contextid' => $context->id,
            'status' => self::STATUS_EXPIRED,
            'defaultexpired' => (int) $info->is_default_expired(),
        ];

        $expiredcontext = new static(0, $record);
        $expiredcontext->set('expiredroles', $info->get_expired_roles());
        $expiredcontext->set('unexpiredroles', $info->get_unexpired_roles());

        if ($save) {
            $expiredcontext->save();
        }

        return $expiredcontext;
    }
284936
public function getContext()
    {
        $context = [];
        foreach ($this->contextProviders as $contextProvider) {
            $context[] = $contextProvider->getContext();
        }

        return empty($context) ? $context : call_user_func_array('array_merge', $context);
    }
235966
public function loadContext($context) {
        global $DB;

        if (!empty($context->getRecordId())) {
            $params = ['id' => $context->getRecordId()];
        } else {
            $params = [
                'consumerid' => $context->getConsumer()->getRecordId(),
                'lticontextkey' => $context->ltiContextId
            ];
        }
        if ($row = $DB->get_record($this->contexttable, $params)) {
            $context->setRecordId($row->id);
            $context->setConsumerId($row->consumerid);
            $context->ltiContextId = $row->lticontextkey;
            $context->type = $row->type;
            $settings = unserialize($row->settings);
            if (!is_array($settings)) {
                $settings = array();
            }
            $context->setSettings($settings);
            $context->created = $row->created;
            $context->updated = $row->updated;
            return true;
        }

        return false;
    }
43426
protected function createCollection($original_key, $original_class)
    {
        $collection = $this->convertToArray($original_key, $original_class);

        foreach ($collection as $key => $class) {
            $this->validateExtension($class);
            $this->collection[$this->getType($class)][$this->getKey($key, $class)] = $class;
        }
    }
518975
public static function build_editor_options(\context $context) {
        global $CFG;

        return [
            'context' => $context,
            'maxfiles' => EDITOR_UNLIMITED_FILES,
            'maxbytes' => $CFG->maxbytes,
            'noclean' => true,
            'autosave' => false
        ];
    }
222489
public function NoSegmentContexts()
	{
		$filtered = array_filter( $this->contexts, function( $context ) {
			// The context may be invalid in which case exclude
			return ( ! isset( $context['entity']['segment']['explicitMember'] ) || count( $context['entity']['segment']['explicitMember'] ) == 0 ) &&
				   ( ! isset( $context['entity']['scenario']['explicitMember'] ) || count( $context['entity']['scenario']['explicitMember'] ) == 0 ) &&
				   ( ! isset( $context['segment']['explicitMember'] ) || count( $context['segment']['explicitMember'] ) == 0 ) &&
				   ( ! isset( $context['scenario']['explicitMember'] ) || count( $context['scenario']['explicitMember'] ) == 0 ) &&
				   ( ! isset( $context['entity']['segment']['typedMember'] ) || count( $context['entity']['segment']['typedMember'] ) == 0 ) &&
				   ( ! isset( $context['entity']['scenario']['typedMember'] ) || count( $context['entity']['scenario']['typedMember'] ) == 0 ) &&
				   ( ! isset( $context['segment']['typedMember'] ) || count( $context['segment']['typedMember'] ) == 0 ) &&
				   ( ! isset( $context['scenario']['typedMember'] ) || count( $context['scenario']['typedMember'] ) == 0 );		} );

		return new ContextsFilter( $this->instance, $filtered );
	}
287089
public static function fromV1ToV2(array $context): array
    {
        if (array_key_exists('key', $context)
            && !\is_array($context['key'])
            && array_key_exists('value', $context)
        ) {
            $context = [$context];
        }

        if (count($context) === 1 && !\is_int(key($context))) {
            $context = [$context];
        }

        $result = [];
        foreach ($context as $item) {
            if (\is_array($item)
                && array_key_exists('key', $item)
                && !\is_array($item['key'])
                && array_key_exists('value', $item)
            ) {
                $result[$item['key']] = $item['value'];
            } elseif (\is_array($item) && count($item) === 1 && !isset($result[key($item)])) {
                $result[key($item)] = current($item);
            }
        }

        return $result;
    }
721383
public function dpgettext($domain, $context, $original)
    {
        $message = $context."\x04".$original;
        $translation = dgettext($domain, $message);

        return ($translation === $message) ? $original : $translation;
    }
808532
private function parseAnnotations(PropertyContext $context, \ReflectionProperty $property, $original)
    {
        $annot = $this->propertyHandler->getPropertyAnnotation($property);

        if ($annot) {
            $context = $this->handleRepresentProperty($property, $annot, $context, $original);
        }

        return $context;
    }