-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivityhooks.php
executable file
·73 lines (60 loc) · 3 KB
/
activityhooks.php
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
<?php
namespace OCA\Files_Accounting;
use \OCP\Util;
use \OCP\User;
use \OCP\DB;
class ActivityHooks {
public static function register() {
Util::connectHook('OC_Activity', 'post_create', 'ActivityHooks', 'invoiceCreate');
Util::connectHook('OC_Activity', 'complete', 'ActivityHooks', 'paymentComplete');
// hooking up the activity manager
$am = \OC::$server->getActivityManager();
$am->registerConsumer(function() {
return new Consumer();
});
}
public static function invoiceCreate($user, $params) {
ActivityHooks::addNotificationsForAction($user, $params, \Bill_Activity::TYPE_INVOICE, 'new_invoice',
$params['priority']);
}
public static function paymentComplete($user, $params) {
ActivityHooks::addNotificationsForAction($user, $params, \Bill_Activity::TYPE_INVOICE, 'payment_complete',
\OCA\UserNotification\Data::PRIORITY_MEDIUM);
}
public static function spaceExceed($user, $params) {
ActivityHooks::addNotificationsForAction($user, $params, \Bill_Activity::TYPE_INVOICE, 'exceeded_space',
\OCA\UserNotification\Data::PRIORITY_HIGH);
}
public static function preapprovedPayments($user) {
ActivityHooks::addNotificationsForAction($user, '', \Bill_Activity::TYPE_INVOICE, 'preapproved_payments',
\OCA\UserNotification\Data::PRIORITY_MEDIUM);
}
public static function automaticPaymentComplete($user, $params) {
ActivityHooks::addNotificationsForAction($user, $params, \Bill_Activity::TYPE_INVOICE, 'automatic_payment_complete',
\OCA\UserNotification\Data::PRIORITY_MEDIUM);
}
public static function addNotificationsForAction($user, $params, $activityType, $subject, $priority) {
ActivityHooks::addNotificationsForUser(
$user, $subject,
$params,
$priority,
$activityType
);
}
protected static function addNotificationsForUser($user, $subject, $params, $priority , $type ) {
$app = 'files_accounting';
$link = $url = \OCA\Files_Accounting\Storage_Lib::getBillingURL($user, false);
ActivityHooks::send($app, $subject, $params, '', array(), '', $link, $user, $type, $priority);
}
public static function send($app, $subject, $subjectparams = array(), $message = '', $messageparams = array(), $file = '', $link = '', $affecteduser = '', $type = '', $prio) {
$timestamp = time();
$user = $affecteduser;
$auser = $affecteduser;
// store in DB
$query = DB::prepare('INSERT INTO `*PREFIX*activity`(`app`, `subject`, `subjectparams`, `message`, `messageparams`, `file`, `link`, `user`, `affecteduser`, `timestamp`, `priority`, `type`)' . ' VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )');
$query->execute(array($app, $subject, serialize($subjectparams), $message, serialize($messageparams), $file, $link, $user, $auser, $timestamp, $prio, $type));
// fire a hook so that other apps like notification systems can connect
Util::emitHook('OC_Activity', 'post_event', array('app' => $app, 'subject' => $subject, 'user' => $user, 'affecteduser' => $affecteduser, 'message' => $message, 'file' => $file, 'link'=> $link, 'prio' => $prio, 'type' => $type));
return true;
}
}