Skip to content

Commit

Permalink
Parity change on editing a linked resource from the event modificatio…
Browse files Browse the repository at this point in the history
…n page
  • Loading branch information
Elisée Chemin committed Nov 7, 2024
1 parent 8db5a85 commit d92a3ad
Showing 1 changed file with 29 additions and 42 deletions.
71 changes: 29 additions & 42 deletions htdocs/resource/element_resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,54 +183,41 @@
$eventDateStart = $object->objelement->datep;
$eventDateEnd = $object->objelement->datef;
$isFullDayEvent = $objstat->fulldayevent;
if (empty($eventDateEnd)) {
if ($isFullDayEvent) {
$eventDateStartArr = dol_getdate($eventDateStart);
$eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
$eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
}
}

$sql = "SELECT er.rowid, r.ref as r_ref, ac.id as ac_id, ac.label as ac_label";
$sql .= " FROM ".MAIN_DB_PREFIX."element_resources as er";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."resource as r ON r.rowid = er.resource_id AND er.resource_type = '".$db->escape($object->resource_type)."'";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm as ac ON ac.id = er.element_id AND er.element_type = '".$db->escape($object->element_type)."'";
$sql .= " WHERE er.resource_id = ".((int) $object->resource_id);
$sql .= " AND ac.id <> ".((int) $object->element_id);
$sql .= " AND er.busy = 1";
$sql .= " AND (";

// event date start between ac.datep and ac.datep2 (if datep2 is null we consider there is no end)
$sql .= " (ac.datep <= '".$db->idate($eventDateStart)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateStart)."'))";
// event date end between ac.datep and ac.datep2
if (!empty($eventDateEnd)) {
$sql .= " OR (ac.datep <= '".$db->idate($eventDateEnd)."' AND (ac.datep2 IS NULL OR ac.datep2 >= '".$db->idate($eventDateEnd)."'))";
}
// event date start before ac.datep and event date end after ac.datep2
$sql .= " OR (";
$sql .= "ac.datep >= '".$db->idate($eventDateStart)."'";
if (!empty($eventDateEnd)) {
$sql .= " AND (ac.datep2 IS NOT NULL AND ac.datep2 <= '".$db->idate($eventDateEnd)."')";
if (empty($eventDateEnd) && $isFullDayEvent) {
$eventDateStartArr = dol_getdate($eventDateStart);
$eventDateStart = dol_mktime(0, 0, 0, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
$eventDateEnd = dol_mktime(23, 59, 59, $eventDateStartArr['mon'], $eventDateStartArr['mday'], $eventDateStartArr['year']);
}
$sql .= ")";

$sql .= ")";
$resql = $db->query($sql);
if (!$resql) {
// Get the ressources busy during the period with the id "id"

Check failure on line 193 in htdocs/resource/element_resource.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

ressources ==> resources
$_busyResources = getBusyResourcesInPeriod($eventDateStart, $eventDateEnd, array((int) $resource_id));

// sql error
if ($_busyResources === false) {
// an error occurred in the sql
$error++;
$object->error = $db->lasterror();
$object->error = $db->lasterror();
$object->errors[] = $object->error;
} else {
if ($db->num_rows($resql) > 0) {
// Resource already in use
$error++;
$object->error = $langs->trans('ErrorResourcesAlreadyInUse').' : ';
while ($obj = $db->fetch_object($resql)) {
$object->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $obj->r_ref, $obj->ac_label.' ['.$obj->ac_id.']');
}
$object->errors[] = $objstat->error;
}

// removing the rows associated with our action id
$ac_id = (int) $object->element_id;
$busyResources = array_filter($_busyResources, function ($row) : bool {

Check warning on line 206 in htdocs/resource/element_resource.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

element_resource.php: PhanPluginUnknownClosureParamType: Closure Closure($row) : bool has no declared or inferred parameter type for $row
global $ac_id;
return $row->ac_id != $ac_id;
});

if (!empty($busyResources)) {
// Resource already in use
$error++;

$object->error = $langs->trans('ErrorResourcesAlreadyInUse') . ' : ' ;
foreach ($busyResources as $row) {
$object->error .= '<br> - '.$langs->trans('ErrorResourceUseInEvent', $row->r_ref, $row->ac_label.' ['.$row->ac_id.']');
}
$db->free($resql);

$object->errors[] = $object->error;
}
}

Expand Down

0 comments on commit d92a3ad

Please sign in to comment.