Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type pinc/ProjectSearch* #1393

Merged
Merged
Show file tree
Hide file tree
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
44 changes: 25 additions & 19 deletions pinc/ProjectSearchForm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ProjectSearchWidget
private int $size;
private array $options;

public function __construct($properties)
public function __construct(array $properties)
{
foreach ($properties as $property => $value) {
$this->$property = $value;
Expand Down Expand Up @@ -76,7 +76,7 @@ class ProjectSearchWidget
}
}

public function echo_search_item()
public function echo_search_item(): void
{
// could fix width of heading cells so they line up when 2nd table is below
echo "
Expand All @@ -86,11 +86,11 @@ class ProjectSearchWidget
</tr>";
}

public function get_sql_contribution()
public function get_sql_contribution(): string
{
$value = $_GET[$this->id] ?? '';
if ($value == '') {
return null;
return '';
}
[$column_name, $comparator] = $this->q_contrib;
if (@$this->can_be_multiple) {
Expand All @@ -102,23 +102,23 @@ class ProjectSearchWidget
// If $value isn't an array, someone is mucking with
// the URL -- return instead of erroring out below.
if (!is_array($values)) {
return null;
return '';
}
// If the user picks the 'any' option as well as some others,
// remove the any option.
if (($key = array_search('', $values)) !== false) {
unset($values[$key]);
}
if (empty($values)) {
return null;
return '';
}
}

$contribution = $this->sql_from_multi($values, $column_name, $comparator);
} else {
// if $value is an array, someone is mucking with URL
if (is_array($value)) {
return null;
return '';
}

$value = DPDatabase::escape($value);
Expand All @@ -132,7 +132,7 @@ class ProjectSearchWidget
return $contribution;
}

public function sql_from_multi($values, $column_name, $comparator)
public function sql_from_multi(array $values, string $column_name, string $comparator): ?string
{
// if any $value is an array, someone is mucking with the URL
foreach ($values as $value) {
Expand All @@ -157,7 +157,7 @@ class ProjectSearchWidget

class SpecialDayWidget extends ProjectSearchWidget
{
public function sql_from_multi($values, $column_name, $comparator)
public function sql_from_multi(array $values, string $column_name, string $comparator): ?string
{
// if any $value is an array, someone is mucking with the URL
foreach ($values as $value) {
Expand Down Expand Up @@ -189,7 +189,7 @@ class HoldWidget extends ProjectSearchWidget
return "<input type='checkbox' name='$this->id'$check>";
}

public function get_sql_contribution()
public function get_sql_contribution(): string
{
if (isset($_GET[$this->id])) { // can only be 'on'
return 'project_holds.projectid IS NOT NULL';
Expand All @@ -208,7 +208,8 @@ class ProjectSearchForm
$this->define_form_widgets();
}

public function all_special_day_options()
/** @return array<string, string> */
public function all_special_day_options(): array
{
return [
'' => _('Any day'),
Expand All @@ -218,7 +219,8 @@ class ProjectSearchForm
] + $this->special_day_options();
}

public static function special_day_options()
/** @return array<string, string> */
public static function special_day_options(): array
{
$special_days = load_special_days();
sort_special_days($special_days, "open_month,open_day");
Expand All @@ -228,7 +230,8 @@ class ProjectSearchForm
);
}

public static function language_options()
/** @return array<string, string> */
public static function language_options(): array
{
$lang_options[''] = _('Any');

Expand All @@ -249,17 +252,20 @@ class ProjectSearchForm
return $lang_options;
}

public static function genre_options()
/** @return array<string, string> */
public static function genre_options(): array
{
return array_merge(['' => _('Any')], load_genre_translation_array());
}

public static function difficulty_options()
/** @return array<string, string> */
public static function difficulty_options(): array
{
return array_merge(['' => _('Any')], get_project_difficulties());
}

public static function state_options()
/** @return array<string, string> */
public static function state_options(): array
{
$state_options[''] = _('Any state');
foreach (ProjectStates::get_states() as $proj_state) {
Expand All @@ -268,7 +274,7 @@ class ProjectSearchForm
return $state_options;
}

public function define_form_widgets()
public function define_form_widgets(): void
{
$this->widgets = [
new ProjectSearchWidget([
Expand Down Expand Up @@ -374,7 +380,7 @@ class ProjectSearchForm
];
}

public function render()
public function render(): void
{
echo "<p>" . _("Search for projects matching the following criteria:")."</p>\n";
echo "<div class='search-columns'>
Expand Down Expand Up @@ -416,7 +422,7 @@ class ProjectSearchForm
";
}

public function get_condition()
public function get_condition(): string
{
$condition = '1';
foreach ($this->widgets as $widget) {
Expand Down
Loading