Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/aphlict/query/AphlictDropdownDataQuery.php
12256 views
1
<?php
2
3
final class AphlictDropdownDataQuery extends Phobject {
4
5
private $viewer;
6
private $notificationData;
7
private $conpherenceData;
8
9
public function setViewer(PhabricatorUser $viewer) {
10
$this->viewer = $viewer;
11
return $this;
12
}
13
14
public function getViewer() {
15
return $this->viewer;
16
}
17
18
private function setNotificationData(array $data) {
19
$this->notificationData = $data;
20
return $this;
21
}
22
23
public function getNotificationData() {
24
if ($this->notificationData === null) {
25
throw new Exception(pht('You must %s first!', 'execute()'));
26
}
27
return $this->notificationData;
28
}
29
30
private function setConpherenceData(array $data) {
31
$this->conpherenceData = $data;
32
return $this;
33
}
34
35
public function getConpherenceData() {
36
if ($this->conpherenceData === null) {
37
throw new Exception(pht('You must %s first!', 'execute()'));
38
}
39
return $this->conpherenceData;
40
}
41
42
public function execute() {
43
$viewer = $this->getViewer();
44
45
$conpherence_app = 'PhabricatorConpherenceApplication';
46
$is_c_installed = PhabricatorApplication::isClassInstalledForViewer(
47
$conpherence_app,
48
$viewer);
49
if ($is_c_installed) {
50
$raw_message_count_number = $viewer->getUnreadMessageCount();
51
$message_count_number = $this->formatNumber($raw_message_count_number);
52
} else {
53
$raw_message_count_number = null;
54
$message_count_number = null;
55
}
56
57
58
$conpherence_data = array(
59
'isInstalled' => $is_c_installed,
60
'countType' => 'messages',
61
'count' => $message_count_number,
62
'rawCount' => $raw_message_count_number,
63
);
64
$this->setConpherenceData($conpherence_data);
65
66
$notification_app = 'PhabricatorNotificationsApplication';
67
$is_n_installed = PhabricatorApplication::isClassInstalledForViewer(
68
$notification_app,
69
$viewer);
70
if ($is_n_installed) {
71
$raw_notification_count_number = $viewer->getUnreadNotificationCount();
72
$notification_count_number = $this->formatNumber(
73
$raw_notification_count_number);
74
} else {
75
$notification_count_number = null;
76
$raw_notification_count_number = null;
77
}
78
79
$notification_data = array(
80
'isInstalled' => $is_n_installed,
81
'countType' => 'notifications',
82
'count' => $notification_count_number,
83
'rawCount' => $raw_notification_count_number,
84
);
85
$this->setNotificationData($notification_data);
86
87
return array(
88
$notification_app => $this->getNotificationData(),
89
$conpherence_app => $this->getConpherenceData(),
90
);
91
}
92
93
private function formatNumber($number) {
94
$formatted = $number;
95
if ($number > 999) {
96
$formatted = "\xE2\x88\x9E";
97
}
98
return $formatted;
99
}
100
101
}
102
103