@param null $id
@param null $contextId

@return array
@throws ForbiddenHttpException
339089
public function run($id = null, $contextId = null)
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        if (false === Yii::$app->user->can('dotplant-structure-view')) {
            throw new ForbiddenHttpException(Yii::t(
                'yii', 'You are not allowed to perform this action.'
            ));
        }
        /** @var BaseStructure | string $class */
        if (null === $current_selected_id = Yii::$app->request->get($this->querySelectedAttribute)) {
            $current_selected_id = Yii::$app->request->get($this->queryParentAttribute);
        }
        $checked = Yii::$app->request->get('checked', '');
        $cacheKey = "AdjacencyFullTreeData:{$this->cacheKey}:{$this->querySortOrder}:{$id}:{$contextId}"
            . Yii::$app->multilingual->language_id . $this->showHiddenInTree . $checked;
        if (false === empty($checked)) {
            $checked = explode(',', $checked);
        } else {
            $checked = [];
        }
        if (false === $result = Yii::$app->cache->get($cacheKey)) {
            $contexts = call_user_func([Yii::$app->multilingual->modelsMap['Context'], 'getListData']);
            /** @var ActiveQuery $query */
            $parentId = ('#' == $id) ? null : $id;
            $query = BaseStructure::find()
                ->where(['parent_id' => $parentId])
                ->orderBy([
                    $this->contextIdAttribute => SORT_ASC,
                    $this->querySortOrder => SORT_ASC
                ]);
            if (count($this->whereCondition) > 0) {
                $query = $query->where($this->whereCondition);
            }
            if ($contextId != 'all') {
                $query->andWhere([$this->contextIdAttribute => $contextId]);
            }

            $entityId = (null !== $this->className) ? Entity::getEntityIdForClass($this->className) : null;
            if (null === $rows = $query->asArray()->all()) {
                return [];
            }
            $result = [];
            $hidden = [];
            $roots = BaseStructure::find()->select(['id'])->where(['is_deleted' => 1])->column();
            $hidden += $roots;
            foreach ($roots as $id) {
                self::treeGoDown($id, $rows, $hidden);
            }
            foreach ($rows as $row) {
                if ((int)$row['expand_in_tree'] === 1) {
                    $c = (new Query())
                        ->from(BaseStructure::tableName())
                        ->where(['parent_id' => $row['id']])
                        ->select('id')
                        ->count();
                    $children = $c > 0;
                } else {
                    $children = false;
                }
                $item = [];
                if (true === in_array($row[$this->modelIdAttribute], $hidden)) {
                    if (true === $this->showHiddenInTree) {
                        self::setState($item, ['disabled' => true]);
                    } else {
                        continue;
                    }
                }
                $text = ($row[$this->modelParentAttribute] > 0)
                    ? $row['defaultTranslation'][$this->modelLabelAttribute]
                    : ($row['defaultTranslation'][$this->modelLabelAttribute]
//                        . " ({$contexts[$row[$this->contextIdAttribute]]})"
                    );
                $item += [
                    'id' => $row[$this->modelIdAttribute],
                    'parent' => ($row[$this->modelParentAttribute] > 0) ? $row[$this->modelParentAttribute] : '#',
                    'text' => $text,
                    'children' => $children,
                    'a_attr' => [
                        'data-id' => $row[$this->modelIdAttribute],
                        'data-parent_id' => $row[$this->modelParentAttribute],
                        'data-context_id' => $row[$this->contextIdAttribute],
                        'data-entity_id' => $row['entity_id'],
                    ],
                ];
                if (null !== $entityId && $entityId != $row['entity_id']) {
                    self::setState($item, ['checkbox_disabled' => true]);
                }
                if (true === in_array($row[$this->modelIdAttribute], $checked)) {
                    self::setState($item, ['opened' => true, 'checked' => true, 'selected' => true]);
                }
                if (null !== $this->varyByTypeAttribute) {
                    $item['type'] = $row[$this->varyByTypeAttribute];
                }
                $result[$row[$this->modelIdAttribute]] = $item;
            }

            Yii::$app->cache->set(
                $cacheKey,
                $result,
                86400,
                new TagDependency([
                    'tags' => [
                        NamingHelper::getCommonTag(BaseStructure::class),
                    ],
                ])
            );
        }

        if (array_key_exists($current_selected_id, $result)) {
            $result[$current_selected_id] = array_merge(
                $result[$current_selected_id],
                ['state' => ['opened' => true, 'selected' => true]]
            );
        }

        return array_values($result);
    }
885087
public function getPager($contextId = null)
    {
        if ($contextId) {
            return $this->pagers[$this->makeParameterId($contextId)];
        } else {
            $initialized = $this->findInitializedPagerId();
            if ($initialized) {
                return $this->pagers[$initialized];
            } else {
                throw new \Exception('Pager not initialized');
            }
        }
    }
226187
public function find($parentId, $id)
    {
        $resource = $this->createPartialResourceUrlForView($parentId, $id);
        $data = $this->client->get($resource);

        return $this->fromArray(reset($data));
    }
213160
public static function create_multiple_from_competencyids($competencyids, $contextid) {
        $events = array();
        foreach ($competencyids as $id) {
            $events[$id] = static::create(array(
                'contextid' => $contextid,
                'objectid' => $id
            ));
        }
        return $events;
    }
208693
public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        if ($model->isAuthor) {
            if ($model->load(Yii::$app->request->post()) && $model->save()) {
                Yii::$app->getSession()->setFlash('success', Yii::t('article', 'Article updated.'));
                return $this->redirect(['view', 'uuid' => $model->uuid]);
            }
            return $this->render('update', ['model' => $model]);
        }
        throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
    }
388445
public static function get_contexts_for_userid(int $userid) : \core_privacy\local\request\contextlist {
        global $DB;
        $contextlist = new \core_privacy\local\request\contextlist();

        // Fetch the block instance IDs.
        $likehidden = $DB->sql_like('name', ':hidden', false, false);
        $likedocked = $DB->sql_like('name', ':docked', false, false);
        $sql = "userid = :userid AND ($likehidden OR $likedocked)";
        $params = [
            'userid' => $userid,
            'hidden' => 'block%hidden',
            'docked' => 'docked_block_instance_%',
        ];
        $prefs = $DB->get_fieldset_select('user_preferences', 'name', $sql, $params);

        $instanceids = array_unique(array_map(function($prefname) {
            if (preg_match('/^block(\d+)hidden$/', $prefname, $matches)) {
                return $matches[1];
            } else if (preg_match('/^docked_block_instance_(\d+)$/', $prefname, $matches)) {
                return $matches[1];
            }
            return 0;
        }, $prefs));

        // Find the context of the instances.
        if (!empty($instanceids)) {
            list($insql, $inparams) = $DB->get_in_or_equal($instanceids, SQL_PARAMS_NAMED);
            $sql = "
                SELECT ctx.id
                  FROM {context} ctx
                 WHERE ctx.instanceid $insql
                   AND ctx.contextlevel = :blocklevel";
            $params = array_merge($inparams, ['blocklevel' => CONTEXT_BLOCK]);
            $contextlist->add_from_sql($sql, $params);
        }

        return $contextlist;
    }
423389
public function actionView($id = 0, $slug= '')
    {
        $model = $this->findModel($id, $slug);
        if (\Yii::$app->user->can('viewPost', ['post' => $model])) {
            return $this->render('view', [
                'model' => $model,
            ]);
        } else
            throw new ForbiddenHttpException(Module::t('core', 'Access denied.'));
    }
978921
public function getPagePart($id, $context = 'main', $sequenceNumber)
    {
        $ppRef = $this->find($id);
        $ppRef->setContext($context);
        $ppRef->setSequenceNumber($sequenceNumber);
        $this->getEntityManager()->persist($ppRef);
        $this->getEntityManager()->flush($ppRef);

        return $this->getEntityManager()->getRepository($ppRef->getPagePartEntityName())->find($ppRef->getPagePartId());
    }
95551
public function index(string $id = null)
    {
        if (empty($id)) {
            throw new InvalidArgumentException();
        }

        $list = $this->DblistItems->Dblists->get($id);
        $query = $this->DblistItems->find('treeEntities', ['listId' => $id]);

        if ($query->isEmpty()) {
            $this->Flash->set('List is empty, do you want to add new item?');

            return $this->redirect(['action' => 'add', $id]);
        }

        $this->set(compact('query', 'list'));
        $this->set('_serialize', ['entities']);
    }
297679
public function getCurrentPage($contextId = null)
    {
        $pager = $this->offsetGet($contextId) ?: $this->offsetGet('');

        return ($pager) ? $pager->current : 1;
    }
158962
public function update($id) {
        if (!$this->Model->admin['editable']) {
            throw new ForbiddenException(__d('admin', 'Update Access Protected'));
        }

        if ($this->overrideAction('update', $id)) {
            return;
        }

        $this->Model->id = $id;

        $result = $this->AdminToolbar->getRecordById($this->Model, $id, false);

        if (!$result) {
            throw new NotFoundException(__d('admin', '%s Not Found', $this->Model->singularName));
        }

        $this->AdminToolbar->setBelongsToData($this->Model);
        $this->AdminToolbar->setHabtmData($this->Model);

        if ($this->request->is('put')) {
            $data = $this->AdminToolbar->getRequestData();

            if ($this->Model->saveAll($data, array('validate' => 'first', 'atomic' => true, 'deep' => true))) {
                $this->Model->set($result);
                $this->AdminToolbar->logAction(ActionLog::UPDATE, $this->Model, $id);

                $this->AdminToolbar->setFlashMessage(__d('admin', 'Successfully updated %s with ID %s', array(mb_strtolower($this->Model->singularName), $id)));
                $this->AdminToolbar->redirectAfter($this->Model);

            } else {
                $this->AdminToolbar->setFlashMessage(__d('admin', 'Failed to update %s with ID %s', array(mb_strtolower($this->Model->singularName), $id)), 'is-error');
            }
        } else {
            $this->request->data = $result;
        }

        $this->set('result', $result);
        $this->overrideView('update');
    }
626223
public function getUserOptions(string $id, string $userID): ?array
    {
        $data = Internal\Data::getValue('.temp/bearcms/userthemeoptions/' . md5($userID) . '/' . md5($id) . '.json');
        if ($data !== null) {
            $data = json_decode($data, true);
            if (isset($data['options'])) {
                return $data['options'];
            }
        }
        return null;
    }
1121947
public static function preload_contexts_by_id(array $contextids) {
        global $DB;

        // Determine which contexts are not already cached.
        $tofetch = [];
        foreach ($contextids as $contextid) {
            if (!self::cache_get_by_id($contextid)) {
                $tofetch[] = $contextid;
            }
        }

        if (count($tofetch) > 1) {
            // There are at least two to fetch.
            // There is no point only fetching a single context as this would be no more efficient than calling the existing code.
            list($insql, $inparams) = $DB->get_in_or_equal($tofetch, SQL_PARAMS_NAMED);
            $ctxs = $DB->get_records_select('context', "id {$insql}", $inparams, '',
                    \context_helper::get_preload_record_columns_sql('{context}'));
            foreach ($ctxs as $ctx) {
                self::preload_from_record($ctx);
            }
        }
    }
158800
def context_by_id(self, context_id, via_id=None, create=True, name=None):
        
        context = self._context_by_id.get(context_id)
        if context:
            return context

        if create and via_id is not None:
            via = self.context_by_id(via_id)
        else:
            via = None

        self._write_lock.acquire()
        try:
            context = self._context_by_id.get(context_id)
            if create and not context:
                context = self.context_class(self, context_id, name=name)
                context.via = via
                self._context_by_id[context_id] = context
        finally:
            self._write_lock.release()

        return context
1077829
public function actionStop($id)
    {
        if (!$this->module->canWorkerStop) {
            throw new ForbiddenHttpException(Module::t('notice', 'Stop is forbidden.'));
        }

        $record = $this->findRecord($id);
        $record->stop();
        return $this
            ->success(Module::t('notice', 'The worker will be stopped within {timeout} sec.', [
                'timeout' => $record->pinged_at + $this->env->workerPingInterval - time(),
            ]))
            ->redirect(['index']);
    }
55946
public function run($id)
    {
        if (!Yii::$app->request->isPost) {
            throw new MethodNotAllowedHttpException('Method Not Allowed. This url can only handle post');
        }
        $position = Yii::$app->request->getQueryParam($this->positionParam, null);
        if (empty($position)) {
            throw new BadRequestHttpException(Yii::t('yii', '{attribute} cannot be blank.', ['attribute' => $this->positionParam]));
        }

        $model = $this->findModel($id);

        $this->positionModel($model, $position);

        return $this->respondSuccess($model);
    }
742510
private boolean isUbiqueInBothContexts(String id)
	{
		return context.containsKey(id) && context.get(id) == null;
	}