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