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

Status-Werte als Klassen-Konstanten #102

Merged
merged 1 commit into from
Sep 7, 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
4 changes: 2 additions & 2 deletions docs/03_neues_entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ Findet Online-Einträge. Wenn eine Kategorie-ID angegeben ist, werden nur Eintr
$entries = FriendsOfRedaxo\Neues\Entry::findOnline(1);
```

### findByCategory(?int $category_id = null, int $status = 1)
### findByCategory(?int $category_id = null, int $status = Entry::ONLINE)

Findet Einträge nach Kategorie.

```php
$entries = FriendsOfRedaxo\Neues\Entry::findByCategory(1, 1);
$entries = FriendsOfRedaxo\Neues\Entry::findByCategory(1, Entry::ONLINE);
```

### getUrl(string $profile = 'neues-entry-id')
Expand Down
2 changes: 1 addition & 1 deletion install/cronjob_publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

$sql->setTable(rex::getTable('cronjob'));
$sql->setValue('name', '[neues] Geplante Beiträge veröffentlichen');
$sql->setValue('description', 'Veröffentlicht alle Beiträge (status = 1), deren Status geplant (status = 0) ist und deren Veröffentlichungszeitpunkt erreicht wurde (publishdate < now()).');
$sql->setValue('description', 'Veröffentlicht alle Beiträge (status = Entry::ONLINE), deren Status geplant (status = Entry::PLANNED) ist und deren Veröffentlichungszeitpunkt erreicht wurde (publishdate < now()).');
$sql->setValue('type', Publish::class);
$sql->setValue('parameters', '[]');
$sql->setValue('interval', json_encode($job_intervall));
Expand Down
4 changes: 2 additions & 2 deletions install/tableset.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"not_required": "",
"multiple": "0",
"expanded": "0",
"choices": "translate:neues_status_draft=-1,translate:neues_status_online=1",
"choices": "FriendsOfRedaxo\\Neues\\Category::statusChoice",
"choice_attributes": "",
"attributes": "",
"default": "0",
Expand Down Expand Up @@ -360,7 +360,7 @@
"not_required": "",
"multiple": "0",
"expanded": "0",
"choices": "translate:neues_status_deleted=2,translate:neues_status_draft=-1,translate:neues_status_planned=0,translate:neues_status_online=1",
"choices": "FriendsOfRedaxo\\Neues\\Entry::statusChoice",
"choice_attributes": "",
"attributes": "",
"default": "-1",
Expand Down
4 changes: 2 additions & 2 deletions lib/Api/Restful.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function init(): void
'path' => '/neues/entry/5.0.0/',
'auth' => '\rex_yform_rest_auth_token::checkToken',
'type' => Entry::class,
'query' => Entry::query()->where('status', 1, '>='),
'query' => Entry::query()->where('status', Entry::ONLINE, '>='),
'get' => [
'fields' => [
Entry::class => [
Expand Down Expand Up @@ -105,7 +105,7 @@ public static function init(): void
'path' => '/neues/category/5.0.0/',
'auth' => '\rex_yform_rest_auth_token::checkToken',
'type' => Category::class,
'query' => Category::query()->where('status', 1, '>='),
'query' => Category::query()->where('status', Category::ONLINE, '>='),
'get' => [
'fields' => [
Category::class => [
Expand Down
18 changes: 18 additions & 0 deletions lib/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FriendsOfRedaxo\Neues;

use rex_i18n;
use rex_yform_manager_collection;
use rex_yform_manager_dataset;

Expand All @@ -22,6 +23,9 @@
*/
class Category extends rex_yform_manager_dataset
{
public const DRAFT = -1;
public const ONLINE = 1;

/**
* Gibt den Namen der Kategorie zurück.
* Returns the name of the Category.
Expand Down Expand Up @@ -90,4 +94,18 @@ public function getUrl(string $profile = 'neues-category-id'): ?string
}
return null;
}

/**
* Callback für das Entry-Formular: Auswahlmöglichkeiten des Status-Feldes
* FriendsOfRedaxo\Neues\Category::statusChoice.
* @api
* @return array<int,string>
*/
public static function statusChoice(): array
{
return [
self::DRAFT => rex_i18n::msg('neues_status_draft'),
self::ONLINE => rex_i18n::msg('neues_status_online'),
];
}
}
4 changes: 2 additions & 2 deletions lib/Cronjob/Publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Publish extends rex_cronjob
public function execute()
{
/* Collection von Neues-Einträgen, die noch nicht veröffentlicht sind, aber es sein sollten. (geplant) */
$neues_entry_to_publish = Entry::query()->where('status', 0)->where('publishdate', date('Y-m-d'), '<')->find();
$neues_entry_to_publish->setValue('status', 1);
$neues_entry_to_publish = Entry::query()->where('status', Entry::PLANNED)->where('publishdate', date('Y-m-d'), '<')->find();
$neues_entry_to_publish->setValue('status', Entry::ONLINE);
if (!$neues_entry_to_publish->save()) {
$this->setMessage(sprintf(rex_i18n::msg('neues_entry_publish_error'), count($neues_entry_to_publish)));
return false;
Expand Down
28 changes: 25 additions & 3 deletions lib/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use rex_csrf_token;
use rex_extension_point;
use rex_formatter;
use rex_i18n;
use rex_media;
use rex_media_plus;
use rex_url;
Expand All @@ -32,6 +33,11 @@
*/
class Entry extends rex_yform_manager_dataset
{
public const DELETED = 2; // FIXME: muss auf -2 geändert werden.
public const DRAFT = -1;
public const PLANNED = 0;
public const ONLINE = 1;

/**
* Standards für das Formular anpassen
* - Editor-Konfiguration einfügen.
Expand Down Expand Up @@ -501,7 +507,7 @@ public static function findOnline(?int $category_id = null): rex_yform_manager_c
if (null !== $category_id) {
return self::findByCategory($category_id);
}
return self::query()->where('status', 1, '>=')->find();
return self::query()->where('status', self::ONLINE, '>=')->find();
}

/**
Expand All @@ -517,7 +523,7 @@ public static function findOnline(?int $category_id = null): rex_yform_manager_c
*
* @api
*/
public static function findByCategory(?int $category_id = null, int $status = 1): rex_yform_manager_collection
public static function findByCategory(?int $category_id = null, int $status = self::ONLINE): rex_yform_manager_collection
{
$query = self::query();
$alias = $query->getTableAlias();
Expand All @@ -538,7 +544,7 @@ public static function findByCategory(?int $category_id = null, int $status = 1)
*
* @api
*/
public static function findByCategoryIds(string|array|null $category_ids = null, int $status = 1): rex_yform_manager_collection
public static function findByCategoryIds(string|array|null $category_ids = null, int $status = self::ONLINE): rex_yform_manager_collection
{
$query = self::query()->where('status', $status, '>=');

Expand Down Expand Up @@ -572,4 +578,20 @@ public function getUrl(string $profile = 'neues-entry-id'): string
{
return rex_getUrl(null, null, [$profile => $this->getId()]);
}

/**
* Callback für das Entry-Formular: Auswahlmöglichkeiten des Status-Feldes
* FriendsOfRedaxo\Neues\Entry::statusChoice.
* @api
* @return array<int,string>
*/
public static function statusChoice(): array
{
return [
self::DELETED => rex_i18n::msg('neues_status_deleted'),
self::DRAFT => rex_i18n::msg('neues_status_draft'),
self::PLANNED => rex_i18n::msg('neues_status_planned'),
self::ONLINE => rex_i18n::msg('neues_status_online'),
];
}
}
2 changes: 1 addition & 1 deletion lib/neues.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Neues
public static function getList(int $rowsPerPage = 10, string $pageCursor = 'page'): string
{
$query = Entry::query()
->where('status', 1, '>=')
->where('status', Entry::ONLINE, '>=')
->where('publishdate', rex_sql::datetime(), '<=')
->orderBy('publishdate', 'desc');
$pager = new rex_pager($rowsPerPage, $pageCursor);
Expand Down
Loading