+++ /dev/null
-<?php
-/*
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC. All rights reserved. |
- | |
- | This work is published under the GNU AGPLv3 license with some |
- | permitted exceptions and without any warranty. For full license |
- | and copyright information, see https://civicrm.org/licensing |
- +--------------------------------------------------------------------+
- */
-
-/**
- * This class introduces component to the system and provides all the
- * information about it. It needs to extend CRM_Core_Component_Info
- * abstract class.
- *
- * @package CRM
- * @copyright CiviCRM LLC https://civicrm.org/licensing
- */
-class CRM_Grant_Info extends CRM_Core_Component_Info {
-
- /**
- * @var string
- * @inheritDoc
- */
- protected $keyword = 'grant';
-
- /**
- * @inheritDoc
- * @return array
- */
- public function getInfo() {
- return [
- 'name' => 'CiviGrant',
- 'translatedName' => ts('CiviGrant'),
- 'title' => 'CiviCRM Grant Management Engine',
- 'path' => 'CRM_Grant_',
- 'search' => 1,
- 'showActivitiesInCore' => 1,
- ];
- }
-
- /**
- * @inheritDoc
- * @param bool $getAllUnconditionally
- * @param bool $descriptions
- * Whether to return permission descriptions
- *
- * @return array
- */
- public function getPermissions($getAllUnconditionally = FALSE, $descriptions = FALSE) {
- $permissions = [
- 'access CiviGrant' => [
- ts('access CiviGrant'),
- ts('View all grants'),
- ],
- 'edit grants' => [
- ts('edit grants'),
- ts('Create and update grants'),
- ],
- 'delete in CiviGrant' => [
- ts('delete in CiviGrant'),
- ts('Delete grants'),
- ],
- ];
-
- if (!$descriptions) {
- foreach ($permissions as $name => $attr) {
- $permissions[$name] = array_shift($attr);
- }
- }
-
- return $permissions;
- }
-
- /**
- * @inheritDoc
- * @return null
- */
- public function getUserDashboardElement() {
- // no dashboard element for this component
- return NULL;
- }
-
- /**
- * @inheritDoc
- * @return null
- */
- public function getUserDashboardObject() {
- // no dashboard element for this component
- return NULL;
- }
-
- /**
- * @inheritDoc
- * @return array
- */
- public function registerTab() {
- return [
- 'title' => ts('Grants'),
- 'url' => 'grant',
- 'weight' => 60,
- ];
- }
-
- /**
- * @inheritDoc
- * @return string
- */
- public function getIcon() {
- return 'crm-i fa-money';
- }
-
- /**
- * @inheritDoc
- * @return array
- */
- public function registerAdvancedSearchPane() {
- return [
- 'title' => ts('Grants'),
- 'weight' => 50,
- ];
- }
-
- /**
- * @inheritDoc
- * @return null
- */
- public function getActivityTypes() {
- return NULL;
- }
-
- /**
- * add shortcut to Create New.
- * @param $shortCuts
- */
- public function creatNewShortcut(&$shortCuts) {
- if (CRM_Core_Permission::check('access CiviGrant') &&
- CRM_Core_Permission::check('edit grants')
- ) {
- $shortCuts = array_merge($shortCuts, [
- [
- 'path' => 'civicrm/grant/add',
- 'query' => "reset=1&action=add&context=standalone",
- 'ref' => 'new-grant',
- 'title' => ts('Grant'),
- ],
- ]);
- }
- }
-
-}
function civigrant_civicrm_entityTypes(&$entityTypes) {
_civigrant_civix_civicrm_entityTypes($entityTypes);
}
+
+/**
+ * Implements hook_civicrm_links().
+ *
+ * Add shortcut link to create new grant.
+ */
+function civigrant_civicrm_links($context, $name, $id, &$links) {
+ if ($context === 'create.new.shortcuts' && CRM_Core_Permission::check(['access CiviGrant', 'edit grants'])) {
+ $links[] = [
+ 'path' => 'civicrm/grant/add',
+ 'query' => "reset=1&action=add&context=standalone",
+ 'ref' => 'new-grant',
+ 'title' => ts('Grant'),
+ ];
+ }
+}
+
+/**
+ * Implements hook_civicrm_permission().
+ *
+ * Define CiviGrant permissions.
+ */
+function civigrant_civicrm_permission(&$permissions) {
+ $permissions['access CiviGrant'] = [
+ E::ts('access CiviGrant'),
+ E::ts('View all grants'),
+ ];
+ $permissions['edit grants'] = [
+ E::ts('edit grants'),
+ E::ts('Create and update grants'),
+ ];
+ $permissions['delete in CiviGrant'] = [
+ E::ts('delete in CiviGrant'),
+ E::ts('Delete grants'),
+ ];
+}
+
+/**
+ * Implements hook_civicrm_tabSet().
+ *
+ * Add grants tab to contact summary screen.
+ */
+function civigrant_civicrm_tabSet($tabSetName, &$tabs, $context) {
+ if ($tabSetName === 'civicrm/contact/view' && !empty($context['contact_id'])) {
+ $cid = $context['contact_id'];
+ $tabs[] = [
+ 'id' => 'grant',
+ 'url' => CRM_Utils_System::url("civicrm/contact/view/grant", ['reset' => 1, 'cid' => $cid]),
+ 'title' => E::ts('Grants'),
+ 'weight' => 60,
+ 'count' => CRM_Grant_BAO_Grant::getContactGrantCount($cid),
+ 'class' => 'livePage',
+ 'icon' => 'crm-i fa-money',
+ ];
+ }
+}