Skip to content

Commit

Permalink
Merge pull request #466 from BracketSpace/feature/Notifications-table…
Browse files Browse the repository at this point in the history
…/CU-3mp4ad

Notification table
  • Loading branch information
jakubmikita authored Jun 2, 2024
2 parents ed5a2ed + 61ce41a commit 438628e
Show file tree
Hide file tree
Showing 79 changed files with 2,193 additions and 1,912 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
use BracketSpace\Notification\Dependencies\Micropackage\Casegnostic\Helpers\CaseHelper;
use BracketSpace\Notification\Interfaces;
use BracketSpace\Notification\Core\Notification;
use function BracketSpace\Notification\addNotification;

/**
* Adapter class
*
* @mixin \BracketSpace\Notification\Core\Notification
* @deprecated [Next]
*/
abstract class Adapter implements Interfaces\Adaptable
{
Expand All @@ -39,6 +39,8 @@ abstract class Adapter implements Interfaces\Adaptable
*/
public function __construct(Notification $notification)
{
notification_deprecated_class( __CLASS__, '[Next]' );

$this->notification = $notification;
}

Expand Down Expand Up @@ -81,6 +83,7 @@ public function getNotification()
/**
* Sets up Notification object with data.
*
* phpcs:ignore SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation.NonFullyQualifiedClassName
* @param array<mixed> $data Data array.
* @return \BracketSpace\Notification\Core\Notification
* @since 6.0.0
Expand Down Expand Up @@ -109,6 +112,6 @@ public function isEnabled()
*/
public function registerNotification()
{
addNotification($this->getNotification());
notification_add($this->getNotification());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
namespace BracketSpace\Notification\Defaults\Adapter;

use BracketSpace\Notification\Abstracts;
use function BracketSpace\Notification\convertNotificationData;

/**
* JSON Adapter class
*
* @deprecated [Next]
*/
class JSON extends Abstracts\Adapter
{
Expand All @@ -33,7 +34,7 @@ public function read($input = null)
throw new \Exception('Read method of JSON adapter expects valid JSON string');
}

$this->setupNotification(convertNotificationData((array)$data));
$this->setupNotification(notification_convert_data((array)$data));
$this->setSource('JSON');

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@

use BracketSpace\Notification\Abstracts;
use BracketSpace\Notification\Core\Notification;
use function BracketSpace\Notification\adaptNotificationFrom;
use function BracketSpace\Notification\convertNotificationData;
use function BracketSpace\Notification\swapNotificationAdapter;

/**
* WordPress Adapter class
*
* @mixin \BracketSpace\Notification\Core\Notification
* @deprecated [Next]
*/
class WordPress extends Abstracts\Adapter
{
Expand Down Expand Up @@ -61,15 +59,15 @@ public function read($input = null)
}

try {
$jsonAdapter = adaptNotificationFrom(
$jsonAdapter = notification_adapt_from(
'JSON',
wp_specialchars_decode(
$this->post->post_content,
ENT_COMPAT
)
);
$this->setupNotification(
convertNotificationData(
notification_convert_data(
$jsonAdapter->getNotification()->toArray()
)
);
Expand Down Expand Up @@ -101,7 +99,7 @@ public function save()
$data = $this->getNotification()->toArray();

/** @var \BracketSpace\Notification\Defaults\Adapter\JSON */
$jsonAdapter = swapNotificationAdapter('JSON', $this);
$jsonAdapter = notification_swap_adapter('JSON', $this);
$json = $jsonAdapter->save(JSON_UNESCAPED_UNICODE);

// Update the hash.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,31 @@

declare(strict_types=1);

namespace BracketSpace\Notification\Queries;
namespace BracketSpace\Notification\Database\Queries;

use function BracketSpace\Notification\adaptNotificationFrom;
use BracketSpace\Notification\Core\Notification;
use BracketSpace\Notification\Database\NotificationDatabaseService as Db;

/**
* Notification Queries class
*
* @deprecated [Next]
*/
class NotificationQueries
{
/**
* Class constructor
*/
public function __construct()
{
notification_deprecated_class( __CLASS__, '[Next]' );
}

/**
* Gets Notification posts.
*
* @param bool $includingDisabled If should include disabled notifications as well.
* @return array<int, \BracketSpace\Notification\Defaults\Adapter\WordPress>
* @return array<Notification>
* @since 8.0.0
*/
public static function all(bool $includingDisabled = false): array
Expand All @@ -48,7 +59,13 @@ public static function all(bool $includingDisabled = false): array
}

foreach ($wpposts as $wppost) {
$posts[] = adaptNotificationFrom('WordPress', $wppost);
$notification = Db::postToNotification($wppost);

if (!($notification instanceof Notification)) {
continue;
}

$posts[] = $notification;
}

return $posts;
Expand All @@ -58,15 +75,13 @@ public static function all(bool $includingDisabled = false): array
* Gets Notification post by hash.
*
* @param string $hash Notification hash.
* @return \BracketSpace\Notification\Interfaces\Adaptable|null
* @return ?Notification
* @since 8.0.0
*/
public static function withHash(string $hash)
{
$post = get_page_by_path($hash, OBJECT, 'notification');

return empty($post)
? null
: adaptNotificationFrom('WordPress', $post);
return empty($post) ? null : Db::postToNotification($post);
}
}
File renamed without changes.
Loading

0 comments on commit 438628e

Please sign in to comment.