public function renderNew()
 {
     $articleId = $this->getInt('id');
     //if user tries to create a section before an article exists,
     //create the article for them and give them a section to write in
     if ($articleId == 0) {
         $article = new Article();
         $article->title = '';
         $article->subTitle = '';
         $article->saveChanges();
         $articleId = $article->id();
     }
     $platforms = Platform::collection()->loadAll();
     if ($platforms->hasMappers()) {
         $blockGroup = new ArticleSection();
         $blockGroup->articleId = $articleId;
         $blockGroup->order = ArticleSection::collection(['article_id' => $articleId])->count() + 1;
         $blockGroup->saveChanges();
         foreach ($platforms as $platform) {
             $sectionBlock = new ArticleSectionBlock();
             $sectionBlock->articleSectionId = $blockGroup->id();
             $sectionBlock->platformId = $platform->id();
             $sectionBlock->title = '';
             $sectionBlock->content = '';
             $sectionBlock->saveChanges();
         }
         Redirect::to('/admin/article/' . $articleId . '/edit')->now();
     } else {
         Redirect::to('/admin/article/' . $articleId . '/edit')->with('msg', new TransportMessage('error', 'Failed to add section to article. No Platforms exist. ' . 'Ensure you had created ' . 'some platforms first. <a href="/admin/platform/new">' . 'Create Platform Now</a>'))->now();
     }
 }
Example #2
0
 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();
 }
Example #3
0
 /**
  * Execute the process
  *
  * @return int|void
  */
 public function execute()
 {
     $articles = Article::collection();
     if ($articles->count() === 0) {
         echo 'No articles to list.';
         exit;
     }
     $platforms = Platform::collection();
     foreach ($articles as $article) {
         echo PHP_EOL;
         echo Shell::colourText("Title: " . $article->title . PHP_EOL, true, Shell::COLOUR_FOREGROUND_BROWN, Shell::COLOUR_BACKGROUND_RED);
         echo 'Article ID:  ' . $article->id() . PHP_EOL;
         echo 'Sub-Title:   ' . $article->subTitle . PHP_EOL;
         echo 'View:   ' . $article . PHP_EOL;
         foreach ($article->getBlockGroups() as $blockGroup) {
             foreach ($blockGroup->getBlocks() as $block) {
                 /** @var Platform $platform */
                 $platform = $platforms->getById($block->platformId);
                 echo PHP_EOL;
                 echo 'Block Platform: ' . $platform->name . PHP_EOL;
                 echo 'Block Title: ' . $block->title . PHP_EOL;
                 echo 'Block Content: ' . $block->content . PHP_EOL;
             }
         }
         echo PHP_EOL;
     }
     return $this;
 }
Example #4
0
 public function renderPdf($id, $platformId)
 {
     $article = new Article($id);
     if (!$article->exists()) {
         return $this->renderNotFound();
     }
     $markdown = new MarkdownParser();
     $pdf = new \mPDF();
     $pdf->WriteHTML(sprintf('<h1>%s</h1>', $article->title));
     if ($article->title) {
         $pdf->WriteHTML(sprintf('<h2>%s</h2>', $article->subTitle));
     }
     foreach ($article->getArticleSections() as $section) {
         foreach ($section->getBlocks($platformId) as $block) {
             $pdf->WriteHTML($markdown->transformMarkdown($block->content));
             $pdf->WriteHTML('<br/>');
         }
     }
     $pdf->Output();
     exit;
 }
Example #5
0
 public function renderDestroy()
 {
     $categoryId = $this->getInt('id');
     $articlesInCategory = Article::collection(['category_id' => $categoryId]);
     $videosInCategory = Video::collection(['category_id' => $categoryId]);
     if ($articlesInCategory->hasMappers() || $videosInCategory->hasMappers()) {
         Redirect::to('/' . $this->baseUri())->with('msg', new TransportMessage('error', 'Category cannot be deleted. Some Articles/Videos belong to it'))->now();
     } else {
         $category = new Category($categoryId);
         $category->delete();
         Redirect::to('/' . $this->baseUri())->with('msg', new TransportMessage('success', 'Category was successfully deleted'))->now();
     }
 }
Example #6
0
 /**
  * Add example articles
  *
  * @return $this
  */
 protected function _addArticles()
 {
     echo 'Adding Articles: ';
     $count = 0;
     /** @var Category[] $categories */
     $categories = Category::collection();
     /** @var Platform[] $platforms */
     $platforms = Platform::collection();
     foreach ($categories as $category) {
         $articleTitles = $this->_getTitleArray('Article', rand(1, 3));
         foreach ($articleTitles as $articleTitle) {
             $article = new Article();
             $article->categoryId = $category->id();
             $article->title = $articleTitle;
             $article->slug = Strings::urlize($articleTitle);
             $article->subTitle = $this->_getExampleContent(rand(4, 20));
             $article->saveChanges();
             $blockCount = rand(2, 6);
             $i = 0;
             do {
                 $section = new ArticleSection();
                 $section->articleId = $article->id();
                 $section->saveChanges();
                 foreach ($platforms as $platform) {
                     $block = new ArticleSectionBlock();
                     $block->articleSectionId = $section->id();
                     $block->platformId = $platform->id();
                     $block->title = $this->_getExampleContent(3);
                     $block->content = $this->_getExampleContent(rand(10, 30));
                     $block->saveChanges();
                 }
                 $i++;
             } while ($i <= $blockCount);
             $count++;
         }
     }
     echo $count . PHP_EOL;
     return $this;
 }