1. Переписал модуль выпадающего слева меню 2. Добавил механику Архивации задач 3. Запоминания выбранного отдела
129 lines
4.2 KiB
PHP
129 lines
4.2 KiB
PHP
<?php
|
|
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
|
|
if ($method === 'POST') {
|
|
$data = RestApi::getInput();
|
|
$action = $data['action'] ?? null;
|
|
$task = new Task();
|
|
|
|
// Получение колонок
|
|
if ($action === 'get_columns') {
|
|
$result = $task->getColumns();
|
|
RestApi::response(['success' => true, 'data' => $result]);
|
|
}
|
|
|
|
// Получение департаментов
|
|
if ($action === 'get_departments') {
|
|
$result = $task->getDepartments();
|
|
RestApi::response(['success' => true, 'data' => $result]);
|
|
}
|
|
|
|
// Получение меток
|
|
if ($action === 'get_labels') {
|
|
$result = $task->getLabels();
|
|
RestApi::response(['success' => true, 'data' => $result]);
|
|
}
|
|
|
|
// Загрузка изображения
|
|
if ($action === 'upload_image') {
|
|
$task_id = $data['task_id'] ?? null;
|
|
$file_base64 = $data['file_data'] ?? null;
|
|
$file_name = $data['file_name'] ?? null;
|
|
|
|
$result = TaskImage::upload($task_id, $file_base64, $file_name);
|
|
RestApi::response($result);
|
|
}
|
|
|
|
// Удаление изображений (принимает file_names массив или file_name строку)
|
|
if ($action === 'delete_image') {
|
|
$task_id = $data['task_id'] ?? null;
|
|
$file_names = $data['file_names'] ?? $data['file_name'] ?? null;
|
|
|
|
$result = TaskImage::delete($task_id, $file_names);
|
|
RestApi::response($result);
|
|
}
|
|
|
|
// Изменение порядка и колонки задачи
|
|
if ($action === 'update_order') {
|
|
$id = $data['id'] ?? null;
|
|
$column_id = $data['column_id'] ?? null;
|
|
$to_index = $data['to_index'] ?? 0;
|
|
|
|
$result = Task::updateOrder($id, $column_id, $to_index);
|
|
RestApi::response($result);
|
|
}
|
|
|
|
// Обновление задачи
|
|
if ($action === 'update') {
|
|
$task->id = $data['id'] ?? null;
|
|
$task->id_department = $data['id_department'] ?? null;
|
|
$task->id_label = $data['id_label'] ?? null;
|
|
$task->id_account = $data['id_account'] ?? null;
|
|
$task->column_id = $data['column_id'] ?? null;
|
|
$task->order = $data['order'] ?? null;
|
|
$task->date = $data['date'] ?? null;
|
|
$task->title = $data['title'] ?? '';
|
|
$task->descript = $data['descript'] ?? '';
|
|
$task->descript_full = $data['descript_full'] ?? '';
|
|
|
|
$result = $task->update();
|
|
RestApi::response($result);
|
|
}
|
|
|
|
// Создание задачи
|
|
if ($action === 'create') {
|
|
$task->id_department = $data['id_department'] ?? null;
|
|
$task->id_label = $data['id_label'] ?? null;
|
|
$task->id_account = $data['id_account'] ?? null;
|
|
$task->column_id = $data['column_id'] ?? null;
|
|
$task->order = $data['order'] ?? 0;
|
|
$task->date = $data['date'] ?? null;
|
|
$task->title = $data['title'] ?? '';
|
|
$task->descript = $data['descript'] ?? '';
|
|
$task->descript_full = $data['descript_full'] ?? '';
|
|
$files = $data['files'] ?? [];
|
|
|
|
$result = $task->create($files);
|
|
RestApi::response($result);
|
|
}
|
|
|
|
// Удаление задачи
|
|
if ($action === 'delete') {
|
|
$id = $data['id'] ?? null;
|
|
$result = Task::delete($id);
|
|
RestApi::response($result);
|
|
}
|
|
|
|
// Установка статуса архивации задачи
|
|
if ($action === 'set_archive') {
|
|
$id = $data['id'] ?? null;
|
|
$archive = $data['archive'] ?? 1;
|
|
$result = Task::setArchive($id, $archive);
|
|
RestApi::response($result);
|
|
}
|
|
|
|
// Метод не указан
|
|
if (!$action) {
|
|
RestApi::response(['success' => false, 'error' => 'Укажите метод'], 400);
|
|
}
|
|
}
|
|
|
|
if ($method === 'GET') {
|
|
// Получение всех задач
|
|
// ?archive=0 (неархивные, по умолчанию), ?archive=1 (архивные), ?archive=all (все)
|
|
$archive = $_GET['archive'] ?? 0;
|
|
if ($archive === 'all') {
|
|
$archive = null;
|
|
} else {
|
|
$archive = (int)$archive;
|
|
}
|
|
|
|
$task = new Task();
|
|
$tasks = $task->getAll($archive);
|
|
|
|
RestApi::response(['success' => true, 'data' => $tasks]);
|
|
}
|
|
|
|
?>
|