Completed
Push — master ( 8c750e...83c768 )
by Maxence
01:45
created

Broadcaster::createShareToUser()   A

Complexity

Conditions 2
Paths 8

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 2
eloc 12
nc 8
nop 2
1
<?php
2
3
namespace OCA\Mood\Circles;
4
5
use OCA\Circles\IBroadcaster;
6
use OCA\Circles\Model\SharingFrame;
7
use OCA\Mood\AppInfo\Application;
8
use OCP\Activity\IManager;
9
10
class Broadcaster implements IBroadcaster {
11
12
	/** @var IManager */
13
	private $activityManager;
14
15
	/**
16
	 * {@inheritdoc}
17
	 */
18
	public function init() {
19
		$app = new Application();
20
		$c = $app->getContainer();
21
22
		$this->activityManager = $c->query('ActivityManager');
23
	}
24
25
	/**
26
	 * {@inheritdoc}
27
	 */
28
	public function createShareToUser(SharingFrame $frame, $userId) {
29
30
		try {
31
			$event = $this->activityManager->generateEvent();
32
			$event->setApp('mood');
33
			$event->setType('mood');
34
			$event->setAffectedUser($userId);
35
			$event->setAuthor($frame->getAuthor());
36
			$event->setSubject('mood_item', ['share' => json_encode($frame)]);
37
38
			$this->activityManager->publish($event);
39
40
			return true;
41
		} catch (\Exception $e) {
42
			return false;
43
		}
44
	}
45
46
47
	/**
48
	 * {@inheritdoc}
49
	 */
50
	public function deleteShareToUser(SharingFrame $frame, $userId) {
51
		return true;
52
	}
53
54
55
	/**
56
	 * {@inheritdoc}
57
	 */
58
	public function editShareToUser(SharingFrame $frame, $userId) {
59
		return true;
60
	}
61
62
63
	/**
64
	 * {@inheritdoc}
65
	 */
66
	public function createShareToCircle(SharingFrame $frame) {
67
		return true;
68
	}
69
70
	/**
71
	 * {@inheritdoc}
72
	 */
73
	public function deleteShareToCircle(SharingFrame $frame) {
74
		return true;
75
	}
76
77
	/**
78
	 * {@inheritdoc}
79
	 */
80
	public function editShareToCircle(SharingFrame $frame) {
81
		return true;
82
	}
83
84
85
}