public function loadModel($id) { if (!($model = Tag::findOne($id))) { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested tag does not exist.')); } return $model; }
/** * @param $event \Yii\base\Event */ public function afterSave($event) { $this->owner->getDb()->transaction(function () use($event) { if (isset($this->_tags) && is_array($this->_tags)) { $newTags = $this->_tags; $this->_tags = null; $oldTags = ArrayHelper::map($this->owner->tags, 'id', 'id'); $this->owner->setIsNewRecord(false); $toAppend = array_diff($newTags, $oldTags); $toRemove = array_diff($oldTags, $newTags); foreach ($toAppend as $id) { if ($tag = Tag::findOne($id)) { $this->owner->link('tags', $tag, ['item_class' => $this->owner->className()]); } } if ($event->name == BaseActiveRecord::EVENT_AFTER_UPDATE) { foreach ($toRemove as $id) { if ($tag = Tag::findOne($id)) { $this->owner->unlink('tags', $tag, true); } } } } }); }
protected function launch() { if (!$this->tag instanceof Tag) { $this->tag = Tag::findOne(intval($this->tag)); } if (empty($this->tag)) { throw new InvalidConfigException(Yii::t('gromver.platform', 'Tag not found.')); } echo $this->render($this->layout, ['dataProvider' => new ActiveDataProvider(['query' => $this->tag->getTagToItems(), 'pagination' => ['pageSize' => $this->pageSize]]), 'itemLayout' => $this->itemLayout, 'model' => $this->tag]); $this->getView()->registerAssetBundle(TagAsset::className()); }
/** * @param \gromver\platform\core\components\MenuRequestInfo $requestInfo * @return array */ public function parseTagCloud($requestInfo) { if (preg_match('/^\\d+$/', $requestInfo->requestRoute)) { return ['tag/frontend/default/view', ['id' => $requestInfo->requestRoute]]; } else { /** @var Tag $tag */ if ($tag = Tag::findOne(['alias' => $requestInfo->requestRoute, 'language' => $requestInfo->menuMap->language])) { return ['tag/frontend/default/view', ['id' => $tag->id, 'alias' => $tag->alias, UrlManager::LANGUAGE_PARAM => $requestInfo->menuMap->language]]; } } }
/** * Finds the Tag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Tag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tag::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.')); } }