function oa_notification_parse in Open Atrium Notifications 7.2
Helper function to parse notifications from the input field value
Parameters
$values:
$source_type type of source entity, usually 'node': if empty, then remove the notifications instead of adding them
$source_id nid of node to add notifications:
$notifications:
$do_save bool optional to write each record to db as parsed:
4 calls to oa_notification_parse()
- oa_notifications_form_fields in ./
oa_notifications.module - Define the fields that are used for configuring notifications.
- oa_notifications_process_add in ./
oa_notifications.module - Adds any notifications added by javascript
- oa_notifications_process_remove in ./
oa_notifications.module - Remove any notifications added by javascript
- oa_notifications_save_notifications in ./
oa_notifications.module - Saves notifications.
File
- ./
oa_notifications.module, line 275
Code
function oa_notification_parse($value, $source_type, $source_id, &$notifications, $do_save = FALSE) {
$items = explode(',', $value);
if (!empty($items)) {
foreach ($items as $item) {
if (strpos($item, ':') !== FALSE) {
list($type, $id) = explode(':', $item);
if (!empty($id) && !empty($type)) {
if (empty($source_type)) {
if ($do_save && $notifications[$type][$id]) {
oa_notifications_delete_for_target($id, $type);
}
unset($notifications[$type][$id]);
}
else {
$n = oa_notifications_make($type, $id, $source_type, $source_id);
if ($do_save && !isset($notifications[$type][$id])) {
// only save if its a new notification
drupal_write_record('oa_notifications', $n);
}
$notifications[$type][$id] = $n;
}
}
}
}
}
}