[TYPO3-mvc] query for objects with at least one category
Claus Due
claus at wildside.dk
Tue Jun 21 12:22:42 CEST 2011
Hi Dmitri,
Nice to hear that it works :)
> One final thing, do you know if I can access settings of the extension (namely storagePid) from repository, or do I need to pass it by parameter from controller?
Yes, I do :)
Passing as param from Controller is preferred, but...
See Tx_Extbase_Configuration_ConfigurationManager::getConfiguration($configurationType, $extensionName = NULL, $pluginName = NULL) {
$configurationType is either "Framework", "Settings" or "FullTypoScript".
NOTE: The code comment notes that it is a low-level function which should only be used by Extbase internally - but I use it myself in some places to avoid manually parsing TSFE etc.
PS: ConfigurationManager is injectable ;)
--
Med venlig hilsen / Kind regards
Claus Due
Code Monkey
--
Wildside A/S
Katrinebjergvej 113, DK-8200 Århus N
tlf. 86 12 64 65
http://www.wildside.dk
On Jun 20, 2011, at 11:48 PM, Dmitri Pisarev wrote:
> Hello once again, Claus!
> Your advice works like a charm! I'll do my best to document and clean up my code and release it to TER as a way to give something back.
> Claus, wish I'll manage to participate in some of the future conferences and buy you a drink in return:)
>
> Here's my final code:
> if ($category) {
> $filter_array[] = $query->contains('category', $category);
> } else { //if not searching by any particular category...
> $categoryPid = 45;
> $filter_array[] = $query->equals('category.pid', $categoryPid);
> $filter_array[] = $query->logicalNot($query->equals('category', 0));
> }
> if ($filter_array)
> $query->matching($query->logicalAnd($filter_array));
>
> One final thing, do you know if I can access settings of the extension (namely storagePid) from repository, or do I need to pass it by parameter from controller?
>
> Very happy and yet again inspired by the support of the community,
> Dmitri.
> On 20.06.2011 22:16, Claus Due wrote:
>> Hi again Dmitri,
>>
>> See below :)
>>
>> On Jun 20, 2011, at 7:51 PM, Dmitri Pisarev wrote:
>>
>>> Hey!
>>> Once again I'm stuck...
>>> I need to write a query, that shall select all of the objects (with any pid, $query->getQuerySettings()->setRespectStoragePage(FALSE);), that have at least one category assigned (Categories only from storagePid).
>>> The only way which I could think out was $query->matching($query->in('category', $categories)); where $categories I have to pass to repository action. Not convinent and didn't work right away.
>>>
>>> The other solution would if I could temporary use category field of tt_news as simple int, instead of as a relation, e.g I need this query SELECT * FROM tt_news where category> 0
>>> But how do I do it? Set a custom mapping for this field, and map it to a custom property like category_count? Will this work?
>>> Any better advice?
>>>
>>> Sorry for being silly and annoying!
>>
>> Interference from WiFi which makes my Magic TrackPad spazz out is silly and annoying... this is just fun ;)
>>
>> Perhaps this could work:
>>
>> $constraints = array(
>> $query->equals('newsitem.categories.pid', $categoryPid),
>> $query->not($query->equals('newsitem.categories', 0)) // this, because the relation field is actually a count of the number of relations.
>> );
>> $query->matching($query->logicalAnd($constraints));
>>
>> (freestyled again).
>>
>> Very unsure if this works as expected...
>>
>> Cheers,
>> Claus
>>
>>> Regards,
>>> Dmitri.
>>>
>>>
>>> PS:I use the tables from tt_news:
>>> config.tx_extbase{
>>> persistence {
>>> classes {
>>> Tx_Lister_Domain_Model_Article.mapping.tableName = tt_news Tx_Lister_Domain_Model_Category.mapping.tableName = tt_news_cat
>>> }
>>> }
>>> }
>>> _______________________________________________
>>> TYPO3-project-typo3v4mvc mailing list
>>> TYPO3-project-typo3v4mvc at lists.typo3.org
>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>>
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
More information about the TYPO3-project-typo3v4mvc
mailing list