feat: Refactor task handling to improve status change and enable boolean checks for task properties

This commit is contained in:
2026-02-13 00:11:54 +01:00
parent dfa83b57a6
commit c9795ca866
3 changed files with 31 additions and 9 deletions

View File

@@ -97,7 +97,7 @@ class Cron
$row['show_in_calendar'] ? $show_in_calendar = 'on' : $show_in_calendar = 'off';
$new_task_id = \factory\Tasks::task_save(
null, $row['id'], $row['created_by'], $row['name'], $row['text'], $new_date_start, $new_date_end, $row['project_id'], $row['client_id'], $row['pay_rate'], $row['reminders_interval'], $row['recursively'] ? 'on' : 'off', $row['frequency'], $row['period'], $task_users, $row['date_end_month_day'], $row['date_start_month_day'], null, $row['task_change_status'], true, $status, $show_in_calendar, $row['priority']
null, $row['id'], $row['created_by'], $row['name'], $row['text'], $new_date_start, $new_date_end, $row['project_id'], $row['client_id'], $row['pay_rate'], $row['reminders_interval'], $row['recursively'] ? 'on' : 'off', $row['frequency'], $row['period'], $task_users, $row['date_end_month_day'], $row['date_start_month_day'], null, $row['status_change_mail'], true, $status, $show_in_calendar, $row['priority']
);
if ( $new_task_id ) {

View File

@@ -407,6 +407,14 @@ class Tasks
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania zadania wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
$values['recursively'] = isset( $values['recursively'] ) ? $values['recursively'] : 'off';
$values['frequency'] = isset( $values['frequency'] ) && $values['frequency'] !== '' ? $values['frequency'] : 1;
$values['period'] = isset( $values['period'] ) && $values['period'] !== '' ? $values['period'] : 1;
$values['show_in_calendar'] = isset( $values['show_in_calendar'] ) ? $values['show_in_calendar'] : 'off';
$values['status_change_mail'] = isset( $values['status_change_mail'] ) ? $values['status_change_mail'] : 'off';
$values['send_email_notification'] = isset( $values['send_email_notification'] ) ? $values['send_email_notification'] : 'off';
$values['users'] = isset( $values['users'] ) ? $values['users'] : [];
$values['priority'] = isset( $values['priority'] ) && $values['priority'] !== '' ? $values['priority'] : 0;
$status = \Controllers\TasksController::resolveTaskStatusForSave( $values );
if ( $id = \factory\Tasks::task_save(

View File

@@ -5,6 +5,20 @@ class Tasks
{
private const MIN_WORK_LOG_SECONDS = 60;
private static function isEnabled( $value )
{
if ( is_bool( $value ) )
return $value;
if ( is_numeric( $value ) )
return (int)$value === 1;
if ( is_string( $value ) )
return in_array( strtolower( trim( $value ) ), [ '1', 'on', 'true', 'yes' ], true );
return false;
}
public static $statuses = [ 0 => 'nowe', 3 => 'do rozliczenia', 5 => 'do zrobienia', 1 => 'do sprawdzenia', 2 => 'zamknięte' ];
public static $priorities = [ 0 => 'niski', 1 => 'normalny', 2 => 'wysoki', 3 => 'pilny' ];
@@ -452,15 +466,15 @@ class Tasks
'client_id' => $client_id ? $client_id : null,
'pay_rate' => ( $pay_rate != '' and $pay_rate > 0 ) ? $pay_rate : null,
'reminders_interval' => $reminders_interval != '' ? $reminders_interval : null,
'recursively' => $recursively == 'on' ? 1 : 0,
'recursively' => self::isEnabled( $recursively ) ? 1 : 0,
'frequency' => $frequency,
'period' => $period,
'date_end_month_day' => $date_end_month_day,
'date_start_month_day' => $date_start_month_day,
'status_change_mail' => $status_change_mail == 'on' ? 1 : 0,
'status_change_mail' => self::isEnabled( $status_change_mail ) ? 1 : 0,
'o' => ++$order,
'status' => $status,
'show_in_calendar' => $show_in_calendar == 'on' ? 1 : 0,
'show_in_calendar' => self::isEnabled( $show_in_calendar ) ? 1 : 0,
'priority' => $priority,
] );
$id = $mdb -> id();
@@ -471,7 +485,7 @@ class Tasks
if ( $id and $user and !$mdb -> count( 'task_user', [ 'AND' => [ 'task_id' => (int)$id, 'user_id' => (int)$user ] ] ) )
{
if ( $mdb -> insert( 'task_user', [ 'task_id' => (int)$id, 'user_id' => (int)$user ] ) )
if ( $send_email_notification == 'on' )
if ( self::isEnabled( $send_email_notification ) )
\factory\Projects::send_email_notification( $id, $user );
}
}
@@ -479,7 +493,7 @@ class Tasks
{
if ( $id and $users and !$mdb -> count( 'task_user', [ 'AND' => [ 'task_id' => (int)$id, 'user_id' => (int)$users ] ] ) )
if ( $mdb -> insert( 'task_user', [ 'task_id' => (int)$id, 'user_id' => (int)$users ] ) );
if ( $send_email_notification == 'on' )
if ( self::isEnabled( $send_email_notification ) )
\factory\Projects::send_email_notification( $id, $users );
}
@@ -496,13 +510,13 @@ class Tasks
'client_id' => $client_id ? $client_id : null,
'pay_rate' => ( $pay_rate != '' and $pay_rate > 0 ) ? $pay_rate : null,
'reminders_interval' => $reminders_interval,
'recursively' => $recursively == 'on' ? 1 : 0,
'recursively' => self::isEnabled( $recursively ) ? 1 : 0,
'frequency' => $frequency,
'period' => $period,
'reminders_send' => 0,
'status_change_mail' => $status_change_mail == 'on' ? 1 : 0,
'status_change_mail' => self::isEnabled( $status_change_mail ) ? 1 : 0,
'status' => $status,
'show_in_calendar' => $show_in_calendar == 'on' ? 1 : 0,
'show_in_calendar' => self::isEnabled( $show_in_calendar ) ? 1 : 0,
'priority' => $priority,
], [
'AND' => [