Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions api/v1_projects.inc
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ function api_v1_projects(string $method, array $data, array $query_params)
foreach ($query as $field => $values) {
$values = array_map("DPDatabase::escape", $values);
$column_name = $valid_fields[$field];

if (in_array($field, ["author", "title", "languages", "clearance"])) {
// Languages occur as one language or two and are stored as
// "Lang1" or "Lang1 with Lang2" in projects.language.
// See Project.inc:encode_languages
if ($field == "languages") {
$likes_str = surround_and_join($values, "language LIKE '%", "%'", ' OR ');
$where .= " AND ($likes_str)";
} elseif (in_array($field, ["author", "title", "clearance"])) {
Comment on lines -74 to +79
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me way to long to spot the difference here, this might be more straightforward:

// The API exposes "languages" but the table column is "language" and
// are stored as "Lang1" or "Lang1 with Lang2".
// See Project.inc:encode_languages
if ($field == "languages") {
    $column_name = "language";
}

$likes_str = surround_and_join($values, "$column_name LIKE '%", "%'", ' OR ');
$where .= " AND ($likes_str)";
} else {
Expand Down