Use LP item audio with different path BT#17524

pull/3357/head
Julio Montoya 6 years ago
parent 0ba1308c36
commit 2339dcecb5
  1. 11
      main/inc/lib/document.lib.php
  2. 30
      main/lp/learnpathItem.class.php
  3. 56
      main/lp/lp_add_audio.php
  4. 2
      main/lp/lp_controller.php

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
@ -9,8 +10,6 @@ use ChamiloSession as Session;
* It is / will be used to provide a service layer to all document-using tools.
* and eliminate code duplication fro group documents, scorm documents, main documents.
* Include/require it in your code to use its functionality.
*
* @package chamilo.library
*/
class DocumentManager
{
@ -4973,7 +4972,8 @@ class DocumentManager
$group_dir = '',
$change_renderer = false,
&$form = null,
$selectName = 'id'
$selectName = 'id',
$attributes = []
) {
$doc_table = Database::get_course_table(TABLE_DOCUMENT);
$course_id = api_get_course_int_id();
@ -4999,7 +4999,6 @@ class DocumentManager
}
}
$attributes = [];
if (empty($form)) {
$form = new FormValidator('selector', 'GET', api_get_self().'?'.api_get_cidreq());
$attributes = ['onchange' => 'javascript: document.selector.submit();'];
@ -5056,9 +5055,7 @@ class DocumentManager
}
}
$html = $form->toHtml();
return $html;
return $form->toHtml();
}
/**

@ -189,6 +189,12 @@ class learnpathItem
$this->seriousgame_mode = 0;
$this->audio = null;
if (isset($row['audio'])) {
// Fix old audio format /file.wav to /audio/file.wav
$parts = explode('/', $row['audio']);
$parts = array_filter($parts);
if (count($parts) === 1) {
$row['audio'] = '/audio'.$row['audio'];
}
$this->audio = $row['audio'];
}
}
@ -4137,31 +4143,27 @@ class learnpathItem
/**
* Adds an audio file to the current item, using a file already in documents.
*
* @param int $doc_id
* @param int $documentId
*
* @return string
*/
public function add_audio_from_documents($doc_id)
public function add_audio_from_documents($documentId)
{
$course_info = api_get_course_info();
$document_data = DocumentManager::get_document_data_by_id(
$doc_id,
$course_info['code']
);
$courseInfo = api_get_course_info();
$documentData = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
$file_path = '';
if (!empty($document_data)) {
$file_path = substr($document_data['path'], 6);
$file_path = ltrim($file_path, "/");
$path = '';
if (!empty($documentData)) {
$path = $documentData['path'];
// Store the mp3 file in the lp_item table.
$table = Database::get_course_table(TABLE_LP_ITEM);
$sql = "UPDATE $table SET
audio = '".Database::escape_string($file_path)."'
WHERE iid = ".intval($this->db_id);
audio = '".Database::escape_string($path)."'
WHERE iid = ".$this->db_id;
Database::query($sql);
}
return $file_path;
return $path;
}
/**

@ -14,6 +14,7 @@ api_protect_course_script();
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$isStudentView = api_is_student_view_active();
$learnpath_id = (int) $_REQUEST['lp_id'];
$lp_item_id = isset($_GET['id']) ? (int) $_GET['id'] : null;
$submit = isset($_POST['submit_button']) ? $_POST['submit_button'] : null;
$type = isset($_GET['type']) ? $_GET['type'] : null;
$action = isset($_GET['action']) ? $_GET['action'] : null;
@ -24,6 +25,10 @@ if (!$is_allowed_to_edit || $isStudentView) {
exit;
}
if (empty($lp_item_id)) {
api_not_allowed();
}
/** @var learnpath $lp */
$lp = Session::read('oLP');
@ -78,12 +83,6 @@ if ($action === 'add_item' && $type === 'document') {
// Theme calls.
$show_learn_path = true;
$lp_item_id = isset($_GET['id']) ? (int) $_GET['id'] : null;
if (empty($lp_item_id)) {
api_not_allowed();
}
$lp_item = new learnpathItem($lp_item_id);
$form = new FormValidator(
'add_audio',
@ -96,12 +95,21 @@ $suredel = trim(get_lang('AreYouSureToDeleteJS'));
$lpPathInfo = $lp->generate_lp_folder($courseInfo);
DocumentManager::createDefaultAudioFolder($courseInfo);
$audioFolderId = DocumentManager::get_document_id($courseInfo, '/audio');
$currentDir = '/audio';
$audioFolderId = DocumentManager::get_document_id($courseInfo, $currentDir);
if (isset($_REQUEST['folder_id'])) {
$documentData = DocumentManager::get_document_data_by_id($_REQUEST['folder_id'], $courseInfo['code']);
if ($documentData) {
$audioFolderId = (int) $_REQUEST['folder_id'];
$currentDir = $documentData['path'];
}
}
$file = null;
//$lp_item->audio = '/aaaaa.wav';
if (isset($lp_item->audio) && !empty($lp_item->audio)) {
$file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio;
$urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$lp_item->audio.'?'.api_get_cidreq();
$file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/'.$lp_item->audio;
$urlFile = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/'.$lp_item->audio.'?'.api_get_cidreq();
if (!file_exists($file)) {
$file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$lpPathInfo['dir'].'/'.$lp_item->audio;
@ -124,9 +132,7 @@ $page .= $lp->return_new_tree(null, true);
$page .= '</div>';
$recordVoiceForm = '<h3 class="page-header">'.get_lang('RecordYourVoice').'</h3>';
$page .= '<div id="doc_form" class="col-md-8">';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'rtc/RecordRTC.js"></script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/recorder.js"></script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/gui.js"></script>';
@ -172,6 +178,14 @@ $form->addElement('file', 'file');
$form->addElement('hidden', 'id', $lp_item_id);
$form->addButtonSave(get_lang('SaveRecordedAudio'));
$folders = DocumentManager::get_all_document_folders(
$courseInfo,
null,
true,
false,
$currentDir
);
$documentTree = DocumentManager::get_document_preview(
$courseInfo,
$lp->get_id(),
@ -191,6 +205,26 @@ $page .= $recordVoiceForm;
$page .= '<br>';
$page .= $form->returnForm();
$page .= '<h3 class="page-header"><small>'.get_lang('Or').'</small> '.get_lang('SelectAnAudioFileFromDocuments').'</h3>';
$form = new FormValidator(
'selector',
'POST',
api_get_self().'?view=build&id='.$lp_item_id.'&lp_id='.$learnpath_id.'&action=add_audio&'.api_get_cidreq()
);
$attributes = ['onchange' => 'javascript: document.selector.submit();'];
$selector = DocumentManager::build_directory_selector(
$folders,
$audioFolderId,
null,
false,
$form,
'folder_id',
$attributes
);
$page .= $selector;
$page .= '<ul class="lp_resource">';
$page .= '<li class="doc_folder" style="margin-left: 36px;">'.get_lang('Audio').'</li>';
$page .= '<li class="doc_folder">';

@ -692,7 +692,7 @@ switch ($action) {
if (isset($_REQUEST['document_id']) && !empty($_REQUEST['document_id'])) {
$_SESSION['oLP']->set_modified_on();
$lp_item_obj->add_audio_from_documents($_REQUEST['document_id']);
Display::addFlash(Display::return_message(get_lang('UplUploadSucceeded')));
Display::addFlash(Display::return_message(get_lang('Updated')));
}
require 'lp_add_audio.php';

Loading…
Cancel
Save