Document - Add extra fields list for documents - refs BT#20418

pull/4482/head
Christian 3 years ago
parent 2a50f60422
commit 3edb2bfe83
  1. 33
      main/document/edit_document.php
  2. 1
      main/inc/lib/extra_field.lib.php
  3. 6
      main/install/configuration.dist.php

@ -334,13 +334,11 @@ if ($is_allowed_to_edit) {
} }
} }
if (true === api_get_configuration_value('documents_hide_download_icon')) { // It saves extra fields values
$extraFieldValue = new ExtraFieldValue('document'); $extraFieldValue = new ExtraFieldValue('document');
$fieldValues = []; $values = $_REQUEST;
$fieldValues['item_id'] = $document_id; $values['item_id'] = $document_id;
$fieldValues['extra_can_be_downloaded'] = (int) $_REQUEST['download']['can_download']; $extraFieldValue->saveFieldValues($values);
$extraFieldValue->saveFieldValues($fieldValues);
}
$url = 'document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : ''); $url = 'document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : '');
@ -467,15 +465,18 @@ if ($owner_id == api_get_user_id() ||
$form->addElement('textarea', 'comment', get_lang('Comment'), ['cols-size' => [2, 10, 0]]); $form->addElement('textarea', 'comment', get_lang('Comment'), ['cols-size' => [2, 10, 0]]);
} }
// Define if a document can be downloaded or not. $itemId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (true === api_get_configuration_value('documents_hide_download_icon')) { $extraField = new ExtraField('document');
$itemId = isset($_GET['id']) ? (int) $_GET['id'] : 0; $extraField->addElements(
$group = []; $form,
$group[] = $form->createElement('radio', 'can_download', null, get_lang('Yes'), 1, ['id' => 'can_download_yes']); $itemId,
$group[] = $form->createElement('radio', 'can_download', null, get_lang('No'), 0, ['id' => 'can_download_no']); [], //exclude
$form->addGroup($group, 'download', get_lang('DefineIfDocumentCanBeDownloaded')); false, // filter
$defaults['download']['can_download'] = DocumentManager::getHideDownloadIcon($itemId); false, // tag as select
} [], //show only fields
[], // order fields
[] // extra data
);
if ($file_type != 'link') { if ($file_type != 'link') {
if ($owner_id == api_get_user_id() || api_is_platform_admin()) { if ($owner_id == api_get_user_id() || api_is_platform_admin()) {

@ -207,6 +207,7 @@ class ExtraField extends Model
'lp_view', 'lp_view',
'course_announcement', 'course_announcement',
'message', 'message',
'document'
]; ];
if (api_get_configuration_value('allow_scheduled_announcements')) { if (api_get_configuration_value('allow_scheduled_announcements')) {

@ -2318,11 +2318,7 @@ INSERT INTO `extra_field` (`extra_field_type`, `field_type`, `variable`, `displa
// $_configuration['gradebook_hide_link_to_item_for_student'] = false; // $_configuration['gradebook_hide_link_to_item_for_student'] = false;
// It adds option to define if a document can be downloaded or not. // It adds option to define if a document can be downloaded or not.
// Requires DB changes: // Create an extra field document named "CanBeDownloaded" of type "Yes/No" that is set to "No" by default.
/*
INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, default_value, field_order, visible_to_self, visible_to_others, changeable, filter, created_at) VALUES
(23, 1, 'can_be_downloaded', 'CanBeDownloaded', '', 0, 1, 0, 1, 0, NOW());
*/
// $_configuration['documents_hide_download_icon'] = false; // $_configuration['documents_hide_download_icon'] = false;
// KEEP THIS AT THE END // KEEP THIS AT THE END

Loading…
Cancel
Save