Merge pull request #5086 from deepak-srivastava/CRM-15490
[civicrm-core.git] / CRM / Report / Page / Options.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /**
37 * Page for displaying list of Gender
38 */
39 class CRM_Report_Page_Options extends CRM_Core_Page_Basic {
40
41 public $useLivePageJS = TRUE;
42
43 /**
44 * The action links that we need to display for the browse screen.
45 *
46 * @var array
47 */
48 static $_links = NULL;
49
50 /**
51 * The option group name.
52 *
53 * @var array
54 */
55 static $_gName = NULL;
56
57 /**
58 * The option group name in display format (capitalized, without underscores...etc)
59 *
60 * @var array
61 */
62 static $_GName = NULL;
63
64 /**
65 * The option group id.
66 *
67 * @var array
68 */
69 static $_gId = NULL;
70
71 /**
72 * Obtains the group name from url and sets the title.
73 *
74 * @return void
75 */
76 public function preProcess() {
77 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
78 $this->_id = CRM_Utils_Request::retrieve('id', 'String', $this, FALSE);
79
80 self::$_gName = "report_template";
81
82 if (self::$_gName) {
83 self::$_gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'id', 'name');
84 }
85 else {
86 CRM_Core_Error::fatal();
87 }
88
89 self::$_GName = ucwords(str_replace('_', ' ', self::$_gName));
90
91 $this->assign('GName', self::$_GName);
92 $newReportURL = CRM_Utils_System::url("civicrm/admin/report/register",
93 'reset=1'
94 );
95 $this->assign('newReport', $newReportURL);
96 CRM_Utils_System::setTitle(ts('Registered Templates'));
97 }
98
99 /**
100 * Get BAO Name.
101 *
102 * @return string
103 * Classname of BAO.
104 */
105 public function getBAOName() {
106 return 'CRM_Core_BAO_OptionValue';
107 }
108
109 /**
110 * Get action Links.
111 *
112 * @return array
113 * (reference) of action links
114 */
115 public function &links() {
116 if (!(self::$_links)) {
117 self::$_links = array(
118 CRM_Core_Action::UPDATE => array(
119 'name' => ts('Edit'),
120 'url' => 'civicrm/admin/report/register/' . self::$_gName,
121 'qs' => 'action=update&id=%%id%%&reset=1',
122 'title' => ts('Edit %1', array(1 => self::$_gName)),
123 ),
124 CRM_Core_Action::DISABLE => array(
125 'name' => ts('Disable'),
126 'ref' => 'crm-enable-disable',
127 'title' => ts('Disable %1', array(1 => self::$_gName)),
128 ),
129 CRM_Core_Action::ENABLE => array(
130 'name' => ts('Enable'),
131 'ref' => 'crm-enable-disable',
132 'title' => ts('Enable %1', array(1 => self::$_gName)),
133 ),
134 CRM_Core_Action::DELETE => array(
135 'name' => ts('Delete'),
136 'url' => 'civicrm/admin/report/register/' . self::$_gName,
137 'qs' => 'action=delete&id=%%id%%&reset=1',
138 'title' => ts('Delete %1 Type', array(1 => self::$_gName)),
139 ),
140 );
141 }
142
143 return self::$_links;
144 }
145
146 /**
147 * Run the basic page (run essentially starts execution for that page).
148 *
149 * @return void
150 */
151 public function run() {
152 $this->preProcess();
153 return parent::run();
154 }
155
156 /**
157 * Browse all options.
158 *
159 *
160 * @return void
161 */
162 public function browse() {
163 $groupParams = array('name' => self::$_gName);
164 $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'weight');
165 $gName = self::$_gName;
166 $returnURL = CRM_Utils_System::url("civicrm/admin/report/options/$gName",
167 "reset=1"
168 );
169 $filter = "option_group_id = " . self::$_gId;
170
171 $session = new CRM_Core_Session();
172 $session->replaceUserContext($returnURL);
173 CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue',
174 'id', $returnURL, $filter
175 );
176 $this->assign('rows', $optionValue);
177 }
178
179 /**
180 * Get name of edit form.
181 *
182 * @return string
183 * Classname of edit form.
184 */
185 public function editForm() {
186 return 'CRM_Report_Form_Register';
187 }
188
189 /**
190 * Get edit form name.
191 *
192 * @return string
193 * name of this page.
194 */
195 public function editName() {
196 return self::$_GName;
197 }
198
199 /**
200 * Get user context.
201 *
202 * @param null $mode
203 *
204 * @return string
205 * user context.
206 */
207 public function userContext($mode = NULL) {
208 return 'civicrm/report/options/' . self::$_gName;
209 }
210
211 /**
212 * Get userContext params.
213 *
214 * @param int $mode
215 * Mode that we are in.
216 *
217 * @return string
218 */
219 public function userContextParams($mode = NULL) {
220 return 'reset=1&action=browse';
221 }
222
223 }