/** * Action that renders the view to add or edit a category.<br /> * The request has to provide the id of the category the link should be created in, in the url parameter 'category_id'.<br /> * If an existing ling should be edited, the link's id has to be given in 'link_id'.<br /> * @see views/linklist/editCategory.php * @throws HttpException 404, if the logged in User misses the rights to access this view. */ public function actionEditLink() { $link_id = (int) Yii::$app->request->get('link_id'); $category_id = (int) Yii::$app->request->get('category_id'); $link = Link::find()->where(array('linklist_link.id' => $link_id))->contentContainer($this->contentContainer)->one(); // access level 0 may neither create nor edit if ($this->accessLevel == 0) { throw new HttpException(404, Yii::t('LinklistModule.base', 'You miss the rights to add/edit links!')); } else { if ($link == null) { // access level 1 + 2 may create $link = new Link(); if (Category::find()->contentContainer($this->contentContainer)->where(['linklist_category.id' => $category_id])->one() == null) { throw new HttpException(404, Yii::t('LinklistModule.base', 'The category you want to create your link in could not be found!')); } $link->category_id = $category_id; $link->content->container = $this->contentContainer; } else { if ($this->accessLevel == 1 && $link->content->created_by != Yii::$app->user->id) { // access level 1 may edit own links, 2 all links throw new HttpException(404, Yii::t('LinklistModule.base', 'You miss the rights to edit this link!')); } } } if ($link->load(Yii::$app->request->post()) && $link->validate() && $link->save()) { return $this->redirect($this->contentContainer->createUrl('/linklist/linklist/index')); } return $this->render('editLink', array('link' => $link)); }