Skip to content

Commit

Permalink
#4171 [PreventionPlan] fix: no more php8 warning in prevention plan list
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-kilyan committed Dec 4, 2024
1 parent d997a22 commit 84fe131
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
6 changes: 6 additions & 0 deletions class/preventionplan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ public function LibStatut($status, $mode = 0): string
$this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('ValidatePendingSignature');
$this->labelStatus[self::STATUS_LOCKED] = $langs->trans('Locked');
$this->labelStatus[self::STATUS_ARCHIVED] = $langs->trans('Archived');

$this->labelStatusShort[self::STATUS_DELETED] = $langs->transnoentitiesnoconv('Deleted');
$this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled');
$this->labelStatusShort[self::STATUS_LOCKED] = $langs->transnoentitiesnoconv('Locked');
$this->labelStatusShort[self::STATUS_ARCHIVED] = $langs->transnoentitiesnoconv('Archived');
}

$statusType = 'status' . $status;
Expand Down
29 changes: 17 additions & 12 deletions view/preventionplan/preventionplan_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
print '<input type="hidden" name="type" value="' . $type . '">';
print '<input type="hidden" name="type" value="' . ($type ?? '') . '">';
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';

include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php';
Expand All @@ -280,16 +280,17 @@
$sql = preg_replace('/,\s*$/', '', $sql);
$sql .= " FROM " . MAIN_DB_PREFIX . $object->table_element . " as t";

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


foreach ($search as $key => $val) {
if ($key == 'status' && $search[$key] == -1) continue;
$mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
if (strpos($object->fields[$key]['type'], 'integer:') === 0) {
$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;
}
Expand Down Expand Up @@ -353,7 +354,7 @@
$arrayfields['ExtSocietyResponsible'] = array('label' => 'ExtSocietyResponsible', 'checked' => 1);
$arrayfields['ExtSocietyAttendant'] = array('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);
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);

$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
Expand All @@ -373,10 +374,10 @@
if ( ! empty($arrayfields['t.' . $key]['checked'])) {
print '<td class="liste_titre' . ($cssforfield ? ' ' . $cssforfield : '') . '">';

if (is_array($val['arrayofkeyval'])) print $form->selectarray('search_' . $key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
if (isset($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) print $form->selectarray('search_' . $key, $val['arrayofkeyval'], $search[$key] ?? '', $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth75');
elseif (strpos($val['type'], 'integer:') === 0) {
print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
} elseif ( ! preg_match('/^(date|timestamp)/', $val['type'])) print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag($search[$key]) . '">';
print $object->showInputField($val, $key, $search[$key] ?? '', '', '', 'search_', 'maxwidth150', 1);
} elseif ( ! preg_match('/^(date|timestamp)/', $val['type'])) print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag($search[$key] ?? '') . '">';
print '</td>';
}
if ($key == 'Custom') {
Expand Down Expand Up @@ -449,7 +450,7 @@

// contenu
$i = 0;
$totalarray = array();
$totalarray = ['nbfield' => 0];

while ($i < ($limit ? min($num, $limit) : $num)) {
$obj = $db->fetch_object($resql);
Expand All @@ -459,7 +460,11 @@
// Store properties in $objectdocument
$object->setVarsFromFetchObj($obj);

$json = json_decode($object->json, false, 512, JSON_UNESCAPED_UNICODE)->PreventionPlan;
if (isset($object->json)) {
$json = json_decode($object->json, false, 512, JSON_UNESCAPED_UNICODE)->PreventionPlan;
} else {
$json = [];
}

// Show here line of result
print '<tr class="oddeven preventionplandocument-row preventionplan_row_' . $object->id . ' preventionplandocument-row-content-' . $object->id . '" id="preventionplan_row_' . $object->id . '">';
Expand Down Expand Up @@ -492,7 +497,7 @@
print '<td>';
if ($resource['label'] == 'MasterWorker') {
$element = $signatory->fetchSignatory('MasterWorker', $object->id, 'preventionplan');
if (is_array($element)) {
if (is_array($element) && !empty($element)) {
$element = array_shift($element);
$usertmp->fetch($element->element_id);
print $usertmp->getNomUrl(1);
Expand All @@ -505,7 +510,7 @@
}
if ($resource['label'] == 'ExtSocietyResponsible') {
$element = $signatory->fetchSignatory('ExtSocietyResponsible', $object->id, 'preventionplan');
if (is_array($element)) {
if (is_array($element) && !empty($element)) {
$element = array_shift($element);
$contact->fetch($element->element_id);
print $contact->getNomUrl(1);
Expand Down

0 comments on commit 84fe131

Please sign in to comment.