Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Eichhorn committed Oct 9, 2023
1 parent cb31112 commit 7fc48d2
Show file tree
Hide file tree
Showing 30 changed files with 254 additions and 84 deletions.
4 changes: 2 additions & 2 deletions Admin/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static function createTaskAttributeTypes(ApplicationAbstract $app, array

$module->apiTaskAttributeTypeCreate($request, $response);

$responseData = $response->get('');
$responseData = $response->getData('');

Check failure on line 95 in Admin/Installer.php

View workflow job for this annotation

GitHub Actions / general_module_workflow / static-tests (8.1)

Call to an undefined method phpOMS\Message\Http\HttpResponse::getData().
if (!\is_array($responseData)) {
continue;
}
Expand Down Expand Up @@ -164,7 +164,7 @@ private static function createTaskAttributeValues(ApplicationAbstract $app, arra

$module->apiTaskAttributeValueCreate($request, $response);

$responseData = $response->get('');
$responseData = $response->getData('');

Check failure on line 167 in Admin/Installer.php

View workflow job for this annotation

GitHub Actions / general_module_workflow / static-tests (8.1)

Call to an undefined method phpOMS\Message\Http\HttpResponse::getData().
if (!\is_array($responseData)) {
continue;
}
Expand Down
11 changes: 11 additions & 0 deletions Admin/Routes/Web/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@
],
],
],
'^.*/task/reminder(\?.*|$)' => [
[
'dest' => '\Modules\Tasks\Controller\ApiController:apiTaskReminderCreate',
'verb' => RouteVerb::PUT,
'permission' => [
'module' => ApiController::NAME,
'type' => PermissionType::CREATE,
'state' => PermissionCategory::TASK,
],
],
],
'^.*/task/element.*$' => [
[
'dest' => '\Modules\Tasks\Controller\ApiController:apiTaskElementCreate',
Expand Down
85 changes: 81 additions & 4 deletions Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
use Modules\Tasks\Models\TaskElement;
use Modules\Tasks\Models\TaskElementMapper;
use Modules\Tasks\Models\TaskMapper;
use Modules\Tasks\Models\TaskSeen;
use Modules\Tasks\Models\TaskSeenMapper;
use Modules\Tasks\Models\TaskStatus;
use Modules\Tasks\Models\TaskType;
use phpOMS\Localization\BaseStringL11n;
Expand All @@ -57,6 +59,53 @@
*/
final class ApiController extends Controller
{
/**
* Api method to remind a task
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param array $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiTaskReminderCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
{
if (!empty($val = $this->validateTaskReminderCreate($request))) {
$response->header->status = RequestStatusCode::R_400;
$this->createInvalidCreateResponse($request, $response, $val);

return;
}

/** @var TaskSeen[] $reminder */
$reminder = $this->createTaskReminderFromRequest($request);
$this->createModel($request->header->account, $reminder, TaskSeenMapper::class, 'reminder', $request->getOrigin());
$this->createStandardCreateResponse($request, $response, $reminder);
}

/**
* Validate reminder create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool> Returns the validation array of the request
*
* @since 1.0.0
*/
private function validateTaskReminderCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['id'] = !$request->hasData('id'))) {
return $val;
}

return [];
}

/**
* Validate task create request
*
Expand All @@ -78,6 +127,34 @@ private function validateTaskCreate(RequestAbstract $request) : array
return [];
}

/**
* Method to create remeinder from request.
*
* @param RequestAbstract $request Request
*
* @return TaskSeen[] Returns the created reminders from the request
*
* @since 1.0.0
*/
public function createTaskReminderFromRequest(RequestAbstract $request) : array
{
/** @var AccountRelation[] $responsible */
$responsible = TaskMapper::getResponsible((int) $request->getData('id'));

Check failure on line 142 in Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / general_module_workflow / static-tests (8.1)

PHPDoc tag @var for variable $responsible contains unknown class Modules\Tasks\Controller\AccountRelation.

$reminder = [];
foreach ($responsible as $account) {
$unseen = new TaskSeen();
$unseen->task = (int) $request->getData('id');
$unseen->seenBy = $account->relation->id;

Check failure on line 148 in Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / general_module_workflow / static-tests (8.1)

Access to property $relation on an unknown class Modules\Tasks\Controller\AccountRelation.
$unseen->reminderBy = new NullAccount($request->header->account);
$unseen->reminderAt = new \DateTime('now');

$remidner[] = $unseen;
}

return $reminder;
}

/**
* Api method to create a task
*
Expand Down Expand Up @@ -303,7 +380,7 @@ public function createTaskFromRequest(RequestAbstract $request) : Task
$internalResponse = new HttpResponse();
$this->app->moduleManager->get('Tag')->apiTagCreate($request, $internalResponse);

if (!\is_array($data = $internalResponse->get($request->uri->__toString()))) {
if (!\is_array($data = $internalResponse->getDataArray($request->uri->__toString()))) {
continue;
}

Expand Down Expand Up @@ -780,11 +857,11 @@ private function createTaskAttributeFromRequest(RequestAbstract $request) : Task
$attribute->task = (int) $request->getData('task');
$attribute->type = new NullTaskAttributeType((int) $request->getData('type'));

if ($request->hasData('value')) {
$attribute->value = new NullTaskAttributeValue((int) $request->getData('value'));
if ($request->hasData('value_id')) {
$attribute->value = new NullTaskAttributeValue((int) $request->getData('value_id'));
} else {
$newRequest = clone $request;
$newRequest->setData('value', $request->getData('custom'), true);
$newRequest->setData('value', $request->getData('value'), true);

$value = $this->createTaskAttributeValueFromRequest($request);

Expand Down
94 changes: 68 additions & 26 deletions Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,24 @@ public function viewTaskDashboard(RequestAbstract $request, ResponseAbstract $re

if ($request->getData('ptype') === 'p') {
$view->data['tasks'] = $mapperQuery->with('createdBy')
->where('id', $request->getDataInt('id') ?? 0, '<')
->execute();
->where('id', $request->getDataInt('id') ?? 0, '<')
->execute();
} elseif ($request->getData('ptype') === 'n') {
$view->data['tasks'] = $mapperQuery->with('createdBy')
->where('id', $request->getDataInt('id') ?? 0, '>')
->execute();
->where('id', $request->getDataInt('id') ?? 0, '>')
->execute();
} else {
$view->data['tasks'] = $mapperQuery->with('createdBy')
->where('id', 0, '>')
->execute();
->where('id', 0, '>')
->execute();
}

$view->data['task_media'] = [];
foreach ($view->data['tasks'] as $task) {

Check failure on line 96 in Controller/BackendController.php

View workflow job for this annotation

GitHub Actions / general_module_workflow / static-tests (8.1)

Argument of an invalid type mixed supplied for foreach, only iterables are supported.
$view->data['task_media'][$task->id] = TaskMapper::has()

Check failure on line 97 in Controller/BackendController.php

View workflow job for this annotation

GitHub Actions / general_module_workflow / static-tests (8.1)

Call to an undefined static method Modules\Tasks\Models\TaskMapper::has().

Check failure on line 97 in Controller/BackendController.php

View workflow job for this annotation

GitHub Actions / general_module_workflow / static-tests (8.1)

Cannot access property $id on mixed.
->with('media')
->where('id', $task->id)

Check failure on line 99 in Controller/BackendController.php

View workflow job for this annotation

GitHub Actions / general_module_workflow / static-tests (8.1)

Cannot access property $id on mixed.
->execute();
}

$openQuery = new Builder($this->app->dbPool->get(), true);
Expand All @@ -112,6 +120,13 @@ public function viewTaskDashboard(RequestAbstract $request, ResponseAbstract $re

$view->data['open'] = $open;

foreach ($view->data['open'] as $task) {
$view->data['task_media'][$task->id] = TaskMapper::has()

Check failure on line 124 in Controller/BackendController.php

View workflow job for this annotation

GitHub Actions / general_module_workflow / static-tests (8.1)

Call to an undefined static method Modules\Tasks\Models\TaskMapper::has().
->with('media')
->where('id', $task->id)
->execute();
}

// given
// @todo: this should also include forwarded tasks
/** @var \Modules\Tasks\Models\Task[] $given */
Expand All @@ -127,6 +142,13 @@ public function viewTaskDashboard(RequestAbstract $request, ResponseAbstract $re

$view->data['given'] = $given;

foreach ($view->data['given'] as $task) {
$view->data['task_media'][$task->id] = TaskMapper::has()

Check failure on line 146 in Controller/BackendController.php

View workflow job for this annotation

GitHub Actions / general_module_workflow / static-tests (8.1)

Call to an undefined static method Modules\Tasks\Models\TaskMapper::has().
->with('media')
->where('id', $task->id)
->execute();
}

/** @var \Modules\Tasks\Models\TaskSeen[] $unread */
$unread = TaskSeenMapper::getAll()
->where('task', \array_keys($open), 'in')
Expand All @@ -144,6 +166,13 @@ public function viewTaskDashboard(RequestAbstract $request, ResponseAbstract $re

$view->data['unread'] = $unseen;

foreach ($view->data['unread'] as $task) {
$view->data['task_media'][$task->id] = TaskMapper::has()
->with('media')
->where('id', $task->id)
->execute();
}

return $view;
}

Expand Down Expand Up @@ -230,21 +259,45 @@ public function viewTaskView(RequestAbstract $request, ResponseAbstract $respons
->where('tags/title/language', $request->header->l11n->language)
->execute();

$accountId = $request->header->account;

if (!($task->createdBy->id === $accountId
|| $task->isCCAccount($accountId)
|| $task->isToAccount($accountId))
&& !$this->app->accountManager->get($accountId)->hasPermission(
PermissionType::READ, $this->app->unitId, $this->app->appId, self::NAME, PermissionCategory::TASK, $task->id)
) {
$view->setTemplate('/Web/Backend/Error/403_inline');
$response->header->status = RequestStatusCode::R_403;
return $view;
}

$reminderStatus = [];

// Set task as seen
if ($task !== 0) {
if ($task->id !== 0) {
/** @var \Modules\Tasks\Models\TaskSeen[] $taskSeen */
$taskSeen = TaskSeenMapper::getAll()
->where('task', (int) $request->getData('id'))
->with('reminderBy')
->where('task', $task->id)
->where('seenBy', $request->header->account)
->execute();

foreach ($taskSeen as $unseen) {
if ($unseen->isRemindered && ($unseen->reminderAt?->getTimestamp() ?? 0) < $request->header->getRequestTime()) {
$old = clone $unseen;

$unseen->isRemindered = false;

$this->updateModel($request->header->account, $old, $unseen, TaskSeenMapper::class, 'task_seen', $request->getOrigin());
// Shows all reminders
if ($unseen->reminderBy !== null
&& ($unseen->reminderAt?->getTimestamp() ?? 0) < $request->header->getRequestTime()
&& ($unseen->reminderAt?->getTimestamp() ?? 0) > ($unseen->seenAt?->getTimestamp() ?? 0) - 300
) {
$reminderStatus[] = $unseen;

if ($unseen->isRemindered) {
$new = clone $unseen;
$new->seenAt = new \DateTime('now');
$new->isRemindered = false;

$this->updateModel($request->header->account, $unseen, $new, TaskSeenMapper::class, 'reminder_seen', $request->getOrigin());
}
}
}

Expand All @@ -257,18 +310,7 @@ public function viewTaskView(RequestAbstract $request, ResponseAbstract $respons
}
}

$accountId = $request->header->account;

if (!($task->createdBy->id === $accountId
|| $task->isCCAccount($accountId)
|| $task->isToAccount($accountId))
&& !$this->app->accountManager->get($accountId)->hasPermission(
PermissionType::READ, $this->app->unitId, $this->app->appId, self::NAME, PermissionCategory::TASK, $task->id)
) {
$view->setTemplate('/Web/Backend/Error/403_inline');
$response->header->status = RequestStatusCode::R_403;
return $view;
}
$view->data['reminder'] = $reminderStatus;

$view->setTemplate('/Modules/Tasks/Theme/Backend/task-single');
$view->data['task'] = $task;
Expand Down
22 changes: 22 additions & 0 deletions Models/TaskMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,28 @@ public static function getOpenCreatedBy(int $user) : array
return self::getAll()->execute($query);
}

/**
* Get responsible users for task
*
* @param int $task Task
*
* @return AccountRelation[]
*
* @since 1.0.0
*/
public static function getResponsible(int $task) : array
{
$query = AccountRelationMapper::getQuery();
$query->innerJoin(TaskElementMapper::TABLE)
->on(AccountRelationMapper::TABLE . '_d1.task_account_task_element', '=', TaskElementMapper::TABLE . '.task_element_task')
->innerJoin(self::TABLE)
->on(TaskElementMapper::TABLE . '_d1.task_element_task', '=', self::TABLE . '.task_id')
->where(self::TABLE . '.task_id', '=', $task);

return AccountRelationMapper::getAll()
->execute($query);
}

/**
* Get open tasks for user
*
Expand Down
4 changes: 2 additions & 2 deletions Theme/Backend/Lang/ar.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'BCC' => 'bcc',
'By' => 'بواسطة',
'CC' => 'نسخة',
'Completion' => '#VALUE!',
'Completion' => '',
'Created' => 'خلقت',
'Creator' => 'المنشئ',
'Day' => 'يوم',
Expand Down Expand Up @@ -65,7 +65,7 @@
'Size' => 'بحجم',
'Statistics' => 'إحصائيات',
'Status' => 'حالة',
'Tag' => '#VALUE!',
'Tag' => '',
'Task' => 'مهمة',
'Tasks' => 'مهام',
'Template' => 'نموذج',
Expand Down
4 changes: 2 additions & 2 deletions Theme/Backend/Lang/cs.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'BCC' => 'Bcc.',
'By' => 'Podle',
'CC' => 'Cc.',
'Completion' => '#VALUE!',
'Completion' => '',
'Created' => 'Vytvořený',
'Creator' => 'Tvůrce',
'Day' => 'Den',
Expand Down Expand Up @@ -65,7 +65,7 @@
'Size' => 'Velikost',
'Statistics' => 'Statistika',
'Status' => 'Postavení',
'Tag' => '#VALUE!',
'Tag' => '',
'Task' => 'Úkol',
'Tasks' => 'Úkoly',
'Template' => 'Šablona',
Expand Down
4 changes: 2 additions & 2 deletions Theme/Backend/Lang/da.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'BCC' => 'BCC.',
'By' => 'Ved',
'CC' => 'Cc.',
'Completion' => '#VALUE!',
'Completion' => '',
'Created' => 'Oprettet',
'Creator' => 'Skaber.',
'Day' => 'Dag',
Expand Down Expand Up @@ -65,7 +65,7 @@
'Size' => 'Størrelse',
'Statistics' => 'Statistikker',
'Status' => 'Status.',
'Tag' => '#VALUE!',
'Tag' => '',
'Task' => 'Opgave',
'Tasks' => 'Opgaver.',
'Template' => 'Template.',
Expand Down
Loading

0 comments on commit 7fc48d2

Please sign in to comment.