Merge pull request #17533 from eileenmcnaughton/fatal
[civicrm-core.git] / CRM / Report / Page / Options.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 Gender
20 */
21 class CRM_Report_Page_Options 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 * The option group name.
34 *
35 * @var array
36 */
37 public static $_gName = NULL;
38
39 /**
40 * The option group name in display format (capitalized, without underscores...etc)
41 *
42 * @var array
43 */
44 public static $_GName = NULL;
45
46 /**
47 * The option group id.
48 *
49 * @var array
50 */
51 public static $_gId = NULL;
52
53 /**
54 * Obtains the group name from url and sets the title.
55 */
56 public function preProcess() {
57 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
58 $this->_id = CRM_Utils_Request::retrieve('id', 'String', $this, FALSE);
59
60 self::$_gName = "report_template";
61
62 if (self::$_gName) {
63 self::$_gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'id', 'name');
64 }
65 else {
66 CRM_Core_Error::statusBounce('Unable to determine the Option Group');
67 }
68
69 self::$_GName = ucwords(str_replace('_', ' ', self::$_gName));
70
71 $this->assign('GName', self::$_GName);
72 $newReportURL = CRM_Utils_System::url("civicrm/admin/report/register",
73 'reset=1'
74 );
75 $this->assign('newReport', $newReportURL);
76 CRM_Utils_System::setTitle(ts('Registered Templates'));
77 }
78
79 /**
80 * Get BAO Name.
81 *
82 * @return string
83 * Classname of BAO.
84 */
85 public function getBAOName() {
86 return 'CRM_Core_BAO_OptionValue';
87 }
88
89 /**
90 * Get action Links.
91 *
92 * @return array
93 * (reference) of action links.
94 */
95 public function &links() {
96 if (!(self::$_links)) {
97 self::$_links = [
98 CRM_Core_Action::UPDATE => [
99 'name' => ts('Edit'),
100 'url' => 'civicrm/admin/report/register/' . self::$_gName,
101 'qs' => 'action=update&id=%%id%%&reset=1',
102 'title' => ts('Edit %1', [1 => self::$_gName]),
103 ],
104 CRM_Core_Action::DISABLE => [
105 'name' => ts('Disable'),
106 'ref' => 'crm-enable-disable',
107 'title' => ts('Disable %1', [1 => self::$_gName]),
108 ],
109 CRM_Core_Action::ENABLE => [
110 'name' => ts('Enable'),
111 'ref' => 'crm-enable-disable',
112 'title' => ts('Enable %1', [1 => self::$_gName]),
113 ],
114 CRM_Core_Action::DELETE => [
115 'name' => ts('Delete'),
116 'url' => 'civicrm/admin/report/register/' . self::$_gName,
117 'qs' => 'action=delete&id=%%id%%&reset=1',
118 'title' => ts('Delete %1 Type', [1 => self::$_gName]),
119 ],
120 ];
121 }
122
123 return self::$_links;
124 }
125
126 /**
127 * Run the basic page (run essentially starts execution for that page).
128 */
129 public function run() {
130 $this->preProcess();
131 return parent::run();
132 }
133
134 /**
135 * Browse all options.
136 */
137 public function browse() {
138 $groupParams = ['name' => self::$_gName];
139 $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'weight');
140 $gName = self::$_gName;
141 $returnURL = CRM_Utils_System::url("civicrm/admin/report/options/$gName",
142 "reset=1"
143 );
144 $filter = "option_group_id = " . self::$_gId;
145
146 $session = new CRM_Core_Session();
147 $session->replaceUserContext($returnURL);
148 CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue',
149 'id', $returnURL, $filter
150 );
151 $this->assign('rows', $optionValue);
152 }
153
154 /**
155 * Get name of edit form.
156 *
157 * @return string
158 * Classname of edit form.
159 */
160 public function editForm() {
161 return 'CRM_Report_Form_Register';
162 }
163
164 /**
165 * Get edit form name.
166 *
167 * @return string
168 * name of this page.
169 */
170 public function editName() {
171 return self::$_GName;
172 }
173
174 /**
175 * Get user context.
176 *
177 * @param null $mode
178 *
179 * @return string
180 * user context.
181 */
182 public function userContext($mode = NULL) {
183 return 'civicrm/report/options/' . self::$_gName;
184 }
185
186 /**
187 * Get userContext params.
188 *
189 * @param int $mode
190 * Mode that we are in.
191 *
192 * @return string
193 */
194 public function userContextParams($mode = NULL) {
195 return 'reset=1&action=browse';
196 }
197
198 }