Diff #4 - trunk/src/Alerts/AbstractController.php
1,380 bytes
|
|
January 20, 2025 at 08:20
|
Diff
Index: AbstractController.php
--- AbstractController.php (nonexistent)
+++ AbstractController.php (revision 4)
@@ -0,0 +1,66 @@
+<?php
+declare(strict_types = 1);
+
+namespace App\Webapp\Alerts;
+
+use App\Webapp\Models\Alert;
+use Apex\App\Base\Model\ModelIterator;
+use Apex\Armor\Interfaces\ArmorUserInterface;
+
+/**
+ * Dropdown alerts
+ */
+class AbstractController
+{
+
+ /**
+ * Create
+ */
+ public function create(
+ ArmorUserInterface $user,
+ string $title,
+ string $contents,
+ string $url = '',
+ string $sender = '',
+ string $badge = ''
+ ):Alert
+ {
+
+ // Add to database
+ $alert = Alert::insert([
+ 'type' => $this->type,
+ 'uuid' => $user->getUuid(), 'sender' => $sender,
+ 'badge' => $badge,
+ 'title' => $title,
+ 'url' => $url,
+ 'contents' => $contents
+ ]);
+
+ // Return
+ return $alert;
+ }
+
+ /**
+ * Mark read
+ */
+ public function markRead(ArmorUserInterface $user):void
+ {
+ Alert::update(
+ ['id_read' => true],
+ 'where uuid = %s AND type = %s', $user->getUuid(), $this->type);
+
+ }
+
+ /**
+ * List
+ */
+ public function list(ArmorUserInterface $user, int $limit = 20, int $offset = 0):ModelIterator
+ {
+ $alerts = Alert::where("uuid = %s AND type = %s ORDER BY created_at DESC LIMIT $limit OFFSET $offset", $user->getUuid(), $this->type);
+ return $alerts;
+ }
+
+
+}
+
+
Full Code
<?php declare(strict_types = 1);
namespace App\Webapp\Alerts;
use App\Webapp\Models\Alert; use Apex\App\Base\Model\ModelIterator; use Apex\Armor\Interfaces\ArmorUserInterface;
/** * Dropdown alerts */ class AbstractController {
/**
* Create
*/
public function create(
ArmorUserInterface $user,
string $title,
string $contents,
string $url = '',
string $sender = '',
string $badge = ''
):Alert
{
// Add to database
$alert = Alert::insert([
'type' => $this->type,
'uuid' => $user->getUuid(), 'sender' => $sender,
'badge' => $badge,
'title' => $title,
'url' => $url,
'contents' => $contents
]);
// Return
return $alert;
}
/**
* Mark read
*/
public function markRead(ArmorUserInterface $user):void
{
Alert::update(
['id_read' => true],
'where uuid = %s AND type = %s', $user->getUuid(), $this->type);
}
/**
* List
*/
public function list(ArmorUserInterface $user, int $limit = 20, int $offset = 0):ModelIterator
{
$alerts = Alert::where("uuid = %s AND type = %s ORDER BY created_at DESC LIMIT $limit OFFSET $offset", $user->getUuid(), $this->type);
return $alerts;
}
}