Skip to content
Snippets Groups Projects
nbrpanelconsentpack.php 5.7 KiB
Newer Older
ErikHommel's avatar
ErikHommel committed
<?php

require_once 'nbrpanelconsentpack.civix.php';
// phpcs:disable
use CRM_Nbrpanelconsentpack_ExtensionUtil as E;
// phpcs:enable

/**
 * Implements hook_civicrm_config().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
 */
function nbrpanelconsentpack_civicrm_config(&$config) {
  _nbrpanelconsentpack_civix_civicrm_config($config);
}

/**
 * Implements hook_civicrm_postProcess().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postProcess
 */
function nbrpanelconsentpack_civicrm_postProcess($formName, $form) {
  if ($form instanceof CRM_Case_Form_Activity) {
    // only if consent activity and create or edit
    if ($form->_action == CRM_Core_Action::ADD || $form->_action == CRM_Core_Action::UPDATE) {
      $activityTypeId = (int) $form->getVar('_activityTypeId');
      if (CRM_Nbrpanelconsentpack_Utils::isValidActivityType($activityTypeId)) {
        CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::savePanelLinks($form);
        CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::savePackLinks($form);
        $form->ajaxResponse['updateTabs']['#tab_nbr_pack_id'] = 1;
ErikHommel's avatar
ErikHommel committed
    }
  }
}
/**
 * Implements hook_civicrm_buildForm().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm
 */
function nbrpanelconsentpack_civicrm_buildForm($formName, &$form) {
  if ($form instanceof CRM_Case_Form_ActivityView) {
    $activityId = (int) CRM_Utils_Request::retrieveValue('aid', "Integer");
    $activityTypeId = CRM_Nbrpanelconsentpack_Utils::getActivityTypeId((int) $activityId);
    if (CRM_Nbrpanelconsentpack_Utils::isValidActivityType($activityTypeId)) {
      CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::addPackLinksToView($form);
      CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::addPanelLinksToView($form);
      CRM_Core_Region::instance('page-body')->add(['template' => 'CRM/Nbrpanelconsentpack/ActivityViewLinks.tpl']);
    }
  if ($form instanceof CRM_Case_Form_Activity) {
    CRM_Nbrpanelconsentpack_BAO_ConsentPanelLink::addPanelPackLinksToConsent($form);
function nbrpanelconsentpack_civicrm_validateForm(string $formName, array &$fields, array &$files, CRM_Core_Form &$form, array &$errors) {
  if ($form instanceof CRM_Case_Form_Activity) {
    CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::validatePackIdFromForm($form, $fields, $errors);
  }
}

/**
 * Implements hook_civicrm_tabset().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_tabset/
 */
function nbrpanelconsentpack_civicrm_tabset($tabsetName, &$tabs, $context) {
  if ($tabsetName == 'civicrm/contact/view' && !empty($context['contact_id'])) {
    if (CRM_Nbrpanelconsentpack_Utils::isVolunteer((int) $context['contact_id'])) {
      $tabs[] = [
        'id'     => 'nbr_pack_id',
        'url'    => CRM_Utils_System::url('civicrm/nbrpanelconsentpack/page/packid', "reset=1&cid=" . $context['contact_id']),
        'title'  => E::ts('Pack IDs'),
        'count'  => CRM_Nbrpanelconsentpack_BAO_ConsentPackLink::countPackIds((int) $context['contact_id']),
        'weight' => 30
      ];
    }
  }
}
ErikHommel's avatar
ErikHommel committed
/**
 * Implements hook_civicrm_install().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
 */
function nbrpanelconsentpack_civicrm_install() {
  _nbrpanelconsentpack_civix_civicrm_install();
}

/**
 * Implements hook_civicrm_postInstall().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
 */
function nbrpanelconsentpack_civicrm_postInstall() {
  _nbrpanelconsentpack_civix_civicrm_postInstall();
}

/**
 * Implements hook_civicrm_uninstall().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
 */
function nbrpanelconsentpack_civicrm_uninstall() {
  _nbrpanelconsentpack_civix_civicrm_uninstall();
}

/**
 * Implements hook_civicrm_enable().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
 */
function nbrpanelconsentpack_civicrm_enable() {
  _nbrpanelconsentpack_civix_civicrm_enable();
}

/**
 * Implements hook_civicrm_disable().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
 */
function nbrpanelconsentpack_civicrm_disable() {
  _nbrpanelconsentpack_civix_civicrm_disable();
}

/**
 * Implements hook_civicrm_upgrade().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
 */
function nbrpanelconsentpack_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
  return _nbrpanelconsentpack_civix_civicrm_upgrade($op, $queue);
}

/**
 * Implements hook_civicrm_entityTypes().
 *
 * Declare entity types provided by this module.
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
 */
function nbrpanelconsentpack_civicrm_entityTypes(&$entityTypes) {
  _nbrpanelconsentpack_civix_civicrm_entityTypes($entityTypes);
}
function nbrpanelconsentpack_civicrm_xmlMenu(&$files) {
  foreach (glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
    $files[] = $file;
  }
}
ErikHommel's avatar
ErikHommel committed

// --- Functions below this ship commented out. Uncomment as required. ---

/**
 * Implements hook_civicrm_preProcess().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
 */
//function nbrpanelconsentpack_civicrm_preProcess($formName, &$form) {
//
//}

/**
 * Implements hook_civicrm_navigationMenu().
 *
 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
 */
//function nbrpanelconsentpack_civicrm_navigationMenu(&$menu) {
//  _nbrpanelconsentpack_civix_insert_navigation_menu($menu, 'Mailings', [
//    'label' => E::ts('New subliminal message'),
//    'name' => 'mailing_subliminal_message',
//    'url' => 'civicrm/mailing/subliminal',
//    'permission' => 'access CiviMail',
//    'operator' => 'OR',
//    'separator' => 0,
//  ]);
//  _nbrpanelconsentpack_civix_navigationMenu($menu);
//}