public function renderDestroy() { $platformId = $this->getInt('id'); $platform = new Platform($platformId); $platform->delete(); $msg = new \stdClass(); $msg->type = 'success'; $msg->text = 'Platform was successfully deleted'; Redirect::to('/' . $this->baseUri())->with('msg', $msg)->now(); }
/** * 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; }
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(); } }
public function renderEdit() { $articleId = $this->getInt('id'); $platforms = Platform::collection()->loadAll(); $this->requireJs('article'); $this->requireJs('articleEdit'); $this->requireJs('autoSave'); $this->requireCss('articleEdit'); return $this->createView(new ArticleForm("Edit Article", new Article($articleId), $platforms)); }
/** * 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; }