/** * 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 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(); } }
public function renderIndex() { $articles = Article::collection()->loadAll(); return $this->createView(new Index($articles)); }