Refactor task management and add attachment functionality
- Updated task editing template to handle default status for new tasks and corrected variable names. - Enhanced work time reporting by rounding time to the nearest quarter hour and adjusting amount formatting. - Introduced TasksController to manage task-related operations, including status resolution and email notifications. - Added TaskAttachmentRepository for handling task attachments, including upload, rename, and delete functionalities. - Implemented WorkTimeRepository to fetch clients with unsettled tasks and calculate total work time. - Created unit tests for TasksController and TaskAttachmentRepository to ensure functionality and correctness.
This commit is contained in:
100
autoload/Controllers/TasksController.php
Normal file
100
autoload/Controllers/TasksController.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace Controllers;
|
||||
|
||||
class TasksController
|
||||
{
|
||||
private const DEFAULT_NEW_TASK_STATUS = 5; // do zrobienia
|
||||
|
||||
public static function workTime()
|
||||
{
|
||||
$work_time_repository = new \Domain\Tasks\WorkTimeRepository();
|
||||
|
||||
$view_model = self::workTimeViewModel(
|
||||
$work_time_repository -> getClientsWithUnsettledTasks(),
|
||||
\factory\Crm::settings()
|
||||
);
|
||||
|
||||
return \Tpl::view( 'tasks/work-time', $view_model );
|
||||
}
|
||||
|
||||
public static function workTimeViewModel( array $work_time_clients, array $settings )
|
||||
{
|
||||
return [
|
||||
'work_time_clients' => $work_time_clients,
|
||||
'settings' => $settings
|
||||
];
|
||||
}
|
||||
|
||||
public static function resolveTaskStatusForForm( array $task )
|
||||
{
|
||||
$is_new_task = !isset( $task['id'] ) or !(int)$task['id'];
|
||||
|
||||
if ( $is_new_task and ( !isset( $task['status'] ) or $task['status'] === null or $task['status'] === '' ) )
|
||||
return self::DEFAULT_NEW_TASK_STATUS;
|
||||
|
||||
return isset( $task['status'] ) ? (int)$task['status'] : 0;
|
||||
}
|
||||
|
||||
public static function resolveTaskStatusForSave( array $values )
|
||||
{
|
||||
$is_new_task = !isset( $values['id'] ) or !(int)$values['id'];
|
||||
|
||||
if ( $is_new_task and ( !isset( $values['status'] ) or $values['status'] === null or $values['status'] === '' ) )
|
||||
return self::DEFAULT_NEW_TASK_STATUS;
|
||||
|
||||
return isset( $values['status'] ) ? (int)$values['status'] : 0;
|
||||
}
|
||||
|
||||
public static function taskChangeStatus()
|
||||
{
|
||||
global $mdb, $user;
|
||||
|
||||
$task_id = (int)\S::get( 'task_id' );
|
||||
$status = (int)\S::get( 'status' );
|
||||
|
||||
if ( $mdb -> update( 'tasks', [ 'status' => $status ], [ 'id' => $task_id ] ) )
|
||||
{
|
||||
if ( $user and self::shouldStopTimerOnStatus( $status ) )
|
||||
\factory\Tasks::task_end( $task_id, $user['id'] );
|
||||
|
||||
if ( self::shouldSendStatusChangeEmail( $status ) )
|
||||
self::sendEmailTaskChangeStatus( $task_id );
|
||||
|
||||
if ( $status === 2 )
|
||||
$mdb -> update( 'tasks', [ 'date_complete' => date( 'Y-m-d H:i:s' ) ], [ 'id' => $task_id ] );
|
||||
|
||||
echo json_encode( [ 'status' => 'success' ] );
|
||||
}
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error' ] );
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function shouldStopTimerOnStatus( $status )
|
||||
{
|
||||
return in_array( (int)$status, [ 1, 2, 3 ], true );
|
||||
}
|
||||
|
||||
public static function shouldSendStatusChangeEmail( $status )
|
||||
{
|
||||
return in_array( (int)$status, [ 1, 3 ], true );
|
||||
}
|
||||
|
||||
public static function sendEmailTaskChangeStatus( $task_id )
|
||||
{
|
||||
$task = \factory\Tasks::task_details( $task_id );
|
||||
$statuses = \factory\Tasks::get_statuses();
|
||||
|
||||
if ( $task['status_change_mail'] )
|
||||
{
|
||||
\S::send_email(
|
||||
'biuro@project-pro.pl',
|
||||
'crmPRO - zmieniono status zadania',
|
||||
'<p>Witaj<br/>zmieniono status zadania <b>' . $task['name'] . ' - ' . \factory\Crm::get_client_name( (int)$task['client_id'] ) . '</b> na <b>' . $statuses[ $task['status'] ] . '</b>.</p>' .
|
||||
'<p>' . html_entity_decode( $task['text'] ) . '</p>' .
|
||||
'<p>Pozdrawiamy<br/>Zespół crmPRO.pl</p>'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
namespace Controllers;
|
||||
|
||||
class TasksController
|
||||
{
|
||||
public static function workTime()
|
||||
{
|
||||
$work_time_repository = new \Domain\Tasks\WorkTimeRepository();
|
||||
|
||||
$view_model = self::workTimeViewModel(
|
||||
$work_time_repository -> getClientsWithUnsettledTasks(),
|
||||
\factory\Crm::settings()
|
||||
);
|
||||
|
||||
return \Tpl::view( 'tasks/work-time', $view_model );
|
||||
}
|
||||
|
||||
public static function workTimeViewModel( array $work_time_clients, array $settings )
|
||||
{
|
||||
return [
|
||||
'work_time_clients' => $work_time_clients,
|
||||
'settings' => $settings
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user