Skip to content

Commit

Permalink
THFSPRT-6: Add support for file fields in application reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Shahrukh committed Nov 18, 2024
1 parent a02f8b3 commit 1267720
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
31 changes: 31 additions & 0 deletions CRM/CiviAwards/Form/AwardReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,27 @@ public function postProcess() {
$activityContact = $this->getActivityTargetContact();

$this->updateActivity();
if (!empty($_FILES)) {
$existingFile = civicrm_api3('Attachment', 'get', ['entity_table' => 'civicrm_activity', 'entity_id' => $activityId]);
if ($existingFile['id']) {
civicrm_api3('Attachment', 'delete', ['id' => $existingFile['id']]);
}
}
}

$files = array_values($_FILES ?? []);
if ($files[0]['type'] && $files[0]['name'] && $files[0]['tmp_name']) {
civicrm_api3('Attachment', 'create', [
'entity_table' => 'civicrm_activity',
'entity_id' => $activityId,
'mime_type' => $files[0]['type'],
'name' => $files[0]['name'],
'options' => [
'move-file' => $files[0]['tmp_name'],
],
'check_permissions' => false,
]);
}
$profileFields['activity_id'] = $activityId;
$profileFields['contact_id'] = $activityContact;
$profileFields['profile_id'] = $this->profileId;
Expand Down Expand Up @@ -383,6 +402,18 @@ private function displayReviewForm() {
$this->assign('activityStatus', $this->activity['status_id.label']);
$editUrlParams = "action=update&id={$this->activityId}&reset=1";
$this->assign('editUrlParams', $editUrlParams);
if ($this->activityId) {
$existingFile = civicrm_api3('Attachment', 'get', [
'sequential' => 1,
'entity_table' => 'civicrm_activity',
'entity_id' => $this->activityId
]);
$this->assign('existingFileName', $existingFile['values'][0]['name'] ?? '');
$this->assign('existingFileUrl', $existingFile['values'][0]['url'] ?? '');
} else {
$this->assign('existingFileName', '');
$this->assign('existingFileUrl', '');
}
}
else {
$this->addEntityRef('source_contact_id', ts('Reported By'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
entity_id: '$value.id',
entity_type: 'Activity',
'custom_group.name': { IN: applicantReviewCustomGroups }
},
'api.attachment.getsingle': {
entity_id: '$value.id',
entity_table: 'civicrm_activity',

Check failure on line 96 in ang/civiawards/reviews-tab/directives/reviews-case-tab-content.directive.js

View workflow job for this annotation

GitHub Actions / run-linters

Unexpected trailing comma
}
});
}).then(function (response) {
Expand Down Expand Up @@ -123,6 +127,10 @@
activity['api.CustomValue.gettreevalues'].values.map(function (fieldSet) {
Object.keys(fieldSet.fields).forEach(function (key) {
var field = fieldSet.fields[key];
if (field['html_type'] === 'File' && activity['api.attachment.getsingle']['id']) {

Check failure on line 130 in ang/civiawards/reviews-tab/directives/reviews-case-tab-content.directive.js

View workflow job for this annotation

GitHub Actions / run-linters

["html_type"] is better written in dot notation

Check failure on line 130 in ang/civiawards/reviews-tab/directives/reviews-case-tab-content.directive.js

View workflow job for this annotation

GitHub Actions / run-linters

["id"] is better written in dot notation
field.value.display =
'<a href="' + activity['api.attachment.getsingle']['url'] + '" target="_blank">' + activity['api.attachment.getsingle']['name'] + '</a>';

Check failure on line 132 in ang/civiawards/reviews-tab/directives/reviews-case-tab-content.directive.js

View workflow job for this annotation

GitHub Actions / run-linters

["url"] is better written in dot notation

Check failure on line 132 in ang/civiawards/reviews-tab/directives/reviews-case-tab-content.directive.js

View workflow job for this annotation

GitHub Actions / run-linters

["name"] is better written in dot notation
}
var newKey = key + field.id;
fieldSet.fields[newKey] = Object.assign({ id: field.id }, field);
delete fieldSet.fields[key];
Expand All @@ -140,6 +148,7 @@

delete activity['api.OptionValue.getsingle'];
delete activity['api.CustomValue.gettreevalues'];
delete activity['api.attachment.getsingle'];

return activity;
});
Expand Down
8 changes: 7 additions & 1 deletion templates/CRM/CiviAwards/Form/AwardReview.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@
{if $isReviewFromSsp}
<div class="ssp-form-control-description text-muted"> {$element.help_post} </div>
{/if}
<div class="{$form_group_field_class}">{$form[$element.name].html}</div>
<div class="{$form_group_field_class}">
{if $form[$element.name].type === 'file' && $existingFileName && $existingFileUrl}
<a href="{$existingFileUrl}" target="_blank">{$existingFileName}</a>
{else}
{$form[$element.name].html}
{/if}
</div>
<div class="clear"></div>
</div>
{/foreach}
Expand Down

0 comments on commit 1267720

Please sign in to comment.