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