-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-24264: applied QueryController #2 to blog
- Loading branch information
Bertrand Dunogier
committed
Oct 17, 2015
1 parent
99dc9ac
commit 012a1d4
Showing
3 changed files
with
112 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\DemoBundle\QueryType; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Query; | ||
use eZ\Publish\Core\QueryType\OptionsResolverBasedQueryType; | ||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; | ||
use eZ\Publish\Core\QueryType\QueryType; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use eZ\Publish\API\Repository\Values\Content\Query\SortClause; | ||
|
||
/** | ||
* A QueryType that lists the blog_post within a blog_post Location. | ||
*/ | ||
class BlogPostsQueryType extends OptionsResolverBasedQueryType implements QueryType | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $languages; | ||
|
||
/** | ||
* @param array $languages List of languages blog posts must be searched in. | ||
*/ | ||
public function __construct(array $languages = []) | ||
{ | ||
$this->languages = $languages; | ||
} | ||
|
||
/** | ||
* Returns the QueryType name. | ||
* @return string | ||
*/ | ||
public static function getName() | ||
{ | ||
Return 'DemoBundle:BlogPosts'; | ||
} | ||
|
||
/** | ||
* Configures the OptionsResolver for the QueryType. | ||
* Example: | ||
* ```php | ||
* // type is required | ||
* $resolver->setRequired('type'); | ||
* // limit is optional, and has a default value of 10 | ||
* $resolver->setDefault('limit', 10); | ||
* ``` | ||
* | ||
* @param OptionsResolver $optionsResolver | ||
*/ | ||
protected function configureOptions(OptionsResolver $optionsResolver) | ||
{ | ||
$optionsResolver->setRequired('blogPathString'); | ||
|
||
} | ||
|
||
/** | ||
* Builds and returns the Query object. | ||
* The parameters array is processed with the OptionsResolver, meaning that it has been validated, and contains | ||
* the default values when applicable. | ||
* | ||
* @param array $parameters The QueryType parameters, pre-processed by the OptionsResolver | ||
* | ||
* @return Query | ||
*/ | ||
protected function doGetQuery(array $parameters) | ||
{ | ||
$languages = ['eng-GB']; | ||
|
||
$criteria = []; | ||
$criteria[] = new Criterion\Subtree($parameters['blogPathString']); | ||
$criteria[] = new Criterion\ContentTypeIdentifier(array('blog_post')); | ||
$criteria[] = new Criterion\LanguageCode($languages); | ||
|
||
$query = new Query(); | ||
$query->query = new Criterion\LogicalAnd($criteria); | ||
$query->sortClauses = array( | ||
new SortClause\Field('blog_post', 'publication_date', Query::SORT_DESC, $languages[0]), | ||
); | ||
|
||
return $query; | ||
} | ||
} |
This file contains 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
This file contains 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