private function buildQuery()
{
$parameters = array();
// start of query
$query = 'SELECT l.id, l.language, l.application, l.module, l.type, l.name, l.value
FROM locale AS l
WHERE 1';
// add language
if ($this->filter['language'] !== null) {
// create an array for the languages, surrounded by quotes (example: 'en')
$languages = array();
foreach ($this->filter['language'] as $key => $val) {
$languages[$key] = '\'' . $val . '\'';
}
$query .= ' AND l.language IN (' . implode(',', $languages) . ')';
}
// add application
if ($this->filter['application'] !== null) {
$query .= ' AND l.application = ?';
$parameters[] = $this->filter['application'];
}
// add module
if ($this->filter['module'] !== null) {
$query .= ' AND l.module = ?';
$parameters[] = $this->filter['module'];
}
// add type
if ($this->filter['type'] !== null) {
// create an array for the types, surrounded by quotes (example: 'lbl')
$types = array();
foreach ($this->filter['type'] as $key => $val) {
$types[$key] = '\'' . $val . '\'';
}
$query .= ' AND l.type IN (' . implode(',', $types) . ')';
}
// add name
if ($this->filter['name'] !== null) {
$query .= ' AND l.name LIKE ?';
$parameters[] = '%' . $this->filter['name'] . '%';
}
// add value
if ($this->filter['value'] !== null) {
$query .= ' AND l.value LIKE ?';
$parameters[] = '%' . $this->filter['value'] . '%';
}
// filter checkboxes
if ($this->filter['ids']) {
// make really sure we are working with integers
foreach ($this->filter['ids'] as &$id) {
$id = (int) $id;
}
$query .= ' AND l.id IN (' . implode(',', $this->filter['ids']) . ') ';
}
// end of query
$query .= ' ORDER BY l.application, l.module, l.name ASC';
// cough up
return array($query, $parameters);
}