Skip to content

Commit

Permalink
#370 [Lib] clean: more clean and remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Jul 13, 2023
1 parent 5c39678 commit d9e12a8
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 326 deletions.
12 changes: 6 additions & 6 deletions class/actions_dolisirh.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,10 @@ public function printCommonFooter(array $parameters)
require_once __DIR__ . '/../lib/dolisirh_function.lib.php';

if (GETPOST('action') == 'toggleTaskFavorite') {
toggleTaskFavorite(GETPOST('id'), $user->id);
toggle_task_favorite(GETPOST('id'), $user->id);
}

if (isTaskFavorite(GETPOST('id'), $user->id)) {
if (is_task_favorite(GETPOST('id'), $user->id)) {
$favoriteStar = '<span class="fas fa-star toggleTaskFavorite" onclick="toggleTaskFavorite()"></span>';
} else {
$favoriteStar = '<span class="far fa-star toggleTaskFavorite" onclick="toggleTaskFavorite()"></span>';
Expand Down Expand Up @@ -618,7 +618,7 @@ function toggleTaskFavorite () {
$tasksarray = $task->getTasksArray(0, 0, GETPOST('id'));
if (is_array($tasksarray) && !empty($tasksarray)) {
foreach ($tasksarray as $linked_task) {
if (isTaskFavorite($linked_task->id, $user->id)) {
if (is_task_favorite($linked_task->id, $user->id)) {
$favoriteStar = '<span class="fas fa-star toggleTaskFavorite" id="'. $linked_task->id .'" onclick="toggleTaskFavoriteWithId(this.id)"></span>';
} else {
$favoriteStar = '<span class="far fa-star toggleTaskFavorite" id="'. $linked_task->id .'" onclick="toggleTaskFavoriteWithId(this.id)"></span>';
Expand All @@ -642,7 +642,7 @@ function toggleTaskFavorite () {

if (is_array($tasksarray) && !empty($tasksarray)) {
foreach ($tasksarray as $linked_task) {
if (isTaskFavorite($linked_task->id, $user->id)) {
if (is_task_favorite($linked_task->id, $user->id)) {
$favoriteStar = '<span class="fas fa-star toggleTaskFavorite" id="'. $linked_task->id .'" onclick="toggleTaskFavoriteWithId(this.id)"></span>';
} else {
$favoriteStar = '<span class="far fa-star toggleTaskFavorite" id="'. $linked_task->id .'" onclick="toggleTaskFavoriteWithId(this.id)"></span>';
Expand Down Expand Up @@ -788,7 +788,7 @@ function getDiffTimestampEvent() {
print '<script src="../custom/dolisirh/js/dolisirh.js"></script>';
}
if (GETPOST('action') == 'toggleTaskFavorite') {
toggleTaskFavorite(GETPOST('taskId'), $user->id);
toggle_task_favorite(GETPOST('taskId'), $user->id);
}
?>
<script>
Expand Down Expand Up @@ -944,7 +944,7 @@ public function afterCreationOfRecurringInvoice(array $parameters, $object)
$categoryArray[] = $category->id;
}
if (!empty($categoryArray)) {
setCategoriesObject($categoryArray, 'invoice', false, $object);
$object->setCategoriesCommon($categoryArray, 'invoice', false);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions class/dolisirhdashboard.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getTimeSpendingInfos(): array
$isavailable = [];
for ($idw = 0; $idw < $daysInMonth; $idw++) {
$dayInLoop = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
if (isDayAvailable($dayInLoop, $userID)) {
if (is_day_available($dayInLoop, $userID)) {
$isavailable[$dayInLoop] = ['morning'=>1, 'afternoon'=>1];
} else if (date('N', $dayInLoop) >= 6) {
$isavailable[$dayInLoop] = ['morning'=>false, 'afternoon'=>false, 'morning_reason'=>'week_end', 'afternoon_reason'=>'week_end'];
Expand All @@ -127,10 +127,10 @@ public function getTimeSpendingInfos(): array
$workinghours = new Workinghours($db);
$workingHours = $workinghours->fetchCurrentWorkingHours($userID, 'user');

$timeSpendingInfos = loadTimeSpendingInfosWithinRange($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $workingHours, $isavailable, $userID);
$timeSpendingInfos = load_time_spending_infos_within_range($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $workingHours, $isavailable, $userID);

// Planned working time
$planned_working_time = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$planned_working_time = load_planned_time_within_range($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$array['planned']['label'] = $langs->trans('Total') . ' - ' . $langs->trans('ExpectedWorkingHoursMonth', dol_print_date(dol_mktime(0, 0, 0, $month, date('d'), $year), '%B %Y'));
$array['planned']['content'] = (($planned_working_time['minutes'] != 0) ? convertSecondToTime($planned_working_time['minutes'] * 60, 'allhourmin') : '00:00');

Expand Down Expand Up @@ -199,7 +199,7 @@ public function getTimeSpentReport(): array

$currentMonth = date('m', dol_now());
$currentYear = date('Y', dol_now());
if ($currentMonth == date('m') && $currentYear == $year) {
if ($currentMonth == date('m') && $currentYear == $year) {
$currentDate = dol_getdate(dol_now());
$lastdaytoshow = dol_mktime(0, 0, 0, $currentDate['mon'], $currentDate['mday'], $currentDate['year']);
} else {
Expand All @@ -211,7 +211,7 @@ public function getTimeSpentReport(): array
$isavailable = [];
for ($idw = 0; $idw < $daysInMonth; $idw++) {
$dayInLoop = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
if (isDayAvailable($dayInLoop, $userID)) {
if (is_day_available($dayInLoop, $userID)) {
$isavailable[$dayInLoop] = ['morning'=>1, 'afternoon'=>1];
} else if (date('N', $dayInLoop) >= 6) {
$isavailable[$dayInLoop] = ['morning'=>false, 'afternoon'=>false, 'morning_reason'=>'week_end', 'afternoon_reason'=>'week_end'];
Expand All @@ -220,7 +220,7 @@ public function getTimeSpentReport(): array
}
}

$planned_working_time = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$planned_working_time = load_planned_time_within_range($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$working_time = loadTimeSpentWithinRange($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $isavailable, $userID);

$planned_working_time_data = (($planned_working_time['minutes'] != 0) ? convertSecondToTime($planned_working_time['minutes'] * 60, 'fullhour') : 0);
Expand Down Expand Up @@ -285,7 +285,7 @@ public function getTimeSpentCurrentMonthByTaskAndProject(int $showNotConsumedWor
$isavailable = [];
for ($idw = 0; $idw < $daysInMonth; $idw++) {
$dayInLoop = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
if (isDayAvailable($dayInLoop, $userID)) {
if (is_day_available($dayInLoop, $userID)) {
$isavailable[$dayInLoop] = ['morning' => 1, 'afternoon' => 1];
} else if (date('N', $dayInLoop) >= 6) {
$isavailable[$dayInLoop] = ['morning' => false, 'afternoon' => false, 'morning_reason' => 'week_end', 'afternoon_reason' => 'week_end'];
Expand All @@ -295,7 +295,7 @@ public function getTimeSpentCurrentMonthByTaskAndProject(int $showNotConsumedWor

}

$timeSpentOnTasks = loadTimeSpentOnTasksWithinRange($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $isavailable, $userID);
$timeSpentOnTasks = load_time_spent_on_tasks_within_range($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $isavailable, $userID);
$datas = [];
$totalTimeSpent = 0;

Expand Down Expand Up @@ -327,7 +327,7 @@ public function getTimeSpentCurrentMonthByTaskAndProject(int $showNotConsumedWor
}

if ($showNotConsumedWorkingHours > 0) {
$plannedWorkingTime = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$plannedWorkingTime = load_planned_time_within_range($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$plannedWorkingTimeData = (($plannedWorkingTime['minutes'] != 0) ? convertSecondToTime($plannedWorkingTime['minutes'] * 60, 'fullhour') : 0);
$array['labels'][] = ['color' => '#008ECC'];
$array['data'][] = [$langs->transnoentities('NotConsumedWorkingHours'), $plannedWorkingTimeData - $totalTimeSpent, $plannedWorkingTimeData - $totalTimeSpent];
Expand Down
18 changes: 9 additions & 9 deletions class/dolisirhstats.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public function getTimeSpendingInfos(): array
$isavailable = [];
for ($idw = 0; $idw < $daysInMonth; $idw++) {
$dayInLoop = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
if (isDayAvailable($dayInLoop, $userID)) {
if (is_day_available($dayInLoop, $userID)) {
$isavailable[$dayInLoop] = ['morning'=>1, 'afternoon'=>1];
} else if (date('N', $dayInLoop) >= 6) {
$isavailable[$dayInLoop] = ['morning'=>false, 'afternoon'=>false, 'morning_reason'=>'week_end', 'afternoon_reason'=>'week_end'];
Expand All @@ -677,10 +677,10 @@ public function getTimeSpendingInfos(): array
$workinghours = new Workinghours($db);
$workingHours = $workinghours->fetchCurrentWorkingHours($userID, 'user');

$timeSpendingInfos = loadTimeSpendingInfosWithinRange($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $workingHours, $isavailable, $userID);
$timeSpendingInfos = load_time_spending_infos_within_range($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $workingHours, $isavailable, $userID);

// Planned working time
$planned_working_time = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$planned_working_time = load_planned_time_within_range($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$array['planned']['label'] = $langs->trans('Total') . ' - ' . $langs->trans('ExpectedWorkingHoursMonth', dol_print_date(dol_mktime(0, 0, 0, $month, date('d'), $year), '%B %Y'));
$array['planned']['content'] = (($planned_working_time['minutes'] != 0) ? convertSecondToTime($planned_working_time['minutes'] * 60, 'allhourmin') : '00:00');

Expand Down Expand Up @@ -749,7 +749,7 @@ public function getTimeSpentReport(): array

$currentMonth = date('m', dol_now());
$currentYear = date('Y', dol_now());
if ($currentMonth == date('m') && $currentYear == $year) {
if ($currentMonth == date('m') && $currentYear == $year) {
$currentDate = dol_getdate(dol_now());
$lastdaytoshow = dol_mktime(0, 0, 0, $currentDate['mon'], $currentDate['mday'], $currentDate['year']);
} else {
Expand All @@ -761,7 +761,7 @@ public function getTimeSpentReport(): array
$isavailable = [];
for ($idw = 0; $idw < $daysInMonth; $idw++) {
$dayInLoop = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
if (isDayAvailable($dayInLoop, $userID)) {
if (is_day_available($dayInLoop, $userID)) {
$isavailable[$dayInLoop] = ['morning'=>1, 'afternoon'=>1];
} else if (date('N', $dayInLoop) >= 6) {
$isavailable[$dayInLoop] = ['morning'=>false, 'afternoon'=>false, 'morning_reason'=>'week_end', 'afternoon_reason'=>'week_end'];
Expand All @@ -770,7 +770,7 @@ public function getTimeSpentReport(): array
}
}

$planned_working_time = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$planned_working_time = load_planned_time_within_range($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$working_time = loadTimeSpentWithinRange($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $isavailable, $userID);

$planned_working_time_data = (($planned_working_time['minutes'] != 0) ? convertSecondToTime($planned_working_time['minutes'] * 60, 'fullhour') : 0);
Expand Down Expand Up @@ -835,7 +835,7 @@ public function getTimeSpentCurrentMonthByTaskAndProject(int $showNotConsumedWor
$isavailable = [];
for ($idw = 0; $idw < $daysInMonth; $idw++) {
$dayInLoop = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
if (isDayAvailable($dayInLoop, $userID)) {
if (is_day_available($dayInLoop, $userID)) {
$isavailable[$dayInLoop] = ['morning' => 1, 'afternoon' => 1];
} else if (date('N', $dayInLoop) >= 6) {
$isavailable[$dayInLoop] = ['morning' => false, 'afternoon' => false, 'morning_reason' => 'week_end', 'afternoon_reason' => 'week_end'];
Expand All @@ -845,7 +845,7 @@ public function getTimeSpentCurrentMonthByTaskAndProject(int $showNotConsumedWor

}

$timeSpentOnTasks = loadTimeSpentOnTasksWithinRange($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $isavailable, $userID);
$timeSpentOnTasks = load_time_spent_on_tasks_within_range($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $isavailable, $userID);
$datas = [];
$totalTimeSpent = 0;

Expand Down Expand Up @@ -877,7 +877,7 @@ public function getTimeSpentCurrentMonthByTaskAndProject(int $showNotConsumedWor
}

if ($showNotConsumedWorkingHours > 0) {
$plannedWorkingTime = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$plannedWorkingTime = load_planned_time_within_range($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$plannedWorkingTimeData = (($plannedWorkingTime['minutes'] != 0) ? convertSecondToTime($plannedWorkingTime['minutes'] * 60, 'fullhour') : 0);
$array['labels'][] = ['color' => '#008ECC'];
$array['data'][] = [$langs->transnoentities('NotConsumedWorkingHours'), $plannedWorkingTimeData - $totalTimeSpent, $plannedWorkingTimeData - $totalTimeSpent];
Expand Down
3 changes: 2 additions & 1 deletion class/workinghours.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function fetchAll(string $sortorder = '', string $sortfield = '', int $li
*
* @param int $id ID object
* @param string $type Type of object
* @return array|int int <0 if KO, array of pages if OK
* @return Workinghours|int int <0 if KO, array of pages if OK
* @throws Exception
*/
public function fetchCurrentWorkingHours(int $id, string $type)
Expand All @@ -265,6 +265,7 @@ public function fetchCurrentWorkingHours(int $id, string $type)
if (is_array($current_workinghours) && !empty($current_workinghours)) {
$current_workinghours = array_shift($current_workinghours);
}

return $current_workinghours;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
case 'BILL_CREATE':
require_once __DIR__ . '/../../lib/dolisirh_function.lib.php';
$categories = GETPOST('categories', 'array:int');
setCategoriesObject($categories, 'invoice', false, $object);
$object->setCategoriesCommon($categories, 'invoice', false);
break;

case 'BILLREC_CREATE':
Expand All @@ -211,7 +211,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
}
}
if (!empty($categoryArray)) {
setCategoriesObject($categoryArray, 'invoicerec', false, $object);
$object->setCategoriesCommon($categoryArray, 'invoicerec', false);
}
break;

Expand Down
Loading

0 comments on commit d9e12a8

Please sign in to comment.