Elgg /
Elgg
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Site notification factory |
||
| 5 | */ |
||
| 6 | abstract class SiteNotificationFactory { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Create a site notification |
||
| 10 | * |
||
| 11 | * @param ElggUser $recipient Recipient of the notification |
||
| 12 | * @param string $message Notification message |
||
| 13 | * @param ElggUser $actor User who caused the notification event |
||
| 14 | * @param ElggData $object Optional object involved in the notification event |
||
| 15 | * @param string $url Target URL |
||
| 16 | * |
||
| 17 | * @return void|SiteNotification |
||
| 18 | */ |
||
| 19 | 2 | public static function create($recipient, $message, $actor, $object = null, $url = null) { |
|
| 20 | 2 | $note = new SiteNotification(); |
|
| 21 | 2 | $note->owner_guid = $recipient->guid; |
|
| 22 | 2 | $note->container_guid = $recipient->guid; |
|
| 23 | 2 | $note->access_id = ACCESS_PRIVATE; |
|
| 24 | 2 | $note->description = $message; |
|
| 25 | |||
| 26 | 2 | if (!isset($url) && $object) { |
|
| 27 | // TODO Add support for setting an URL for a notification about a new relationship |
||
| 28 | switch ($object->getType()) { |
||
| 29 | case 'annotation': |
||
| 30 | // Annotations do not have an URL so we use the entity URL |
||
| 31 | $url = $object->getEntity()->getURL(); |
||
|
1 ignored issue
–
show
Bug
introduced
by
Loading history...
|
|||
| 32 | break; |
||
| 33 | default: |
||
| 34 | $url = $object->getURL(); |
||
| 35 | break; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | 2 | if ($url && $url != elgg_get_site_url()) { |
|
| 40 | 2 | $note->setURL($url); |
|
| 41 | } |
||
| 42 | |||
| 43 | 2 | $note->setRead(false); |
|
| 44 | |||
| 45 | 2 | if ($note->save()) { |
|
| 46 | 2 | $note->setActor($actor); |
|
| 47 | 2 | return $note; |
|
| 48 | } |
||
| 49 | } |
||
| 50 | } |
||
| 51 |