Last active
April 29, 2019 13:39
-
-
Save MarioBlazek/d6444ceb983393f43d33120390df52ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Controller; | |
use Netgen\Bundle\EzPlatformSiteApiBundle\Controller\Controller; | |
use Netgen\Bundle\EzPlatformSiteApiBundle\View\ContentView; | |
use Netgen\TagsBundle\API\Repository\Values\Content\Query\Criterion\TagId; | |
use Netgen\TagsBundle\API\Repository\Values\Tags\Tag; | |
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; | |
use eZ\Publish\API\Repository\Values\Content\Query\SortClause; | |
use eZ\Publish\API\Repository\Values\Content\LocationQuery; | |
class FullViewController extends Controller | |
{ | |
public function viewRecipe(ContentView $view) | |
{ | |
$content = $view->getSiteContent(); | |
if ($content->hasField('tags') && !$content->getField('tags')->isEmpty()) { | |
$tags = $content->getFieldValue('tags'); | |
$tagsIds = array_map( | |
function(Tag $tag) { | |
return $tag->id; | |
}, | |
$tags->tags | |
); | |
$criteria = [ | |
new Criterion\Visibility(Criterion\Visibility::VISIBLE), | |
new Criterion\ContentTypeIdentifier('ng_recipe'), | |
new TagId($tagsIds), | |
new Criterion\LogicalNot( | |
new Criterion\ContentId($content->id) | |
) | |
]; | |
$query = new LocationQuery(); | |
$query->limit = 4; | |
$query->filter = new Criterion\LogicalAnd($criteria); | |
$query->sortClauses = [ | |
new SortClause\DatePublished(LocationQuery::SORT_DESC), | |
]; | |
$recipies = $this->getSite()->getFilterService()->filterLocations($query); | |
$view->addParameters([ | |
'recipes' => $this->extractValueObjects($recipies), | |
]); | |
} | |
return $view; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment