ReWork Notification Model/Module/Object/Repository/Factory
- Introduce Repository for interaction with "notify" table - Introduce Factory for read-only notification objects (they're just loosely based on notification the table!) - Introduce Objects for type-safe usage at the presentation layer - Reworked Model, which is now fully based on the notify table, including generated fields (cache, ..)
This commit is contained in:
parent
230bb6dd53
commit
0850fb88dd
17 changed files with 1413 additions and 851 deletions
|
|
@ -482,47 +482,25 @@ function notification($params)
|
|||
$notify_id = 0;
|
||||
|
||||
if ($show_in_notification_page) {
|
||||
Logger::log("adding notification entry", Logger::DEBUG);
|
||||
$notification = DI::notification()->insert([
|
||||
'name' => $params['source_name'],
|
||||
'url' => $params['source_link'],
|
||||
'photo' => $params['source_photo'],
|
||||
'uid' => $params['uid'],
|
||||
'iid' => $item_id,
|
||||
'parent' => $parent_id,
|
||||
'type' => $params['type'],
|
||||
'verb' => $params['verb'],
|
||||
'otype' => $params['otype'],
|
||||
]);
|
||||
|
||||
/// @TODO One statement is enough
|
||||
$datarray = [];
|
||||
$datarray['name'] = $params['source_name'];
|
||||
$datarray['name_cache'] = strip_tags(BBCode::convert($params['source_name']));
|
||||
$datarray['url'] = $params['source_link'];
|
||||
$datarray['photo'] = $params['source_photo'];
|
||||
$datarray['date'] = DateTimeFormat::utcNow();
|
||||
$datarray['uid'] = $params['uid'];
|
||||
$datarray['link'] = $itemlink;
|
||||
$datarray['iid'] = $item_id;
|
||||
$datarray['parent'] = $parent_id;
|
||||
$datarray['type'] = $params['type'];
|
||||
$datarray['verb'] = $params['verb'];
|
||||
$datarray['otype'] = $params['otype'];
|
||||
$datarray['abort'] = false;
|
||||
$notification->link = DI::baseUrl() . '/notification/view/' . $notification->id;
|
||||
$notification->msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $notification->link]);
|
||||
|
||||
Hook::callAll('enotify_store', $datarray);
|
||||
DI::notification()->update($notification);
|
||||
|
||||
if ($datarray['abort']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// create notification entry in DB
|
||||
$fields = ['name' => $datarray['name'], 'url' => $datarray['url'],
|
||||
'photo' => $datarray['photo'], 'date' => $datarray['date'], 'uid' => $datarray['uid'],
|
||||
'link' => $datarray['link'], 'iid' => $datarray['iid'], 'parent' => $datarray['parent'],
|
||||
'type' => $datarray['type'], 'verb' => $datarray['verb'], 'otype' => $datarray['otype'],
|
||||
'name_cache' => $datarray["name_cache"]];
|
||||
DBA::insert('notify', $fields);
|
||||
|
||||
$notify_id = DBA::lastInsertId();
|
||||
|
||||
$itemlink = DI::baseUrl().'/notification/view/'.$notify_id;
|
||||
$msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $itemlink]);
|
||||
$msg_cache = format_notification_message($datarray['name_cache'], strip_tags(BBCode::convert($msg)));
|
||||
|
||||
$fields = ['msg' => $msg, 'msg_cache' => $msg_cache];
|
||||
$condition = ['id' => $notify_id, 'uid' => $params['uid']];
|
||||
DBA::update('notify', $fields, $condition);
|
||||
$itemlink = $notification->link;
|
||||
$notify_id = $notification->id;
|
||||
}
|
||||
|
||||
// send email notification if notification preferences permit
|
||||
|
|
@ -732,27 +710,3 @@ function check_item_notification($itemid, $uid, $notification_type) {
|
|||
|
||||
notification($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a notification message with the notification author
|
||||
*
|
||||
* Replace the name with {0} but ensure to make that only once. The {0} is used
|
||||
* later and prints the name in bold.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $message
|
||||
* @return string Formatted message
|
||||
*/
|
||||
function format_notification_message($name, $message) {
|
||||
if ($name != '') {
|
||||
$pos = strpos($message, $name);
|
||||
} else {
|
||||
$pos = false;
|
||||
}
|
||||
|
||||
if ($pos !== false) {
|
||||
$message = substr_replace($message, '{0}', $pos, strlen($name));
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue