Skip to content

Instantly share code, notes, and snippets.

@damianoporta
Created November 2, 2015 14:22
Show Gist options
  • Save damianoporta/41fcb214cdb76bf46d70 to your computer and use it in GitHub Desktop.
Save damianoporta/41fcb214cdb76bf46d70 to your computer and use it in GitHub Desktop.
/**
* Filtro per il recupero degli annunci che appartengono a determinati servizi
*
* @param Query $query
* @param array $options
* @return Query
*/
public function findServices(Query $query, array $options)
{
if (empty($options['matching'])) {
return $query->contain(['Services']);
} else {
return $query
->matching('Services', function(Query $q) use ($options) {
$operator = empty($options['exclude']) ? 'IN' : 'NOT IN';
return $q->where(["Services.id $operator" => $options['Services.id']]);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment