Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Maarch
maarchRM
Commits
f4450810
Commit
f4450810
authored
Nov 24, 2021
by
Cyril Vazquez
Committed by
Arnaud Pauget
Nov 29, 2021
Browse files
Notification system V2
parent
4df8ea9d
Changes
6
Hide whitespace changes
Inline
Side-by-side
data/maarchRM/notifications/simple.html
0 → 100644
View file @
f4450810
<div>
This is a sample message
to notify
<?merge event.accountId ?>
that a
<b>
<?merge event.eventType ?>
</b>
was performed on
<?merge event.objectClass ?>
<?merge event.objectId ?>
Now let's use clearer informations:
-
<?merge account.displayName ?>
</div>
\ No newline at end of file
data/maarchRM/notifications/simple_recipients.php
0 → 100644
View file @
f4450810
<?php
$accountController
=
\
laabs
::
newController
(
'auth/userAccount'
);
$orgController
=
\
laabs
::
newController
(
'organization/organization'
);
$archiveController
=
\
laabs
::
newController
(
'recordsManagement/archive'
);
$archive
=
$archiveController
->
read
(
$event
->
objectId
);
$originatorUserPositions
=
$orgController
->
readUserPositions
(
$archive
->
originatorOrgRegNumber
);
$recipients
=
[];
foreach
(
$originatorUserPositions
as
$originatorUserPosition
)
{
$account
=
$accountController
->
get
(
$originatorUserPosition
->
userAccountId
);
$recipients
[]
=
$account
->
displayName
.
' <'
.
$account
->
emailAddress
.
'>'
;
}
return
$recipients
;
data/maarchRM/notifications/simple_sources.php
0 → 100644
View file @
f4450810
<?php
$accountController
=
\
laabs
::
newController
(
'auth/userAccount'
);
$account
=
$accountController
->
get
(
$event
->
accountId
);
return
[
'account'
=>
$account
,
];
src/bundle/batchProcessing/Controller/notification.php
View file @
f4450810
...
...
@@ -78,7 +78,7 @@ class notification
$notification
->
title
=
$title
;
$notification
->
message
=
$message
;
$notification
->
receivers
=
\
laabs\implode
(
" "
,
$receivers
);
$notification
->
receivers
=
json_encode
(
$receivers
);
$this
->
sdoFactory
->
create
(
$notification
,
"batchProcessing/notification"
);
...
...
@@ -96,7 +96,7 @@ class notification
foreach
(
$notifications
as
$notification
)
{
$notification
->
status
=
self
::
_PROCESSING_
;
$this
->
sdoFactory
->
update
(
$notification
,
"batchProcessing/notification"
);
$this
->
notificationDependency
->
send
(
$notification
->
title
,
$notification
->
message
,
\
laabs\explode
(
" "
,
$notification
->
receivers
));
$this
->
notificationDependency
->
send
(
$notification
->
title
,
$notification
->
message
,
json_decode
(
$notification
->
receivers
));
$notification
->
status
=
self
::
_CLOSE_
;
$notification
->
sendDate
=
\
laabs
::
newDateTime
();
$notification
->
sendBy
=
\
laabs
::
getToken
(
"AUTH"
)
->
accountId
;
...
...
src/bundle/lifeCycle/Controller/eventNotifier.php
0 → 100644
View file @
f4450810
<?php
/*
* Copyright (C) 2015 Maarch
*
* This file is part of bundle lifeCycle.
*
* Bundle lifeCycle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Bundle lifeCycle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bundle lifeCycle. If not, see <http://www.gnu.org/licenses/>.
*/
namespace
bundle\lifeCycle\Controller
;
/**
* Class of archives life cycle journal
*
* @author Prosper DE LAURE <prosper.delaure@maarch.org>
*/
class
eventNotifier
{
protected
$sdoFactory
;
protected
$notifications
;
protected
$notificationController
;
/**
* Constructs a new event notifier
*/
public
function
__construct
(
\
dependency\sdo\Factory
$sdoFactory
,
$notifications
=
[])
{
$this
->
sdoFactory
=
$sdoFactory
;
$this
->
notifications
=
$notifications
;
$this
->
notificationController
=
\
laabs
::
newController
(
'batchProcessing/notification'
);
}
/**
* Sends a notification or not
* @param lifeCycle/event $event
*
*/
public
function
dispatch
(
$event
)
{
$notifications
=
$this
->
selectNotifications
(
$event
);
foreach
(
$notifications
as
$notification
)
{
$this
->
sendNotification
(
$notification
,
$event
);
}
}
protected
function
selectNotifications
(
$event
)
{
$notifications
=
[];
foreach
(
$this
->
notifications
as
$notification
)
{
// check if a rule matches the event
if
(
!
isset
(
$notification
[
'filter'
])
||
empty
(
$notification
[
'filter'
]))
{
continue
;
}
if
(
!
$this
->
matchFilter
(
$notification
[
'filter'
],
$event
))
{
continue
;
}
$notifications
[]
=
$notification
;
}
return
$notifications
;
}
protected
function
matchFilter
(
$filter
,
$event
)
{
foreach
(
$filter
as
$name
=>
$value
)
{
if
(
!
$this
->
matchAssert
(
$event
,
$name
,
$value
))
{
return
;
}
}
return
true
;
}
protected
function
matchAssert
(
$event
,
$name
,
$value
)
{
if
(
is_string
(
$value
))
{
return
(
$event
->
{
$name
}
==
$value
);
}
}
protected
function
sendNotification
(
$notification
,
$event
)
{
if
(
is_array
(
$notification
[
'recipients'
]))
{
$recipients
=
$notification
[
'recipients'
];
}
else
{
$recipients
=
include
$notification
[
'recipients'
];
}
if
(
empty
(
$recipients
))
{
return
;
}
$subject
=
$notification
[
'title'
]
??
'Notification'
;
$message
=
''
;
if
(
isset
(
$notification
[
'message'
]))
{
if
(
is_string
(
$notification
[
'message'
]))
{
$message
=
$notification
[
'message'
];
}
else
{
$template
=
\
laabs
::
newService
(
'dependency/html/Document'
);
$template
->
setSource
(
'event'
,
$event
);
$template
->
setSource
(
'recipients'
,
$recipients
);
$message
=
$this
->
composeMessage
(
$notification
[
'message'
],
$template
,
$event
);
}
}
$this
->
notificationController
->
create
(
$subject
,
$message
,
$recipients
);
}
protected
function
composeMessage
(
$message
,
$template
,
$event
)
{
$htmlTemplate
=
file_get_contents
(
$message
[
'template'
]);
$template
->
loadHTML
(
$htmlTemplate
);
if
(
isset
(
$message
[
'sources'
]))
{
$sources
=
include
$message
[
'sources'
];
foreach
(
$sources
as
$name
=>
$source
)
{
$template
->
setSource
(
$name
,
$source
);
}
}
$template
->
merge
();
$message
=
$template
->
saveHTML
();
return
$message
;
}
}
\ No newline at end of file
src/bundle/lifeCycle/Controller/journal.php
View file @
f4450810
...
...
@@ -45,6 +45,8 @@ class journal
protected
$journals
;
protected
$eventNotifier
;
/**
* Constructor
* @param \dependency\sdo\Factory $sdoFactory The sdo factory
...
...
@@ -65,6 +67,8 @@ class journal
foreach
(
$this
->
eventFormats
as
$eventFormat
)
{
$eventFormat
->
format
=
explode
(
' '
,
$eventFormat
->
format
);
}
$this
->
eventNotifier
=
\
laabs
::
newController
(
"lifeCycle/eventNotifier"
);
}
/**
...
...
@@ -158,6 +162,8 @@ class journal
$this
->
sdoFactory
->
create
(
$event
);
$this
->
eventNotifier
->
dispatch
(
$event
);
if
(
!
$operationResult
&&
$eventFormat
->
notification
==
true
)
{
$this
->
notify
(
$event
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment