Skip to content
Snippets Groups Projects
Forked from Extensions / Certificates
15 commits ahead of the upstream repository.
Edselopez's avatar
Edselopez authored
Changes from Edsel

See merge request !2
68cf3380
History

certificates

A framework for generating PDF certificates.

The extension is licensed under AGPL-3.0.

Installation

Learn more about installing CiviCRM extensions in the CiviCRM Sysadmin Guide.

Getting Started

Permissions

The following permissions control who can download certificates:

  • Print all Participant Certificates: Allow user to print event attendance certificates for any event
  • Print all Activity Certificates: Allow user to print any "activity" certificate
  • Print all Membership Certificates: Allow user to print membership certificates for any contact
  • Print own Certificate: Print certificate for logged in contact only.

Additionally you can implement an event subscriber for civi.certificates.authorize:

Example:

class CertificatesAuthorizeEventSubscriber extends AutoSubscriber {

  /**
   * @inheritDoc
   */
  public static function getSubscribedEvents(): array {
    return [
      'civi.certificates.authorize' => ['onCertificateAuthorize', 0],
    ];
  }

  /**
   * Handler for civi.certificates.authorize event
   *
   * @param \Civi\Certificates\Event\AuthorizeEvent $event
   */
  public function onCertificateAuthorize(AuthorizeEvent $event): void {
    switch ($event->getCertificateType()) {
      case 'membership':
        // Allow the "Main Contact" (relationship) of the Organization to download membership certificate
        //   for that Organization.
        if (!empty(Relationship::get(FALSE)
          ->addWhere('contact_id_a', '=', \CRM_Core_Session::getLoggedInContactID())
          ->addWhere('contact_id_b', '=', $event->getContactID())
          ->addWhere('relationship_type_id:name', '=', 'Main Contact of')
          ->addWhere('is_active', '=', TRUE)
          ->execute()
          ->first())) {
          $event->authorize();
          return;
        }
        \Civi::log()->debug('certificate for membership: contactID: ' . $event->getContactID() . '; membershipID: ' . $event->getEntityID() . ' NOT AUTHORIZED');
        $event->setAuthorized(FALSE);
        break;
    }
  }
}

Event certificates

Configuration

Administer->Communications->Certificates Settings:

  • Event Attendance Certificate Message Template ID: Set to the ID of a message template that you have setup as a template for the event attendance certificate.

Usage

Embed the URL with parameters somewhere (eg. via a button on a searchkit):

civicrm/certificates/attendance/pdf

Parameters (required):

  • cid: Contact ID
  • pid: Participant ID

Example: https://example.org/civicrm/certificates/attendance/pdf?cid=123&pid=456

Activity certificates

Configuration

Administer->Communications->Certificates Settings:

  • List of activity types that are certificates: Specify a list of activitytypes mapped to message templates eg.:
  58:70
  12:68

This would mean: Activity type ID 58 should use message template ID 70 to generate a certificate. Activity type ID 12 should use message template ID 68 to generate a certificate.

Usage

Embed the URL with parameters somewhere (eg. via a button on a searchkit):

civicrm/certificates/activity/pdf

Parameters (required):

  • cid: Contact ID
  • aid: Activity ID

Example: https://example.org/civicrm/certificates/activity/pdf?cid=123&aid=456

Membership certificates

Configuration

Administer->Communications->Certificates Settings:

  • Membership Certificate Message Template ID: Set to the ID of a message template that you have setup as a template for the membership certificate.

Usage

Embed the URL with parameters somewhere (eg. via a button on a searchkit):

civicrm/certificates/membership/pdf

Parameters (required):

  • cid: Contact ID
  • mid: Membership ID

Example: https://example.org/civicrm/certificates/attendance/pdf?cid=123&pid=456