Skip to content

Commit

Permalink
Sync with ezdemo content
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz Serwatka committed Nov 19, 2012
1 parent 0c1a560 commit dbb13a2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
47 changes: 45 additions & 2 deletions src/EzSystems/DemoBundle/Controller/DemoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult;
use \DateTime;

class DemoController extends Controller
Expand Down Expand Up @@ -46,19 +47,61 @@ public function testWithLegacyAction( $contentId )
* Renders the top menu, with cache control
*
* @param int $locationId
* @param array $excludeContentTypes
* @return \Symfony\Component\HttpFoundation\Response
*/
public function topMenuAction( $locationId )
public function topMenuAction( $locationId, array $excludeContentTypes = array() )
{
$response = new Response;
$response->setPublic();
$response->setMaxAge( 60 );
$location = $this->getRepository()->getLocationService()->loadLocation( $locationId );

$excludeCriterion = array();
if ( !empty( $excludeContentTypes ) )
{
foreach( $excludeContentTypes as $contentTypeIdentifier )
{
$contentType = $this->getRepository()->getContentTypeService()->loadContentTypeByIdentifier( $contentTypeIdentifier );
$excludeCriterion[] = new Criterion\LogicalNot(
new Criterion\ContentTypeId( $contentType->id )
);
}
}
$criteria = array(
new Criterion\Subtree( $location->pathString ),
new Criterion\ParentLocationId( $locationId )
);

if ( !empty( $excludeCriterion ) )
$criteria[] = new Criterion\LogicalAnd( $excludeCriterion );

$query = new Query(
array(
'criterion' => new Criterion\LogicalAnd(
$criteria
),
'sortClauses' => array(
new SortClause\DatePublished( Query::SORT_DESC )
)
)
);

$searchResult = $this->getRepository()->getSearchService()->findContent( $query );

$locationList = array();
if ( $searchResult instanceof SearchResult )
{
foreach ( $searchResult->searchHits as $searchHit )
{
$locationList[] = $this->getRepository()->getLocationService()->loadLocation( $searchHit->valueObject->contentInfo->mainLocationId );
}
}

return $this->render(
"eZDemoBundle::page_topmenu.html.twig",
array(
"locationList" => $this->getRepository()->getLocationService()->loadLocationChildren( $location )
"locationList" => $locationList
),
$response
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<div class="nav-collapse">
<ul class="nav">
{% for location in locationList.locations %}
{% for location in locationList %}
{% if location.contentInfo.contentType.identifer == 'link' %}
<li id=""><a href="#">{{ location.contentInfo.name }}</a></li>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="navbar main-navi">
<!-- Top menu area: START -->
{% block topMenu %}
{% render "eZDemoBundle:Demo:topMenu" with {'locationId': 2}, {'standalone': true} %}
{% render "eZDemoBundle:Demo:topMenu" with {'locationId': 2, 'excludeContentTypes': [ 'article' ]}, {'standalone': true} %}
{% endblock %}
<!-- Top menu area: END -->
{# TODO: implement logic to control path visibility #}
Expand Down

0 comments on commit dbb13a2

Please sign in to comment.