Skip to content
Open
Changes from 1 commit
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
149 changes: 149 additions & 0 deletions htdocs/api/class/api_setup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,155 @@
return $list;
}

/**
* Get the list of holiday types.
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Number of items per page
* @param int $page Page number (starting from zero)
* @param string $fk_country To filter on country
* @param int $active Holiday is active or not {@min 0} {@max 1}
* @param string $lang Code of the language the label of the holiday must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of holiday types
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/holiday_types
*
* @throws RestException 400 Bad value for sqlfilters
* @throws RestException 503 Error when retrieving list of holiday types
*/
public function getListOfHolidayTypes($sortfield = "sortorder", $sortorder = 'ASC', $limit = 100, $page = 0, $fk_country = '', $active = 1, $lang = '', $sqlfilters = '')
{
global $langs;
$langs->loadLangs(array('holiday'));

$list = array();

$sql = "SELECT rowid, code, label, affect, delay, newbymonth, fk_country";
$sql .= " FROM ".MAIN_DB_PREFIX."c_holiday_types as t";
$sql .= " WHERE t.active = ".((int) $active);
if ($fk_country) {
$sql .= " AND (t.fk_country = ".((int) $fk_country);
$sql .= " OR t.fk_country is null)";

Check failure on line 1054 in htdocs/api/class/api_setup.class.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Whitespace found at end of line
}
// Add sql filters
if ($sqlfilters) {
$errormessage = '';
$sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
if ($errormessage) {
throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
}
}

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

if ($limit) {
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;

$sql .= $this->db->plimit($limit, $offset);
}

$result = $this->db->query($sql);

if ($result) {
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
for ($i = 0; $i < $min; $i++) {
$holiday = $this->db->fetch_object($result);
$tmplabel = $langs->trans($holiday->code);
if ($tmplabel != $holiday->code) {
$holiday->label = $tmplabel;
}
//$this->translateLabel($holiday, $lang, 'Holiday', array('dict'));
$list[] = $holiday;
}
} else {
throw new RestException(503, 'Error when retrieving list of holiday : '.$this->db->lasterror());
}

return $list;
}

/**
* Get the list of public holiday.
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Number of items per page
* @param int $page Page number (starting from zero)
* @param string $fk_country To filter on country
* @param int $active Holiday is active or not {@min 0} {@max 1}
* @param string $lang Code of the language the label of the holiday must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of public holiday
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/public_holiday
*
* @throws RestException 400 Bad value for sqlfilters
* @throws RestException 503 Error when retrieving list of holiday types
*/
public function getListOfPublicHolidays($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $fk_country = '', $active = 1, $lang = '', $sqlfilters = '')
{
global $langs;
$langs->loadLangs(array('hrm'));

$list = array();

$sql = "SELECT id, code, dayrule, day, month, year, fk_country, code as label";
$sql .= " FROM ".MAIN_DB_PREFIX."c_hrm_public_holiday as t";
$sql .= " WHERE t.active = ".((int) $active);
if ($fk_country) {
$sql .= " AND (t.fk_country = ".((int) $fk_country);
$sql .= " OR t.fk_country is null)";

Check failure on line 1129 in htdocs/api/class/api_setup.class.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Whitespace found at end of line
}
// Add sql filters
if ($sqlfilters) {
$errormessage = '';
$sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
if ($errormessage) {
throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
}
}

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

if ($limit) {
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;

$sql .= $this->db->plimit($limit, $offset);
}

$result = $this->db->query($sql);

if ($result) {
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
for ($i = 0; $i < $min; $i++) {
$holiday = $this->db->fetch_object($result);
$tmplabel = $langs->trans($holiday->code);
if ($tmplabel != $holiday->code) {
$holiday->label = $tmplabel;
}
//$this->translateLabel($holiday, $lang, 'Holiday', array('dict'));
$list[] = $holiday;
}
} else {
throw new RestException(503, 'Error when retrieving list of public holiday : '.$this->db->lasterror());
}

return $list;
}

/**
* Get the list of contacts types.
Expand Down
Loading