Forum

Filtering on fields  Bottom

espaan / Jan 12, 2012 / 01:27 Link to this post

espaan

Hi, I asked some question to Axel by mail. I will post it here for others too icon_smile

QuoteThe question. I want one of the fields of an entity to be able to "filter" on on the URL. So with a &field=value as url. In other modules you just call the API with a selection then.


Normally MOST modules would be able to do this automatically. But this
filtering is blocked at the moment by https://github.com/zikula/core/issues/118

QuoteI tried the to use where clause in the user_view method.
So on the
Code<code>$selectionArgs = array(

'ot' => $objectType,

'where' => '',

'orderBy' => $sort . ' ' . $sdir

);</code>
lines filling in some where clause. But that gives errors.


Hm this should work.
Another (probably more adequate) place to inject custom filters is the
repository class of the corresponding entity. Look at the
lib/YourModule/Entity/Repository/ folder. You can either override selectWhere,
selectWherePaginated or (most centrally) _intBaseQuery methods.

Here is an example:

Code<code>public function selectWherePaginated($where = '', $orderBy = '',

$currentPage = 1, $resultsPerPage = 25, $useJoins = true)

{

$group = (int) FormUtil::getPassedValue('g', 2, 'GET');

if (!is_numeric($group) || ($group != 1 && $group != 2)) {

$group = 2;

}



if (!empty($where)) {

$where .= ' AND ';

}

$where .= 'tbl.addressGroup = \'' . DataUtil::formatForStore($group) .

'\'';



return parent::selectWherePaginated($where, $orderBy, $currentPage,

$resultsPerPage, $useJoins);

}</code>


Options

Rating

Replies

How to set up relations

8 Replies
Axel on May 15, 2012 - 06:04



Neue Umfragen

You have not voted in the poll:
What should be improved in future?
 
 
 

ModuleStudio Honey

Close

You don't have permission to e-mail this story - please login