From d712b93585d8d06f75701711922c265033f2cb43 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 23 Nov 2018 13:25:24 +0100 Subject: [PATCH 1/9] Minor - flint fixes --- main/inc/lib/message.lib.php | 33 ++++++++++--------- main/inc/lib/sortable_table.class.php | 10 +++--- main/messages/inbox.php | 3 +- main/messages/new_message.php | 4 +-- main/messages/outbox.php | 22 ++++++------- main/messages/view_message.php | 5 +-- src/CoreBundle/Component/Utils/ChamiloApi.php | 12 ++++--- 7 files changed, 43 insertions(+), 46 deletions(-) diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index c30abc5084..d5e71bc6f8 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -1213,8 +1213,8 @@ class MessageManager user_sender_id FROM $table WHERE - user_sender_id = " . api_get_user_id() . " AND - msg_status = " . MESSAGE_STATUS_OUTBOX . " + user_sender_id = ".api_get_user_id()." AND + msg_status = ".MESSAGE_STATUS_OUTBOX." $keywordCondition ORDER BY col$column $direction LIMIT $from, $number_of_items"; @@ -1229,7 +1229,7 @@ class MessageManager $senderId = $row['user_sender_id']; if ($request === true) { - $message[0] = ''; + $message[0] = ''; } else { $message[0] = $messageId; } @@ -1238,29 +1238,29 @@ class MessageManager $title = Security::remove_XSS($title); $userInfo = api_get_user_info($senderId); if ($request === true) { - $message[1] = '' . $userInfo['complete_name_with_username'] . ''; - $message[2] = '' . str_replace( + $message[1] = ''.$userInfo['complete_name_with_username'].''; + $message[2] = ''.str_replace( "\\", "", $title - ) . ''; + ).''; //date stays the same $message[3] = api_convert_and_format_date($sendDate, DATE_TIME_FORMAT_LONG); - $message[4] = '' . - Display::returnFontAwesomeIcon('trash', 2) . ''; + ).'" onclick="delete_one_message_outbox('.$messageId.')" href="javascript:void(0)" >'. + Display::returnFontAwesomeIcon('trash', 2).''; } else { $message[1] = ''; - $message[1].= $userInfo['complete_name_with_username']; - $message[2] = '' . $title . ''; + $message[1] .= $userInfo['complete_name_with_username']; + $message[2] = ''.$title.''; $message[3] = api_convert_and_format_date($sendDate, DATE_TIME_FORMAT_LONG); - $message[4] = '' . - Display::returnFontAwesomeIcon('trash', 'fa-sm') . ''; + )."'".')) return false;" >'. + Display::returnFontAwesomeIcon('trash', 'fa-sm').''; } $message_list[] = $message; @@ -2166,7 +2166,8 @@ class MessageManager 2, 20, 'DESC', - null,'table-custom' + null, + 'table-custom' ); $table->set_header(0, '', false, ['style' => 'width:15px;']); $table->set_header(1, get_lang('Messages'), false); diff --git a/main/inc/lib/sortable_table.class.php b/main/inc/lib/sortable_table.class.php index 37dd0f2390..9f097bc0d1 100755 --- a/main/inc/lib/sortable_table.class.php +++ b/main/inc/lib/sortable_table.class.php @@ -104,16 +104,16 @@ class SortableTable extends HTML_Table /** * Create a new SortableTable. * - * @param string $table_name A name for the table (default = 'table') + * @param string $table_name A name for the table (default = 'table') * @param string $get_total_number_function A user defined function to get * the total number of items in the table - * @param string $get_data_function A function to get the data to display on + * @param string $get_data_function A function to get the data to display on * the current page - * @param int $default_column The default column on which the data should be + * @param int $default_column The default column on which the data should be * sorted - * @param int $default_items_per_page The default number of items to show + * @param int $default_items_per_page The default number of items to show * on one page - * @param string $default_order_direction The default order direction; + * @param string $default_order_direction The default order direction; * either the constant 'ASC' or 'DESC' * @param string $table_id * @param string $style diff --git a/main/messages/inbox.php b/main/messages/inbox.php index 01623f83c5..859f90ebd7 100755 --- a/main/messages/inbox.php +++ b/main/messages/inbox.php @@ -112,7 +112,7 @@ $keyword = ''; // Comes from normal profile if ($allowMessage) { $actionsLeft = ''. - Display::return_icon('new-message.png', get_lang('ComposeMessage'),null,ICON_SIZE_MEDIUM).''; + Display::return_icon('new-message.png', get_lang('ComposeMessage'), null, ICON_SIZE_MEDIUM).''; $actionsLeft .= ''. Display::return_icon('inbox.png', get_lang('Inbox'), null, ICON_SIZE_MEDIUM).''; $actionsLeft .= ''. @@ -174,4 +174,3 @@ $content = $tpl->fetch($social_layout); $tpl->assign('message', $show_message); $tpl->assign('content', $content); $tpl->display_one_col_template(); - diff --git a/main/messages/new_message.php b/main/messages/new_message.php index c982927ee5..f61a8c25cb 100755 --- a/main/messages/new_message.php +++ b/main/messages/new_message.php @@ -343,10 +343,9 @@ $message_content = null; $actions = null; if ($group_id != 0) { $actions .= ''. - Display::return_icon('back.png', api_xml_http_response_encode(get_lang('ComposeMessage')),null, ICON_SIZE_MEDIUM).''; + Display::return_icon('back.png', api_xml_http_response_encode(get_lang('ComposeMessage')), null, ICON_SIZE_MEDIUM).''; $actions .= ''. Display::return_icon('message_new.png', api_xml_http_response_encode(get_lang('ComposeMessage')), null, ICON_SIZE_MEDIUM).''; - } else { $actions .= ''. Display::return_icon('back.png', get_lang('Back'), null, ICON_SIZE_MEDIUM).''; @@ -419,4 +418,3 @@ $social_layout = $tpl->get_template('message/inbox.tpl'); $content = $tpl->fetch($social_layout); $tpl->assign('content', $content); $tpl->display_one_col_template(); - diff --git a/main/messages/outbox.php b/main/messages/outbox.php index a50a0f256d..dae4584115 100755 --- a/main/messages/outbox.php +++ b/main/messages/outbox.php @@ -42,16 +42,16 @@ $interbreadcrumb[] = [ $actions = null; if ($allowMessage) { - $actionsLeft = '' . - Display::return_icon('back.png', get_lang('Back'), null, ICON_SIZE_MEDIUM) . ''; - $actionsLeft .= '' . - Display::return_icon('new-message.png', get_lang('ComposeMessage'), null, ICON_SIZE_MEDIUM) . ''; - $actionsLeft .= '' . - Display::return_icon('inbox.png', get_lang('Inbox'), null, ICON_SIZE_MEDIUM) . ''; - $actionsLeft .= '' . - Display::return_icon('outbox.png', get_lang('Outbox'), null, ICON_SIZE_MEDIUM) . ''; - - $form = MessageManager::getSearchForm(api_get_path(WEB_PATH) . 'main/messages/outbox.php'); + $actionsLeft = ''. + Display::return_icon('back.png', get_lang('Back'), null, ICON_SIZE_MEDIUM).''; + $actionsLeft .= ''. + Display::return_icon('new-message.png', get_lang('ComposeMessage'), null, ICON_SIZE_MEDIUM).''; + $actionsLeft .= ''. + Display::return_icon('inbox.png', get_lang('Inbox'), null, ICON_SIZE_MEDIUM).''; + $actionsLeft .= ''. + Display::return_icon('outbox.png', get_lang('Outbox'), null, ICON_SIZE_MEDIUM).''; + + $form = MessageManager::getSearchForm(api_get_path(WEB_PATH).'main/messages/outbox.php'); if ($form->validate()) { $values = $form->getSubmitValues(); $keyword = $values['keyword']; @@ -68,7 +68,6 @@ if (isset($_REQUEST['action'])) { $keyword = ''; $message_content = null; - $actions .= Display::toolbarAction( 'toolbar', [$actionsLeft, $actionsRight] @@ -117,4 +116,3 @@ $content = $tpl->fetch($social_layout); $tpl->assign('message', $show_message); $tpl->assign('content', $content); $tpl->display_one_col_template(); - diff --git a/main/messages/view_message.php b/main/messages/view_message.php index 8e93befc64..d61b95d63d 100755 --- a/main/messages/view_message.php +++ b/main/messages/view_message.php @@ -28,14 +28,13 @@ $actions = null; if (api_get_setting('allow_message_tool') === 'true') { $actionsLeft = ''. - Display::return_icon('new-message.png', get_lang('ComposeMessage'), null,ICON_SIZE_MEDIUM).''; + Display::return_icon('new-message.png', get_lang('ComposeMessage'), null, ICON_SIZE_MEDIUM).''; $actionsLeft .= ''. Display::return_icon('inbox.png', get_lang('Inbox'), null, ICON_SIZE_MEDIUM).''; $actionsLeft .= ''. Display::return_icon('outbox.png', get_lang('Outbox'), null, ICON_SIZE_MEDIUM).''; } - $actions .= Display::toolbarAction( 'toolbar', [$actionsLeft] @@ -51,7 +50,6 @@ if (empty($_GET['id'])) { $show_menu = 'messages_inbox'; } - // MAIN CONTENT $message_content = MessageManager::showMessageBox($messageId, $source); @@ -73,4 +71,3 @@ $social_layout = $tpl->get_template('message/inbox.tpl'); $content = $tpl->fetch($social_layout); $tpl->assign('content', $content); $tpl->display_one_col_template(); - diff --git a/src/CoreBundle/Component/Utils/ChamiloApi.php b/src/CoreBundle/Component/Utils/ChamiloApi.php index df161994b2..ba8df78c99 100644 --- a/src/CoreBundle/Component/Utils/ChamiloApi.php +++ b/src/CoreBundle/Component/Utils/ChamiloApi.php @@ -289,12 +289,15 @@ class ChamiloApi return api_get_path(WEB_CSS_PATH).'editor_content.css'; } + /** * Get a list of colors from the palette at main/palette/pchart/default.color - * and return it as an array of strings + * and return it as an array of strings. + * * @param bool $decimalOpacity Whether to return the opacity as 0..100 or 0..1 - * @param bool $wrapInRGBA Whether to return it as 1,1,1,100 or rgba(1,1,1,100) - * @param int $fillUpTo If the number of colors is smaller than this number, generate more colors + * @param bool $wrapInRGBA Whether to return it as 1,1,1,100 or rgba(1,1,1,100) + * @param int $fillUpTo If the number of colors is smaller than this number, generate more colors + * * @return array An array of string colors */ public static function getColorPalette( @@ -324,9 +327,10 @@ class ChamiloApi $count = count($palette); if (isset($fillUpTo) && $fillUpTo > $count) { for ($i = $count; $i < $fillUpTo; $i++) { - $palette[$i] = $palette[$i%$count]; + $palette[$i] = $palette[$i % $count]; } } + return $palette; } } From 87c0a19e422e72bc5dfc33cccd6b3c85f23a928c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 23 Nov 2018 13:26:00 +0100 Subject: [PATCH 2/9] WIP: Fix get documents, reading resource tables --- main/inc/lib/add_course.lib.inc.php | 186 +++++++-------------------- main/inc/lib/document.lib.php | 191 +++++++++++++--------------- 2 files changed, 131 insertions(+), 246 deletions(-) diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index 667dc91b29..bbf2faf900 100755 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -21,7 +21,8 @@ class AddCourse * @param bool Add unique prefix * @param bool Use code-independent keys * - * @return array An array with the needed keys ['currentCourseCode'], ['currentCourseId'], ['currentCourseDbName'], ['currentCourseRepository'] + * @return array An array with the needed keys ['currentCourseCode'], ['currentCourseId'], ['currentCourseDbName'], + * ['currentCourseRepository'] * * @todo Eliminate the global variables. * @assert (null) === false @@ -443,10 +444,9 @@ class AddCourse $settingsManager->setCourse($course); $alert = api_get_setting('email_alert_manager_on_new_quiz'); + $defaultEmailExerciseAlert = 0; if ($alert === 'true') { $defaultEmailExerciseAlert = 1; - } else { - $defaultEmailExerciseAlert = 0; } /* course_setting table (courseinfo tool) */ @@ -479,7 +479,7 @@ class AddCourse $counter = 1; foreach ($settings as $variable => $setting) { - $title = isset($setting['title']) ? $setting['title'] : ''; + $title = $setting['title'] ?? ''; Database::query( "INSERT INTO $TABLESETTING (id, c_id, title, variable, value, category) VALUES ($counter, $course_id, '".$title."', '".$variable."', '".$setting['default']."', '".$setting['category']."')" @@ -525,8 +525,6 @@ class AddCourse $counter++; } - $sys_course_path = api_get_path(SYS_COURSE_PATH); - /* Documents */ if ($fill_with_exemplary_content) { $files = [ @@ -543,141 +541,49 @@ class AddCourse $counter++; } - // FILL THE COURSE DOCUMENT WITH DEFAULT COURSE PICTURES - $folders_to_copy_from_default_course = [ - 'images', - 'audio', - 'flash', - 'video', - 'certificates', - ]; - - $default_course_path = api_get_path(SYS_CODE_PATH).'default_course_document/'; - - $default_document_array = []; - foreach ($folders_to_copy_from_default_course as $folder) { - $default_course_folder_path = $default_course_path.$folder.'/'; - $files = self::browse_folders( - $default_course_folder_path, - [], - $folder - ); - - $sorted_array = self::sort_pictures($files, 'dir'); - $sorted_array = array_merge( - $sorted_array, - self::sort_pictures($files, 'file') - ); - $default_document_array[$folder] = $sorted_array; - } - - $example_cert_id = 0; - if (is_array($default_document_array) && count( - $default_document_array - ) > 0 - ) { - foreach ($default_document_array as $media_type => $array_media) { - $path_documents = "/$media_type/"; - /* - //hack until feature #5242 is implemented - if ($media_type == 'images') { - $media_type = 'images/gallery'; - $images_folder = $sys_course_path.$course_repository."/document/images/"; - - if (!is_dir($images_folder)) { - //Creating index.html - mkdir($images_folder, $perm); - $fd = fopen($images_folder.'index.html', 'w'); - fwrite($fd, $htmlpage); - @chmod($images_folder.'index.html', $perm_file); - } - }*/ - - $course_documents_folder = $sys_course_path.$course_repository."/document/$media_type/"; - $default_course_path = api_get_path(SYS_CODE_PATH).'default_course_document'.$path_documents; - /* - if (!is_dir($course_documents_folder)) { - // Creating index.html - mkdir($course_documents_folder, $perm); - $fd = fopen( - $course_documents_folder.'index.html', - 'w' - ); - fwrite($fd, $htmlpage); - @chmod( - $course_documents_folder.'index.html', - $perm_file - ); - }*/ - - if (is_array($array_media) && count($array_media) > 0) { - foreach ($array_media as $key => $value) { - if (isset($value['dir']) && !empty($value['dir'])) { - if (!is_dir($course_documents_folder.$value['dir'])) { - // Inserting folder in the DB - $folder_path = substr( - $value['dir'], - 0, - strlen($value['dir']) - 1 - ); - $temp = explode('/', $folder_path); - $title = $temp[count($temp) - 1]; - - //hack until feature #5242 is implemented - if ($title == 'gallery') { - $title = get_lang('DefaultCourseImages'); - } - - if ($media_type == 'images/gallery') { - $folder_path = 'gallery/'.$folder_path; - } - - create_unexisting_directory( - $courseInfo, - api_get_user_id(), - 0, - 0, - 0, - $path_documents.$folder_path, - $title, - $title - ); - } - } - - if (isset($value['file']) && !empty($value['file'])) { - if (!file_exists($default_course_path.$value['file'])) { - // Copying file - /*copy( - $default_course_path.$value['file'], - $course_documents_folder.$value['file'] - );*/ - $temp = explode('/', $value['file']); - - //hack until feature #5242 is implemented - if ($media_type == 'images/gallery') { - $value["file"] = 'gallery/'.$value["file"]; - } - //$default_course_path.$value['file'] - DocumentManager::addDocument( - $courseInfo, - $default_course_path.$value['file'], - 'file', - filesize($default_course_path.$value['file']), - $temp[count($temp) - 1], - '' - ); - - // Inserting file in the DB - /*Database::query( - "INSERT INTO $TABLETOOLDOCUMENT (c_id, path,title,filetype,size) - VALUES ($course_id,'$path_documents".$value["file"]."','".$temp[count($temp) - 1]."','file','$file_size')" - ); - $image_id = Database:: insert_id();*/ - } - } - } + $finder = new Symfony\Component\Finder\Finder(); + $defaultPath = api_get_path(SYS_CODE_PATH).'default_course_document'; + $finder->in($defaultPath); + /** @var SplFileInfo $file */ + foreach ($finder as $file) { + $path = str_replace($defaultPath, '', $file->getRealPath()); + $parentName = dirname(str_replace($defaultPath, '', $file->getRealPath())); + $title = $file->getFilename(); + if ($file->isDir()) { + create_unexisting_directory( + $courseInfo, + api_get_user_id(), + 0, + 0, + 0, + $path, + $title, + $title + ); + } else { + $parent = DocumentManager::getDocumentByPathInCourse($courseInfo, $parentName); + $parentId = 0; + if (!empty($parent)) { + $parent = $parent[0]; + $parentId = $parent['iid']; } + + DocumentManager::addDocument( + $courseInfo, + $file->getRealPath(), + 'file', + $file->getSize(), + $title, + '', + null, + null, + null, + null, + null, + false, + null, + $parentId + ); } } diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 94ff7c883d..842dc69090 100644 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -431,7 +431,7 @@ class DocumentManager */ public static function getSessionFolderFilters($path, $sessionId) { - $sessionId = intval($sessionId); + $sessionId = (int) $sessionId; $condition = null; if (!empty($sessionId)) { @@ -638,7 +638,7 @@ class DocumentManager * Gets the paths of all folders in a course * can show all folders (except for the deleted ones) or only visible ones. * - * @param array $_course + * @param array $courseInfo * @param int $groupIid iid * @param bool $can_see_invisible * @param bool $getInvisibleList @@ -647,19 +647,20 @@ class DocumentManager * @return array with paths */ public static function get_all_document_folders( - $_course, + $courseInfo, $groupIid = 0, $can_see_invisible = false, $getInvisibleList = false, $path = '' ) { - $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); - $groupIid = intval($groupIid); - $document_folders = []; + $groupIid = (int) $groupIid; + $courseId = $courseInfo['real_id']; + $sessionId = api_get_session_id(); + $folders = []; $students = CourseManager::get_user_list_from_course_code( - $_course['code'], + $courseInfo['code'], api_get_session_id() ); @@ -670,9 +671,9 @@ class DocumentManager } } - $groupCondition = " l.to_group_id = $groupIid"; + $groupCondition = " l.group_id = $groupIid"; if (empty($groupIid)) { - $groupCondition = " (l.group_id = 0 OR l.group_id IS NULL)"; + $groupCondition = ' (l.group_id = 0 OR l.group_id IS NULL)'; } $show_users_condition = ''; @@ -681,50 +682,32 @@ class DocumentManager } if ($can_see_invisible) { - // condition for the session - $session_id = api_get_session_id(); - $session_id = $session_id ?: api_get_session_id(); - $condition_session = " AND (l.session_id = '$session_id' OR (l.session_id = '0' OR l.session_id IS NULL) )"; - $condition_session .= self::getSessionFolderFilters($path, $session_id); + $sessionId = $sessionId ?: api_get_session_id(); + $condition_session = " AND (l.session_id = '$sessionId' OR (l.session_id = '0' OR l.session_id IS NULL) )"; + $condition_session .= self::getSessionFolderFilters($path, $sessionId); + + $sql = "SELECT DISTINCT docs.id, docs.path + FROM resource_node AS n + INNER JOIN $TABLE_DOCUMENT AS docs + ON (docs.resource_node_id = n.id) + INNER JOIN resource_link l + ON (l.resource_node_id = n.id) + WHERE + docs.c_id = $courseId AND + docs.filetype = 'folder' AND + $groupCondition AND + docs.path NOT LIKE '%shared_folder%' AND + docs.path NOT LIKE '%_DELETED_%' AND + l.visibility NOT IN ('".ResourceLink::VISIBILITY_DELETED."') + $condition_session "; if ($groupIid != 0) { - $sql = "SELECT DISTINCT docs.id, path - FROM $TABLE_ITEMPROPERTY AS last - INNER JOIN $TABLE_DOCUMENT AS docs - ON ( - docs.id = last.ref AND - docs.c_id = last.c_id - ) - WHERE - last.tool = '".TOOL_DOCUMENT."' AND - last.c_id = {$_course['real_id']} AND - docs.c_id = {$_course['real_id']} AND - docs.filetype = 'folder' AND - $groupCondition AND - docs.path NOT LIKE '%shared_folder%' AND - docs.path NOT LIKE '%_DELETED_%' AND - last.visibility <> 2 - $condition_session "; + $sql .= " AND docs.path NOT LIKE '%shared_folder%' "; } else { - $sql = "SELECT DISTINCT docs.id, docs.path - FROM resource_node AS n - INNER JOIN $TABLE_DOCUMENT AS docs - ON (docs.resource_node_id = n.id) - INNER JOIN resource_link l - ON (l.resource_node_id = n.id) - WHERE - docs.c_id = {$_course['real_id']} AND - docs.filetype = 'folder' AND - docs.path NOT LIKE '%_DELETED_%' AND - $groupCondition AND - l.visibility NOT IN ('".ResourceLink::VISIBILITY_DELETED."') - $show_users_condition - $condition_session - "; + $sql .= $show_users_condition; } $result = Database::query($sql); - if ($result && Database::num_rows($result) != 0) { while ($row = Database::fetch_array($result, 'ASSOC')) { if (self::is_folder_to_avoid($row['path'])) { @@ -737,53 +720,49 @@ class DocumentManager } } - $document_folders[$row['id']] = $row['path']; + $folders[$row['id']] = $row['path']; } - if (!empty($document_folders)) { - natsort($document_folders); + if (!empty($folders)) { + natsort($folders); } - return $document_folders; + return $folders; } else { return false; } } else { // No invisible folders // Condition for the session - $session_id = api_get_session_id(); $condition_session = api_get_session_condition( - $session_id, + $sessionId, true, false, 'docs.session_id' ); - $visibilityCondition = 'last.visibility = 1'; + $visibilityCondition = 'l.visibility = 1'; $fileType = "docs.filetype = 'folder' AND"; if ($getInvisibleList) { - $visibilityCondition = 'last.visibility = 0'; + $visibilityCondition = 'l.visibility = 0'; $fileType = ''; } //get visible folders - $sql = "SELECT DISTINCT docs.id, path - FROM - $TABLE_ITEMPROPERTY AS last - INNER JOIN $TABLE_DOCUMENT AS docs - ON (docs.id = last.ref AND last.c_id = docs.c_id) + $sql = "SELECT DISTINCT docs.id, docs.path + FROM resource_node AS n + INNER JOIN $TABLE_DOCUMENT AS docs + ON (docs.resource_node_id = n.id) + INNER JOIN resource_link l + ON (l.resource_node_id = n.id) WHERE - $fileType - last.tool = '".TOOL_DOCUMENT."' AND + $fileType $groupCondition AND $visibilityCondition $show_users_condition - $condition_session AND - last.c_id = {$_course['real_id']} AND - docs.c_id = {$_course['real_id']} "; - + $condition_session AND + docs.c_id = $courseId "; $result = Database::query($sql); - $visibleFolders = []; while ($row = Database::fetch_array($result, 'ASSOC')) { $visibleFolders[$row['id']] = $row['path']; @@ -793,34 +772,36 @@ class DocumentManager return $visibleFolders; } - //get invisible folders - $sql = "SELECT DISTINCT docs.id, path - FROM $TABLE_ITEMPROPERTY AS last - INNER JOIN $TABLE_DOCUMENT AS docs - ON (docs.id = last.ref AND last.c_id = docs.c_id) + // get invisible folders + $sql = "SELECT DISTINCT docs.id, docs.path + FROM resource_node AS n + INNER JOIN $TABLE_DOCUMENT AS docs + ON (docs.resource_node_id = n.id) + INNER JOIN resource_link l + ON (l.resource_node_id = n.id) WHERE - docs.filetype = 'folder' AND - last.tool = '".TOOL_DOCUMENT."' AND - $groupCondition AND - last.visibility = 0 $condition_session AND - last.c_id = {$_course['real_id']} AND - docs.c_id = {$_course['real_id']} "; + docs.filetype = 'folder' AND + $groupCondition AND + l.visibility IN ('".ResourceLink::VISIBILITY_PENDING."') + $condition_session AND + docs.c_id = $courseId "; $result = Database::query($sql); $invisibleFolders = []; while ($row = Database::fetch_array($result, 'ASSOC')) { //get visible folders in the invisible ones -> they are invisible too - $sql = "SELECT DISTINCT docs.id, path - FROM $TABLE_ITEMPROPERTY AS last - INNER JOIN $TABLE_DOCUMENT AS docs - ON (docs.id = last.ref AND docs.c_id = last.c_id) + $sql = "SELECT DISTINCT docs.id, docs.path + FROM resource_node AS n + INNER JOIN $TABLE_DOCUMENT AS docs + ON (docs.resource_node_id = n.id) + INNER JOIN resource_link l + ON (l.resource_node_id = n.id) WHERE docs.path LIKE '".Database::escape_string($row['path'].'/%')."' AND - docs.filetype = 'folder' AND - last.tool = '".TOOL_DOCUMENT."' AND + docs.filetype = 'folder' AND $groupCondition AND - last.visibility = 1 $condition_session AND - last.c_id = {$_course['real_id']} AND - docs.c_id = {$_course['real_id']} "; + l.visibility NOT IN ('".ResourceLink::VISIBILITY_DELETED."') + $condition_session AND + docs.c_id = $courseId "; $folder_in_invisible_result = Database::query($sql); while ($folders_in_invisible_folder = Database::fetch_array($folder_in_invisible_result, 'ASSOC')) { $invisibleFolders[$folders_in_invisible_folder['id']] = $folders_in_invisible_folder['path']; @@ -829,18 +810,20 @@ class DocumentManager // If both results are arrays -> //calculate the difference between the 2 arrays -> only visible folders are left :) if (is_array($visibleFolders) && is_array($invisibleFolders)) { - $document_folders = array_diff($visibleFolders, $invisibleFolders); - natsort($document_folders); + $folders = array_diff($visibleFolders, $invisibleFolders); + natsort($folders); - return $document_folders; - } elseif (is_array($visibleFolders)) { + return $folders; + } + + if (is_array($visibleFolders)) { natsort($visibleFolders); return $visibleFolders; - } else { - //no visible folders found - return false; } + + // no visible folders found + return false; } } @@ -851,7 +834,7 @@ class DocumentManager * @param array $_course * @param int $user_id id of the current user * @param string $file path stored in the database (if not defined, $documentId must be used) - * @param int $document_id in case you dont have the file path , + * @param int $document_id in case you don't have the file path , * insert the id of the file here and leave $file in blank '' * @param bool $to_delete * @param int $sessionId @@ -867,16 +850,13 @@ class DocumentManager $sessionId = null, $documentId = null ) { + $sessionId = (int) $sessionId; if (empty($sessionId)) { $sessionId = api_get_session_id(); - } else { - $sessionId = intval($sessionId); } - - if (empty($document_id) || !is_numeric($document_id)) { + $document_id = (int) $document_id; + if (empty($document_id)) { $document_id = self::get_document_id($_course, $file, $sessionId); - } else { - $document_id = intval($document_id); } $TABLE_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); @@ -884,7 +864,7 @@ class DocumentManager $course_id = $_course['real_id']; if ($to_delete) { - if (self::is_folder($_course, $document_id)) { + if (self::isFolder($_course, $document_id)) { if (!empty($file)) { $path = Database::escape_string($file); // Check @@ -952,7 +932,7 @@ class DocumentManager * * @return bool true/false * */ - public static function is_folder($_course, $id) + public static function isFolder($_course, $id) { $table = Database::get_course_table(TABLE_DOCUMENT); if (empty($_course)) { @@ -964,7 +944,7 @@ class DocumentManager WHERE c_id = $course_id AND id= $id"; $result = Database::fetch_array(Database::query($sql), 'ASSOC'); - return $result['filetype'] == 'folder'; + return $result['filetype'] === 'folder'; } /** @@ -4380,7 +4360,7 @@ class DocumentManager } /** - * Check if the past is used in this course. + * Check if the path is used in this course. * * @param array $courseInfo * @param string $path @@ -6468,7 +6448,6 @@ class DocumentManager $em = Database::getManager(); $documentRepo = Container::$container->get('Chamilo\CourseBundle\Repository\CDocumentRepository'); - //$documentRepo = $em->getRepository('ChamiloCourseBundle:CDocument'); $parentNode = null; if (!empty($parentId)) { From c4c9d7ec1063ae5c94408f226678bd986a147e24 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 23 Nov 2018 14:09:59 +0100 Subject: [PATCH 3/9] Minor - replace get_lang with trans --- .../views/Admin/switcher_links.html.twig | 23 ---- .../Resources/views/Index/page.html.twig | 2 +- .../views/Layout/base-layout.html.twig | 4 +- .../Resources/views/Layout/footer.html.twig | 8 +- .../Resources/views/Layout/menu.html.twig | 6 +- .../Resources/views/Layout/sidebar.html.twig | 6 +- .../Resources/views/Layout/topbar.html.twig | 6 +- .../Resources/views/LearnPath/list.html.twig | 130 +++++++++--------- .../views/LearnPath/record_voice.html.twig | 6 +- .../views/LearnPath/report.html.twig | 18 +-- .../Resources/views/LearnPath/view.html.twig | 26 ++-- .../Exercise/result_alert_body.html.twig | 10 +- .../Resources/views/Navbar/user.html.twig | 4 +- .../Resources/views/News/slider.html.twig | 4 +- .../Resources/views/News/view.html.twig | 4 +- .../Resources/views/Online/index.html.twig | 8 +- .../Online/online_users_in_course.html.twig | 8 +- .../views/Social/user_block.html.twig | 24 ++-- .../default/layout/hot_course_item.html.twig | 4 +- .../default/layout/hot_courses.html.twig | 10 +- 20 files changed, 144 insertions(+), 167 deletions(-) diff --git a/src/ThemeBundle/Resources/views/Admin/switcher_links.html.twig b/src/ThemeBundle/Resources/views/Admin/switcher_links.html.twig index 8832853f54..1fab42d261 100644 --- a/src/ThemeBundle/Resources/views/Admin/switcher_links.html.twig +++ b/src/ThemeBundle/Resources/views/Admin/switcher_links.html.twig @@ -24,26 +24,3 @@ {% endautoescape %} {% endif %} - -{##} diff --git a/src/ThemeBundle/Resources/views/Index/page.html.twig b/src/ThemeBundle/Resources/views/Index/page.html.twig index 60e356784d..d59a8dd6bb 100644 --- a/src/ThemeBundle/Resources/views/Index/page.html.twig +++ b/src/ThemeBundle/Resources/views/Index/page.html.twig @@ -10,7 +10,7 @@ {% set content %} - {{ macro.box_header("IntroductionOfPlatform" | get_lang, buttons) }} + {{ macro.box_header("IntroductionOfPlatform" | trans, buttons) }} {{ sonata_page_render_container('content', page) }} {% endset %} diff --git a/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig b/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig index 21096722cb..4755441011 100644 --- a/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig +++ b/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig @@ -122,7 +122,7 @@