Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Certificates
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Monish Deb
Certificates
Commits
272f7ff5
Commit
272f7ff5
authored
3 weeks ago
by
Monish Deb
Browse files
Options
Downloads
Patches
Plain Diff
QA fixes
parent
9f8f04f7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CRM/Certificates/Upgrader.php
+7
-27
7 additions, 27 deletions
CRM/Certificates/Upgrader.php
certificates.php
+24
-43
24 additions, 43 deletions
certificates.php
managed/EventCertificate.mgd.php
+24
-2
24 additions, 2 deletions
managed/EventCertificate.mgd.php
with
55 additions
and
72 deletions
CRM/Certificates/Upgrader.php
+
7
−
27
View file @
272f7ff5
...
...
@@ -9,37 +9,17 @@ use CRM_Certificates_ExtensionUtil as E;
class
CRM_Certificates_Upgrader
extends
CRM_Extension_Upgrader_Base
{
public
function
upgrade_1002
()
{
// check if the custom group exists
$customGroups
=
\Civi\Api4\CustomGroup
::
get
(
TRUE
)
->
addWhere
(
'name'
,
'='
,
'Event_Certificate'
)
->
setLimit
(
25
)
->
execute
()
->
first
();
if
(
!
$customGroup
)
{
// create the custom group
$customGroup
=
\Civi\Api4\CustomGroup
::
create
(
TRUE
)
->
addValue
(
'title'
,
'Event Certificate'
)
->
addValue
(
'name'
,
'Event_Certificate'
)
->
addValue
(
'extends'
,
'Event'
)
->
addValue
(
'is_active'
,
TRUE
)
->
execute
()
->
first
();
}
$customGroupId
=
$customGroup
[
'id'
];
// check if the custom field exists
$customField
=
\Civi\Api4\CustomField
::
get
(
TRU
E
)
$customField
ID
=
\Civi\Api4\CustomField
::
get
(
FALS
E
)
->
addWhere
(
'name'
,
'='
,
'event_certificate'
)
->
setLimit
(
25
)
->
addWhere
(
'custom_group_id:name'
,
'='
,
'Event_Certificate'
)
->
execute
()
->
first
();
->
first
()
[
'id'
]
??
NULL
;
if
(
!
$customField
)
{
if
(
!
$customField
ID
)
{
// create the custom field
\Civi\Api4\CustomField
::
create
(
TRU
E
)
->
addValue
(
'custom_group_id
'
,
$customGroupId
)
\Civi\Api4\CustomField
::
create
(
FALS
E
)
->
addValue
(
'custom_group_id
.name'
,
'Event_Certificate'
)
->
addValue
(
'label'
,
'Select Certificate for event'
)
->
addValue
(
'name'
,
'event_certificate'
)
->
addValue
(
'data_type'
,
'EntityReference'
)
...
...
@@ -50,6 +30,6 @@ class CRM_Certificates_Upgrader extends CRM_Extension_Upgrader_Base {
->
execute
();
}
return
true
;
return
TRUE
;
}
}
This diff is collapsed.
Click to expand it.
certificates.php
+
24
−
43
View file @
272f7ff5
...
...
@@ -78,32 +78,26 @@ function certificates_civicrm_permission(array &$permissions): void {
function
certificates_civicrm_pre
(
$op
,
$objectName
,
$id
,
&
$params
)
{
if
(
$op
==
'edit'
&&
$objectName
==
'Participant'
)
{
$contactI
d
=
$params
[
'contact_id'
];
$contactI
D
=
$params
[
'contact_id'
];
try
{
$statusId
=
CRM_Core_PseudoConstant
::
getKey
(
'CRM_Event_BAO_Participant'
,
'status_id'
,
'Attended'
);
//get current participant status before data is changed and get event type
$participant
=
\Civi\Api4\Participant
::
get
(
FALSE
)
->
addSelect
(
'status_id'
,
'id'
,
'event_id.Event_Certificate.event_certificate'
)
->
addJoin
(
'Event AS event'
,
'LEFT'
,
[
'event_id'
,
'='
,
'event.id'
])
->
addWhere
(
'contact_id'
,
'='
,
$contactId
)
->
addWhere
(
'status_id:name'
,
'='
,
'Attended'
)
->
execute
()
->
first
();
$participantId
=
$participant
[
'id'
];
// checks if participant status_id is now status id for Attended --> then send email
if
(
$participant
[
'status_id'
]
!==
$statusId
&&
$params
[
'status_id'
]
===
$statusId
)
{
$contact
=
\Civi\Api4\Contact
::
get
(
TRUE
)
->
addSelect
(
'email_primary.email'
,
'display_name'
)
->
addWhere
(
'id'
,
'='
,
$contactId
)
->
setLimit
(
25
)
->
execute
()
->
first
();
if
(
!
empty
(
$participant
))
{
[
$toDisplayName
,
$toEmail
]
=
CRM_Contact_BAO_Contact_Location
::
getEmailDetails
(
$contactID
);
$participantInfo
=
[
'id'
=>
$participant
Id
,
'contact
I
d'
=>
$contactI
d
,
'name'
=>
$
contact
[
'd
isplay
_n
ame
'
]
,
'email'
=>
$
contact
[
'email_primary.email'
]
,
'certificateid'
=>
$participant
[
'event_id.Event_Certificate.event_certificate'
]
'id'
=>
$participant
[
'id'
]
,
'contact
_i
d'
=>
$contactI
D
,
'name'
=>
$
toD
isplay
N
ame
,
'email'
=>
$
toEmail
,
'certificate
_
id'
=>
$participant
[
'event_id.Event_Certificate.event_certificate'
]
];
getEmailContent
(
$participantInfo
);
...
...
@@ -119,19 +113,11 @@ function certificates_civicrm_pre($op, $objectName, $id, &$params) {
* Sends an email with a certificate attachment.
*/
function
getEmailContent
(
$participant
)
{
$mailAttachments
=
[];
try
{
// searches for the certificate, if none found will fallback to default
$eventCertificateID
=
$participant
[
'certificateid'
];
if
(
!
$eventCertificateID
)
{
// fallback to default
$messageTemplateID
=
\Civi
::
settings
()
->
get
(
'certificates_event_defaultmessagetemplateid'
);
}
else
{
$messageTemplateID
=
$eventCertificateID
;
}
$messageTemplateID
=
$participant
[
'certificate_id'
]
??
\Civi
::
settings
()
->
get
(
'certificates_event_defaultmessagetemplateid'
);
if
(
empty
(
$messageTemplateID
))
{
\Civi
::
log
()
->
error
(
'Event attendance certificate has no message template ID set!'
);
...
...
@@ -139,20 +125,18 @@ function getEmailContent($participant) {
}
// query to get the html of the message template given the message template id
$messageTemplate
=
\Civi\Api4\MessageTemplate
::
get
(
TRU
E
)
$messageTemplate
=
\Civi\Api4\MessageTemplate
::
get
(
FALS
E
)
->
addSelect
(
'msg_html'
)
->
addWhere
(
'id'
,
'='
,
$messageTemplateID
)
->
setLimit
(
25
)
->
execute
()
->
first
();
$messageTemplateHTML
=
$messageTemplate
[
'msg_html'
];
->
execute
()
->
first
();
// add default for here
$emailTemplate
=
\Civi\Api4\MessageTemplate
::
get
(
TRU
E
)
$emailTemplate
=
\Civi\Api4\MessageTemplate
::
get
(
FALS
E
)
->
addSelect
(
'msg_subject'
,
'msg_html'
)
->
addWhere
(
'msg_title'
,
'='
,
'Certificate Email'
)
->
setLimit
(
25
)
->
execute
()
->
first
();
->
execute
(
)
->
first
();
if
(
empty
(
$emailTemplate
))
{
// fallback to default email message template if 'Certificate Email' is not found
...
...
@@ -162,7 +146,7 @@ function getEmailContent($participant) {
return
;
}
$emailTemplate
=
\Civi\Api4\MessageTemplate
::
get
(
TRU
E
)
$emailTemplate
=
\Civi\Api4\MessageTemplate
::
get
(
FALS
E
)
->
addSelect
(
'msg_subject'
,
'msg_html'
)
->
addWhere
(
'id'
,
'='
,
$defaultEmailTemplateID
)
->
setLimit
(
1
)
...
...
@@ -174,19 +158,16 @@ function getEmailContent($participant) {
return
;
}
}
$emailTemplateHTML
=
$emailTemplate
[
'msg_html'
];
$emailSubject
=
$emailTemplate
[
'msg_subject'
];
try
{
try
{
$tokenProcessor
=
new
TokenProcessor
(
\Civi
::
dispatcher
(),
[
'controller'
=>
__CLASS__
,
'smarty'
=>
FALSE
,
'schema'
=>
[
'contactId'
,
'participantId'
]
// change depending on what other fields are present in template
]);
$tokenProcessor
->
addMessage
(
'body_html'
,
$messageTemplate
HTML
,
'text/html'
);
$tokenProcessor
->
addRow
([
'contactId'
=>
$participant
[
'contact
I
d'
],
'participantId'
=>
$participant
[
'id'
]]);
$tokenProcessor
->
addMessage
(
'body_html'
,
$messageTemplate
[
'msg_html'
]
,
'text/html'
);
$tokenProcessor
->
addRow
([
'contactId'
=>
$participant
[
'contact
_i
d'
],
'participantId'
=>
$participant
[
'id'
]]);
$tokenProcessor
->
evaluate
();
$tokenProcessorEmail
=
new
TokenProcessor
(
\Civi
::
dispatcher
(),
[
...
...
@@ -195,8 +176,8 @@ function getEmailContent($participant) {
'schema'
=>
[
'contactId'
,
'participantId'
]
// change depending on what other fields are present in template
]);
$tokenProcessorEmail
->
addMessage
(
'body_html'
,
$emailTemplate
HTML
,
'text/html'
);
$tokenProcessorEmail
->
addRow
([
'contactId'
=>
$participant
[
'contact
I
d'
],
'participantId'
=>
$participant
[
'id'
]]);
$tokenProcessorEmail
->
addMessage
(
'body_html'
,
$emailTemplate
[
'msg_html'
]
,
'text/html'
);
$tokenProcessorEmail
->
addRow
([
'contactId'
=>
$participant
[
'contact
_i
d'
],
'participantId'
=>
$participant
[
'id'
]]);
$tokenProcessorEmail
->
evaluate
();
}
catch
(
TypeError
$e
)
{
...
...
@@ -227,9 +208,9 @@ function getEmailContent($participant) {
'from'
=>
$fromEmail
,
'toName'
=>
$participant
[
'name'
],
'toEmail'
=>
$participant
[
'email'
],
'subject'
=>
$email
S
ubject
,
'subject'
=>
$email
Template
[
'msg_s
ubject
'
]
,
'html'
=>
$htmlEmail
,
'contactId'
=>
$participant
[
'contact
I
d'
],
'contactId'
=>
$participant
[
'contact
_i
d'
],
];
$certificateEmail
[
'attachments'
]
=
$mailAttachments
;
...
...
This diff is collapsed.
Click to expand it.
managed/EventCertificate.mgd.php
+
24
−
2
View file @
272f7ff5
...
...
@@ -66,7 +66,6 @@ return [
'time_format'
=>
NULL
,
'note_columns'
=>
60
,
'note_rows'
=>
4
,
'column_name'
=>
'download_certificate_123'
,
'option_group_id'
=>
NULL
,
'serialize'
=>
0
,
'filter'
=>
NULL
,
...
...
@@ -109,7 +108,6 @@ return [
'time_format'
=>
NULL
,
'note_columns'
=>
60
,
'note_rows'
=>
4
,
'column_name'
=>
'duration_130'
,
'option_group_id'
=>
NULL
,
'serialize'
=>
0
,
'filter'
=>
NULL
,
...
...
@@ -122,4 +120,28 @@ return [
],
],
],
[
'name'
=>
'CustomGroup_Event_Certificate_CustomField_Select_Certificate_for_event'
,
'entity'
=>
'CustomField'
,
'cleanup'
=>
'unused'
,
'update'
=>
'unmodified'
,
'params'
=>
[
'version'
=>
4
,
'values'
=>
[
'custom_group_id.name'
=>
'Event_Certificate'
,
'name'
=>
'event_certificate'
,
'label'
=>
E
::
ts
(
'Select Certificate for event'
),
'data_type'
=>
'EntityReference'
,
'html_type'
=>
'Autocomplete-Select'
,
'text_length'
=>
255
,
'note_columns'
=>
60
,
'note_rows'
=>
4
,
'fk_entity'
=>
'MessageTemplate'
,
],
'match'
=>
[
'name'
,
'custom_group_id'
,
],
],
],
];
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment