Merge pull request #16192 from eileenmcnaughton/mem_add
[civicrm-core.git] / CRM / Member / Info.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 * This class introduces component to the system and provides all the
14 * information about it. It needs to extend CRM_Core_Component_Info
15 * abstract class.
16 *
17 * @package CRM
18 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * $Id$
20 *
21 */
22 class CRM_Member_Info extends CRM_Core_Component_Info {
23
24 /**
25 * @var string
26 * @inheritDoc
27 */
28 protected $keyword = 'member';
29
30 /**
31 * @inheritDoc
32 * Provides base information about the component.
33 * Needs to be implemented in component's information
34 * class.
35 *
36 * @return array
37 * collection of required component settings
38 */
39
40 /**
41 * @return array
42 */
43 public function getInfo() {
44 return [
45 'name' => 'CiviMember',
46 'translatedName' => ts('CiviMember'),
47 'title' => ts('CiviCRM Membership Engine'),
48 'search' => 1,
49 'showActivitiesInCore' => 1,
50 ];
51 }
52
53 /**
54 * @inheritDoc
55 * Provides permissions that are used by component.
56 * Needs to be implemented in component's information
57 * class.
58 *
59 * NOTE: if using conditionally permission return,
60 * implementation of $getAllUnconditionally is required.
61 *
62 * @param bool $getAllUnconditionally
63 * @param bool $descriptions
64 * Whether to return permission descriptions
65 *
66 * @return array|null
67 * collection of permissions, null if none
68 */
69 public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
70 $permissions = [
71 'access CiviMember' => [
72 ts('access CiviMember'),
73 ts('View memberships'),
74 ],
75 'edit memberships' => [
76 ts('edit memberships'),
77 ts('Create and update memberships'),
78 ],
79 'delete in CiviMember' => [
80 ts('delete in CiviMember'),
81 ts('Delete memberships'),
82 ],
83 ];
84
85 if (!$descriptions) {
86 foreach ($permissions as $name => $attr) {
87 $permissions[$name] = array_shift($attr);
88 }
89 }
90
91 return $permissions;
92 }
93
94 /**
95 * @inheritDoc
96 * Provides information about user dashboard element
97 * offered by this component.
98 *
99 * @return array|null
100 * collection of required dashboard settings,
101 * null if no element offered
102 */
103
104 /**
105 * @return array|null
106 */
107 public function getUserDashboardElement() {
108 return [
109 'name' => ts('Memberships'),
110 'title' => ts('Your Membership(s)'),
111 // this is CiviContribute specific permission, since
112 // there is no permission that could be checked for
113 // CiviMember
114 'perm' => ['make online contributions'],
115 'weight' => 30,
116 ];
117 }
118
119 /**
120 * @inheritDoc
121 * Provides information about user dashboard element
122 * offered by this component.
123 *
124 * @return array|null
125 * collection of required dashboard settings,
126 * null if no element offered
127 */
128
129 /**
130 * @return array|null
131 */
132 public function registerTab() {
133 return [
134 'title' => ts('Memberships'),
135 'url' => 'membership',
136 'weight' => 30,
137 ];
138 }
139
140 /**
141 * @inheritDoc
142 * @return string
143 */
144 public function getIcon() {
145 return 'crm-i fa-id-badge';
146 }
147
148 /**
149 * @inheritDoc
150 * Provides information about advanced search pane
151 * offered by this component.
152 *
153 * @return array|null
154 * collection of required pane settings,
155 * null if no element offered
156 */
157
158 /**
159 * @return array|null
160 */
161 public function registerAdvancedSearchPane() {
162 return [
163 'title' => ts('Memberships'),
164 'weight' => 30,
165 ];
166 }
167
168 /**
169 * @inheritDoc
170 * Provides potential activity types that this
171 * component might want to register in activity history.
172 * Needs to be implemented in component's information
173 * class.
174 *
175 * @return array|null
176 * collection of activity types
177 */
178
179 /**
180 * @return array|null
181 */
182 public function getActivityTypes() {
183 return NULL;
184 }
185
186 /**
187 * add shortcut to Create New.
188 * @param $shortCuts
189 * @param $newCredit
190 */
191 public function creatNewShortcut(&$shortCuts, $newCredit) {
192 if (CRM_Core_Permission::check('access CiviMember') &&
193 CRM_Core_Permission::check('edit memberships')
194 ) {
195 $shortCut[] = [
196 'path' => 'civicrm/member/add',
197 'query' => "reset=1&action=add&context=standalone",
198 'ref' => 'new-membership',
199 'title' => ts('Membership'),
200 ];
201 if ($newCredit) {
202 $title = ts('Membership') . '<br />&nbsp;&nbsp;(' . ts('credit card') . ')';
203 $shortCut[0]['shortCuts'][] = [
204 'path' => 'civicrm/member/add',
205 'query' => "reset=1&action=add&context=standalone&mode=live",
206 'ref' => 'new-membership-cc',
207 'title' => $title,
208 ];
209 }
210 $shortCuts = array_merge($shortCuts, $shortCut);
211 }
212 }
213
214 }