<?php
namespace CoreBundle\Controller;
use Pimcore\Tool;
use Symfony\Component\HttpFoundation\Request;
use Pimcore\Model\DataObject\Recipe;
class RecipeController extends AbstractController
{
public function listAction(Request $request)
{
$channel = $this->document->getProperty('applicationChannel');
$recipesList = new Recipe\Listing();
$recipesList->setCondition('channels like "%,' . $channel->getId() . ',%"');
$recipesList->load();
foreach ($recipesList as $recipe) {
$recipe->urlTitle = \Pimcore\File::getValidFilename($recipe->getTitle());
}
$this->view->recipes = $recipesList;
return $this->render('Recipe/list.html.twig', $this->view->getAllParameters());
}
public function showByIdAction(Request $request)
{
$recipeId = $request->get('rezeptid', 0);
$recipe = Recipe::getById($recipeId);
if ($recipe instanceof Recipe) {
$this->view->error = false;
$this->view->recipe = $recipe;
} else {
$this->view->error = 'recipe not found';
}
// Set SEO title and description if available
$this->view->seoTitle = $recipe->getTitle() ?? null;
$this->view->seoDescription = $recipe->getTeaserText() ?? null;
return $this->render('Recipe/showById.html.twig', $this->view->getAllParameters());
}
}