Skip to content

Commit

Permalink
Merge pull request #23 from damo-veda/master
Browse files Browse the repository at this point in the history
Added more info Documentation, related to the issue: #19.
  • Loading branch information
rajeshrhino authored Nov 18, 2020
2 parents 2f1bc2c + 30b90cc commit 3e35af6
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 115 deletions.
61 changes: 54 additions & 7 deletions CRM/CivirulesActions/Participant/AddToZoom.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,31 +239,78 @@ public static function getZoomRegistrants($eventId){
$settings = CRM_NcnCiviZoom_Utils::getZoomSettings();

if(!empty($meetingId)){
$url = $settings['base_url'] . "/meetings/".$meetingId.'/registrants?page=';
$url = $settings['base_url'] . "/meetings/".$meetingId.'/registrants?';
} elseif (!empty($webinarId)) {
$url = $settings['base_url'] . "/webinars/".$webinarId.'/registrants?page=';
$url = $settings['base_url'] . "/webinars/".$webinarId.'/registrants?';
}
$page = 1;
$token = $object->createJWTToken($accountId);
$result = [];
$next_page_token = null;
do {
$fetchUrl = $url.$page;
$fetchUrl = $url.$next_page_token;
$token = $object->createJWTToken($accountId);
$response = Zttp::withHeaders([
'Content-Type' => 'application/json;charset=UTF-8',
'Authorization' => "Bearer $token"
])->get($fetchUrl);
CRM_Core_Error::debug_var('zoom response', $response);
$result = $response->json();
CRM_Core_Error::debug_var('zoom result', $result);
if(!empty($result['registrants'])){
$zoomRegistrantsList = array_merge($result['registrants'], $zoomRegistrantsList);
$zoomRegistrantsList = array_merge($zoomRegistrantsList, $result['registrants']);
}
$page++;
} while ($page <= $result['page_count']);
$next_page_token = 'next_page_token='.$result['next_page_token'];
} while ($result['next_page_token']);

return $zoomRegistrantsList;
}

public static function getZoomAttendeeOrAbsenteesList($eventId){
if(empty($eventId)){
return [];
}
$object = new CRM_CivirulesActions_Participant_AddToZoom;
$webinarId = $object->getWebinarID($eventId);
$meetingId = $object->getMeetingID($eventId);
$returnZoomList = [];
if(empty($webinarId) && empty($meetingId)){
return $returnZoomList;
}
$url = $array_name = $key_name = '';
$accountId = CRM_NcnCiviZoom_Utils::getZoomAccountIdByEventId($eventId);
$settings = CRM_NcnCiviZoom_Utils::getZoomSettings();
if(!empty($meetingId)){
$url = $settings['base_url'] . "/past_meetings/$meetingId/participants?";
$array_name = 'participants';
$key_name = 'user_email';
} elseif (!empty($webinarId)) {
$url = $settings['base_url'] . "/past_webinars/$webinarId/absentees?";
$array_name = 'absentees';
$key_name = 'email';
}
$token = $object->createJWTToken($accountId);
$result = [];
$next_page_token = null;
do {
$fetchUrl = $url.$next_page_token;
$token = $object->createJWTToken($accountId);
$response = Zttp::withHeaders([
'Content-Type' => 'application/json;charset=UTF-8',
'Authorization' => "Bearer $token"
])->get($fetchUrl);
$result = $response->json();
CRM_Core_Error::debug_var('zoom result', $result);
if(!empty($result[$array_name])){
$list = $result[$array_name];
foreach ($list as $item) {
$returnZoomList[] = $item[$key_name];
}
}
$next_page_token = 'next_page_token='.$result['next_page_token'];
} while ($result['next_page_token']);
return $returnZoomList;
}

/**
* Method to return the url for additional form processing for action
* and return false if none is needed
Expand Down
1 change: 1 addition & 0 deletions CRM/NcnCiviZoom/Form/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public function postProcess() {
}

if(empty($this->_act) && empty($this->_id)){
$zoomSettings = CRM_NcnCiviZoom_Utils::getZoomSettings();
$zoomSettings['base_url'] = $values['base_url'];
$zoomSettings['custom_field_id_webinar'] = $values['custom_field_id_webinar'];
$zoomSettings['custom_field_id_meeting'] = $values['custom_field_id_meeting'];
Expand Down
33 changes: 6 additions & 27 deletions CRM/NcnCiviZoom/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,34 +162,13 @@ public function upgrade_1002(){

//Upgrade function to add the note type custom field to the events
public function upgrade_1003(){
$customGroupName = CRM_NcnCiviZoom_Constants::CG_Event_Zoom_Notes;
$customFieldName = CRM_NcnCiviZoom_Constants::CF_Event_Zoom_Notes;

$customGroupDetails = civicrm_api3('CustomGroup', 'create', [
'sequential' => 1,
'title' => "Event Zoom Notes",
'extends' => "Event",
'name' => $customGroupName,
]);

civicrm_api3('CustomField', 'create', [
'sequential' => 1,
'custom_group_id' => $customGroupDetails['values'][0]['id'],
'label' => "Event Zoom Notes",
'name' => $customFieldName,
'data_type' => "Memo",
'html_type' => "TextArea",
'is_view' => 1,
]);
CRM_NcnCiviZoom_Utils::forUpgrade1003();
return TRUE;
}

$sendZoomRegistrantsEmailTemplateTitle = CRM_NcnCiviZoom_Constants::SEND_ZOOM_REGISTRANTS_EMAIL_TEMPLATE_TITLE;
$msgHtml = "<br> {event_title} <br> {registrants} <br>";
$msgSubject = "Recently Joined to the zoom event: {event_title}";
civicrm_api3('MessageTemplate', 'create', [
'msg_title' => $sendZoomRegistrantsEmailTemplateTitle,
'msg_html' => $msgHtml,
'msg_subject' => $msgSubject,
]);
//Upgrade function to add the email template id to zoom settings
public function upgrade_1004(){
CRM_NcnCiviZoom_Utils::forUpgrade1004();
return TRUE;
}

Expand Down
64 changes: 62 additions & 2 deletions CRM/NcnCiviZoom/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,15 @@ public static function getMessageTemplateDetails($title = null, $id = null) {
));

return $result ['values'][0];
}elseif(!empty($id)){
$result = civicrm_api3('MessageTemplate', 'get', array(
'sequential' => 1,
'id' => $id,
));

return $result ['values'][0];
}else{
return [];
}
}

Expand All @@ -384,8 +393,9 @@ public static function sendZoomRegistrantsToEmail($toEmails, $registrantsList =
return;
}

$msgTitle = CRM_NcnCiviZoom_Constants::SEND_ZOOM_REGISTRANTS_EMAIL_TEMPLATE_TITLE;
$emailContent = self::getMessageTemplateDetails($msgTitle);
// $msgTitle = CRM_NcnCiviZoom_Constants::SEND_ZOOM_REGISTRANTS_EMAIL_TEMPLATE_TITLE;
$msgId = CRM_NcnCiviZoom_Utils::getEmailTemplateIdToSendZoomRegistrants();
$emailContent = self::getMessageTemplateDetails(null, $msgId);
if(empty($emailContent)){
return 'Email Template Not found.';
}
Expand Down Expand Up @@ -430,4 +440,54 @@ public static function sendEmail($email, $emailContent) {

return $emailSent;
}

public static function forUpgrade1003(){
$customGroupName = CRM_NcnCiviZoom_Constants::CG_Event_Zoom_Notes;
$customFieldName = CRM_NcnCiviZoom_Constants::CF_Event_Zoom_Notes;

$customGroupDetails = civicrm_api3('CustomGroup', 'create', [
'sequential' => 1,
'title' => "Event Zoom Notes",
'extends' => "Event",
'name' => $customGroupName,
]);

civicrm_api3('CustomField', 'create', [
'sequential' => 1,
'custom_group_id' => $customGroupDetails['values'][0]['id'],
'label' => "Event Zoom Notes",
'name' => $customFieldName,
'data_type' => "Memo",
'html_type' => "TextArea",
'is_view' => 1,
]);

$sendZoomRegistrantsEmailTemplateTitle = CRM_NcnCiviZoom_Constants::SEND_ZOOM_REGISTRANTS_EMAIL_TEMPLATE_TITLE;
$msgHtml = "<br> {event_title} <br> {registrants} <br>";
$msgSubject = "Recently Joined to the zoom event: {event_title}";
civicrm_api3('MessageTemplate', 'create', [
'msg_title' => $sendZoomRegistrantsEmailTemplateTitle,
'msg_html' => $msgHtml,
'msg_subject' => $msgSubject,
]);
}

public static function forUpgrade1004(){
$sendZoomRegistrantsEmailTemplateTitle = CRM_NcnCiviZoom_Constants::SEND_ZOOM_REGISTRANTS_EMAIL_TEMPLATE_TITLE;
$templateDetails = civicrm_api3('MessageTemplate', 'get', [
'sequential' => 1,
'msg_title' => $sendZoomRegistrantsEmailTemplateTitle,
]);
$zoomSettings = self::getZoomSettings();
if(!empty($templateDetails['id'])){
$zoomSettings['registrants_email_template_id'] = $templateDetails['id'];
}
CRM_Core_BAO_Setting::setItem($zoomSettings, ZOOM_SETTINGS, 'zoom_settings');
}

public static function getEmailTemplateIdToSendZoomRegistrants(){
$settings = self::getZoomSettings();
$templateId = CRM_Utils_Array::value('registrants_email_template_id', $settings, NULL);
return $templateId;
}
}
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@







# ncn-civi-zoom
Civirules Conditions/Actions that talk with Zoom developed for NCN.

Expand Down Expand Up @@ -39,10 +43,20 @@ The JWT App within your Zoom account will allow you to connect CiviCRM to zoom,
### Sign into CiviCRM and setup custom fields for Zoom
Create custom fields against the Event entity (you can select which types of events Zoom fields applicable too or leave blank for all events).
Also note we would recommend turning off the public setting on the custom field group as you probably dont want the IDs being exposed publicly on information pages.

The fields needed are
* Zoom Account ID. As the extension supports multiple zoom accounts in a single installation this field will store which zoom account the meeting or webinar is for.
* Zoom Webinar ID. Will hold Zoom Webinar IDs
* Zoom Meeting ID. Will hold the Zoom Meeting ID.
#### Zoom Account ID:
*As the extension supports multiple zoom accounts in a single installation this field will store to which zoom account the meeting or webinar belongs to.
* Please ensure that this custom field is set as **Data Type** to _Integer_ and **Field Type** to _Text_ as this field will only hold small natural numbers.
* Please ensure that this custom field is set as **View Only?** to _TRUE_ as its value is set from the 'zoom_account_list' and we don't want end users mistakenly entering invalid values.

#### Zoom Webinar ID
* Will hold Zoom Webinar IDs.
* Please ensure that this custom field is set as **Data Type** to _Number_ and **Field Type** to _Text_ as these fields will only contain large numbers (spaces in meeting numbers are trimmed before saving).

#### Zoom Meeting ID
* Will hold the Zoom Meeting ID.
* Please ensure that this custom field is set as **Data Type** to _Number_ and **Field Type** to _Text_ as these fields will only contain large numbers (spaces in meeting numbers are trimmed before saving).

### Sign into CiviCRM and install the CiviCRM Zoom extension

Expand Down Expand Up @@ -80,7 +94,9 @@ Once you've decided this you can create a new CiviRule as per the below.

## Creating Scheduled Jobs
### Scheduled Job for Zoom attendance
* Once you've created a zoom event, you need to create a scheduled job for that event. The Api Entity should be **Zoom Event** and the api action should be **Generatezoomattendance**. This api has only one parameter which is 'days'. This will be used the events using the event's end date i.e the events ended 'x' number of days from current date, where 'x' is the 'days' paramter you enter. You can schedule the Job as frequent as you need it to run.
* Once you've created a zoom event, you need to create a scheduled job for that event. The Api Entity should be **Zoomevent** and the api action should be **Generatezoomattendance**. This api has only one parameter which is ***days*** this will be used to pickup the events which ended up within that number of days given(using the event's end date). For example if the days=10, then events(in your civi) ended within past 10 days from current date will be picked up and only for these events the participants' status will be picked up from the zoom and updated in the civicrm. You can schedule the Job as frequent as you need it to run.
* An example has been done below![Screenshot of Scheduled Job](images/generate-zoom-attendance.PNG)

### Scheduled Job for updating Zoom registrants
* Once you've created a zoom event, you need to create a scheduled job for that event. The Api Entity should be **Zoom Event** and the api action should be **Getrecentzoomregistrants**. This api has two parameters one is 'mins' i.e registrants registered that many 'minutes' before will be filtered and will be taken for updation and for sending email. The other parameter is the Email address to which you want the regitrants list to be sent, for multiple email addresses seperate each by a comma symbol.
### Scheduled Job for emailing new Zoom registrants
* Once you've created a zoom event, you need to create a scheduled job for that event. The Api Entity should be **Zoomevent** and the api action should be **Getrecentzoomregistrants**. This api has two parameters one is ***mins*** i.e registrants who registered that many 'minutes' before will be filtered and their details(such as First name, Last name and Email) will be updated to the 'Event Zoom Notes' custom field under that civi event. The other parameter is the ***to_emails*** , which is the Email address to which you want the filtered regitrants list could be sent, for multiple email addresses seperate each by a comma(,) symbol.
* An example has been done below![Screenshot of Scheduled Job](images/email-zoom-registrants.PNG)
Loading

0 comments on commit 3e35af6

Please sign in to comment.