-
Notifications
You must be signed in to change notification settings - Fork 37
Add status constants and extension point for flexible user status management #525
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5360715
Initial plan
Copilot 6c5619c
Initial exploration complete
Copilot 8798519
Add status constants, getStatusOptions method, and update JSON to use…
Copilot d653dc4
Add documentation for status constants and extension point, add unit …
Copilot e8d3a2e
Add comprehensive examples documentation for status constants and ext…
Copilot da55cdf
Update lib/ycom_user.php
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| .phpunit.result.cache | ||
| .php-cs-fixer.cache | ||
| vendor/composer/*.zip~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # YCom User Status - Beispiele | ||
|
|
||
| ## Status-Konstanten verwenden | ||
|
|
||
| ### Im PHP-Code | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| // Neuen User erstellen mit bestätigtem Status | ||
| $user = rex_ycom_user::create(); | ||
| $user->setValue('email', '[email protected]'); | ||
| $user->setValue('login', '[email protected]'); | ||
| $user->setValue('status', rex_ycom_user::STATUS_CONFIRMED); | ||
| $user->save(); | ||
|
|
||
| // Status prüfen | ||
| $currentUser = rex_ycom_user::getMe(); | ||
| if ($currentUser && $currentUser->getValue('status') >= rex_ycom_user::STATUS_CONFIRMED) { | ||
| // User ist eingeloggt und bestätigt | ||
| } | ||
|
|
||
| // Status auf inaktiv setzen | ||
| $user->setValue('status', rex_ycom_user::STATUS_INACTIVE); | ||
| $user->save(); | ||
| ``` | ||
|
|
||
| ## Status-Optionen erweitern via Extension Point | ||
|
|
||
| ### Beispiel 1: Eigenen Status hinzufügen | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| rex_extension::register('YCOM_USER_STATUS_OPTIONS', function (rex_extension_point $ep) { | ||
| /** @var array<int,string> $statusOptions */ | ||
| $statusOptions = $ep->getSubject(); | ||
|
|
||
| // Premium-Status hinzufügen (Wert 3) | ||
| $statusOptions[3] = 'translate:ycom_account_premium'; | ||
|
|
||
| // VIP-Status hinzufügen (Wert 4) | ||
| $statusOptions[4] = 'translate:ycom_account_vip'; | ||
|
|
||
| return $statusOptions; | ||
| }); | ||
| ``` | ||
|
|
||
| ### Beispiel 2: Status-Optionen anpassen und sortieren | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| rex_extension::register('YCOM_USER_STATUS_OPTIONS', function (rex_extension_point $ep) { | ||
| /** @var array<int,string> $statusOptions */ | ||
| $statusOptions = $ep->getSubject(); | ||
|
|
||
| // Bestimmte Stati entfernen (optional) | ||
| unset($statusOptions[rex_ycom_user::STATUS_INACTIVE_TERMINATION]); | ||
|
|
||
| // Eigene Stati hinzufügen | ||
| $statusOptions[10] = 'translate:ycom_account_special'; | ||
|
|
||
| // Nach Schlüssel sortieren | ||
| ksort($statusOptions); | ||
|
|
||
| return $statusOptions; | ||
| }); | ||
| ``` | ||
|
|
||
| ### Beispiel 3: Status-Labels projektspezifisch anpassen | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| rex_extension::register('YCOM_USER_STATUS_OPTIONS', function (rex_extension_point $ep) { | ||
| /** @var array<int,string> $statusOptions */ | ||
| $statusOptions = $ep->getSubject(); | ||
|
|
||
| // Standard-Labels durch eigene ersetzen | ||
| $statusOptions[rex_ycom_user::STATUS_ACTIVE] = 'Aktives Mitglied'; | ||
| $statusOptions[rex_ycom_user::STATUS_CONFIRMED] = 'Bestätigtes Mitglied'; | ||
| $statusOptions[rex_ycom_user::STATUS_REQUESTED] = 'Registrierung ausstehend'; | ||
|
|
||
| return $statusOptions; | ||
| }); | ||
| ``` | ||
|
|
||
| ## Verfügbare Status-Konstanten | ||
|
|
||
| | Konstante | Wert | Standard-Label | | ||
| |-----------|------|----------------| | ||
| | `rex_ycom_user::STATUS_INACTIVE_TERMINATION` | -3 | Zugang wurde gekündigt | | ||
| | `rex_ycom_user::STATUS_INACTIVE_LOGINS` | -2 | Zugang wurde deaktiviert [Loginfehlversuche] | | ||
| | `rex_ycom_user::STATUS_INACTIVE` | -1 | Zugang ist inaktiv | | ||
| | `rex_ycom_user::STATUS_REQUESTED` | 0 | Zugang wurde angefragt | | ||
| | `rex_ycom_user::STATUS_CONFIRMED` | 1 | Zugang wurde bestätigt und ist aktiv | | ||
| | `rex_ycom_user::STATUS_ACTIVE` | 2 | Zugang ist aktiv | | ||
|
|
||
| ## Status-Logik | ||
|
|
||
| - **Login erlaubt**: Status >= 1 (STATUS_CONFIRMED oder höher) | ||
| - **Login nicht erlaubt**: Status <= -1 (STATUS_INACTIVE oder niedriger) | ||
| - **Registriert, aber Nutzungsbedingungen fehlen**: Status = 0 (STATUS_REQUESTED) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <?php | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| class rex_ycom_user_status_test extends TestCase | ||
| { | ||
| public function testStatusConstantsExist() | ||
| { | ||
| // Test that all status constants are defined | ||
| self::assertTrue(defined('rex_ycom_user::STATUS_INACTIVE_TERMINATION')); | ||
| self::assertTrue(defined('rex_ycom_user::STATUS_INACTIVE_LOGINS')); | ||
| self::assertTrue(defined('rex_ycom_user::STATUS_INACTIVE')); | ||
| self::assertTrue(defined('rex_ycom_user::STATUS_REQUESTED')); | ||
| self::assertTrue(defined('rex_ycom_user::STATUS_CONFIRMED')); | ||
| self::assertTrue(defined('rex_ycom_user::STATUS_ACTIVE')); | ||
| } | ||
|
|
||
| public function testStatusConstantValues() | ||
| { | ||
| // Test that constants have the correct values | ||
| self::assertEquals(-3, rex_ycom_user::STATUS_INACTIVE_TERMINATION); | ||
| self::assertEquals(-2, rex_ycom_user::STATUS_INACTIVE_LOGINS); | ||
| self::assertEquals(-1, rex_ycom_user::STATUS_INACTIVE); | ||
| self::assertEquals(0, rex_ycom_user::STATUS_REQUESTED); | ||
| self::assertEquals(1, rex_ycom_user::STATUS_CONFIRMED); | ||
| self::assertEquals(2, rex_ycom_user::STATUS_ACTIVE); | ||
| } | ||
|
|
||
| public function testDefaultStatusOptions() | ||
| { | ||
| // Test that default status options contain all expected entries | ||
| $defaultOptions = rex_ycom_user::DEFAULT_STATUS_OPTIONS; | ||
|
|
||
| self::assertIsArray($defaultOptions); | ||
| self::assertArrayHasKey(-3, $defaultOptions); | ||
| self::assertArrayHasKey(-2, $defaultOptions); | ||
| self::assertArrayHasKey(-1, $defaultOptions); | ||
| self::assertArrayHasKey(0, $defaultOptions); | ||
| self::assertArrayHasKey(1, $defaultOptions); | ||
| self::assertArrayHasKey(2, $defaultOptions); | ||
|
|
||
| // Test that values are translation keys | ||
| self::assertEquals('translate:ycom_account_inactive_termination', $defaultOptions[-3]); | ||
| self::assertEquals('translate:ycom_account_inactive_logins', $defaultOptions[-2]); | ||
| self::assertEquals('translate:ycom_account_inactive', $defaultOptions[-1]); | ||
| self::assertEquals('translate:ycom_account_requested', $defaultOptions[0]); | ||
| self::assertEquals('translate:ycom_account_confirm', $defaultOptions[1]); | ||
| self::assertEquals('translate:ycom_account_active', $defaultOptions[2]); | ||
| } | ||
|
|
||
| public function testGetStatusOptionsReturnsArray() | ||
| { | ||
| // Test that getStatusOptions returns an array | ||
| $options = rex_ycom_user::getStatusOptions(); | ||
|
|
||
| self::assertIsArray($options); | ||
| self::assertNotEmpty($options); | ||
|
|
||
| // Test that it returns the default options | ||
| self::assertEquals(rex_ycom_user::DEFAULT_STATUS_OPTIONS, $options); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The placeholder 'X.X' should be replaced with the actual version number when this feature is released.