aboutsummaryrefslogtreecommitdiff
path: root/lib/activities/MessageProvider.php
blob: 0db2ad85ba834402772c30adc1a2cb4ce14d4fd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

/**
 * @author      Till Glöggler <tgloeggl@uos.de>
 * @author      André Klaßen <klassen@elan-ev.de>
 * @license     GPL 2 or later
 */

namespace Studip\Activity;

class MessageProvider implements ActivityProvider
{
    /**
     * get the details for the passed activity
     *
     * @param object $activity the acitivty to fill with details, passed by reference
     */
    public function getActivityDetails($activity)
    {
        $message = \Message::find($activity->object_id);

        if (!$message
            || !$activity->getContextObject()
            || !$message->permissionToRead($activity->getContextObject()->getObserver()->id))
        {
            return false;
        }

        $activity->content = formatReady($message->message);

        $url = \URLHelper::getUrl("dispatch.php/messages/read/{$message->id}", ['cid' => null]);

        $activity->object_url = [
            $url => _('Zur Nachricht')
        ];

        return true;
    }


    /**
     * posts an activity for a given notification event
     *
     * @param String $event a notification for an activity
     * @param Array  $info information which a relevant for the activity
     */
    public static function postActivity($event, $message_id, $data)
    {
        foreach ($data['rec_id'] as $rec_id) {

            // activity for receipent
            $activity = Activity::create(
                [
                    'provider'     => __CLASS__,
                    'context'      => 'user',
                    'context_id'   => $rec_id,
                    'content'      => NULL,
                    'actor_type'   => 'user',           // who initiated the activity?
                    'actor_id'     => $data['user_id'], // id of initiator
                    'verb'         => 'sent',           // the activity type
                    'object_id'    => $message_id,      // the id of the referenced object
                    'object_type'  => 'message',        // type of activity object
                    'mkdate'       => time()
                ]
            );
        }

    }

    /**
     * {@inheritdoc}
     */
    public static function getLexicalField()
    {
        return _('eine Nachricht');
    }

}