clean code bookcal class (#35279)

* clean code bookcal class

* clean code bookcal class

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix
This commit is contained in:
Frédéric FRANCE 2025-09-11 12:12:53 +02:00 committed by GitHub
parent 13dbe2ea58
commit fd2ea78e9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 146 additions and 499 deletions

View file

@ -2286,216 +2286,6 @@ parameters:
count: 1
path: ../../../htdocs/bookcal/calendar_list.php
-
message: '#^If condition is always false\.$#'
identifier: if.alwaysFalse
count: 1
path: ../../../htdocs/bookcal/calendar_note.php
-
message: '#^Negated boolean expression is always false\.$#'
identifier: booleanNot.alwaysFalse
count: 1
path: ../../../htdocs/bookcal/calendar_note.php
-
message: '#^Call to function method_exists\(\) with \$this\(Availabilities\) and ''getLibStatut'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Call to function method_exists\(\) with \$this\(Availabilities\) and ''getNomUrl'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Call to function property_exists\(\) with \$this\(Availabilities\) and ''label'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Call to function property_exists\(\) with Availabilities and ''date_creation'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Call to function property_exists\(\) with Availabilities and ''date_modification'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Call to function property_exists\(\) with Availabilities and ''label'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Call to function property_exists\(\) with Availabilities and ''ref'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Call to function property_exists\(\) with Availabilities and ''status'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Left side of && is always false\.$#'
identifier: booleanAnd.leftAlwaysFalse
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Left side of && is always true\.$#'
identifier: booleanAnd.leftAlwaysTrue
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Method Availabilities\:\:fetchAll\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Method Availabilities\:\:getLinesArray\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Negated boolean expression is always true\.$#'
identifier: booleanNot.alwaysTrue
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Property Availabilities\:\:\$status \(int\) in isset\(\) is not nullable\.$#'
identifier: isset.property
count: 1
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Variable \$url in empty\(\) always exists and is not falsy\.$#'
identifier: empty.variable
count: 2
path: ../../../htdocs/bookcal/class/availabilities.class.php
-
message: '#^Call to function method_exists\(\) with \$this\(Calendar\) and ''getLibStatut'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Call to function method_exists\(\) with \$this\(Calendar\) and ''getNomUrl'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Call to function property_exists\(\) with \$this\(Calendar\) and ''fk_soc'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Call to function property_exists\(\) with \$this\(Calendar\) and ''label'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Call to function property_exists\(\) with Calendar and ''date_creation'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Call to function property_exists\(\) with Calendar and ''date_modification'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Call to function property_exists\(\) with Calendar and ''label'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Call to function property_exists\(\) with Calendar and ''ref'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Call to function property_exists\(\) with Calendar and ''status'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Left side of && is always false\.$#'
identifier: booleanAnd.leftAlwaysFalse
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Left side of && is always true\.$#'
identifier: booleanAnd.leftAlwaysTrue
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Negated boolean expression is always true\.$#'
identifier: booleanNot.alwaysTrue
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Property Calendar\:\:\$status \(int\) in isset\(\) is not nullable\.$#'
identifier: isset.property
count: 1
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^Variable \$url in empty\(\) always exists and is not falsy\.$#'
identifier: empty.variable
count: 2
path: ../../../htdocs/bookcal/class/calendar.class.php
-
message: '#^If condition is always false\.$#'
identifier: if.alwaysFalse
count: 3
path: ../../../htdocs/bookcal/lib/bookcal_availabilities.lib.php
-
message: '#^If condition is always true\.$#'
identifier: if.alwaysTrue
count: 1
path: ../../../htdocs/bookcal/lib/bookcal_availabilities.lib.php
-
message: '#^If condition is always false\.$#'
identifier: if.alwaysFalse
count: 2
path: ../../../htdocs/bookcal/lib/bookcal_calendar.lib.php
-
message: '#^If condition is always true\.$#'
identifier: if.alwaysTrue
count: 2
path: ../../../htdocs/bookcal/lib/bookcal_calendar.lib.php
-
message: '#^Call to function is_array\(\) with array\<mixed\> will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType

View file

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2007-2024 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -40,9 +40,9 @@ $langs->loadLangs(array("agenda", "companies"));
// Get parameters
$id = GETPOSTINT('id');
$ref = GETPOST('ref', 'alpha');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
$cancel = GETPOST('cancel', 'aZ09');
$cancel = GETPOST('cancel', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
// Initialize a technical objects

View file

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2023 Alice Adminson <aadminson@example.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -63,17 +63,9 @@ if ($id > 0 || !empty($ref)) {
// There is several ways to check permission.
// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
$enablepermissioncheck = 0;
if ($enablepermissioncheck) {
$permissiontoread = $user->hasRight('bookcal', 'calendar', 'read');
$permissiontoadd = $user->hasRight('bookcal', 'calendar', 'write');
$permissionnote = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_setnotes.inc.php
} else {
$permissiontoread = 1;
$permissiontoadd = 1;
$permissionnote = 1;
}
$permissiontoread = $user->hasRight('bookcal', 'calendar', 'read');
$permissiontoadd = $user->hasRight('bookcal', 'calendar', 'write');
$permissionnote = $user->hasRight('bookcal', 'calendar', 'write'); // Used by the include of actions_setnotes.inc.php
// Security check (enable the most restrictive one)
//if ($user->socid > 0) accessforbidden();

View file

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2022 Alice Adminson <aadminson@example.com>
/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2022 Alice Adminson <aadminson@example.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
*
@ -43,7 +43,13 @@ class Availabilities extends CommonObject
public $element = 'availabilities';
/**
* @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
* @var string Prefix to check for any trigger code of any business class to prevent bad value for trigger code.
* @see CommonTrigger::call_trigger()
*/
public $TRIGGER_PREFIX = 'AVAILABILITIES';
/**
* @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
*/
public $table_element = 'bookcal_availabilities';
@ -162,10 +168,7 @@ class Availabilities extends CommonObject
* @var string
*/
public $model_pdf;
/**
* @var int
*/
public $status;
/**
* @var string
*/
@ -192,43 +195,6 @@ class Availabilities extends CommonObject
public $fk_bookcal_calendar;
// END MODULEBUILDER PROPERTIES
// If this object has a subtable with lines
// /**
// * @var string Name of subtable line
// */
// public $table_element_line = 'bookcal_availabilitiesline';
// /**
// * @var string Field with ID of parent key if this object has a parent
// */
// public $fk_element = 'fk_availabilities';
// /**
// * @var string Name of subtable class that manage subtable lines
// */
// public $class_element_line = 'Availabilitiesline';
// /**
// * @var array List of child tables. To test if we can delete object.
// */
// protected $childtables = array();
// /**
// * @var array List of child tables. To know object to delete on cascade.
// * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
// * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
// */
// protected $childtablesoncascade = array('bookcal_availabilitiesdet');
// /**
// * @var AvailabilitiesLine[] Array of subtable lines
// */
// public $lines = array();
/**
* Constructor
*
@ -325,23 +291,12 @@ class Availabilities extends CommonObject
unset($object->import_key);
// Clear fields
if (property_exists($object, 'ref')) {
$object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
}
if (property_exists($object, 'label')) {
// @phan-suppress-next-line PhanTypeInvalidDimOffset
$object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
}
if (property_exists($object, 'status')) {
$object->status = self::STATUS_DRAFT;
}
if (property_exists($object, 'date_creation')) {
$object->date_creation = dol_now();
}
if (property_exists($object, 'date_modification')) {
$object->date_modification = null;
}
// ...
$object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
$object->label = $langs->trans("CopyOf")." ".$object->label;
$object->status = self::STATUS_DRAFT;
$object->date_creation = dol_now();
$object->date_modification = null;
// Clear extrafields that are unique
if (is_array($object->array_options) && count($object->array_options) > 0) {
$extrafields->fetch_name_optionals_label($this->table_element);
@ -423,7 +378,7 @@ class Availabilities extends CommonObject
* @param string $filter Filter as an Universal Search string.
* Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')'
* @param string $filtermode No more used
* @return array|int int <0 if KO, array of pages if OK
* @return Availabilities[]|int int <0 if KO, array of pages if OK
*/
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
{
@ -551,7 +506,7 @@ class Availabilities extends CommonObject
$this->db->begin();
// Define new ref
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
$num = $this->getNextNumRef();
} else {
$num = (string) $this->ref;
@ -736,7 +691,7 @@ class Availabilities extends CommonObject
if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
$add_save_lastsearch_values = 1;
}
if ($url && $add_save_lastsearch_values) {
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
}
@ -753,13 +708,13 @@ class Availabilities extends CommonObject
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
if ($option == 'nolink' || empty($url)) {
if ($option == 'nolink') {
$linkstart = '<span';
} else {
$linkstart = '<a href="'.$url.'"';
}
$linkstart .= $linkclose.'>';
if ($option == 'nolink' || empty($url)) {
if ($option == 'nolink') {
$linkend = '</span>';
} else {
$linkend = '</a>';
@ -835,20 +790,16 @@ class Availabilities extends CommonObject
$return .= img_picto('', $this->picto);
$return .= '</span>';
$return .= '<div class="info-box-content">';
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl() . '</span>';
if ($selected >= 0) {
$return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
}
if (property_exists($this, 'label')) {
$return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
}
$return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
if (property_exists($this, 'amount')) {
$return .= '<br>';
$return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
}
if (method_exists($this, 'getLibStatut')) {
$return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
}
$return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
$return .= '</div>';
$return .= '</div>';
$return .= '</div>';
@ -962,7 +913,7 @@ class Availabilities extends CommonObject
/**
* Create an array of lines
*
* @return array|int array of lines if OK, <0 if KO
* @return CommonObject[]|int array of lines if OK, <0 if KO
*/
public function getLinesArray()
{
@ -972,8 +923,7 @@ class Availabilities extends CommonObject
$result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_availabilities:=:'.((int) $this->id).')');
if (is_numeric($result)) {
$this->error = $objectline->error;
$this->errors = $objectline->errors;
$this->setErrorsFromObject($objectline);
return $result;
} else {
$this->lines = $result;
@ -1018,6 +968,7 @@ class Availabilities extends CommonObject
if (class_exists($classname)) {
$obj = new $classname();
'@phan-var-force CommonNumRefGenerator $obj';
/** @var CommonNumRefGenerator $obj */
$numref = $obj->getNextValue($this);
@ -1054,7 +1005,6 @@ class Availabilities extends CommonObject
global $conf, $langs;
$result = 0;
$includedocgeneration = 0;
$langs->load("agenda");
@ -1070,7 +1020,7 @@ class Availabilities extends CommonObject
$modelpath = "core/modules/bookcal/doc/";
if ($includedocgeneration && !empty($modele)) {
if (!empty($modele)) {
$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
}

View file

@ -42,6 +42,12 @@ class Calendar extends CommonObject
*/
public $element = 'calendar';
/**
* @var string Prefix to check for any trigger code of any business class to prevent bad value for trigger code.
* @see CommonTrigger::call_trigger()
*/
public $TRIGGER_PREFIX = 'CALENDAR';
/**
* @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
*/
@ -124,10 +130,7 @@ class Calendar extends CommonObject
* @var int
*/
public $rowid;
/**
* @var string
*/
public $ref;
/**
* @var string
*/
@ -148,14 +151,7 @@ class Calendar extends CommonObject
* @var string
*/
public $description;
/**
* @var string
*/
public $note_public;
/**
* @var string
*/
public $note_private;
/**
* @var int
*/
@ -168,10 +164,7 @@ class Calendar extends CommonObject
* @var string
*/
public $import_key;
/**
* @var int
*/
public $status;
// END MODULEBUILDER PROPERTIES
@ -272,24 +265,12 @@ class Calendar extends CommonObject
unset($object->import_key);
// Clear fields
if (property_exists($object, 'ref')) {
// @phan-suppress-next-line PhanTypeInvalidDimOffset
$object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
}
if (property_exists($object, 'label')) {
// @phan-suppress-next-line PhanTypeInvalidDimOffset
$object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
}
if (property_exists($object, 'status')) {
$object->status = self::STATUS_DRAFT;
}
if (property_exists($object, 'date_creation')) {
$object->date_creation = dol_now();
}
if (property_exists($object, 'date_modification')) {
$object->date_modification = null;
}
// ...
$object->ref = "Copy_Of_".$object->ref;
$object->label = $langs->trans("CopyOf")." ".$object->label;
$object->status = self::STATUS_DRAFT;
$object->date_creation = dol_now();
$object->date_modification = null;
// Clear extrafields that are unique
if (is_array($object->array_options) && count($object->array_options) > 0) {
$extrafields->fetch_name_optionals_label($this->table_element);
@ -320,7 +301,7 @@ class Calendar extends CommonObject
if (!$error) {
// copy external contacts if same company
if (!empty($object->socid) && property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
if (!empty($object->socid) && $this->fk_soc == $object->socid) {
if ($this->copy_linked_contact($object, 'external') < 0) {
$error++;
}
@ -507,7 +488,7 @@ class Calendar extends CommonObject
$this->db->begin();
// Define new ref
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
$num = $this->getNextNumRef();
} else {
$num = (string) $this->ref;
@ -537,7 +518,7 @@ class Calendar extends CommonObject
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('MYOBJECT_VALIDATE', $user);
$result = $this->call_trigger('CALENDAR_VALIDATE', $user);
if ($result < 0) {
$error++;
}
@ -620,7 +601,7 @@ class Calendar extends CommonObject
return 0;
}
return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MYOBJECT_UNVALIDATE');
return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'CALENDAR_UNVALIDATE');
}
/**
@ -637,7 +618,7 @@ class Calendar extends CommonObject
return 0;
}
return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MYOBJECT_CANCEL');
return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'CALENDAR_CANCEL');
}
/**
@ -654,7 +635,7 @@ class Calendar extends CommonObject
return 0;
}
return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MYOBJECT_REOPEN');
return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'CALENDAR_REOPEN');
}
/**
@ -715,7 +696,7 @@ class Calendar extends CommonObject
$label = implode($this->getTooltipContentArray($params));
}
$url = dol_buildpath('/bookcal/calendar_card.php', 1).'?id='.$this->id;
$url = DOL_URL_ROOT . '/bookcal/calendar_card.php?id='.$this->id;
if ($option !== 'nolink') {
// Add param to save lastsearch_values or not
@ -723,7 +704,7 @@ class Calendar extends CommonObject
if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
$add_save_lastsearch_values = 1;
}
if ($url && $add_save_lastsearch_values) {
if ($add_save_lastsearch_values) {
$url .= '&save_lastsearch_values=1';
}
}
@ -740,13 +721,13 @@ class Calendar extends CommonObject
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
if ($option == 'nolink' || empty($url)) {
if ($option == 'nolink') {
$linkstart = '<span';
} else {
$linkstart = '<a href="'.$url.'"';
}
$linkstart .= $linkclose.'>';
if ($option == 'nolink' || empty($url)) {
if ($option == 'nolink') {
$linkend = '</span>';
} else {
$linkend = '</a>';
@ -822,20 +803,12 @@ class Calendar extends CommonObject
$return .= img_picto('', $this->picto);
$return .= '</span>';
$return .= '<div class="info-box-content">';
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl() . '</span>';
if ($selected >= 0) {
$return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
}
if (property_exists($this, 'label')) {
$return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
}
if (property_exists($this, 'amount')) {
$return .= '<br>';
$return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
}
if (method_exists($this, 'getLibStatut')) {
$return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
}
$return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
$return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
$return .= '</div>';
$return .= '</div>';
$return .= '</div>';
@ -978,15 +951,15 @@ class Calendar extends CommonObject
global $langs, $conf;
$langs->load("agenda");
if (getDolGlobalString('BOOKCAL_MYOBJECT_ADDON')) {
$conf->global->BOOKCAL_MYOBJECT_ADDON = 'mod_calendar_standard';
if (getDolGlobalString('BOOKCAL_CALENDAR_ADDON')) {
$conf->global->BOOKCAL_CALENDAR_ADDON = 'mod_calendar_standard';
}
if (getDolGlobalString('BOOKCAL_MYOBJECT_ADDON')) {
if (getDolGlobalString('BOOKCAL_CALENDAR_ADDON')) {
$mybool = false;
$file = getDolGlobalString('BOOKCAL_MYOBJECT_ADDON').".php";
$classname = getDolGlobalString('BOOKCAL_MYOBJECT_ADDON');
$file = getDolGlobalString('BOOKCAL_CALENDAR_ADDON').".php";
$classname = getDolGlobalString('BOOKCAL_CALENDAR_ADDON');
// Include file with class
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
@ -1038,10 +1011,9 @@ class Calendar extends CommonObject
*/
public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
{
global $conf, $langs;
global $langs;
$result = 0;
$includedocgeneration = 0;
$langs->load("agenda");
@ -1050,49 +1022,19 @@ class Calendar extends CommonObject
if (!empty($this->model_pdf)) {
$modele = $this->model_pdf;
} elseif (getDolGlobalString('MYOBJECT_ADDON_PDF')) {
$modele = getDolGlobalString('MYOBJECT_ADDON_PDF');
} elseif (getDolGlobalString('CALENDAR_ADDON_PDF')) {
$modele = getDolGlobalString('CALENDAR_ADDON_PDF');
}
}
$modelpath = "core/modules/bookcal/doc/";
if ($includedocgeneration && !empty($modele)) {
if (!empty($modele)) {
$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
}
return $result;
}
/**
* Action executed by scheduler
* CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
* Use public function doScheduledJob($param1, $param2, ...) to get parameters
*
* @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
*/
public function doScheduledJob()
{
//global $conf, $langs;
//$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
$error = 0;
$this->output = '';
$this->error = '';
dol_syslog(__METHOD__, LOG_DEBUG);
$now = dol_now();
$this->db->begin();
// ...
$this->db->commit();
return $error;
}
}

View file

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2022 Alice Adminson <aadminson@example.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
/* Copyright (C) 2022 Alice Adminson <aadminson@example.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software: you can redistribute it and/or modify
@ -35,11 +35,6 @@ function availabilitiesPrepareHead($object)
$langs->load("agenda");
$showtabofpagecontact = 0;
$showtabofpagenote = 1;
$showtabofpagedocument = 0;
$showtabofpageagenda = 0;
$h = 0;
$head = array();
@ -48,53 +43,45 @@ function availabilitiesPrepareHead($object)
$head[$h][2] = 'card';
$h++;
if ($showtabofpagecontact) {
$head[$h][0] = DOL_URL_ROOT . '/bookcal/availabilities_contact.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Contacts");
$head[$h][2] = 'contact';
$h++;
}
// $head[$h][0] = DOL_URL_ROOT . '/bookcal/availabilities_contact.php?id=' . $object->id;
// $head[$h][1] = $langs->trans("Contacts");
// $head[$h][2] = 'contact';
// $h++;
if ($showtabofpagenote) {
if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
$nbNote = 0;
if (!empty($object->note_private)) {
$nbNote++;
}
if (!empty($object->note_public)) {
$nbNote++;
}
$head[$h][0] = DOL_URL_ROOT . '/bookcal/availabilities_note.php?id=' . $object->id;
$head[$h][1] = $langs->trans('Notes');
if ($nbNote > 0) {
$head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' : '');
}
$head[$h][2] = 'note';
$h++;
if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
$nbNote = 0;
if (!empty($object->note_private)) {
$nbNote++;
}
}
if ($showtabofpagedocument) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
$upload_dir = $conf->bookcal->dir_output . "/availabilities/" . dol_sanitizeFileName($object->ref);
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
$nbLinks = Link::count($db, $object->element, $object->id);
$head[$h][0] = DOL_URL_ROOT . '/bookcal/availabilities_document.php?id=' . $object->id;
$head[$h][1] = $langs->trans('Documents');
if (($nbFiles + $nbLinks) > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($nbFiles + $nbLinks) . '</span>';
if (!empty($object->note_public)) {
$nbNote++;
}
$head[$h][2] = 'document';
$head[$h][0] = DOL_URL_ROOT . '/bookcal/availabilities_note.php?id=' . $object->id;
$head[$h][1] = $langs->trans('Notes');
if ($nbNote > 0) {
$head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' : '');
}
$head[$h][2] = 'note';
$h++;
}
if ($showtabofpageagenda) {
$head[$h][0] = DOL_URL_ROOT . '/bookcal/availabilities_agenda.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Events");
$head[$h][2] = 'agenda';
$h++;
}
// require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
// require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
// $upload_dir = $conf->bookcal->dir_output . "/availabilities/" . dol_sanitizeFileName($object->ref);
// $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
// $nbLinks = Link::count($db, $object->element, $object->id);
// $head[$h][0] = DOL_URL_ROOT . '/bookcal/availabilities_document.php?id=' . $object->id;
// $head[$h][1] = $langs->trans('Documents');
// if (($nbFiles + $nbLinks) > 0) {
// $head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($nbFiles + $nbLinks) . '</span>';
// }
// $head[$h][2] = 'document';
// $h++;
// $head[$h][0] = DOL_URL_ROOT . '/bookcal/availabilities_agenda.php?id=' . $object->id;
// $head[$h][1] = $langs->trans("Events");
// $head[$h][2] = 'agenda';
// $h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line

View file

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2023 Alice Adminson <aadminson@example.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
/* Copyright (C) 2023 Alice Adminson <aadminson@example.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software: you can redistribute it and/or modify
@ -35,11 +35,6 @@ function calendarPrepareHead($object)
$langs->load("agenda");
$showtabofpagecontact = 0;
$showtabofpagenote = 1;
$showtabofpagedocument = 0;
$showtabofpageagenda = 1;
$h = 0;
$head = array();
@ -55,54 +50,45 @@ function calendarPrepareHead($object)
$h++;
}
// $head[$h][0] = DOL_URL_ROOT . '/bookcal/calendar_contact.php?id=' . $object->id;
// $head[$h][1] = $langs->trans("Contacts");
// $head[$h][2] = 'contact';
// $h++;
if ($showtabofpagecontact) {
$head[$h][0] = DOL_URL_ROOT . '/bookcal/calendar_contact.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Contacts");
$head[$h][2] = 'contact';
$h++;
}
if ($showtabofpagenote) {
if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
$nbNote = 0;
if (!empty($object->note_private)) {
$nbNote++;
}
if (!empty($object->note_public)) {
$nbNote++;
}
$head[$h][0] = DOL_URL_ROOT . '/bookcal/calendar_note.php?id=' . $object->id;
$head[$h][1] = $langs->trans('Notes');
if ($nbNote > 0) {
$head[$h][1] .= (!getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' : '');
}
$head[$h][2] = 'note';
$h++;
if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
$nbNote = 0;
if (!empty($object->note_private)) {
$nbNote++;
}
}
if ($showtabofpagedocument) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
$upload_dir = $conf->bookcal->dir_output . "/calendar/" . dol_sanitizeFileName($object->ref);
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
$nbLinks = Link::count($db, $object->element, $object->id);
$head[$h][0] = DOL_URL_ROOT . '/bookcal/calendar_document.php?id=' . $object->id;
$head[$h][1] = $langs->trans('Documents');
if (($nbFiles + $nbLinks) > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($nbFiles + $nbLinks) . '</span>';
if (!empty($object->note_public)) {
$nbNote++;
}
$head[$h][2] = 'document';
$head[$h][0] = DOL_URL_ROOT . '/bookcal/calendar_note.php?id=' . $object->id;
$head[$h][1] = $langs->trans('Notes');
if ($nbNote > 0) {
$head[$h][1] .= (!getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">' . $nbNote . '</span>' : '');
}
$head[$h][2] = 'note';
$h++;
}
if ($showtabofpageagenda) {
$head[$h][0] = DOL_URL_ROOT . '/bookcal/calendar_agenda.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Events");
$head[$h][2] = 'agenda';
$h++;
}
// require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
// require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
// $upload_dir = $conf->bookcal->dir_output . "/calendar/" . dol_sanitizeFileName($object->ref);
// $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
// $nbLinks = Link::count($db, $object->element, $object->id);
// $head[$h][0] = DOL_URL_ROOT . '/bookcal/calendar_document.php?id=' . $object->id;
// $head[$h][1] = $langs->trans('Documents');
// if (($nbFiles + $nbLinks) > 0) {
// $head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($nbFiles + $nbLinks) . '</span>';
// }
// $head[$h][2] = 'document';
// $h++;
$head[$h][0] = DOL_URL_ROOT . '/bookcal/calendar_agenda.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Events");
$head[$h][2] = 'agenda';
$h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line

View file

@ -4,7 +4,7 @@
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2023 anthony Berton <anthony.berton@bb2a.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -411,8 +411,8 @@ if ($action == 'afteradd') {
setEventMessages($availability->error, $availability->errors, 'errors');
} else {
foreach ($arrayofavailabilities as $key => $value) {
$startarray = dol_getdate($value->start);
$endarray = dol_getdate($value->end);
$startarray = dol_getdate((int) $value->start);
$endarray = dol_getdate((int) $value->end);
for ($i = $startarray['mday']; $i <= $endarray['mday']; $i++) {
if ($todayarray['mon'] >= $startarray['mon'] && $todayarray['mon'] <= $endarray['mon']) {
$arrayofavailabledays[dol_mktime(0, 0, 0, $todayarray['mon'], $i, $todayarray['year'])] = dol_mktime(0, 0, 0, $todayarray['mon'], $i, $todayarray['year']);