-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1003 [Documents] fix: enhance document list #1021
base: develop
Are you sure you want to change the base?
Changes from 4 commits
1baa1a5
6e6d570
124ea38
bb6fc4e
b285c8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,9 +46,11 @@ | |
* @param string $removeaction (optional) The action to remove a file | ||
* @param int $active (optional) To show gen button disabled | ||
* @param string $tooltiptext (optional) Tooltip text when gen button disabled | ||
* @param string $sortfield (optional) Allows to sort the list of files by a field | ||
* @param string $sortorder (optional) Allows to sort the list of files with a specific order | ||
* @return string Output string with HTML array of documents (might be empty string) | ||
*/ | ||
function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, string $urlsource, $genallowed, int $delallowed = 0, string $modelselected = '', int $allowgenifempty = 1, int $forcenomultilang = 0, int $notused = 0, int $noform = 0, string $param = '', string $title = '', string $buttonlabel = '', string $codelang = '', string $morepicto = '', $object = null, int $hideifempty = 0, string $removeaction = 'remove_file', int $active = 1, string $tooltiptext = ''): string | ||
function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, string $urlsource, $genallowed, int $delallowed = 0, string $modelselected = '', int $allowgenifempty = 1, int $forcenomultilang = 0, int $notused = 0, int $noform = 0, string $param = '', string $title = '', string $buttonlabel = '', string $codelang = '', string $morepicto = '', $object = null, int $hideifempty = 0, string $removeaction = 'remove_file', int $active = 1, string $tooltiptext = '', string $sortfield = '', string $sortorder = ''): string | ||
{ | ||
global $conf, $db, $form, $hookmanager, $langs; | ||
|
||
|
@@ -63,6 +65,23 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
$param .= ($param ? '&' : '') . 'entity=' . (!empty($object->entity) ? $object->entity : $conf->entity); | ||
} | ||
|
||
if (empty($sortfield)) { | ||
if (GETPOST('sortfield')) { | ||
$sortfield = GETPOST('sortfield'); | ||
} else { | ||
$sortfield = 'name'; | ||
} | ||
} | ||
|
||
|
||
if (empty($sortorder)) { | ||
if (GETPOST('sortorder')) { | ||
$sortorder = GETPOST('sortorder'); | ||
} else { | ||
$sortorder = 'desc'; | ||
} | ||
} | ||
|
||
$hookmanager->initHooks(['formfile']); | ||
|
||
// Get list of files | ||
|
@@ -75,7 +94,37 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
} else { | ||
$fileList = dol_dir_list($filedir, 'files', 0, '(\.jpg|\.jpeg|\.png|\.odt|\.zip|\.pdf)', '', 'date', SORT_DESC, 1); | ||
} | ||
} | ||
} | ||
|
||
if (GETPOST('search_name')) { | ||
$fileList = array_filter($fileList, function($file) { | ||
return strpos($file['name'], GETPOST('search_name')) !== false; | ||
}); | ||
} | ||
|
||
if (GETPOST('search_date')) { | ||
$search_date = GETPOST('search_date'); | ||
$fileList = array_filter($fileList, function($file) use ($search_date) { | ||
$file_date = date('Y-m-d', $file['date']); | ||
return $file_date === $search_date; | ||
}); | ||
} | ||
|
||
|
||
$fileList = dol_sort_array($fileList, $sortfield, $sortorder); | ||
|
||
$page = GETPOST('page', 'int') ?: 1; | ||
$filePerPage = 20; | ||
$fileListLength = 0; | ||
if (is_array($fileList) && !empty($fileList)) { | ||
$fileListLength = count($fileList); | ||
} | ||
|
||
if ($fileListLength > $filePerPage) { | ||
$fileList = array_slice($fileList, ($page - 1 ) * $filePerPage, $filePerPage); | ||
} | ||
|
||
$pageNumber = ceil($fileListLength / $filePerPage); | ||
|
||
if ($hideifempty && empty($fileList)) { | ||
return ''; | ||
|
@@ -215,6 +264,20 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
$genbutton = ''; | ||
} | ||
$out .= $genbutton; | ||
$querySeparator = (strpos($_SERVER['REQUEST_URI'], '?') === false) ? '?' : '&'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. il sert à rien ici |
||
|
||
$out .= '<div class="pagination">'; | ||
if($page > 1) { | ||
$out .= '<a href="'. $_SERVER['PHP_SELF'] . '?page=' . ($page - 1) .'&sortfield=' . $sortfield . '&sortorder=' . $sortorder . '#builddoc_form"><i class="fas fa-chevron-left"></i></a>'; | ||
$out .= ' '; | ||
} | ||
$out .= '<input hidden id="page_number" value="' . $pageNumber . '">'; | ||
$out .= '<input name="change_pagination" id="change_pagination" class="maxwidth25" value="' . $page . '" name="page">'; | ||
$out .= ' / '; | ||
$out .= '<a href="'. $_SERVER['PHP_SELF'] . '?page=' . $pageNumber .'&sortfield=' . $sortfield . '&sortorder=' . $sortorder . '#builddoc_form">' . $pageNumber . '</a>'; | ||
$out .= ' '; | ||
$out .= '<a href="'. $_SERVER['PHP_SELF'] . '?page=' . ($page + 1) .'&sortfield=' . $sortfield . '&sortorder=' . $sortorder . '#builddoc_form"><i class="fas fa-chevron-right"></i></a>'; | ||
$out .= '</div>'; | ||
} else { | ||
$out .= '<div class="float">' . $langs->trans('Files') . '</div>'; | ||
} | ||
|
@@ -240,6 +303,25 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
$out .= '<td></td>'; | ||
} | ||
$out .= '</tr>'; | ||
$out .= '<tr class="liste_titre">'; | ||
$out .= get_document_title_search('text', 'Name'); | ||
$out .= '<td></td>'; | ||
$out .= get_document_title_search('date', 'Date', 'right'); | ||
$out .= '<td></td>'; | ||
$out .= '<td class="right ">'; | ||
$out .= '<i class="saturne-search-button fas fa-search" style="cursor: pointer;"></i>'; | ||
$out .= ' '; | ||
$out .= '<i class="saturne-cancel-button fas fa-times" style="cursor: pointer;"></i>'; | ||
$out .= '</td>'; | ||
|
||
$out .= '</tr>'; | ||
$out .= '<tr class="liste_titre">'; | ||
$out .= get_document_title_field($sortfield, $sortorder, 'Name'); | ||
$out .= get_document_title_field($sortfield, $sortorder, 'Size', true, 'right'); | ||
$out .= get_document_title_field($sortfield, $sortorder, 'Date', true, 'right'); | ||
$out .= get_document_title_field($sortfield, $sortorder, 'PDF', false, 'right'); | ||
$out .= get_document_title_field($sortfield, $sortorder, 'Action', false, 'right'); | ||
$out .= '</tr>'; | ||
|
||
// Execute hooks | ||
$parameters = ['colspan' => ($colspan + $colspanmore), 'socid' => ($GLOBALS['socid'] ?? ''), 'id' => ($GLOBALS['id'] ?? ''), 'modulepart' => $modulepart]; | ||
|
@@ -258,7 +340,6 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
if (is_object($object) && $object->id > 0) { | ||
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; | ||
$link = new Link($db); | ||
$sortfield = $sortorder = null; | ||
$link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder); | ||
} | ||
|
||
|
@@ -412,6 +493,52 @@ function saturne_show_documents(string $modulepart, $modulesubdir, $filedir, str | |
return $out; | ||
} | ||
|
||
/** | ||
* Get document title field | ||
* | ||
* @param string $sortfield | ||
* @param string $sortorder | ||
* @param string $name | ||
* @param bool $sortable | ||
* @param string $morehtml | ||
* @return string | ||
*/ | ||
function get_document_title_field(string $sortfield, string $sortorder, string $name, bool $sortable = true, string $morehtml = ''): string { | ||
global $langs; | ||
|
||
$querySeparator = (strpos($_SERVER['PHP_SELF'], '?') === false) ? '?' : '&'; | ||
$out = '<th class="'. $morehtml .'">'; | ||
if ($sortable) { | ||
$out .= '<a href="'. $_SERVER['PHP_SELF'] . $querySeparator . 'sortfield='. (strtolower($name)) .'&sortorder=' . ($sortorder == 'desc' ? 'asc' : 'desc') .'#builddoc_form">'; | ||
$out .= ($sortfield == strtolower($name) ? '<u>' : ''); | ||
} | ||
$out .= $langs->trans($name); | ||
if ($sortable) { | ||
$out .= ' ' . ($sortfield == strtolower($name) ? ($sortorder == 'asc' ? '<i class="fas fa-chevron-up"></i>' : '<i class="fas fa-chevron-down"></i>') : ''); | ||
$out .= ($sortfield == strtolower($name) ? '</u>' : ''); | ||
$out .= '</a>'; | ||
} | ||
$out .='</th>'; | ||
|
||
return $out; | ||
} | ||
|
||
/** | ||
* Get document title search | ||
* | ||
* @param string $type | ||
* @param string $name | ||
* @param string $morehtml | ||
* @return string | ||
*/ | ||
function get_document_title_search(string $type, string $name, string $morehtml = ''): string | ||
{ | ||
$out = '<td class="'. $morehtml .'">'; | ||
$out .= '<input class="saturne-search" id="search_' . strtolower($name) . '" type="'. $type .'" name="search_' . strtolower($name) . '" value="' . GETPOST('search_' . strtolower($name)) . '">'; | ||
$out .= '</td>'; | ||
return $out; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. un espace entre le return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +psr12 |
||
} | ||
|
||
/** | ||
* Exclude index.php files from list of models for document generation | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
psr12