Determines in which context the particular cohort will be created

@param array $hash
@param context $defaultcontext
@return array array of warning strings
489121
protected function resolve_context(&$hash, $defaultcontext) {
        global $DB;

        $warnings = array();

        if (!empty($hash['contextid'])) {
            // Contextid was specified, verify we can post there.
            $contextoptions = $this->get_context_options();
            if (!isset($contextoptions[$hash['contextid']])) {
                $warnings[] = new lang_string('contextnotfound', 'cohort', $hash['contextid']);
                $hash['contextid'] = $defaultcontext->id;
            }
            return $warnings;
        }

        if (!empty($hash['context'])) {
            $systemcontext = context_system::instance();
            if ((core_text::strtolower(trim($hash['context'])) ===
                    core_text::strtolower($systemcontext->get_context_name())) ||
                    ('' . $hash['context'] === '' . $systemcontext->id)) {
                // User meant system context.
                $hash['contextid'] = $systemcontext->id;
                $contextoptions = $this->get_context_options();
                if (!isset($contextoptions[$hash['contextid']])) {
                    $warnings[] = new lang_string('contextnotfound', 'cohort', $hash['context']);
                    $hash['contextid'] = $defaultcontext->id;
                }
            } else {
                // Assume it is a category.
                $hash['category'] = trim($hash['context']);
            }
        }

        if (!empty($hash['category_path'])) {
            // We already have array with available categories, look up the value.
            $contextoptions = $this->get_context_options();
            if (!$hash['contextid'] = array_search($hash['category_path'], $contextoptions)) {
                $warnings[] = new lang_string('categorynotfound', 'cohort', s($hash['category_path']));
                $hash['contextid'] = $defaultcontext->id;
            }
            return $warnings;
        }

        if (!empty($hash['category'])) {
            // Quick search by category path first.
            // Do not issue warnings or return here, further we'll try to search by id or idnumber.
            $contextoptions = $this->get_context_options();
            if ($hash['contextid'] = array_search($hash['category'], $contextoptions)) {
                return $warnings;
            }
        }

        // Now search by category id or category idnumber.
        if (!empty($hash['category_id'])) {
            $field = 'id';
            $value = clean_param($hash['category_id'], PARAM_INT);
        } else if (!empty($hash['category_idnumber'])) {
            $field = 'idnumber';
            $value = $hash['category_idnumber'];
        } else if (!empty($hash['category'])) {
            $field = is_numeric($hash['category']) ? 'id' : 'idnumber';
            $value = $hash['category'];
        } else {
            // No category field was specified, assume default category.
            $hash['contextid'] = $defaultcontext->id;
            return $warnings;
        }

        if (empty($this->categoriescache[$field][$value])) {
            $record = $DB->get_record_sql("SELECT c.id, ctx.id contextid
                FROM {context} ctx JOIN {course_categories} c ON ctx.contextlevel = ? AND ctx.instanceid = c.id
                WHERE c.$field = ?", array(CONTEXT_COURSECAT, $value));
            if ($record && ($contextoptions = $this->get_context_options()) && isset($contextoptions[$record->contextid])) {
                $contextid = $record->contextid;
            } else {
                $warnings[] = new lang_string('categorynotfound', 'cohort', s($value));
                $contextid = $defaultcontext->id;
            }
            // Next time when we can look up and don't search by this value again.
            $this->categoriescache[$field][$value] = $contextid;
        }
        $hash['contextid'] = $this->categoriescache[$field][$value];

        return $warnings;
    }
131803
def for_context(context)
      contexts = hash.keys.select { |ckey| context.matches?([ckey]) }
      contexts.map { |exc| hash[exc] }
    end
117502
public function getContext( $key = null, $default = null ) {
		if ( $key === null ) {
			return $this->context;
		}

		return Arr::get( $this->context, $key, $default );
	}
302020
public function getContents($hash) {
		$file = $this->file($hash);
		
		if (!$file) {
			return $this->setError(elFinder::ERROR_FILE_NOT_FOUND);
		}
		
		if ($file['mime'] == 'directory') {
			return $this->setError(elFinder::ERROR_NOT_FILE);
		}
		
		if (!$file['read']) {
			return $this->setError(elFinder::ERROR_PERM_DENIED);
		}
		
		return $this->convEncOut($this->_getContents($this->convEncIn($this->decode($hash))));
	}
523186
public function finalizeUpload(string $hash, ?string $context = null): bool
    {
        $this->init();
        $entity = $this->repository->findByHash($hash, $context, false);
        if ($entity) {
            $entity->setConfirmed(true);
            $entity->setSize(strlen($entity->getContents()));
            $this->manager->persist($entity);
            $this->manager->flush();
            return true;
        }
        return false;
    }
630384
private function get_context_courseid(\context $context) {

        if (empty($this->contextcourseids[$context->id])) {

            $coursecontext = $context->get_course_context(false);
            if (!$coursecontext) {
                // Default to the frontpage course context.
                $coursecontext = \context_course::instance(SITEID);
            }
            $this->contextcourseids[$context->id] = $coursecontext->instanceid;
        }

        return $this->contextcourseids[$context->id];
    }
252950
public function getResource(string $hash, ?string $context = null)
    {
        return $this->read($this->adapters, $hash, $context);
    }
143907
public function activate(string $hash): Response
    {
        $accountKey = $this->accountKeyRepository->getByHash($hash);

        if (!$accountKey instanceof EzUserAccountKey) {
            throw new NotFoundHttpException();
        }

        if (time() - $accountKey->getTime() > $this->getConfigResolver()->getParameter('user.activate_hash_validity_time', 'ngsite')) {
            $this->accountKeyRepository->removeByHash($hash);

            return $this->render(
                $this->getConfigResolver()->getParameter('template.user.activate_done', 'ngsite'),
                [
                    'error' => 'hash_expired',
                ]
            );
        }

        try {
            $user = $this->userService->loadUser($accountKey->getUserId());
        } catch (NotFoundException $e) {
            throw new NotFoundHttpException();
        }

        $userUpdateStruct = $this->userService->newUserUpdateStruct();
        $userUpdateStruct->enabled = true;

        $preActivateEvent = new UserEvents\PreActivateEvent($user, $userUpdateStruct);
        $this->eventDispatcher->dispatch(SiteEvents::USER_PRE_ACTIVATE, $preActivateEvent);
        $userUpdateStruct = $preActivateEvent->getUserUpdateStruct();

        $user = $this->getRepository()->sudo(
            static function (Repository $repository) use ($user, $userUpdateStruct): User {
                return $repository->getUserService()->updateUser($user, $userUpdateStruct);
            }
        );

        $postActivateEvent = new UserEvents\PostActivateEvent($user);
        $this->eventDispatcher->dispatch(SiteEvents::USER_POST_ACTIVATE, $postActivateEvent);

        return $this->render(
            $this->getConfigResolver()->getParameter('template.user.activate_done', 'ngsite')
        );
    }
128799
protected function extractHash(DOMNode $configHash)
    {
        $hash = [];

        foreach ($configHash->childNodes as $node) {
            /** @var \DOMText|\DOMElement $node */
            if ($node->nodeType === XML_ELEMENT_NODE) {
                $hash[$node->getAttribute('key')] = $this->extractHash($node);
            } elseif ($node->nodeType === XML_TEXT_NODE && !$node->isWhitespaceInElementContent()) {
                return $node->wholeText;
            }
        }

        return $hash;
    }
704970
public function bind(Context $context)
    {
        if (! isset($context->__UBID)) {
            $context->__UBID = 0;
        }
        $context->__UBID ++;
        
        return spl_object_hash($context) . $context->__UBID;
    }
735765
def default_hash(env = ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_s)
      default = find_db_config(env)
      default.config if default
    end
1296868
protected function initContext($context)
    {
        foreach ($context as $key => &$value) {
            switch (gettype($value)) {
                case 'string':
                case 'integer':
                case 'double':
                    // These types require no conversion
                    break;
                case 'array':
                case 'boolean':
                    $value = json_encode($value);
                    break;
                case 'object':
                    if (method_exists($value, '__toString')) {
                        $value = (string)$value;
                    } else {
                        $value = '[object (' . get_class($value) . ')]';
                    }
                    break;
                case 'NULL':
                    $value = 'NULL';
                    break;
                default:
                    $value = '[' . gettype($value) . ']';
                    break;
            }
        }

        return $context;
    }
295973
public function getWord($key, $default = null, $hash = 'input')
	{
		$result = $this->getVar($key, $default, $hash);
		$result = is_array($result) ? implode('', $result) : $result;
		return preg_replace(static::$filters['word'], '', $result);
	}
852137
protected function mergeContextPropertiesWithDefaults(array $contextProperties)
    {
        $contextProperties = $this->removeDeprecatedProperties($contextProperties);

        $defaultContextProperties = [
            'workspaceName' => 'live',
            'currentDateTime' => $this->now,
            'dimensions' => [],
            'targetDimensions' => [],
            'invisibleContentShown' => false,
            'removedContentShown' => false,
            'inaccessibleContentShown' => false
        ];

        $mergedProperties = Arrays::arrayMergeRecursiveOverrule($defaultContextProperties, $contextProperties, true);

        $this->mergeDimensionValues($contextProperties, $mergedProperties);
        $this->mergeTargetDimensionContextProperties($contextProperties, $mergedProperties, $defaultContextProperties);

        return $mergedProperties;
    }
1334259
protected static function _getDefaultContext()
    {
        if (!static::$_defaultContext) {
            static::$_defaultContext = new View(Router::getRequest(), null, EventManager::instance(), []);
        }

        return static::$_defaultContext;
    }
289337
public function getContextHash()
    {
        if ($this->areAuthorizationChecksDisabled()) {
            return self::CONTEXT_HASH_UNINITIALIZED;
        }
        if (!$this->isInitialized()) {
            if (!$this->canBeInitialized()) {
                return self::CONTEXT_HASH_UNINITIALIZED;
            }
            $this->initialize();
        }

        if ($this->contextHash !== null) {
            return $this->contextHash;
        }

        $contextHashSoFar = implode('|', array_keys($this->getRoles()));

        $this->withoutAuthorizationChecks(function () use (&$contextHashSoFar) {
            foreach ($this->globalObjects as $globalObjectsRegisteredClassName) {
                if (is_subclass_of($globalObjectsRegisteredClassName, CacheAwareInterface::class)) {
                    $globalObject = $this->objectManager->get($globalObjectsRegisteredClassName);
                    $contextHashSoFar .= '<' . $globalObject->getCacheEntryIdentifier();
                }
            }
        });

        $this->contextHash = md5($contextHashSoFar);

        return $this->contextHash;
    }
671323
public function deleteConstructor($hash = null)
    {
        $url = self::resolveFullUrl([$this->id, 'constructor']);

        if (isset($hash)) {
            $url = self::resolveFullUrl([$this->id, 'constructor', $hash]);
        }

        return static::delete($this->client, $url);
    }