Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MMB-78: Merge workstream branch #90

Merged
merged 24 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
776731e
MMB-270: Introduce min and max validity dates for certificates
shahrukh-moby Nov 2, 2023
4fc1c9e
MMB-270: Add min and max date fields to certificate forms
shahrukh-moby Nov 2, 2023
23e32fb
MMB-270: Add min and max dates to test fabricators
shahrukh-moby Nov 2, 2023
bfcf3a5
Merge pull request #78 from compucorp/MMB-270-add-min-max-date-fields
shahrukh-compuco Nov 3, 2023
2ad7abb
MMB-271: Add certificate validity date tokens
shahrukh-moby Nov 3, 2023
799c096
MMB-272: Add validity dates check for certificate download
shahrukh-moby Nov 6, 2023
39a67e5
MMB-78: Update test container
shahrukh-moby Nov 6, 2023
6228ebd
Merge branch 'MMB-78-workstream' of github.com:compucorp/uk.co.compuc…
shahrukh-moby Nov 6, 2023
00c5c68
Merge branch 'MMB-78-workstream' into MMB-271-add-min-max-date-tokens
shahrukh-moby Nov 6, 2023
57e196a
Merge branch 'MMB-78-workstream' into MMB-272-restrict-certificate-ac…
shahrukh-moby Nov 6, 2023
6620a27
MMB-271: Refactor code to use status name instead of status id
shahrukh-moby Nov 6, 2023
1c57150
MMB-273: Add renewal or rolling start date token
shahrukh-moby Nov 6, 2023
31c2d35
Merge pull request #81 from compucorp/MMB-272-restrict-certificate-ac…
shahrukh-compuco Nov 27, 2023
66dea7d
MMB-284: Handle multiple active memberships for a contact
shahrukh-moby Nov 7, 2023
e37e80f
Merge pull request #83 from compucorp/MMB-284-multiple-current-member…
shahrukh-compuco Dec 5, 2023
8e0666c
MMB-282: Add field to store certificate type of file
olayiwola-compucorp Nov 14, 2023
4fb9053
MMB-282: Allow user to specify certificate download file
olayiwola-compucorp Nov 14, 2023
086dfc6
MMB-282: Allow downloading the certificate uploaded file
olayiwola-compucorp Nov 14, 2023
ba7103f
Merge pull request #84 from compucorp/MMB-282-certificate-type
olayiwola-compucorp Dec 12, 2023
e7819f7
MMB-302: Add help text to certificate download type field
olayiwola-compucorp Dec 12, 2023
a53c1aa
MMB-306: Restrict validity dates and tokens to just membership type c…
shahrukh-moby Dec 21, 2023
0c1a6f8
MMB-306: Change logic for calculating rolling date token value
Jan 29, 2024
1ac2cea
Merge pull request #86 from compucorp/MMB-306-Restrict-tokens-to-memb…
shahrukh-compuco Jan 29, 2024
b15c1f8
Merge pull request #85 from compucorp/MMB-302-help-type
olayiwola-compucorp Feb 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
run-unit-tests:

runs-on: ubuntu-latest
container: compucorp/civicrm-buildkit:1.3.0-php8.0-chrome
container: compucorp/civicrm-buildkit:1.3.1-php8.0-chrome

env:
CIVICRM_EXTENSIONS_DIR: site/web/sites/all/modules/civicrm/tools/extensions
Expand Down
26 changes: 26 additions & 0 deletions CRM/Certificate/BAO/CompuCertificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use CRM_Certificate_ExtensionUtil as E;
use CRM_Contact_BAO_Relationship as Relationship;
use CRM_Certificate_Enum_DownloadType as DownloadType;
use CRM_Certificate_Enum_DownloadFormat as DownloadFormat;
use CRM_Certificate_BAO_CompuCertificateStatus as CompuCertificateStatus;
use CRM_Certificate_BAO_CompuCertificateEntityType as CompuCertificateEntityType;
Expand Down Expand Up @@ -35,6 +36,8 @@ public static function deleteById($id) {
$entityName = 'CompuCertificate';

CRM_Utils_Hook::pre('delete', $entityName, $id);
\CRM_Core_BAO_File::deleteEntityFile(self::getTableName(), $id);

$instance = new $className();
$instance->id = $id;
$instance->delete();
Expand Down Expand Up @@ -114,6 +117,18 @@ public static function getSupportedDownloadFormats() {
];
}

/**
* Returns the supported download types.
*
* @return array
*/
public static function getSupportedDownloadTypes() {
return [
DownloadType::TEMPLATE => E::ts('Message Template'),
DownloadType::FILE_DOWNLOAD => E::ts('Download File'),
];
}

/**
* Add condition to ensure the certificate start_date and end_date is valid.
*/
Expand All @@ -134,4 +149,15 @@ public function getRelationshipTypes(string $column = NULL) {
return $relationshipTypes;
}

/**
* Returens the certificate file
*
* @param int $id
*
* @return array
*/
public static function getFile($id) {
return \CRM_Core_BAO_File::getEntityFile(CRM_Certificate_DAO_CompuCertificate::getTableName(), $id);
}

}
102 changes: 94 additions & 8 deletions CRM/Certificate/DAO/CompuCertificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from uk.co.compucorp.certificate/xml/schema/CRM/Certificate/CompuCertificate.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:92a589ff877665033271ff1e67bee30e)
* (GenCodeChecksum:18ec0a71f942b6ee070017e3e236afb5)
*/
use CRM_Certificate_ExtensionUtil as E;

Expand Down Expand Up @@ -34,52 +34,89 @@ class CRM_Certificate_DAO_CompuCertificate extends CRM_Core_DAO {
/**
* Unique CompuCertificate ID
*
* @var int
* @var int|string|null
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $id;

/**
* Certificate name
*
* @var string
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
public $name;

/**
* Predefined CompuCertificate Entity ID (1 - CASE, 2 - MEMBERSHIP, 3 - EVENT)
*
* @var int
* @var int|string
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $entity;

/**
* FK to message template
*
* @var int
* @var int|string
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $template_id;

/**
* Predefined CompuCertificate download format (1 - PDF, 2 - IMAGE)
*
* @var int
* @var int|string
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $download_format;

/**
* Predefined CompuCertificate download type (1 - MESSAGE TEMPLATE, 2 - FILE)
*
* @var int|string
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $download_type;

/**
* Date the certificate validity starts
*
* @var date
* @var string
* (SQL type: date)
* Note that values will be retrieved from the database as a string.
*/
public $start_date;

/**
* Date the certificate validity ends
*
* @var date
* @var string
* (SQL type: date)
* Note that values will be retrieved from the database as a string.
*/
public $end_date;

/**
* Min date the certificate validity starts
*
* @var date
*/
public $min_valid_from_date;

/**
* Max date the certificate validity ends
*
* @var date
*/
public $max_valid_through_date;

/**
* Class constructor.
*/
Expand Down Expand Up @@ -175,7 +212,7 @@ public static function &fields() {
'name' => 'template_id',
'type' => CRM_Utils_Type::T_INT,
'description' => E::ts('FK to message template'),
'required' => TRUE,
'required' => FALSE,
'where' => 'compucertificate_certificate.template_id',
'table_name' => 'compucertificate_certificate',
'entity' => 'CompuCertificate',
Expand Down Expand Up @@ -203,6 +240,23 @@ public static function &fields() {
],
'add' => NULL,
],
'download_type' => [
'name' => 'download_type',
'type' => CRM_Utils_Type::T_INT,
'title' => E::ts('Download Type'),
'description' => E::ts('Predefined CompuCertificate download type (1 - MESSAGE TEMPLATE, 2 - FILE)'),
'required' => FALSE,
'where' => 'compucertificate_certificate.download_type',
'default' => '1',
'table_name' => 'compucertificate_certificate',
'entity' => 'CompuCertificate',
'bao' => 'CRM_Certificate_DAO_CompuCertificate',
'localizable' => 0,
'html' => [
'type' => 'Number',
],
'add' => NULL,
],
'start_date' => [
'name' => 'start_date',
'type' => CRM_Utils_Type::T_DATE,
Expand Down Expand Up @@ -235,6 +289,38 @@ public static function &fields() {
],
'add' => NULL,
],
'min_valid_from_date' => [
'name' => 'min_valid_from_date',
'type' => CRM_Utils_Type::T_DATE,
'title' => E::ts('Min Valid From Date'),
'description' => E::ts('Min date the certificate validity starts'),
'required' => FALSE,
'where' => 'compucertificate_certificate.min_valid_from_date',
'table_name' => 'compucertificate_certificate',
'entity' => 'CompuCertificate',
'bao' => 'CRM_Certificate_DAO_CompuCertificate',
'localizable' => 0,
'html' => [
'type' => 'Select Date',
],
'add' => NULL,
],
'max_valid_through_date' => [
'name' => 'max_valid_through_date',
'type' => CRM_Utils_Type::T_DATE,
'title' => E::ts('Max Valid Through Date'),
'description' => E::ts('Max date the certificate validity ends'),
'required' => FALSE,
'where' => 'compucertificate_certificate.max_valid_through_date',
'table_name' => 'compucertificate_certificate',
'entity' => 'CompuCertificate',
'bao' => 'CRM_Certificate_DAO_CompuCertificate',
'localizable' => 0,
'html' => [
'type' => 'Select Date',
],
'add' => NULL,
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
Expand Down
19 changes: 18 additions & 1 deletion CRM/Certificate/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ public function getCertificateConfigurationById($certificateId) {
'type' => $certificateBAO->entity,
'end_date' => $certificateBAO->end_date,
'start_date' => $certificateBAO->start_date,
'download_type' => $certificateBAO->download_type,
'download_format' => $certificateBAO->download_format,
'message_template_id' => $certificateBAO->template_id,
'linked_to' => implode(',', array_column($types, 'id')),
'statuses' => implode(',', array_column($statuses, 'id')),
'relationship_types' => implode(',', array_column($relationshipTypes, 'relationship_type_id')),
'min_valid_from_date' => $certificateBAO->min_valid_from_date,
'max_valid_through_date' => $certificateBAO->max_valid_through_date,
];

$this->addEntityExtraField($certificateBAO, $certificate);
Expand Down Expand Up @@ -110,7 +113,7 @@ public function getCertificateConfiguration($entityId, $contactId) {
$certificateBAO->selectAdd(CRM_Certificate_DAO_CompuCertificate::$_tableName . '.id');
$certificateBAO->find(TRUE);

if (!empty($certificateBAO->id)) {
if (!empty($certificateBAO->id) && $this->isCertificateValidForAnEntity($certificateBAO, $contactId)) {
return $certificateBAO;
}
}
Expand Down Expand Up @@ -161,6 +164,20 @@ abstract protected function addEntityConditionals($certificateBAO, $entityId, $c
*/
protected function addEntityExtraField($certificateBAO, &$certificate) {}

/**
* Validate a certificate against entity specific checks.
*
* @param \CRM_Certificate_BAO_CompuCertificate $certificate
* Certificate.
* @param int $contactId
* Contact id.
*
* @return bool
*/
protected function isCertificateValidForAnEntity(\CRM_Certificate_BAO_CompuCertificate $certificate, int $contactId) {
return TRUE;
}

/**
* Gets all entity certificates vailable for a contact.
*
Expand Down
10 changes: 10 additions & 0 deletions CRM/Certificate/Entity/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,14 @@ public function getEntity() {
return CertificateType::MEMBERSHIPS;
}

/**
* @inheritDoc
*/
protected function isCertificateValidForAnEntity(\CRM_Certificate_BAO_CompuCertificate $certificate, int $contactId) {
$membershipDates = (new CRM_Certificate_Service_CertificateMembership())->getMembershipDates($certificate->id, $contactId);

return ($membershipDates['startDate'] === NULL || $certificate->max_valid_through_date === NULL || $membershipDates['startDate'] <= $certificate->max_valid_through_date)
&& ($membershipDates['endDate'] === NULL || $certificate->min_valid_from_date === NULL || $membershipDates['endDate'] >= $certificate->min_valid_from_date);
}

}
14 changes: 14 additions & 0 deletions CRM/Certificate/Enum/DownloadType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* Declares the constants for supported download formats.
*
* This is different from DownloadFormat, as this specifies
* the content that will be returned to the user.
*/
class CRM_Certificate_Enum_DownloadType {

const TEMPLATE = '1';
const FILE_DOWNLOAD = '2';

}
Loading
Loading