public function renderDestroy()
 {
     $articleId = $this->getInt('id');
     $article = new Article($articleId);
     $article->delete();
     $sections = ArticleSection::collection(['article_id' => $articleId]);
     foreach ($sections as $section) {
         $articleSection = new ArticleSection($section->id());
         $articleSection->delete();
         $sectionBlocks = ArticleSectionBlock::collection(['article_section_id' => $section->id()]);
         foreach ($sectionBlocks as $block) {
             $block->delete();
         }
     }
     Redirect::to('/' . $this->baseUri())->with('msg', new TransportMessage('success', 'Article was successfully deleted'))->now();
 }
 public function renderOrder()
 {
     $sectionId = $this->getInt('id');
     $direction = $this->getStr('direction');
     $blockGroup = new ArticleSection($sectionId);
     $oldOrder = $blockGroup->order;
     $lastOrder = ArticleSection::collection(['article_id' => $blockGroup->articleId])->count();
     if ($oldOrder == 1 && $direction == 'up' || $oldOrder == $lastOrder && $direction == 'down') {
         // Invalid Order Action
         Redirect::to('/admin/article/' . $blockGroup->articleId . '/edit')->now();
     } else {
         $oldOrder = (int) $oldOrder;
         switch ($direction) {
             case 'up':
                 $swapOrder = $oldOrder - 1;
                 $swapOrder = $swapOrder < 1 ? 0 : $swapOrder;
                 break;
             case 'down':
                 $swapOrder = $oldOrder + 1;
                 break;
         }
         $swapBlockGroup = ArticleSection::collection()->loadWhere(['article_id' => $blockGroup->articleId, 'order' => $swapOrder])->first();
         if ($swapBlockGroup !== null) {
             $swapBlockGroup->order = $oldOrder;
             $swapBlockGroup->saveChanges();
         }
         $blockGroup->order = $swapOrder;
         $blockGroup->saveChanges();
         Redirect::to('/admin/article/' . $blockGroup->articleId . '/edit')->now();
     }
 }
Beispiel #3
0
 /**
  * @return ArticleSection[]|RecordCollection
  */
 public function getArticleSections()
 {
     $sections = ArticleSection::collection(['article_id' => $this->id()]);
     return $sections->setOrderBy('order');
 }