Skip to content

#4153 [PreventionPlanList] add: filter on prevention plan list for ExtSociety #4213

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 51 additions & 30 deletions view/preventionplan/preventionplan_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,35 +282,44 @@

if (isset($extrafields->attributes[$object->table_element]['label']) &&
is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'digiriskdolibarr_digiriskresources as rs ON rs.ref = "ExtSociety" AND rs.object_type = "preventionplan" AND rs.object_id = t.rowid';

if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ")";
else $sql .= " WHERE 1 = 1";
$sql .= ' AND status != -1';
$sql .= ' AND t.status != -1';


foreach ($search as $key => $val) {
if ($key == 'status' && $search[$key] == -1) continue;
$mode_search = ((isset($object->fields[$key]) && ($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))) ? 1 : 0);
if ($key == 'status' && $search[$key] == -1)
continue;
$mode_search = ((isset($object->fields[$key]) && ($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))) ? 1 : 0);
if (strpos($object->fields[$key]['type'] ?? '', 'integer:') === 0) {
if ($search[$key] == '-1') $search[$key] = '';
$mode_search = 2;
if ($search[$key] == '-1')
$search[$key] = '';
$mode_search = 2;
}
if ($search[$key] != '') $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
if ($search[$key] != '')
$sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
}
if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);

if (GETPOSTISSET('search_extsociety') && GETPOSTINT('search_extsociety') != -1) {
$sql .= ' AND rs.element_id = ' . GETPOSTINT('search_extsociety');
}
if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
// Add where from extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $objectdocument may have been modified by hook
$sql .= $hookmanager->resPrint;

$sql .= $db->order($sortfield, $sortorder);

// Count total nb of records
$nbtotalofrecords = '';

// Add where from extra fields
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
// Add where from hooks
$parameters = [];
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $objectdocument may have been modified by hook
$sql .= $hookmanager->resPrint;

$sql .= $db->order($sortfield, $sortorder);

// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$resql = $db->query($sql);

$nbtotalofrecords = $db->num_rows($resql);
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
$page = 0;
Expand Down Expand Up @@ -349,10 +358,16 @@

$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;

$arrayfields['MasterWorker'] = array('label' => 'MasterWorker', 'checked' => 1);
$arrayfields['ExtSociety'] = array('label' => 'ExtSociety', 'checked' => 1);
$arrayfields['ExtSocietyResponsible'] = array('label' => 'ExtSocietyResponsible', 'checked' => 1);
$arrayfields['ExtSocietyAttendant'] = array('label' => 'ExtSocietyAttendant', 'checked' => 1);
$arrayfields['MasterWorker'] = ['label' => 'MasterWorker', 'checked' => 1];
$arrayfields['ExtSociety'] = ['label' => 'ExtSociety', 'checked' => 1, 'arrayofkeyval' => [], 'sortfield' => 'rs.object_id'];
$tmpsql = 'SELECT rowid, nom FROM ' . MAIN_DB_PREFIX . 'societe WHERE entity = ' . $conf->entity;
$tmpresql = $db->query($tmpsql);
while ($tmpobj = $db->fetch_object($tmpresql)) {
$arrayfields['ExtSociety']['arrayofkeyval'][$tmpobj->rowid] = $tmpobj->nom;
}
$db->free($tmpresql);
$arrayfields['ExtSocietyResponsible'] = ['label' => 'ExtSocietyResponsible', 'checked' => 1];
$arrayfields['ExtSocietyAttendant'] = ['label' => 'ExtSocietyAttendant', 'checked' => 1];

print_barre_liste($form->textwithpicto($title, $texthelp ?? ''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);

Expand Down Expand Up @@ -383,9 +398,12 @@
if ($key == 'Custom') {
foreach ($val as $resource) {
if ($resource['checked']) {
print '<td>';
print '</td>';
}
print '<td>';
if (isset($resource['arrayofkeyval']) && is_array($resource['arrayofkeyval'])) {
print $form->selectarray('search_' . dol_strtolower($resource['label']), $resource['arrayofkeyval'], GETPOSTINT('search_' . dol_strtolower($resource['label'])), 1, 0, 0, '', 1, 0, 0, '', 'maxwidth150');
}
print '</td>';
}
}
}
}
Expand Down Expand Up @@ -422,10 +440,13 @@
}
if ($key == 'Custom') {
foreach ($val as $resource) {
if ($resource['checked']) {
print '<td>';
print $langs->trans($resource['label']);
print '</td>';
if (!empty($resource['checked'])) {
if (!empty($resource['sortfield'])) {
$disablesort = 0;
} else {
$disablesort = 1;
}
print getTitleFieldOfList($resource['label'], 0, $_SERVER['PHP_SELF'], $resource['sortfield'], '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : ''), $disablesort) . "\n";
}
}
}
Expand Down