Пример #1
0
 /**
  * @inheritdoc
  */
 public function disableContentContainer(ContentContainerActiveRecord $container)
 {
     parent::disableContentContainer($container);
     foreach (Category::find()->contentContainer($container)->all() as $content) {
         $content->delete();
     }
     foreach (Link::find()->contentContainer($container)->all() as $content) {
         $content->delete();
     }
 }
Пример #2
0
 public function run()
 {
     $container = $this->contentContainer;
     if (!$container->getSetting('enableWidget', 'linklist')) {
         return;
     }
     $categoryBuffer = Category::find()->contentContainer($this->contentContainer)->orderBy(['sort_order' => SORT_ASC])->all();
     $categories = array();
     $links = array();
     $render = false;
     foreach ($categoryBuffer as $category) {
         $linkBuffer = Link::find()->where(array('category_id' => $category->id))->orderBy(['sort_order' => SORT_ASC])->all();
         // categories are only displayed in the widget if they contain at least one link
         if (!empty($linkBuffer)) {
             $categories[] = $category;
             $links[$category->id] = $linkBuffer;
             $render = true;
         }
     }
     // if none of the categories contains a link, the linklist widget is not rendered.
     if ($render) {
         return $this->render('linklistPanel', array('container' => $container, 'categories' => $categories, 'links' => $links));
     }
 }
Пример #3
0
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }
 /**
  * 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));
 }
 public function up()
 {
     $this->renameClass('Link', Link::className());
     $this->renameClass('Category', Category::className());
 }