Merge pull request #17473 from eileenmcnaughton/anet
[civicrm-core.git] / CRM / SMS / Page / Provider.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 Providers
20 */
21 class CRM_SMS_Page_Provider 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_SMS_BAO_Provider';
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 self::$_links = array(
51 CRM_Core_Action::UPDATE => array(
52 'name' => ts('Edit'),
53 'url' => 'civicrm/admin/sms/provider',
54 'qs' => 'action=update&id=%%id%%&reset=1',
55 'title' => ts('Edit Provider'),
56 ),
57 CRM_Core_Action::DELETE => array(
58 'name' => ts('Delete'),
59 'url' => 'civicrm/admin/sms/provider',
60 'qs' => 'action=delete&id=%%id%%',
61 'title' => ts('Delete Provider'),
62 ),
63 CRM_Core_Action::ENABLE => array(
64 'name' => ts('Enable'),
65 'ref' => 'crm-enable-disable',
66 'title' => ts('Enable Provider'),
67 ),
68 CRM_Core_Action::DISABLE => array(
69 'name' => ts('Disable'),
70 'ref' => 'crm-enable-disable',
71 'title' => ts('Disable Provider'),
72 ),
73 );
74 }
75 return self::$_links;
76 }
77
78 /**
79 * Run the page.
80 *
81 * This method is called after the page is created. It checks for the
82 * type of action and executes that action.
83 * Finally it calls the parent's run method.
84 */
85 public function run() {
86 // set title and breadcrumb
87 CRM_Utils_System::setTitle(ts('Settings - SMS Provider'));
88 $breadCrumb = array(
89 array(
90 'title' => ts('SMS Provider'),
91 'url' => CRM_Utils_System::url('civicrm/admin/sms/provider',
92 'reset=1'
93 ),
94 ),
95 );
96 CRM_Utils_System::appendBreadCrumb($breadCrumb);
97
98 $this->_id = CRM_Utils_Request::retrieve('id', 'String',
99 $this, FALSE, 0
100 );
101 $this->_action = CRM_Utils_Request::retrieve('action', 'String',
102 $this, FALSE, 0
103 );
104
105 return parent::run();
106 }
107
108 /**
109 * Browse all Providers.
110 *
111 * @param array $action
112 */
113 public function browse($action = NULL) {
114 $providers = CRM_SMS_BAO_Provider::getProviders();
115 $rows = [];
116 foreach ($providers as $provider) {
117 $action = array_sum(array_keys($this->links()));
118 // update enable/disable links.
119 if ($provider['is_active']) {
120 $action -= CRM_Core_Action::ENABLE;
121 }
122 else {
123 $action -= CRM_Core_Action::DISABLE;
124 }
125
126 $apiTypes = CRM_Core_OptionGroup::values('sms_api_type', FALSE, FALSE, FALSE, NULL, 'label');
127 $provider['api_type'] = $apiTypes[$provider['api_type']];
128
129 $provider['action'] = CRM_Core_Action::formLink(self::links(), $action,
130 array('id' => $provider['id']),
131 ts('more'),
132 FALSE,
133 'sms.provider.row',
134 'SMSProvider',
135 $provider['id']
136 );
137 $rows[] = $provider;
138 }
139 $this->assign('rows', $rows);
140 }
141
142 /**
143 * Get name of edit form.
144 *
145 * @return string
146 * Classname of edit form.
147 */
148 public function editForm() {
149 return 'CRM_SMS_Form_Provider';
150 }
151
152 /**
153 * Get edit form name.
154 *
155 * @return string
156 * name of this page.
157 */
158 public function editName() {
159 return 'SMS Provider';
160 }
161
162 /**
163 * Get user context.
164 *
165 * @param null $mode
166 *
167 * @return string
168 * user context.
169 */
170 public function userContext($mode = NULL) {
171 return 'civicrm/admin/sms/provider';
172 }
173
174 }