When uploading a document set parent id #2326

pull/2715/head
Julio Montoya 8 years ago
parent acd64d3511
commit 56bf3a9689
  1. 11
      main/document/upload.php
  2. 6
      main/inc/ajax/document.ajax.php
  3. 7
      main/inc/lib/document.lib.php
  4. 20
      main/inc/lib/fileUpload.lib.php

@ -164,7 +164,7 @@ $index = isset($_POST['index_document']) ? $_POST['index_document'] : null;
// User has submitted a file
if (!empty($_FILES)) {
DocumentManager::upload_document(
$document = DocumentManager::upload_document(
$_FILES,
$_POST['curdirpath'],
$_POST['title'],
@ -172,14 +172,17 @@ if (!empty($_FILES)) {
$unzip,
$_POST['if_exists'],
$index,
true
true,
'file',
true,
$_REQUEST['id'] ?? 0
);
$redirectUrl = api_get_self().'?'.api_get_cidreq().$certificateLink;
if ($document_data) {
if ($document) {
$redirectUrl .= '&'.http_build_query(
[
'id' => $document_data['iid'],
'id' => $document->getId(),
]
);
}

@ -128,10 +128,10 @@ switch ($action) {
exit;
break;
case 'document_preview':
$course_info = api_get_course_info_by_id($_REQUEST['course_id']);
if (!empty($course_info) && is_array($course_info)) {
$courseInfo = api_get_course_info_by_id($_REQUEST['course_id']);
if (!empty($courseInfo) && is_array($courseInfo)) {
echo DocumentManager::get_document_preview(
$course_info,
$courseInfo,
false,
'_blank',
$_REQUEST['session_id']

@ -2825,6 +2825,7 @@ class DocumentManager
* @param bool $show_output print html messages
* @param string $fileKey
* @param bool $treat_spaces_as_hyphens
* @param int $parentId
*
* @return CDocument|false
*/
@ -2838,7 +2839,8 @@ class DocumentManager
$index_document = false,
$show_output = false,
$fileKey = 'file',
$treat_spaces_as_hyphens = true
$treat_spaces_as_hyphens = true,
$parentId = 0
) {
$course_info = api_get_course_info();
$sessionId = api_get_session_id();
@ -2864,7 +2866,8 @@ class DocumentManager
null,
$sessionId,
$treat_spaces_as_hyphens,
$fileKey
$fileKey,
$parentId
);
// Showing message when sending zip files

@ -217,6 +217,7 @@ function process_uploaded_file($uploaded_file, $show_output = true)
* @param int $sessionId
* @param bool $treat_spaces_as_hyphens
* @param string $uploadKey
* @param int $parentId
*
* So far only use for unzip_uploaded_document function.
* If no output wanted on success, set to false.
@ -238,7 +239,8 @@ function handle_uploaded_document(
$comment = null,
$sessionId = null,
$treat_spaces_as_hyphens = true,
$uploadKey = ''
$uploadKey = '',
$parentId = 0
) {
if (!$userId) {
return false;
@ -564,7 +566,6 @@ function handle_uploaded_document(
);
$documentTitle = disable_dangerous_file($cleanName);
$fullPath = $whereToSave.$fileSystemName;
$filePath = $uploadPath.$fileSystemName;
$request = \Chamilo\CoreBundle\Framework\Container::getRequest();
@ -590,7 +591,8 @@ function handle_uploaded_document(
$sessionId,
0,
true,
$content
$content,
$parentId
);
// Display success message to user
@ -1310,6 +1312,7 @@ function filter_extension(&$filename)
* @param int $userId creator user id
* @param bool $sendNotification
* @param string $content
* @param int $parentId
*
* @return CDocument
*/
@ -1326,7 +1329,8 @@ function add_document(
$sessionId = 0,
$userId = 0,
$sendNotification = true,
$content = ''
$content = '',
$parentId = 0
) {
$sessionId = empty($sessionId) ? api_get_session_id() : $sessionId;
$userId = empty($userId) ? api_get_user_id() : $userId;
@ -1339,6 +1343,12 @@ function add_document(
$em = Database::getManager();
$documentRepo = $em->getRepository('ChamiloCourseBundle:CDocument');
$parentNode = null;
if (!empty($parentId)) {
$parent = $documentRepo->find($parentId);
$parentNode = $parent->getResourceNode();
}
$document = new CDocument();
$document
->setCourse($courseEntity)
@ -1355,6 +1365,8 @@ function add_document(
$em->flush();
$resourceNode = $documentRepo->addResourceNode($document, $userEntity);
$resourceNode->setParent($parentNode);
$document->setResourceNode($resourceNode);
if ($fileType === 'file') {

Loading…
Cancel
Save