Skip to content
Open
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
11 changes: 11 additions & 0 deletions Engine/Modules/Notifications/.meta/.phpstorm.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace PHPSTORM_META {

if (function_exists('override')) {
override(\Oforge\Engine\Modules\Core\Manager\Services\ServiceManager::get(0), map([
'backend.notifications' => \Oforge\Engine\Modules\Notifications\BackendNotificationService::class,
]));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@

use Oforge\Engine\Modules\Core\Abstracts\AbstractDatabaseAccess;

abstract class AbstractNotificationService extends AbstractDatabaseAccess {
const ALL = "all";
const UNSEEN = "unseen";
const SEEN = "seen";
abstract class AbstractNotificationService extends AbstractDatabaseAccess
{
public const ALL = "all";
public const UNSEEN = "unseen";
public const SEEN = "seen";

public function __construct($models) {
public function __construct($models)
{
parent::__construct($models);
}

abstract function getNotifications($userId, $selector = AbstractNotificationService::ALL);
abstract public function addNotification(int $userId, string $type, string $message, ?string $link = null);

abstract function addNotification($userId, $type, $message, $link);
abstract public function getUserNotifications(int $userId, string $selector = AbstractNotificationService::ALL) : array;

abstract public function markAsSeen(int $id) : bool;

abstract function markAsSeen($id);
}
23 changes: 13 additions & 10 deletions Engine/Modules/Notifications/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Oforge\Engine\Modules\Notifications;

use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Oforge\Engine\Modules\AdminBackend\Core\Services\BackendNavigationService;
use Oforge\Engine\Modules\Core\Abstracts\AbstractBootstrap;
Expand All @@ -19,11 +18,13 @@
*
* @package Oforge\Engine\Modules\Notifications
*/
class Bootstrap extends AbstractBootstrap {
class Bootstrap extends AbstractBootstrap
{
/**
* Bootstrap constructor.
*/
public function __construct() {
public function __construct()
{
$this->endpoints = [
BackendNotificationController::class,
];
Expand All @@ -40,19 +41,21 @@ public function __construct() {
/**
* @throws ServiceNotFoundException
* @throws ORMException
* @throws OptimisticLockException
* @throws ConfigElementAlreadyExistException
* @throws ConfigOptionKeyNotExistException
* @throws ParentNotFoundException
*/
public function activate() {
public function activate()
{
/** @var BackendNavigationService $backendNavigationService */
$backendNavigationService = Oforge()->Services()->get('backend.navigation');
$backendNavigationService->add([
'name' => 'notifications',
'order' => 1,
'position' => 'topbar',
]);
$backendNavigationService->add(
[
'name' => 'notifications',
'order' => 1,
'position' => 'topbar',
]
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Oforge\Engine\Modules\Notifications\Controller;

use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Oforge\Engine\Modules\AdminBackend\Core\Abstracts\SecureBackendController;
use Oforge\Engine\Modules\Auth\Models\User\BackendUser;
Expand All @@ -20,9 +19,11 @@
* @package Oforge\Engine\Modules\Notifications\Controller
* @EndpointClass(path="/backend/notifications", name="backend_notifications", assetScope="Backend")
*/
class BackendNotificationController extends SecureBackendController {
class BackendNotificationController extends SecureBackendController
{

public function initPermissions() {
public function initPermissions()
{
$this->ensurePermission('indexAction', BackendUser::ROLE_LOGGED_IN);
}

Expand All @@ -33,11 +34,11 @@ public function initPermissions() {
*
* @return Response
* @throws ORMException
* @throws OptimisticLockException
* @throws ServiceNotFoundException
* @EndpointAction(path="/{id}")
*/
public function indexAction(Request $request, Response $response, array $args) {
public function indexAction(Request $request, Response $response, array $args)
{
if (isset($args['id'])) {
/** @var BackendNotificationService $backendNotificationService */
$backendNotificationService = Oforge()->Services()->get('backend.notifications');
Expand Down
90 changes: 50 additions & 40 deletions Engine/Modules/Notifications/Models/BackendNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Oforge\Engine\Modules\Notifications\Models;

use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\ManyToOne;
use Oforge\Engine\Modules\Core\Abstracts\AbstractModel;
Expand All @@ -11,121 +12,123 @@
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
*/
class BackendNotification extends AbstractModel {
class BackendNotification extends AbstractModel
{
/**
* @var int
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;

/**
* @var string
* @ORM\Column(name="notification_type", type="string", nullable=false)
*/
private $type;

/**
* @var string
* @ORM\Column(name="notification_message", type="string", nullable=false)
*/
private $message;

/**
* @var string
* @var string|null
* @ORM\Column(name="link", type="string", nullable=true)
*/
private $link;

private $link = null;
/**
* @var int
* @var int|null
* @ORM\Column(name="user_id", type="integer", nullable=true)
* @ManyToOne(targetEntity="\Oforge\Engine\Modules\Auth\Models\BackendUser", fetch="EXTRA_LAZY")
*/
private $userId = null;

/**
* @var int|null
* @ORM\Column(name="role", type="integer", nullable=true)
*/
private $role = null;
/**
* @var bool
* @ORM\Column(name="seen", type="boolean")
*/
private $seen = false;

/**
* @var \DateTime
* @var DateTime
* @ORM\Column(name="timestamp", type="datetime", nullable=true);
*/
private $timestamp;

/**
* @var int
* @ORM\Column(name="role", type="integer", nullable=true)
*/
private $role = null;

/**
* Triggered on insert
*
* @ORM\PrePersist
* @throws \Exception
*/
public function onPrePersist() {
$this->timestamp = new \DateTime("now");
public function onPrePersist()
{
$this->timestamp = new DateTime("now");
}

/**
* @return int
*/
public function getId() : int {
public function getId() : int
{
return $this->id;
}

/**
* @return string
*/
public function getType() : string {
public function getType() : string
{
return $this->type;
}

/**
* @return string | null
*/
public function getLink() : ?string {
public function getLink() : ?string
{
return $this->link;
}

/**
* @return int
* @return int|null
*/
public function getUserId() : int {
public function getUserId() : ?int
{
return $this->userId;
}

/**
* @return bool
*/
public function isSeen() : bool {
public function isSeen() : bool
{
return $this->seen;
}

/**
* @return \DateTime|null
* @return DateTime
*/
public function getTimestamp() : ?\DateTime {
public function getTimestamp() : DateTime
{
return $this->timestamp;
}

/**
* @return int
* @return int|null
*/
public function getRole() : int {
public function getRole() : ?int
{
return $this->role;
}

/**
* @return string
*/
public function getMessage() : string {
public function getMessage() : string
{
return $this->message;
}

Expand All @@ -134,29 +137,32 @@ public function getMessage() : string {
*
* @return BackendNotification
*/
public function setType(string $type) : BackendNotification {
public function setType(string $type) : BackendNotification
{
$this->type = $type;

return $this;
}

/**
* @param string $link
* @param string|null $link
*
* @return BackendNotification
*/
public function setLink(string $link) : BackendNotification {
public function setLink(?string $link) : BackendNotification
{
$this->link = $link;

return $this;
}

/**
* @param int $userId
* @param int|null $userId
*
* @return BackendNotification
*/
public function setUserId(int $userId) : BackendNotification {
public function setUserId(?int $userId) : BackendNotification
{
$this->userId = $userId;

return $this;
Expand All @@ -167,18 +173,20 @@ public function setUserId(int $userId) : BackendNotification {
*
* @return BackendNotification
*/
public function setSeen(bool $seen) : BackendNotification {
public function setSeen(bool $seen) : BackendNotification
{
$this->seen = $seen;

return $this;
}

/**
* @param int $role
* @param int|null $role
*
* @return BackendNotification
*/
public function setRole(int $role) : BackendNotification {
public function setRole(?int $role) : BackendNotification
{
$this->role = $role;

return $this;
Expand All @@ -189,9 +197,11 @@ public function setRole(int $role) : BackendNotification {
*
* @return BackendNotification
*/
public function setMessage(string $message) : BackendNotification {
public function setMessage(string $message) : BackendNotification
{
$this->message = $message;

return $this;
}

}
Loading