| 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 | */ |
| 20 | class CRM_Pledge_Info extends CRM_Core_Component_Info { |
| 21 | |
| 22 | /** |
| 23 | * @var string |
| 24 | * @inheritDoc |
| 25 | */ |
| 26 | protected $keyword = 'pledge'; |
| 27 | |
| 28 | /** |
| 29 | * Provides base information about the component. |
| 30 | * Needs to be implemented in component's information |
| 31 | * class. |
| 32 | * |
| 33 | * @return array |
| 34 | * collection of required component settings |
| 35 | */ |
| 36 | public function getInfo() { |
| 37 | return [ |
| 38 | 'name' => 'CiviPledge', |
| 39 | 'translatedName' => ts('CiviPledge'), |
| 40 | 'title' => ts('CiviCRM Pledge Engine'), |
| 41 | 'search' => 1, |
| 42 | 'showActivitiesInCore' => 1, |
| 43 | ]; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @inheritDoc |
| 48 | * Provides permissions that are used by component. |
| 49 | * Needs to be implemented in component's information |
| 50 | * class. |
| 51 | * |
| 52 | * NOTE: if using conditionally permission return, |
| 53 | * implementation of $getAllUnconditionally is required. |
| 54 | * |
| 55 | * @param bool $getAllUnconditionally |
| 56 | * @param bool $descriptions |
| 57 | * Whether to return permission descriptions |
| 58 | * |
| 59 | * @return array|null |
| 60 | * collection of permissions, null if none |
| 61 | */ |
| 62 | public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) { |
| 63 | $permissions = [ |
| 64 | 'access CiviPledge' => [ |
| 65 | ts('access CiviPledge'), |
| 66 | ts('View pledges'), |
| 67 | ], |
| 68 | 'edit pledges' => [ |
| 69 | ts('edit pledges'), |
| 70 | ts('Create and update pledges'), |
| 71 | ], |
| 72 | 'delete in CiviPledge' => [ |
| 73 | ts('delete in CiviPledge'), |
| 74 | ts('Delete pledges'), |
| 75 | ], |
| 76 | ]; |
| 77 | |
| 78 | if (!$descriptions) { |
| 79 | foreach ($permissions as $name => $attr) { |
| 80 | $permissions[$name] = array_shift($attr); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return $permissions; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @inheritDoc |
| 89 | * Provides information about user dashboard element |
| 90 | * offered by this component. |
| 91 | * |
| 92 | * @return array|null |
| 93 | * collection of required dashboard settings, |
| 94 | * null if no element offered |
| 95 | */ |
| 96 | public function getUserDashboardElement() { |
| 97 | return [ |
| 98 | 'name' => ts('Pledges'), |
| 99 | 'title' => ts('Your Pledge(s)'), |
| 100 | // we need to check this permission since you can click on contribution page link for making payment |
| 101 | 'perm' => ['make online contributions'], |
| 102 | 'weight' => 15, |
| 103 | ]; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @inheritDoc |
| 108 | * Provides information about user dashboard element |
| 109 | * offered by this component. |
| 110 | * |
| 111 | * @return array|null |
| 112 | * collection of required dashboard settings, |
| 113 | * null if no element offered |
| 114 | */ |
| 115 | public function registerTab() { |
| 116 | return [ |
| 117 | 'title' => ts('Pledges'), |
| 118 | 'url' => 'pledge', |
| 119 | 'weight' => 25, |
| 120 | ]; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @inheritDoc |
| 125 | * @return string |
| 126 | */ |
| 127 | public function getIcon() { |
| 128 | return 'crm-i fa-paper-plane'; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * @inheritDoc |
| 133 | * Provides information about advanced search pane |
| 134 | * offered by this component. |
| 135 | * |
| 136 | * @return array|null |
| 137 | * collection of required pane settings, |
| 138 | * null if no element offered |
| 139 | */ |
| 140 | public function registerAdvancedSearchPane() { |
| 141 | return [ |
| 142 | 'title' => ts('Pledges'), |
| 143 | 'weight' => 25, |
| 144 | ]; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * @inheritDoc |
| 149 | * Provides potential activity types that this |
| 150 | * component might want to register in activity history. |
| 151 | * Needs to be implemented in component's information |
| 152 | * class. |
| 153 | * |
| 154 | * @return array|null |
| 155 | * collection of activity types |
| 156 | */ |
| 157 | public function getActivityTypes() { |
| 158 | return NULL; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * add shortcut to Create New. |
| 163 | * @param $shortCuts |
| 164 | */ |
| 165 | public function creatNewShortcut(&$shortCuts) { |
| 166 | if (CRM_Core_Permission::check('access CiviPledge') && |
| 167 | CRM_Core_Permission::check('edit pledges') |
| 168 | ) { |
| 169 | $shortCuts = array_merge($shortCuts, [ |
| 170 | [ |
| 171 | 'path' => 'civicrm/pledge/add', |
| 172 | 'query' => 'reset=1&action=add&context=standalone', |
| 173 | 'ref' => 'new-pledge', |
| 174 | 'title' => ts('Pledge'), |
| 175 | ], |
| 176 | ]); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | } |