'type' => 1,
'FKClassName' => 'CRM_Core_DAO_Tag',
'FKApiName' => 'Tag',
+ 'supports_joins' => TRUE,
+ );
+ $params['file_id'] = array(
+ 'title' => 'Attached Files',
+ 'description' => 'Find activities with attached files.',
+ 'type' => 1,
+ 'FKClassName' => 'CRM_Core_DAO_File',
+ 'FKApiName' => 'File',
);
$params['case_id'] = array(
'title' => 'Cases',
$sql->where('a.id IN (SELECT entity_id FROM civicrm_entity_tag WHERE entity_table = "civicrm_activity" AND !clause)', array('!clause' => $clause));
}
}
+ if (!empty($params['file_id'])) {
+ _civicrm_api3_validate_integer($params, 'file_id', $extraFieldSpecs['file_id'], 'Activity');
+ if (!is_array($params['file_id'])) {
+ $params['file_id'] = array('=' => $params['file_id']);
+ }
+ $clause = \CRM_Core_DAO::createSQLFilter('file_id', $params['file_id']);
+ if ($clause) {
+ $sql->where('a.id IN (SELECT entity_id FROM civicrm_entity_file WHERE entity_table = "civicrm_activity" AND !clause)', array('!clause' => $clause));
+ }
+ }
if (!empty($params['case_id'])) {
_civicrm_api3_validate_integer($params, 'case_id', $extraFieldSpecs['case_id'], 'Activity');
if (!is_array($params['case_id'])) {
$returns['assignee_contact_id'] = 1;
}
+ $tagGet = array('tag_id', 'entity_id');
+ foreach (array_keys($returns) as $key) {
+ if (strpos($key, 'tag_id.') === 0) {
+ $tagGet[] = $key;
+ $returns['tag_id'] = 1;
+ }
+ }
+
foreach ($returns as $n => $v) {
switch ($n) {
case 'assignee_contact_id':
$tags = civicrm_api3('EntityTag', 'get', array(
'entity_table' => 'civicrm_activity',
'entity_id' => array('IN' => array_keys($activities)),
- 'return' => array('tag_id', 'entity_id'),
+ 'return' => $tagGet,
'options' => array('limit' => 0),
));
foreach ($tags['values'] as $tag) {
- $activities[$tag['entity_id']]['tag_id'][] = (int) $tag['tag_id'];
+ $key = (int) $tag['entity_id'];
+ unset($tag['entity_id'], $tag['id']);
+ $activities[$key]['tag_id'][$tag['tag_id']] = $tag;
+ }
+ break;
+
+ case 'file_id':
+ $dao = CRM_Core_DAO::executeQuery("SELECT entity_id, file_id FROM civicrm_entity_file WHERE entity_table = 'civicrm_activity' AND entity_id IN (%1)",
+ array(1 => array(implode(',', array_keys($activities)), 'String', CRM_Core_DAO::QUERY_FORMAT_NO_QUOTES)));
+ while ($dao->fetch()) {
+ $activities[$dao->entity_id]['file_id'][] = $dao->file_id;
}
break;
}
}
- // Legacy ouput
+ // Legacy extras
if (!empty($params['contact_id'])) {
$statusOptions = CRM_Activity_BAO_Activity::buildOptions('status_id', 'get');
$typeOptions = CRM_Activity_BAO_Activity::buildOptions('activity_type_id', 'validate');
$this->assertEquals($activityget['id'], $activity['id']);
}
+ /**
+ * Return tag info
+ */
+ public function testJoinOnTags() {
+ $tagName = 'act_tag_nm_' . mt_rand();
+ $tagDescription = 'act_tag_ds_' . mt_rand();
+ $tagColor = '#' . substr(md5(mt_rand()), 0, 6);
+ $tag = $this->callAPISuccess('Tag', 'create', array('name' => $tagName, 'color' => $tagColor, 'description' => $tagDescription, 'used_for' => 'Activities'));
+ $activity = $this->callAPISuccess('Activity', 'Create', $this->_params);
+ $this->callAPISuccess('EntityTag', 'create', array('entity_table' => 'civicrm_activity', 'tag_id' => $tag['id'], 'entity_id' => $activity['id']));
+ $activityget = $this->callAPISuccess('activity', 'getsingle', array(
+ 'id' => $activity['id'],
+ 'return' => array('tag_id.name', 'tag_id.description', 'tag_id.color'),
+ ));
+ $this->assertEquals($tagName, $activityget['tag_id'][$tag['id']]['tag_id.name']);
+ $this->assertEquals($tagColor, $activityget['tag_id'][$tag['id']]['tag_id.color']);
+ $this->assertEquals($tagDescription, $activityget['tag_id'][$tag['id']]['tag_id.description']);
+ }
+
+
+ /**
+ * Test that activity.get api works to filter on and return files.
+ */
+ public function testActivityGetFile() {
+ $activity = $this->callAPISuccess('Activity', 'create', $this->_params);
+ $activity2 = $this->callAPISuccess('Activity', 'create', $this->_params2);
+ $file = $this->callAPISuccess('Attachment', 'create', array(
+ 'name' => 'actAttachment.txt',
+ 'mime_type' => 'text/plain',
+ 'description' => 'My test description',
+ 'content' => 'My test content',
+ 'entity_table' => 'civicrm_activity',
+ 'entity_id' => $activity2['id'],
+ ));
+ $activityget = $this->callAPISuccess('activity', 'getsingle', array(
+ 'file_id' => $file['id'],
+ 'return' => 'file_id',
+ ));
+ $this->assertEquals($activityget['id'], $activity2['id']);
+ $this->assertEquals($file['id'], $activityget['file_id'][0]);
+ }
+
/**
* test that get functioning does filtering.
*/