This commit is contained in:
Dennis Eichhorn 2024-02-28 05:09:12 +00:00
parent 74b01a2186
commit 35ef0b13bc
26 changed files with 803 additions and 343 deletions

40
.github/user_bug_report.md vendored Executable file
View File

@ -0,0 +1,40 @@
---
name: User Bug Report
about: Create a report to help us improve
title: ''
labels: stat_backlog, type_bug
assignees: ''
---
# Bug Description
A clear and concise description of what the bug is.
# How to Reproduce
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
# Expected Behavior
A clear and concise description of what you expected to happen.
# Screenshots
If applicable, add screenshots to help explain your problem.
# System Information
- System: [e.g. PC or iPhone11, ...]
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- KarakaVersion [e.g. 22]
# Additional Information
Add any other context about the problem here.

21
.github/user_feature_request.md vendored Executable file
View File

@ -0,0 +1,21 @@
---
name: User Feature Request
about: Suggest an idea for this project
title: ''
labels: stat_backlog, type_feature
assignees: ''
---
# What is the feature you request
* A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
* A clear and concise description of what you want to happen.
# Alternatives
A clear and concise description of any alternative solutions or features you've considered.
# Additional Information
Add any other context or screenshots about the feature request here.

13
.github/workflows/greetings.yml vendored Executable file
View File

@ -0,0 +1,13 @@
name: Greetings
on: [pull_request, issues]
jobs:
greeting:
runs-on: ubuntu-latest
steps:
- uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'Thank you for createing this issue. We will check it as soon as possible.'
pr-message: 'Thank you for your pull request. We will check it as soon as possible.'

10
.github/workflows/image.yml vendored Executable file
View File

@ -0,0 +1,10 @@
name: Image optimization
on: [push, pull_request]
jobs:
general_image_workflow:
uses: Karaka-Management/Karaka/.github/workflows/image.yml@develop
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_PAT: ${{ secrets.GH_PAT }}

22
.github/workflows/main.yml vendored Executable file
View File

@ -0,0 +1,22 @@
name: CI
on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
schedule:
- cron: '0 0 1,15 * *'
jobs:
general_module_workflow:
uses: Karaka-Management/Karaka/.github/workflows/php_template.yml@develop
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_PAT: ${{ secrets.GH_PAT }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

View File

@ -4,11 +4,11 @@
"pid": "/",
"type": 1,
"subtype": 1,
"name": "Notification",
"name": "",
"uri": "{/base}/notification/dashboard?{?}",
"target": "self",
"icon": "notifications",
"order": 15,
"order": 20,
"from": "Notification",
"permission": { "permission": 2, "category": null, "element": null },
"parent": 0,

View File

@ -34,6 +34,16 @@
"type": "TINYINT",
"null": false
},
"notification_category": {
"name": "notification_category",
"type": "INT",
"null": false
},
"notification_element": {
"name": "notification_element",
"type": "INT",
"null": false
},
"notification_redirect": {
"name": "notification_redirect",
"type": "VARCHAR(255)",
@ -46,11 +56,24 @@
"foreignTable": "account",
"foreignKey": "account_id"
},
"notification_for": {
"name": "notification_for",
"type": "INT",
"null": false,
"foreignTable": "account",
"foreignKey": "account_id"
},
"notification_created_at": {
"name": "notification_created_at",
"type": "DATETIME",
"null": false
},
"notification_seen_at": {
"name": "notification_seen_at",
"type": "DATETIME",
"null": true,
"default": null
},
"notification_module": {
"name": "notification_module",
"type": "VARCHAR(190)",
@ -60,37 +83,5 @@
"foreignKey": "module_id"
}
}
},
"notification_seen": {
"name": "notification_seen",
"fields": {
"notification_seen_id": {
"name": "notification_seen_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"notification_seen_at": {
"name": "notification_seen_at",
"type": "DATETIME",
"null": true,
"default": null
},
"notification_seen_by": {
"name": "notification_seen_by",
"type": "INT",
"null": false,
"foreignTable": "account",
"foreignKey": "account_id"
},
"notification_seen_notification": {
"name": "notification_seen_notification",
"type": "INT",
"null": false,
"foreignTable": "notification",
"foreignKey": "notification_id"
}
}
}
}

32
Admin/Routes/Web/Api.php Normal file
View File

@ -0,0 +1,32 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
use Modules\Notification\Controller\ApiController;
use Modules\Notification\Models\PermissionCategory;
use phpOMS\Account\PermissionType;
use phpOMS\Router\RouteVerb;
return [
'^.*/notification/seen(\?.*|$)' => [
[
'dest' => '\Modules\Notification\Controller\ApiController:apiNotificationSeenCreate',
'verb' => RouteVerb::SET,
'permission' => [
'module' => ApiController::NAME,
'type' => PermissionType::CREATE,
'state' => PermissionCategory::NOTIFICATION,
],
],
],
];

View File

@ -20,7 +20,7 @@ use phpOMS\Router\RouteVerb;
return [
'^.*/notification/dashboard(\?.*$|$)' => [
[
'dest' => '\Modules\Notification\Controller\BackendController:viewTaskDashboard',
'dest' => '\Modules\Notification\Controller\BackendController:viewNotificationDashboard',
'verb' => RouteVerb::GET,
'permission' => [
'module' => BackendController::NAME,

View File

@ -1,46 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at spl1nes.com@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View File

@ -1,196 +0,0 @@
## Development environment
The setup and configuration of the development environment is in the hands of every developer themselves. However, it is recommended to follow the setup instructions in the [Developer-Guide](https://github.com/Karaka-Management/Developer-Guide/blob/develop/general/setup.md).
## Code of conduct
Every organization member and contributor to the organization must follow the [Code of Conduct](../Policies%20&%20Guidelines/Code%20of%20Conduct.md).
## Becoming a contributor
For public repositories you can immediately start by creating forks and pull requests. For private repositories which are necessary to setup the complete developer environment, feel free to request access. Please not that we may not immediately give you access to private repositories and instead will give you smaller tasks regarding public repositories. Please contact info@jingga.app for more details. (**R1**)
For all contributions our [Contributor License Agreement "CLA"](https://github.com/Karaka-Management/Organization-Guide/blob/master/Processes/HR/Hiring/Individual%20Contributor%20License%20Agreement.md) comes into effect. (**R2**)
## Code changes
### Topics / Tasks / Todos
Generally, the development philosophy is result orientated. This means that anyone can propose tasks, pick up existing tasks or right away implement their code changes. However, implementing code changes without consulting with a senior developer in advance has a much higher risk of code changes not getting admitted. The easiest way to discuss a code change idea in advance are the github [issues](https://github.com/Karaka-Management/Karaka/issues) or [discussions](https://github.com/Karaka-Management/Karaka/discussions).
Developers are encouraged to pick open tasks with high priorities according to their own skill level. Senior developers may directly assign tasks to developers based on their importance. New developers may find it easier to start with a task that has a low priority as they often also have a lower difficulty.
Open tasks can be found in the project overview: [Todos](https://github.com/orgs/Karaka-Management/projects/10)
Tasks currently in development are prefixed in the priority column with an asterisk `*` and a name tag in the task description of the developer who is working on the task.
The open tasks are reviewed once a month by a senior developer. The senior developer updates the project overview if necessary and requests feedback regarding development status of important tasks under development. During this process important tasks may also get directly assigned to developers. This review is performed on a judgmental bases of the senior basis.
### Quality
#### Code style
Code changes must follow the [style guidelines](https://github.com/Karaka-Management/Developer-Guide/tree/develop/standards) (**R3**). Additionally, the automatic code style inspection tools must return no errors, failures or warnings. Developers should test their changes with inspection tools and configurations mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) in advance before submitting them for review. (**R4**)
In rare cases errors, failures or warnings during the automatic inspection are acceptable. Reasons can be for example special cases which are difficult automatize or must be individually configured in the inspection settings. If this is the case for a code change and if inspection configuration changes are necessary are decided by the senior developer performing the code review. (**R5**)
Automated checks which are run during the review process (**R4**):
```sh
php ./vendor/bin/phpcs ./ --standard="Build/Config/phpcs.xml"
php ./vendor/bin/php-cs-fixer fix ./ --config=Build/Config/.php-cs-fixer.php --allow-risky=yes
php ./vendor/bin/phpcbf --standard=Build/Config/phpcs.xml ./
php ./vendor/bin/rector process --dry-run --config Build/Config/rector.php ./
npx eslint ./ -c ./Build/Config/.eslintrc.json
```
#### Tests
Code changes must follow the inspection guidelines (i.e. code coverage) mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) (**R6**). Developers should test their changes with inspection tools and configurations mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) in advance before submitting them for review. (**R7**)
In rare cases it might be not possible to follow the inspection guidelines. In such cases the senior developer performing the code review may decide if the code change still gets accepted. (**R8**)
Automated tests which are run during the review process (**R7**):
```sh
php ./vendor/bin/phpunit -c tests/PHPUnit/phpunit_default.xml
php ./vendor/bin/phpstan analyse --no-progress -l 9 -c Build/Config/phpstan.neon ./
npx jasmine-node ./
./cOMS/tests/test.sh
```
Additional inspections which are run but might be ignored during the review depending on the use case are mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) as other checks. (**R7**)
#### Performance
Developers should occasionaly check performance statistics. At this point no target metrics are defined.
Since the primary application is a web based application a similar tool as the Google lighthouse tool can be used to inspect the application for best practicies which can significantly improve the application performance. The sitespeed.io tool shows potential performance improvements and slow pages. With the php trace and profiler enabled in the `php.ini` file the VM automatically generates profiling and trace reports for every web request. These can be found in the webgrind logs directory and inspected in webgrind and dropped into the trace visualizer for a flame chart visualization. With mysqldumpslow you can inspect slow sql queries which may need optimization.
1. Automatic trace and benchmark generation with every web request in `/var/www/html/webgrind/Logs`
2. Webgrind view `http://vm_ip:82`
3. Trace visualization `http://vm_ip:81`
1. Download the latest trace from `http://vm_ip:82/Logs`
2. Drag and drop that downloaded `*.xt` file in the trace visualizer
4. `sitespeed.io ./Build/Helper/Scripts/sitespeedDemoUrls.txt -b chrome --outputFolder /var/www/html/sitespeed`
5. Slow query inspection.
```sh
mysqldumpslow -t 10 /var/log/mysql/mysql-slow.log
mysqldumpslow -t 10 -s l /var/log/mysql/mysql-slow.log
```
#### Code review
In addition to the automatic code review performed by the various inspection tools such as (phpcs, phpstan, phpunit, eslint and custom scripts) a senior developer must check the proposed code change before it is merged with the respective `develop` branch. Only upon the approval by the reviewer a code change requests gets merged as no other developers have permission in the software to make such code merges.
In case a code change request is not approved the reviewer states the reason for the decision, this may include some tips and requests which will allow the contributor to make improvements so that the code change may get approved.
If the code reviewer only finds minor issues with the proposed code change the reviewer may make small changes to the proposed code change and inform the contributor to speed up the implementation process. Code reviewers are encouraged to do this with new contributors to avoid long iteration processes and to not discourage new developers. However, communication is key and severe issues with code change requests or if the contributor already made multiple code change requests in the past the reviewer should not implement the improvements by himself and rather decline the code change requests with his reasoning. (**R5**+**R8**)
#### Demo
Some code changes may also require changes or extensions in the demo setup scripts. The demo setup script try to simulate a real world use case by generating and modifying mostly random data. This is also a good way to setup and “manually” test the code changes in a larger picture. The demo setup script can be found in the [demoSetup](https://github.com/Karaka-Management/demoSetup) repository. The demo setup script takes a long time due to the large amount of user input simulated data which is generated. Therefore it is recommended to run this only sporadically. (**R9**)
```sh
sudo -u www-data php -dxdebug.remote_enable=1 -dxdebug.start_with_request=yes -dxdebug.mode=coverage,develop,debug demoSetup/setup.php
```
#### Documentation
Occasionally new code or code changes also require new documentation or documentation changes. Developers should make sure that the new code is also reflected in the existing documentation ([Developer-Guide](), [User-Guide]() and/or module documentation) or if additional documentation is necessary.
#### Improvements, features, bugs
If a developer (or employee in general) has an idea for an improvement, feature or finds a potential bug it should be reported at https://github.com/Karaka-Management/Karaka/issues. A senior developer has to check these issues and decide how to proceed with them. The decision how to proceed with the issue must be explained by the senior developer as a response in the issue. Possible steps are:
* Accept the issue and put the task into the [Todos](https://github.com/orgs/Karaka-Management/projects/10)
* Dismiss the issue with an explanation
### Release flow
In case SCSS/CSS or JS files got changed they must get re-built locally before comitting the code change:
```sh
npx esbuild Web/Backend/js/backend.js --bundle --outfile=Install/Application/Backend/js/backend.min.js --minify
scss cssOMS/styles.scss > cssOMS/styles.css
```
For JS you may also use the shorthand command `npm run build`.
Code changes must be performed in a new branch. A new branch can be created with:
```sh
git checkout -b new-branch-name
```
The name of the branch can be chosen freely however it is recommended to follow the following branch naming conventions:
* `feature-*` for feature implementations
* `hotfix-*` for security related fixes/improvements
* `bug-*` for bug fixes
* `security-*` for security related fixes/improvements
* `general-*` for general improvements (i.e. documentation, code style & performance improvements)
```mermaid
%%{init: { 'gitGraph': {'mainBranchName': 'master'}} }%%
gitGraph
commit
branch hotfix-xxx
commit
checkout master
branch develop
checkout master
merge hotfix-xxx
checkout develop
branch bug-xxx
commit
commit
checkout hotfix-xxx
commit
checkout master
merge hotfix-xxx
checkout develop
merge bug-xxx
commit
checkout develop
branch feature-xxx
commit
commit
commit
checkout develop
merge feature-xxx
checkout master
merge develop
checkout develop
branch general-xxx
commit
checkout develop
merge general-xxx
branch security-xxx
commit
commit
checkout develop
merge security-xxx
checkout master
merge develop
```
The senior developer who performs the code review merges the change request into the `develop` branch after their successful code review. Unsuccessful reviews lead to change requests by the original developer, other developers who can make the requested changes, changes by the senior developer who performed the review, or dismissal of the changed code. (**R10**)
## Approved dependencies
### Customer dependencies
Developers may only rely on the dependencies defined in [Approved Customer Software]() when developing a solution. If new software should be added to this list or a different version is required developers should make a request with their team leader/head of department who forwards this requests if appropriate to the CTO and explain the reasoning for the different dependency needs. The CTO can decide if the dependency will be accepted. (**R11**)
### Developer dependencies
Developers may only rely on the dependencies defined in [IT Equipment & Software](). If new software should be added to this list or a different version is required developers should make a request with their team leader/head of department who forwards this requests if appropriate to the CTO and explain the reasoning for the different dependency needs. The CTO can decide if the dependency will be accepted. Changing the package managers such as `composer.json` or `package.json` is not allowed by anyone else than the CTO. (**R12**)
## Other related documents
* [Confidentiality Policy](../Policies%20&%20Guidelines/Confidentiality%20Policy.md)
* [Organization Activity Policy](../Policies%20&%20Guidelines/Organization%20Activity%20Policy.md)
* [Tutorials](./Development/Tutorials)

View File

@ -14,6 +14,11 @@ declare(strict_types=1);
namespace Modules\Notification\Controller;
use Modules\Notification\Models\NotificationMapper;
use phpOMS\DataStorage\Database\Query\OrderType;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
/**
* Api controller for the tasks module.
*
@ -24,4 +29,36 @@ namespace Modules\Notification\Controller;
*/
final class ApiController extends Controller
{
/**
* Api method to create a task
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param array $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiNotificationSeenCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
{
$now = new \DateTimeImmutable('now');
$notifications = NotificationMapper::getAll()
->where('createdFor', $request->header->account)
->where('seenAt', null)
->where('createdAt', $now, '<') // Don't show pre-created notifications
->sort('createdAt', OrderType::ASC)
->execute();
foreach ($notifications as $notification) {
$new = clone $notification;
$new->seenAt = $now;
$this->updateModel($request->header->account, $notification, $new, NotificationMapper::class, 'notification', $request->getOrigin());
}
$this->createStandardUpdateResponse($request, $response, []);
}
}

View File

@ -15,7 +15,9 @@ declare(strict_types=1);
namespace Modules\Notification\Controller;
use Modules\Dashboard\Models\DashboardElementInterface;
use Modules\Notification\Models\NotificationMapper;
use phpOMS\Contract\RenderableInterface;
use phpOMS\DataStorage\Database\Query\OrderType;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Views\View;
@ -49,6 +51,13 @@ final class BackendController extends Controller implements DashboardElementInte
$view = new View($this->app->l11nManager, $request, $response);
$view->setTemplate('/Modules/Notification/Theme/Backend/notification-dashboard');
$view->data['notifications'] = NotificationMapper::getAll()
->where('createdFor', $request->header->account)
->where('seenAt', null)
->where('createdAt', new \DateTime('now'), '<') // Don't show pre-created notifications
->sort('createdAt', OrderType::ASC)
->execute();
return $view;
}
@ -61,10 +70,32 @@ final class BackendController extends Controller implements DashboardElementInte
$view = new View($this->app->l11nManager, $request, $response);
$view->setTemplate('/Modules/Notification/Theme/Backend/dashboard-notification');
$notifications = [];
$view->data['notifications'] = $notifications;
$view->data['notifications'] = NotificationMapper::getAll()
->where('createdFor', $request->header->account)
->where('seenAt', null)
->where('createdAt', new \DateTime('now'), '<') // Don't show pre-created notifications
->sort('createdAt', OrderType::ASC)
->limit(5)
->execute();
return $view;
}
/**
* Count unread messages
*
* @param int $account Account id
*
* @return int Returns the amount of unread tasks
*
* @since 1.0.0
*/
public function openNav(int $account) : int
{
return NotificationMapper::count()
->where('createdFor', $account)
->where('seenAt', null)
->where('createdAt', new \DateTime('now'), '<') // Don't show pre-created notifications
->execute();
}
}

163
Models/Notification.php Executable file
View File

@ -0,0 +1,163 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Notification\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Notification\Models;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
/**
* Notification class.
*
* @package Modules\Notification\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
class Notification implements \JsonSerializable
{
/**
* ID.
*
* @var int
* @since 1.0.0
*/
public int $id = 0;
/**
* Title.
*
* @var string
* @since 1.0.0
*/
public string $title = '';
/**
* Redirect.
*
* Used as reference or for redirection when opened.
* This allows to open the task on a different page with a different layout if needed (e.g. ticket system, workflow, checklist, ...)
*
* @var string
* @since 1.0.0
*/
public string $redirect = '';
/**
* Creator.
*
* @var Account
* @since 1.0.0
*/
public Account $createdBy;
/**
* Creator.
*
* @var Account
* @since 1.0.0
*/
public Account $createdFor;
/**
* Created.
*
* @var \DateTimeImmutable
* @since 1.0.0
*/
public \DateTimeImmutable $createdAt;
/**
* Created.
*
* @var \DateTimeImmutable
* @since 1.0.0
*/
public ?\DateTimeImmutable $seenAt = null;
/**
* Description.
*
* @var string
* @since 1.0.0
*/
public string $description = '';
/**
* Description raw.
*
* @var string
* @since 1.0.0
*/
public string $descriptionRaw = '';
/**
* Type.
*
* @var int
* @since 1.0.0
*/
public int $type = NotificationType::CREATE;
/**
* Status.
*
* @var int
* @since 1.0.0
*/
public int $status = NotificationStatus::DEFAULT;
public int $category = 0;
public int $element = 0;
public string $module = '';
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
$this->createdBy = new NullAccount();
$this->createdFor = new NullAccount();
$this->createdAt = new \DateTimeImmutable('now');
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'createdBy' => $this->createdBy,
'createdAt' => $this->createdAt,
'title' => $this->title,
'description' => $this->description,
'descriptionRaw' => $this->descriptionRaw,
'status' => $this->status,
'type' => $this->type,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

96
Models/NotificationMapper.php Executable file
View File

@ -0,0 +1,96 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Notification\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Notification\Models;
use Modules\Admin\Models\AccountMapper;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Mapper class.
*
* @package Modules\Notification\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*
* @template T of Notification
* @extends DataMapperFactory<T>
*/
final class NotificationMapper extends DataMapperFactory
{
/**
* Columns.
*
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0
*/
public const COLUMNS = [
'notification_id' => ['name' => 'notification_id', 'type' => 'int', 'internal' => 'id'],
'notification_title' => ['name' => 'notification_title', 'type' => 'string', 'internal' => 'title'],
'notification_desc' => ['name' => 'notification_desc', 'type' => 'string', 'internal' => 'description'],
'notification_desc_raw' => ['name' => 'notification_desc_raw', 'type' => 'string', 'internal' => 'descriptionRaw'],
'notification_type' => ['name' => 'notification_type', 'type' => 'int', 'internal' => 'type'],
'notification_status' => ['name' => 'notification_status', 'type' => 'int', 'internal' => 'status'],
'notification_module' => ['name' => 'notification_module', 'type' => 'string', 'internal' => 'module'],
'notification_category' => ['name' => 'notification_category', 'type' => 'int', 'internal' => 'category'],
'notification_element' => ['name' => 'notification_element', 'type' => 'int', 'internal' => 'element'],
'notification_redirect' => ['name' => 'notification_redirect', 'type' => 'string', 'internal' => 'redirect'],
'notification_created_by' => ['name' => 'notification_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
'notification_for' => ['name' => 'notification_for', 'type' => 'int', 'internal' => 'createdFor'],
'notification_created_at' => ['name' => 'notification_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
'notification_seen_at' => ['name' => 'notification_seen_at', 'type' => 'DateTimeImmutable', 'internal' => 'seenAt'],
];
/**
* Has one relation.
*
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0
*/
public const OWNS_ONE = [
'createdFor' => [
'mapper' => AccountMapper::class,
'external' => 'notification_for',
],
'createdBy' => [
'mapper' => AccountMapper::class,
'external' => 'notification_created_by',
],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'notification';
/**
* Created at.
*
* @var string
* @since 1.0.0
*/
public const CREATED_AT = 'notification_created_at';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD = 'notification_id';
}

30
Models/NotificationStatus.php Executable file
View File

@ -0,0 +1,30 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Notification\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Notification\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Notification status enum.
*
* @package Modules\Notification\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
abstract class NotificationStatus extends Enum
{
public const DEFAULT = 0;
}

34
Models/NotificationType.php Executable file
View File

@ -0,0 +1,34 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Notification\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Notification\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Notification type enum.
*
* @package Modules\Notification\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
abstract class NotificationType extends Enum
{
public const CREATE = 1;
public const UPDATE = 2;
public const CHILDREN = 3;
}

47
Models/NullNotification.php Executable file
View File

@ -0,0 +1,47 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Notification\Models
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Notification\Models;
/**
* Null model
*
* @package Modules\Notification\Models
* @license OMS License 2.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullNotification extends Notification
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
$this->id = $id;
parent::__construct();
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

View File

@ -0,0 +1,17 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Localization
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
return ['Navigation' => [
'Notifications' => 'Nachrichten',
]];

View File

@ -0,0 +1,17 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Localization
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
return ['Navigation' => [
'Notifications' => 'Notifications',
]];

View File

@ -0,0 +1,25 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Localization
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
return ['Notification' => [
'Notifications' => 'Nachrichten',
'Title' => 'Titel',
'Date' => 'Datum',
':status-text-1' => 'Neues %s Element erstellt',
':status-text-2' => '%s Element upgedated',
':status-text-3' => 'Neues Element zu %s hinzugefügt',
':status-1' => 'Neu',
':status-2' => 'Update',
':status-3' => 'Update',
]];

View File

@ -0,0 +1,26 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Localization
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
return ['Notification' => [
'Notifications' => 'Notifications',
'Title' => 'Title',
'Date' => 'Date',
'MarkSeen' => 'Mark Seen',
':status-text-1' => 'New %s element created',
':status-text-2' => '%s element updated',
':status-text-3' => 'New element added to %s',
':status-1' => 'New',
':status-2' => 'Update',
':status-3' => 'Update',
]];

View File

@ -0,0 +1,55 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Notification
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
use phpOMS\Uri\UriFactory;
$notifications = $this->data['notifications'] ?? [];
?>
<div id="notification-dashboard" class="col-xs-12 col-md-6" draggable="true">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Notifications', 'Notification'); ?></div>
<div class="slider">
<table class="default sticky">
<thead>
<tr>
<td><?= $this->getHtml('Date', 'Notification'); ?>
<td>
<td class="wf-100"><?= $this->getHtml('Title', 'Notification'); ?>
<tbody>
<?php
$c = 0;
foreach ($notifications as $notification) : ++$c;
$url = UriFactory::build($notification->redirect);
?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><?= $notification->createdAt->format('Y-m-d'); ?></a>
<td><a href="<?= $url; ?>"><?= $this->getHtml(':status-' . $notification->type); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($notification->module); ?>: <?= $this->printHtml($notification->title); ?></a>
<?php endforeach; ?>
<?php if ($c === 0) : ?>
<tr><td colspan="3" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
</div>
<div class="portlet-foot">
<a class="button" href="<?= UriFactory::build('{/base}/notification/dashboard?{?}'); ?>"><?= $this->getHtml('More', '0', '0'); ?></a>
<span class="end-xs">
<form id="iNotificationRead" action="<?= \phpOMS\Uri\UriFactory::build('{/api}notification/seen?{?}&csrf={$CSRF}'); ?>" method="POST">
<input type="submit" class="end-xs save" value="<?= $this->getHtml('MarkSeen', 'Notification'); ?>">
</form>
</span>
</div>
</div>
</div>

View File

@ -0,0 +1,57 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Notification
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
use phpOMS\Uri\UriFactory;
/** @var \phpOMS\Views\View $this */
/** @var \Modules\Notification\Models\Notification[] $notifications */
$notifications = $this->data['notifications'] ?? [];
?>
<div class="row">
<div class="col-xs-12">
<div class="portlet">
<div class="portlet-head">
<?= $this->getHtml('Notifications', 'Notification'); ?>
<span class="end-xs">
<form id="iNotificationRead" action="<?= \phpOMS\Uri\UriFactory::build('{/api}notification/seen?{?}&csrf={$CSRF}'); ?>" method="POST">
<input type="submit" class="end-xs save" value="<?= $this->getHtml('MarkSeen', 'Notification'); ?>">
</form>
</span>
</div>
<div class="slider">
<table id="notificationList" class="default sticky">
<thead>
<tr>
<td><?= $this->getHtml('Date', 'Notification'); ?>
<td>
<td class="wf-100"><?= $this->getHtml('Title', 'Notification'); ?>
<tbody>
<?php
$c = 0;
foreach ($notifications as $notification) : ++$c;
$url = UriFactory::build($notification->redirect);
?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><?= $notification->createdAt->format('Y-m-d'); ?></a>
<td><a href="<?= $url; ?>"><?= $this->getHtml(':status-' . $notification->type); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($notification->module); ?>: <?= $this->printHtml($notification->title); ?></a>
<?php endforeach; ?>
<?php if ($c === 0) : ?>
<tr><td colspan="3" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
</div>
</div>
</div>
</div>

View File

@ -1,63 +0,0 @@
<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package Modules\Tasks
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
use Modules\Tasks\Models\TaskPriority;
use phpOMS\Uri\UriFactory;
$notificationList = $this->data['notification'] ?? [];
?>
<div id="notification-dashboard" class="col-xs-12 col-md-6" draggable="true">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('Tasks', 'Tasks'); ?></div>
<div class="slider">
<table class="default sticky">
<thead>
<td><?= $this->getHtml('Status', 'Tasks'); ?>
<td><?= $this->getHtml('Due/Priority', 'Tasks'); ?>
<td class="wf-100"><?= $this->getHtml('Title', 'Tasks'); ?>
<tfoot>
<tbody>
<?php
$c = 0;
foreach ($notificationList as $key => $notification) : ++$c;
$url = UriFactory::build(empty($notification->redirect)
? '{/base}/notification/view?{?}&id=' . $notification->id
: ($notification->redirect)
);
?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>">
<span class="tag <?= $this->printHtml('notification-status-' . $notification->status); ?>">
<?= $this->getHtml('S' . $notification->status, 'Tasks'); ?>
</span></a>
<td><a href="<?= $url; ?>">
<?php if ($notification->priority === TaskPriority::NONE) : ?>
<?= $this->printHtml($notification->due->format('Y-m-d H:i')); ?>
<?php else : ?>
<?= $this->getHtml('P' . $notification->priority); ?>
<?php endif; ?>
</a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($notification->title); ?></a>
<?php endforeach; ?>
<?php if ($c == 0) : ?>
<tr><td colspan="6" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
</div>
<div class="portlet-foot">
<a class="button" href="<?= UriFactory::build('{/base}/notification/dashboard?{?}'); ?>"><?= $this->getHtml('More', '0', '0'); ?></a>
</div>
</div>
</div>

View File

@ -20,6 +20,7 @@
"Admin": "1.0.0"
},
"providing": {
"Navigation": "*",
"Dashboard": "*"
},
"load": [