Slide 7
Slide 7 text
SEARCH
https://github.com/CakeDC/Search
array('with'
=>
'Tagged'));
public
$filterArgs
=
array(
array('name'
=>
'title',
'type'
=>
'like'),
array('name'
=>
'status',
'type'
=>
'value'),
array('name'
=>
'blog_id',
'type'
=>
'value'),
array('name'
=>
'search',
'type'
=>
'like',
'field'
=>
'Article.description'),
array('name'
=>
'username',
'type'
=>
'like',
'field'
=>
'User.username'),
array('name'
=>
'tags',
'type'
=>
'subquery',
'method'
=>
'findByTags',
'field'
=>
'Article.id'),
array('name'
=>
'filter',
'type'
=>
'query',
'method'
=>
'orConditions'),
);
public
function
findByTags($data
=
array())
{
$this-‐>Tagged-‐>Behaviors-‐>attach('Containable',
array('autoFields'
=>
false));
$this-‐>Tagged-‐>Behaviors-‐>attach('Search.Searchable');
$query
=
$this-‐>Tagged-‐>getQuery('all',
array(
'conditions'
=>
array('Tag.name'
=>
$data['tags']),
'fields'
=>
array('foreign_key'),
'contain'
=>
array('Tag')
));
return
$query;
}
public
function
orConditions($data
=
array())
{
$filter
=
$data['filter'];
$cond
=
array(
'OR'
=>
array(
$this-‐>alias
.
'.title
LIKE'
=>
'%'
.
$filter
.
'%',
$this-‐>alias
.
'.body
LIKE'
=>
'%'
.
$filter
.
'%',
));
return
$cond;
}
}