/** * [[@doctodo method_description:actionView]]. * * @throws HttpException [[@doctodo exception_description:HttpException]] * @return [[@doctodo return_type:actionView]] [[@doctodo return_description:actionView]] * */ public function actionView() { if (empty($_GET['id']) || !($object = $this->params['object'] = Registry::getObject($_GET['id'], false)) || !($typeItem = $this->params['typeItem'] = $object->objectTypeItem)) { throw new HttpException(404, "Unknown object."); } if (!$object->can('read')) { throw new HttpException(403, "Unable to access object."); } $action = isset($_GET['subaction']) ? $_GET['subaction'] : 'view'; Yii::$app->request->object = $object; $object->loadChildParentIds(); $type = $this->params['type'] = $object->objectType; $viewEvent = new ObjectViewEvent(['object' => $object, 'action' => $action]); $type->trigger(TypeModule::EVENT_VIEW_OBJECT, $viewEvent); //Yii::$app->collectors['widgets']->lazy = true; if ($viewEvent->handled) { if ($viewEvent->accessed) { ObjectFamiliarity::accessed($object); } return; } if (empty($_GET['h']) or !($relatedObject = $this->params['relatedObject'] = Registry::getObject($_GET['h'], false)) or !($relatedTypeItem = $this->params['relatedTypeItem'] = $relatedObject->objectTypeItem)) { $relatedObject = null; } elseif (!$object->can('read')) { $relatedObject = null; } if (!$type->hasDashboard) { $relatedObjectOptions = []; $relatedObjects = $object->queryRelations(false)->all(); foreach ($relatedObjects as $relation) { if ($relation->child_object_id === $object->primaryKey) { $relatedTest = Registry::getObject($relation->parent_object_id, false); } else { $relatedTest = Registry::getObject($relation->child_object_id, false); } if (!$relatedTest || !$relatedTest->objectType->hasDashboard || !$relatedTest->can('read')) { continue; } $relatedObjectOptions[$relatedTest->primaryKey] = ['descriptor' => $relatedTest->descriptor, 'url' => $relatedTest->getUrl('view', ['h' => $object->primaryKey], false)]; } if (isset($relatedObject) && isset($relatedObjectOptions[$relatedObject->primaryKey])) { $this->redirect($relatedObjectOptions[$relatedObject->primaryKey]['url']); return; } elseif (sizeof($relatedObjectOptions) === 1) { $relatedObject = array_pop($relatedObjectOptions); $this->redirect($relatedObject['url']); return; } else { $this->params['options'] = $relatedObjectOptions; Yii::$app->response->view = 'viewOptions'; return; } throw new HttpException(400, "Bad request"); } $this->params['highlight'] = $relatedObject; ObjectFamiliarity::accessed($object); Yii::$app->response->view = 'view'; $sections = $this->params['sections'] = $typeItem->getSections($object); $this->params['active'] = $this->params['default'] = null; foreach ($sections as $section) { if ($section->priority > 0) { $this->params['active'] = $this->params['default'] = $section->systemId; break; } } if (!empty($_GET['section'])) { $this->params['active'] = $_GET['section']; } }
/** * [[@doctodo method_description:handleInstructions]]. * * @param [[@doctodo param_type:params]] $params [[@doctodo param_description:params]] */ public function handleInstructions($params) { $this->clearParams($params); //\d($params); $this->scope = ArrayHelper::getValue($params, 'scope', 'watching'); $direction = $this->direction = ArrayHelper::getValue($params, 'direction', '_older'); $limit = ArrayHelper::getValue($params, 'limit', 25); $object = $this->context = ArrayHelper::getValue($params, 'object', false); if ($direction === '_newer') { $mostRecentItem = ArrayHelper::getValue($params, 'mostRecentItem', false); $this->query->andWhere($this->query->primaryAlias . '.[[created]] > FROM_UNIXTIME(' . (double) $mostRecentItem . ')'); $this->query->orderBy([$this->query->primaryAlias . '.[[created]]' => SORT_DESC]); $this->pagination->pageSize = false; //\d(["newer", $this->query->createCommand()->rawSql]);exit; } else { // _older $this->pagination->pageSize = $limit; $lastTime = ArrayHelper::getValue($params, 'lastItemTimestamp', false); $lastItem = ArrayHelper::getValue($params, 'lastItem', false); if ($lastItem) { $this->query->andWhere($this->query->primaryAlias . '.[[created]] < FROM_UNIXTIME(' . (double) $lastItem . ')'); } $this->query->orderBy([$this->query->primaryAlias . '.[[created]]' => SORT_DESC]); //SORT_ASC //\d($lastTime); //echo $this->query->createCommand()->rawSql;exit; } if ($this->scope === 'object' && $object) { $this->query->andWhere(['or', [$this->query->primaryAlias . '.direct_object_id' => $object], [$this->query->primaryAlias . '.indirect_object_id' => $object]]); } elseif ($this->scope !== 'all' && !empty(Yii::$app->user->id)) { $subquery = ObjectFamiliarity::find(); $subquery->andWhere([$subquery->primaryAlias . '.user_id' => Yii::$app->user->id]); if ($this->scope === 'watching') { $subquery->andWhere([$subquery->primaryAlias . '.watching' => 1]); } $subquery->select(['object_id']); $this->query->join('INNER JOIN', ['sof' => $subquery], ['or', '{{sof}}.[[object_id]] = {{' . $this->query->primaryAlias . '}}.[[direct_object_id]]', '{{sof}}.[[object_id]] = {{' . $this->query->primaryAlias . '}}.[[indirect_object_id]]']); $this->query->distinct = true; } else { $this->scope = 'all'; } }