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 postEdit() { $postData = $this->request()->postVariables(); $article = new Article($postData['id']); $article->hydrateFromUnserialized($postData); $article->saveChanges(); Redirect::to('/' . $this->baseUri() . '/' . $article->id() . '/edit')->with('msg', new TransportMessage('success', 'Article was successfully updated'))->now(); }
/** * 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; }