Merge pull request #4482 from christianbeeznest/RNA-20418

Document - Add option to define if a document can be downloaded or not - refs BT#20418
pull/4495/head
Nicolas Ducoulombier 3 years ago committed by GitHub
commit 3ce692f93a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      main/document/edit_document.php
  2. 67
      main/inc/lib/document.lib.php
  3. 4
      main/inc/lib/extra_field.lib.php
  4. 4
      main/install/configuration.dist.php
  5. 1
      src/Chamilo/CoreBundle/Entity/ExtraField.php

@ -334,6 +334,12 @@ if ($is_allowed_to_edit) {
}
}
// It saves extra fields values
$extraFieldValue = new ExtraFieldValue('document');
$values = $_REQUEST;
$values['item_id'] = $document_id;
$extraFieldValue->saveFieldValues($values);
$url = 'document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : '');
$redirectToEditPage = isset($_POST['button_ck']) && 1 === (int) $_POST['button_ck'];
@ -459,6 +465,19 @@ if ($owner_id == api_get_user_id() ||
$form->addElement('textarea', 'comment', get_lang('Comment'), ['cols-size' => [2, 10, 0]]);
}
$itemId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$extraField = new ExtraField('document');
$extraField->addElements(
$form,
$itemId,
[], //exclude
false, // filter
false, // tag as select
[], //show only fields
[], // order fields
[] // extra data
);
if ($file_type != 'link') {
if ($owner_id == api_get_user_id() || api_is_platform_admin()) {
$checked = &$form->addElement('checkbox', 'readonly', null, get_lang('ReadOnly'));

@ -5328,31 +5328,41 @@ class DocumentManager
$document_data['file_extension'] = $extension;
if (!$show_as_icon) {
if ($filetype == 'folder') {
if ($isAllowedToEdit ||
api_is_platform_admin() ||
api_get_setting('students_download_folders') == 'true'
) {
// filter: when I am into a shared folder, I can only show "my shared folder" for donwload
if (self::is_shared_folder($curdirpath, $sessionId)) {
if (preg_match('/shared_folder\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link)) ||
preg_match('/shared_folder_session_'.$sessionId.'\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link)) ||
$isAllowedToEdit || api_is_platform_admin()
// to force download if a document can be downloaded or not
$hideDownloadIcon = false;
if (true === api_get_configuration_value('documents_hide_download_icon')) {
$hideDownloadIcon = true;
}
if (self::getHideDownloadIcon($document_data['id'])) {
$hideDownloadIcon = false;
}
if (!$hideDownloadIcon) {
if ($filetype == 'folder') {
if ($isAllowedToEdit ||
api_is_platform_admin() ||
api_get_setting('students_download_folders') == 'true'
) {
// filter: when I am into a shared folder, I can only show "my shared folder" for donwload
if (self::is_shared_folder($curdirpath, $sessionId)) {
if (preg_match('/shared_folder\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link)) ||
preg_match('/shared_folder_session_'.$sessionId.'\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link)) ||
$isAllowedToEdit || api_is_platform_admin()
) {
$force_download_html = $size == 0 ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.
Display::return_icon($forcedownload_icon, get_lang('Download'), [], ICON_SIZE_SMALL).'</a>';
}
} elseif (!preg_match('/shared_folder/', urldecode($forcedownload_link)) ||
$isAllowedToEdit ||
api_is_platform_admin()
) {
$force_download_html = $size == 0 ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.
Display::return_icon($forcedownload_icon, get_lang('Download'), [], ICON_SIZE_SMALL).'</a>';
}
} elseif (!preg_match('/shared_folder/', urldecode($forcedownload_link)) ||
$isAllowedToEdit ||
api_is_platform_admin()
) {
$force_download_html = $size == 0 ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.
Display::return_icon($forcedownload_icon, get_lang('Download'), [], ICON_SIZE_SMALL).'</a>';
}
} else {
$force_download_html = $size == 0 ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.' download="'.$document_data['basename'].'">'.
Display::return_icon($forcedownload_icon, get_lang('Download'), [], ICON_SIZE_SMALL).'</a>';
}
} else {
$force_download_html = $size == 0 ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.' download="'.$document_data['basename'].'">'.
Display::return_icon($forcedownload_icon, get_lang('Download'), [], ICON_SIZE_SMALL).'</a>';
}
// Copy files to user's myfiles
@ -7461,4 +7471,23 @@ class DocumentManager
return $btn;
}
/**
* It gest extra value to define if download icon is visible or not.
*
* @param $documentId
*
* @return bool
*/
public static function getHideDownloadIcon($documentId)
{
$extraFieldValue = new ExtraFieldValue('document');
$extraValue = $extraFieldValue->get_values_by_handler_and_field_variable($documentId, 'can_be_downloaded');
$canBeDownloadedIcon = false;
if (!empty($extraValue) && isset($extraValue['value'])) {
$canBeDownloadedIcon = (bool) $extraValue['value'];
}
return $canBeDownloadedIcon;
}
}

@ -171,6 +171,9 @@ class ExtraField extends Model
case 'message':
$this->extraFieldType = EntityExtraField::MESSAGE_TYPE;
break;
case 'document':
$this->extraFieldType = EntityExtraField::DOCUMENT_TYPE;
break;
}
$this->pageUrl = 'extra_fields.php?type='.$this->type;
@ -204,6 +207,7 @@ class ExtraField extends Model
'lp_view',
'course_announcement',
'message',
'document'
];
if (api_get_configuration_value('allow_scheduled_announcements')) {

@ -2317,6 +2317,10 @@ INSERT INTO `extra_field` (`extra_field_type`, `field_type`, `variable`, `displa
// Disable links in gradebook view for students
// $_configuration['gradebook_hide_link_to_item_for_student'] = false;
// It adds option to define if a document can be downloaded or not.
// Create an extra field document named "CanBeDownloaded" of type "Yes/No" that is set to "No" by default.
// $_configuration['documents_hide_download_icon'] = false;
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email

@ -41,6 +41,7 @@ class ExtraField extends BaseAttribute
public const LP_VIEW_TYPE = 20;
public const COURSE_ANNOUNCEMENT = 21;
public const MESSAGE_TYPE = 22;
public const DOCUMENT_TYPE = 23;
/**
* @var int

Loading…
Cancel
Save