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

findByCategoryIds() #81

Merged
merged 4 commits into from
Aug 16, 2024
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
1 change: 0 additions & 1 deletion boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
$pages = $addon->getProperty('pages');

if ($_REQUEST) {

$_csrf_key = Entry::table()->getCSRFKey();

$token = rex_csrf_token::factory($_csrf_key)->getUrlParams();
Expand Down
32 changes: 32 additions & 0 deletions lib/neues_entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use rex_yform_manager_dataset;
use rex_yform_manager_table;

use function is_string;

/**
* Class neues_entry.
*
Expand Down Expand Up @@ -522,6 +524,36 @@ public static function findByCategory(?int $category_id = null, int $status = 1)
return $query->find();
}

/**
* Findet Einträge durch IDs mehrerer Kategorien.
* Finds entries by multiple Categories.
*
* @param string|array|null $category_ids Die IDs der Kategorien als String oder Array. / The IDs of the Categories as a String or Array.
* @param int $status Der Status der Einträge. / The status of the entries.
* @return rex_yform_manager_collection|null Die gefundenen Einträge oder null, wenn keine Einträge gefunden wurden. / The found entries or null if no entries were found.
*
* Beispiel / Example:
* $entries = FriendsOfRedaxo\Neues\Entry::findByCategoryIds('1,2', 1);
*
* @api
*/
public static function findByCategoryIds(string|array|null $category_ids = null, int $status = 1): ?rex_yform_manager_collection
{
$query = self::query()->where('status', $status, '>=');

if ($category_ids) {
// Wenn es ein String ist, in ein Array umwandeln
if (is_string($category_ids)) {
$category_ids = explode(',', $category_ids);
}

// whereInList anwenden
$query->whereInList('category_ids', $category_ids);
}

return $query->find();
}

/**
* Gibt die URL des Eintrags zurück.
* Returns the URL of the entry.
Expand Down
Loading