Merge pull request #21291 from eileenmcnaughton/541r
[civicrm-core.git] / CRM / Admin / Page / ScheduleReminders.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Page for displaying list of Reminders.
20 */
21 class CRM_Admin_Page_ScheduleReminders extends CRM_Core_Page_Basic {
22
23 public $useLivePageJS = TRUE;
24
25 /**
26 * The action links that we need to display for the browse screen.
27 *
28 * @var array
29 */
30 public static $_links = NULL;
31
32 /**
33 * Get BAO Name.
34 *
35 * @return string
36 * Classname of BAO.
37 */
38 public function getBAOName() {
39 return 'CRM_Core_BAO_ActionSchedule';
40 }
41
42 /**
43 * Get action Links.
44 *
45 * @return array
46 * (reference) of action links
47 */
48 public function &links() {
49 if (!(self::$_links)) {
50 // helper variable for nicer formatting
51 self::$_links = [
52 CRM_Core_Action::UPDATE => [
53 'name' => ts('Edit'),
54 'url' => 'civicrm/admin/scheduleReminders',
55 'qs' => 'action=update&id=%%id%%&reset=1',
56 'title' => ts('Edit Schedule Reminders'),
57 ],
58 CRM_Core_Action::ENABLE => [
59 'name' => ts('Enable'),
60 'ref' => 'crm-enable-disable',
61 'title' => ts('Enable Label Format'),
62 ],
63 CRM_Core_Action::DISABLE => [
64 'name' => ts('Disable'),
65 'ref' => 'crm-enable-disable',
66 'title' => ts('Disable Label Format'),
67 ],
68 CRM_Core_Action::DELETE => [
69 'name' => ts('Delete'),
70 'url' => 'civicrm/admin/scheduleReminders',
71 'qs' => 'action=delete&id=%%id%%',
72 'title' => ts('Delete Schedule Reminders'),
73 ],
74 ];
75 }
76
77 return self::$_links;
78 }
79
80 /**
81 * Get name of edit form.
82 *
83 * @return string
84 * Classname of edit form.
85 */
86 public function editForm() {
87 return 'CRM_Admin_Form_ScheduleReminders';
88 }
89
90 /**
91 * Get edit form name.
92 *
93 * @return string
94 * name of this page.
95 */
96 public function editName() {
97 return 'ScheduleReminders';
98 }
99
100 /**
101 * Get user context.
102 *
103 * @param null $mode
104 *
105 * @return string
106 * user context.
107 */
108 public function userContext($mode = NULL) {
109 return 'civicrm/admin/scheduleReminders';
110 }
111
112 /**
113 * Browse all Scheduled Reminders settings.
114 *
115 * @param null $action
116 *
117 * @throws \CRM_Core_Exception
118 */
119 public function browse($action = NULL) {
120 //CRM-16777: Do not permit access to user, for page 'Administer->Communication->Schedule Reminder',
121 //when do not have 'administer CiviCRM' permission.
122 if (!CRM_Core_Permission::check('administer CiviCRM')) {
123 CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
124 }
125
126 // Get list of configured reminders
127 $reminderList = CRM_Core_BAO_ActionSchedule::getList();
128
129 // Add action links to each of the reminders
130 foreach ($reminderList as & $format) {
131 $action = array_sum(array_keys($this->links()));
132 if ($format['is_active']) {
133 $action -= CRM_Core_Action::ENABLE;
134 }
135 else {
136 $action -= CRM_Core_Action::DISABLE;
137 }
138 $format['action'] = CRM_Core_Action::formLink(
139 self::links(),
140 $action,
141 ['id' => $format['id']],
142 ts('more'),
143 FALSE,
144 'actionSchedule.manage.action',
145 'ActionSchedule',
146 $format['id']
147 );
148 }
149
150 $this->assign('rows', $reminderList);
151 }
152
153 }