-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull.php
82 lines (64 loc) · 2.56 KB
/
pull.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
74
75
76
77
78
79
80
81
82
<?php
ob_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once("base/UserSystem.class.php");
require_once("base/SessionPersistentNotificationSystem.class.php");
require_once("ActionButtonManager.class.php");
$pullRequestHandler = new PullRequestHandler();
$errorsAndWarnings = ob_get_clean();
if (isset($_GET["actionButtonUpdateRequest"])) {
$pullRequestHandler->addActionButtonUpdateResponse();
}
if (isset($_GET["createNotification"])) {
/*TEST*/
$n = createNotificationTargetingAllCurrentlyOpenSessions("Text for Test notification", "TITLE", "success");
$ns = SessionPersistentNotificationSystem::get("main");
$ns->save($n);
/*TEST ENDE*/
}
if (isset($_GET["notificationsPull"])) {
$pullRequestHandler->addNotificationResponse();
}
if ($pullRequestHandler->hasResponse()) {
header('Content-Type: application/json');
echo $pullRequestHandler->createJson();
die();
}
function createNotificationTargetingAllCurrentlyOpenSessions($text = "", $title = "", $classification = "") {
$toIdMapper = function($session) { return $session->getId(); };
$currentSessionIds = array_map($toIdMapper, UserSystem::get()->getAllCurrentlyOpenSessions());
return new SessionTargetingNotification($currentSessionIds, $text, $title, $classification);
}
class PullRequestHandler {
protected $response = [];
public function __construct(){}
public function addNotificationResponse() {
$notificationSystem = SessionPersistentNotificationSystem::get("main");
$notifications = $notificationSystem->getNotificationsForAuthSession();
foreach ($notifications as $notification) {
$builder = XhrResponseBuilder::createFor($notification);
$notificationSystem->delete($notification); //todo löschen von Notifications für einmaliges abholen.
$builder->addArrayValue("cause", "notificationsPull");
$this->response[] = $builder->getResponse();
}
return $this->response;
}
public function addActionButtonUpdateResponse() {
//alternativ könnte man auch den gesamten Button neu printen...
$actionButtons = ActionButtonManager::get()->getActionButtons();
foreach ($actionButtons as $actionButton) {
$builder = XhrResponseBuilder::createFor($actionButton);
$builder->addArrayValue("cause", "actionButtonUpdateRequest");
$this->response[] = $builder->getResponse();
}
return $this->response;
}
public function hasResponse() {
return sizeof($this->response) > 0;
}
public function createJson() {
return json_encode($this->response);
}
}
?>