Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CiviCRM activity report with attachments
?php
/**
* Displays and filters activities with file attachments.
*
* Based on https://github.com/MegaphoneJon/activityAttachmentReport by Jon G.
*/
class CRM_SymbioTIC_Form_Report_ActivitiesWithAttachments extends CRM_Report_Form_Activity {
function __construct() {
parent::__construct();
$this->_columns['civicrm_entity_file'] = [
'dao' => 'CRM_Core_DAO_EntityFile',
'fields' => [
'file_id' => [
'title' => ts('Attachments'),
'type' => CRM_Utils_Type::T_INT,
],
],
'filters' => [
'file_id' => [
'title' => ts('Attachments'),
'type' => CRM_Utils_Type::T_BOOLEAN,
],
],
];
}
function from($recordType) {
parent::from($recordType);
$this->_from .= "
LEFT JOIN civicrm_entity_file {$this->_aliases['civicrm_entity_file']}
ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_entity_file']}.entity_id AND {$this->_aliases['civicrm_entity_file']}.entity_table = 'civicrm_activity'";
}
function where() {
parent::where();
if ($this->_params['file_id_value'] == 1) {
// Show only activities with attachments
$this->_where = preg_replace('/entity_file_civireport.file_id = \d+/', 'entity_file_civireport.file_id IS NOT NULL', $this->_where);
}
else {
$this->_where = preg_replace('/entity_file_civireport.file_id = \d+/', 'entity_file_civireport.file_id IS NULL', $this->_where);
}
}
function alterDisplay(&$rows) {
parent::alterDisplay($rows);
foreach ($rows as $rowNum => $row) {
if (array_key_exists('civicrm_entity_file_file_id', $row) && $row['civicrm_entity_file_file_id']) {
$link = array();
$fid = $row['civicrm_entity_file_file_id'];
$eid = $row['civicrm_activity_id'];
$url = CRM_Utils_System::url("civicrm/file",
"reset=1&id=$fid&eid=$eid",
$this->_absoluteUrl
);
$link[] = "<a href='" . $url . "'>Yes</a>";
$rows[$rowNum]['civicrm_entity_file_file_id'] = implode('; ', $link);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.