Skip to content

Commit

Permalink
Implement Activity exported activity veda-consulting-company#157
Browse files Browse the repository at this point in the history
  • Loading branch information
scardinius committed Aug 2, 2018
1 parent fd09e29 commit 0a54029
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion gdpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,45 @@ function gdpr_civicrm_exportIds($ids, $componentTable, $exportMode) {
break;

case CRM_Export_Form_Select::ACTIVITY_EXPORT:
CRM_Core_Error::debug_var('$ids', $ids);
$session = CRM_Core_Session::singleton();
$loggedUserID = $session->get('userID');
$activityTypeId = CRM_Gdpr_Activity::activityExportedTypeId();
$query = "SELECT DISTINCTROW
ac.contact_id, ac.activity_id, ovt.activity_name, ovs.activity_status,
DATE_FORMAT(a.activity_date_time, '%Y-%m-%d') activity_date
FROM civicrm_activity a
JOIN civicrm_activity_contact ac ON ac.activity_id = a.id
JOIN (SELECT
v.value, v.label activity_name
FROM civicrm_option_value v
JOIN civicrm_option_group g ON g.id = v.option_group_id AND g.name = 'activity_type'
) ovt ON ovt.value = a.activity_type_id
JOIN (SELECT
v.value, v.label activity_status
FROM civicrm_option_value v
JOIN civicrm_option_group g ON g.id = v.option_group_id AND g.name = 'activity_status'
) ovs ON ovs.value = a.status_id
WHERE a.id IN (" . implode(', ', array_values($ids)) .")
AND ac.record_type_id IN (2, 3)";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$params = [
'sequential' => 1,
'source_record_id' => $dao->activity_id,
'source_contact_id' => $loggedUserID,
'activity_type_id' => $activityTypeId,
'parent_id' => $dao->activity_id,
'activity_date_time' => date('YmdHis'),
'status_id' => 'Completed',
'subject' => $dao->activity_name . " (" . $dao->activity_status . ") at " . $dao->activity_date,
'api.ActivityContact.create' => [
'activity_id' => '$value.id',
'contact_id' => $dao->contact_id,
'record_type_id' => 3,
]
];
CRM_Gdpr_Utils::CiviCRMAPIWrapper('Activity', 'create', $params);
}
break;

case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
Expand Down

0 comments on commit 0a54029

Please sign in to comment.