diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json index 3f72c69..36d3141 100755 --- a/Admin/Install/Navigation.install.json +++ b/Admin/Install/Navigation.install.json @@ -33,7 +33,7 @@ "type": 0, "subtype": 1, "name": "Tasks", - "uri": "{/base}/task/single?{?}", + "uri": "{/base}/task/view?{?}", "target": "self", "icon": null, "order": 1, diff --git a/Admin/Install/SearchCommands.php b/Admin/Install/SearchCommands.php index 6f8c29e..519bab8 100755 --- a/Admin/Install/SearchCommands.php +++ b/Admin/Install/SearchCommands.php @@ -17,7 +17,7 @@ use phpOMS\Account\PermissionType; use phpOMS\Router\RouteVerb; return [ - '^:tag .*$' => [ + '^:tag (\?.*$|$)' => [ [ 'dest' => '\Modules\Tasks\Controller\SearchController:searchTag', 'verb' => RouteVerb::ANY, diff --git a/Admin/Install/attributes.json b/Admin/Install/attributes.json index f5242d1..d92bee4 100755 --- a/Admin/Install/attributes.json +++ b/Admin/Install/attributes.json @@ -1,5 +1,5 @@ [ - { + { "name": "category", "l11n": { "en": "Category", diff --git a/Admin/Install/db.json b/Admin/Install/db.json index baea48e..32842df 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -97,6 +97,14 @@ "foreignTable": "account", "foreignKey": "account_id" }, + "task_for": { + "name": "task_for", + "type": "INT", + "null": true, + "default": null, + "foreignTable": "account", + "foreignKey": "account_id" + }, "task_created_at": { "name": "task_created_at", "type": "DATETIME", @@ -119,6 +127,11 @@ "type": "VARCHAR(255)", "null": false }, + "task_attr_type_datatype": { + "name": "task_attr_type_datatype", + "type": "INT(11)", + "null": false + }, "task_attr_type_fields": { "name": "task_attr_type_fields", "type": "INT(11)", @@ -134,6 +147,11 @@ "type": "TINYINT(1)", "null": false }, + "task_attr_type_internal": { + "name": "task_attr_type_internal", + "type": "TINYINT(1)", + "null": false + }, "task_attr_type_required": { "description": "Every task must have this attribute type if set to true.", "name": "task_attr_type_required", @@ -222,6 +240,22 @@ "name": "task_attr_value_unit", "type": "VARCHAR(255)", "null": false + }, + "task_attr_value_deptype": { + "name": "task_attr_value_deptype", + "type": "INT(11)", + "null": true, + "default": null, + "foreignTable": "task_attr_type", + "foreignKey": "task_attr_type_id" + }, + "task_attr_value_depvalue": { + "name": "task_attr_value_depvalue", + "type": "INT(11)", + "null": true, + "default": null, + "foreignTable": "task_attr_value", + "foreignKey": "task_attr_value_id" } } }, @@ -386,6 +420,11 @@ "type": "TINYINT", "null": false }, + "task_element_duration": { + "name": "task_element_duration", + "type": "INT", + "null": false + }, "task_element_due": { "name": "task_element_due", "type": "DATETIME", diff --git a/Admin/Installer.php b/Admin/Installer.php index 4f79fe3..a955448 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -20,7 +20,6 @@ use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Module\InstallerAbstract; use phpOMS\Module\ModuleInfo; -use phpOMS\Uri\HttpUri; /** * Installer class. @@ -74,21 +73,24 @@ final class Installer extends InstallerAbstract /** @var array $taskAttrType */ $taskAttrType = []; - /** @var \Modules\Tasks\Controller\ApiController $module */ - $module = $app->moduleManager->getModuleInstance('Tasks'); + /** @var \Modules\Tasks\Controller\ApiAttributeController $module */ + $module = $app->moduleManager->getModuleInstance('Tasks', 'ApiAttribute'); /** @var array $attribute */ foreach ($attributes as $attribute) { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('name', $attribute['name'] ?? ''); $request->setData('title', \reset($attribute['l11n'])); $request->setData('language', \array_keys($attribute['l11n'])[0] ?? 'en'); + $request->setData('repeatable', $attribute['repeatable'] ?? false); + $request->setData('internal', $attribute['internal'] ?? false); $request->setData('is_required', $attribute['is_required'] ?? false); $request->setData('custom', $attribute['is_custom_allowed'] ?? false); $request->setData('validation_pattern', $attribute['validation_pattern'] ?? ''); + $request->setData('datatype', (int) $attribute['value_type']); $module->apiTaskAttributeTypeCreate($request, $response); @@ -109,7 +111,7 @@ final class Installer extends InstallerAbstract } $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('title', $l11n); @@ -139,8 +141,8 @@ final class Installer extends InstallerAbstract /** @var array $taskAttrValue */ $taskAttrValue = []; - /** @var \Modules\Tasks\Controller\ApiController $module */ - $module = $app->moduleManager->getModuleInstance('Tasks'); + /** @var \Modules\Tasks\Controller\ApiAttributeController $module */ + $module = $app->moduleManager->getModuleInstance('Tasks', 'ApiAttribute'); foreach ($attributes as $attribute) { $taskAttrValue[$attribute['name']] = []; @@ -148,14 +150,13 @@ final class Installer extends InstallerAbstract /** @var array $value */ foreach ($attribute['values'] as $value) { $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('value', $value['value'] ?? ''); - $request->setData('value_type', $attribute['value_type'] ?? 0); $request->setData('unit', $value['unit'] ?? ''); - $request->setData('default', isset($attribute['values']) && !empty($attribute['values'])); - $request->setData('attributetype', $taskAttrType[$attribute['name']]['id']); + $request->setData('default',true); + $request->setData('type', $taskAttrType[$attribute['name']]['id']); if (isset($value['l11n']) && !empty($value['l11n'])) { $request->setData('title', \reset($value['l11n'])); @@ -183,7 +184,7 @@ final class Installer extends InstallerAbstract } $response = new HttpResponse(); - $request = new HttpRequest(new HttpUri('')); + $request = new HttpRequest(); $request->header->account = 1; $request->setData('title', $l11n); diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php index e57e1fa..5eeea53 100755 --- a/Admin/Routes/Web/Api.php +++ b/Admin/Routes/Web/Api.php @@ -58,7 +58,7 @@ return [ ], ], ], - '^.*/task/element.*$' => [ + '^.*/task/element(\?.*$|$)' => [ [ 'dest' => '\Modules\Tasks\Controller\ApiController:apiTaskElementCreate', 'verb' => RouteVerb::PUT, diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index 4f1bdc0..1fb9378 100755 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -18,7 +18,7 @@ use phpOMS\Account\PermissionType; use phpOMS\Router\RouteVerb; return [ - '^.*/task/dashboard.*$' => [ + '^.*/task/dashboard(\?.*$|$)' => [ [ 'dest' => '\Modules\Tasks\Controller\BackendController:viewTaskDashboard', 'verb' => RouteVerb::GET, @@ -29,7 +29,7 @@ return [ ], ], ], - '^.*/task/single.*$' => [ + '^.*/task/view(\?.*$|$)' => [ [ 'dest' => '\Modules\Tasks\Controller\BackendController:viewTaskView', 'verb' => RouteVerb::GET, @@ -40,7 +40,7 @@ return [ ], ], ], - '^.*/task/create.*$' => [ + '^.*/task/create(\?.*$|$)' => [ [ 'dest' => '\Modules\Tasks\Controller\BackendController:viewTaskCreate', 'verb' => RouteVerb::GET, @@ -51,7 +51,7 @@ return [ ], ], ], - '^.*/task/analysis.*$' => [ + '^.*/task/analysis(\?.*$|$)' => [ [ 'dest' => '\Modules\Tasks\Controller\BackendController:viewTaskAnalysis', 'verb' => RouteVerb::GET, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4f4653b..88c5d9c 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,12 +1,16 @@ -# Development - ## Development environment - The setup and configuration of the development environment is in the hands of every developer themselves. However, it is recommended to follow the setup instructions in the [Developer-Guide](https://github.com/Karaka-Management/Developer-Guide/blob/develop/general/setup.md). +The setup and configuration of the development environment is in the hands of every developer themselves. However, it is recommended to follow the setup instructions in the [Developer-Guide](https://github.com/Karaka-Management/Developer-Guide/blob/develop/general/setup.md). ## Code of conduct -Every organization member and contributor to the organization must follow the [code of conduct](../Policies & Guidelines/Code of conduct.md). +Every organization member and contributor to the organization must follow the [Code of Conduct](../Policies%20&%20Guidelines/Code%20of%20Conduct.md). + +## Becoming a contributor + +For public repositories you can immediately start by creating forks and pull requests. For private repositories which are necessary to setup the complete developer environment, feel free to request access. Please not that we may not immediately give you access to private repositories and instead will give you smaller tasks regarding public repositories. Please contact info@jingga.app for more details. (**R1**) + +For all contributions our [Contributor License Agreement "CLA"](https://github.com/Karaka-Management/Organization-Guide/blob/master/Processes/HR/Hiring/Individual%20Contributor%20License%20Agreement.md) comes into effect. (**R2**) ## Code changes @@ -14,58 +18,106 @@ Every organization member and contributor to the organization must follow the [c Generally, the development philosophy is result orientated. This means that anyone can propose tasks, pick up existing tasks or right away implement their code changes. However, implementing code changes without consulting with a senior developer in advance has a much higher risk of code changes not getting admitted. The easiest way to discuss a code change idea in advance are the github [issues](https://github.com/Karaka-Management/Karaka/issues) or [discussions](https://github.com/Karaka-Management/Karaka/discussions). -Developers are encouraged to pick open tasks with high priorities according to their own skill level. Senior developers may directly assign tasks to developers based on their importance. New developers may find it easier to start with a task that has a low priority as they often also have a lower difficulty. +Developers are encouraged to pick open tasks with high priorities according to their own skill level. Senior developers may directly assign tasks to developers based on their importance. New developers may find it easier to start with a task that has a low priority as they often also have a lower difficulty. -Open tasks can be found in the project overview: [PROJECT.md](https://github.com/orgs/Karaka-Management/projects/10) +Open tasks can be found in the project overview: [Todos](https://github.com/orgs/Karaka-Management/projects/10) -Tasks currently in development are prefixed in the priority column with an asterisk `*` and a name tag in the task description of the developer who is working on the task. +Tasks currently in development are prefixed in the priority column with an asterisk `*` and a name tag in the task description of the developer who is working on the task. -The open tasks are reviewed once a month by a senior developer. The senior developer updates the project overview if necessary and requests feedback regarding development status of important tasks under development. During this process important tasks may also get directly assigned to developers. This review is performed on a judgmental bases of the senior basis. +The open tasks are reviewed once a month by a senior developer. The senior developer updates the project overview if necessary and requests feedback regarding development status of important tasks under development. During this process important tasks may also get directly assigned to developers. This review is performed on a judgmental bases of the senior basis. -### Code style +### Quality -Code changes must follow the [style guidelines](https://github.com/Karaka-Management/Developer-Guide/tree/develop/standards). Additionally, the automatic code style inspection tools must return no errors, failures or warnings. Developers should test their changes with inspection tools and configurations mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) in advance before submitting them for review. +#### Code style -In rare cases errors, failures or warnings during the automatic inspection are acceptable. Reasons can be changes in the programming language, special cases which cannot, are difficult or must be individually configured in the inspection settings. If this is the case for a code change and if inspection configuration changes are necessary are decided by the senior developer performing the code review. +Code changes must follow the [style guidelines](https://github.com/Karaka-Management/Developer-Guide/tree/develop/standards) (**R3**). Additionally, the automatic code style inspection tools must return no errors, failures or warnings. Developers should test their changes with inspection tools and configurations mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) in advance before submitting them for review. (**R4**) -Automated checks which are run during the review process: +In rare cases errors, failures or warnings during the automatic inspection are acceptable. Reasons can be for example special cases which are difficult automatize or must be individually configured in the inspection settings. If this is the case for a code change and if inspection configuration changes are necessary are decided by the senior developer performing the code review. (**R5**) + +Automated checks which are run during the review process (**R4**): ```sh -php ./vendor/bin/phpcs --severity=1 ./ --standard="Build/Config/phpcs.xml" +php ./vendor/bin/phpcs ./ --standard="Build/Config/phpcs.xml" +php ./vendor/bin/php-cs-fixer fix ./ --config=Build/Config/.php-cs-fixer.php --allow-risky=yes +php ./vendor/bin/phpcbf --standard=Build/Config/phpcs.xml ./ +php ./vendor/bin/rector process --dry-run --config Build/Config/rector.php ./ npx eslint ./ -c ./Build/Config/.eslintrc.json ``` -### Tests +#### Tests -Code changes must follow the inspection guidelines (i.e. code coverage) mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md). Developers should check if the code changes comply with the inspection guidelines before submitting them. +Code changes must follow the inspection guidelines (i.e. code coverage) mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) (**R6**). Developers should test their changes with inspection tools and configurations mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) in advance before submitting them for review. (**R7**) -In rare cases it might be not possible to follow the inspection guidelines. In such cases the senior developer performing the code review may decide if the code change still gets accepted. +In rare cases it might be not possible to follow the inspection guidelines. In such cases the senior developer performing the code review may decide if the code change still gets accepted. (**R8**) -Automated tests which are run during the review process: +Automated tests which are run during the review process (**R7**): ```sh php ./vendor/bin/phpunit -c tests/PHPUnit/phpunit_default.xml -php ./vendor/bin/phpstan analyse --autoload-file=phpOMS/Autoloader.php -l 9 -c Build/Config/phpstan.neon ./ +php ./vendor/bin/phpstan analyse --no-progress -l 9 -c Build/Config/phpstan.neon ./ npx jasmine-node ./ ./cOMS/tests/test.sh ``` -Additional inspections which are run but might be ignored during the review depending on the use case are mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) as other checks. +Additional inspections which are run but might be ignored during the review depending on the use case are mentioned in the [inspection documentation](https://github.com/Karaka-Management/Developer-Guide/blob/develop/quality/inspections.md) as other checks. (**R7**) -### Demo +#### Performance -Some code changes may also require changes or extensions in the demo setup scripts. The demo setup script try to simulate a real world use case by generating and modifying mostly random data. This is also a good way to setup and “manually” test the code changes in a larger picture. The demo setup script can be found in the [demoSetup](https://github.com/Karaka-Management/demoSetup) repository. The demo setup script takes a long time due to the large amount of user input simulated data which is generated. Therefore it is recommended to run this only sporadically. +Developers should occasionaly check performance statistics. At this point no target metrics are defined. -### Code review +Since the primary application is a web based application a similar tool as the Google lighthouse tool can be used to inspect the application for best practicies which can significantly improve the application performance. The sitespeed.io tool shows potential performance improvements and slow pages. With the php trace and profiler enabled in the `php.ini` file the VM automatically generates profiling and trace reports for every web request. These can be found in the webgrind logs directory and inspected in webgrind and dropped into the trace visualizer for a flame chart visualization. With mysqldumpslow you can inspect slow sql queries which may need optimization. + +1. Automatic trace and benchmark generation with every web request in `/var/www/html/webgrind/Logs` +2. Webgrind view `http://vm_ip:82` +3. Trace visualization `http://vm_ip:81` + 1. Download the latest trace from `http://vm_ip:82/Logs` + 2. Drag and drop that downloaded `*.xt` file in the trace visualizer +4. `sitespeed.io ./Build/Helper/Scripts/sitespeedDemoUrls.txt -b chrome --outputFolder /var/www/html/sitespeed` +5. Slow query inspection. + +```sh +mysqldumpslow -t 10 /var/log/mysql/mysql-slow.log +mysqldumpslow -t 10 -s l /var/log/mysql/mysql-slow.log +``` + +#### Code review In addition to the automatic code review performed by the various inspection tools such as (phpcs, phpstan, phpunit, eslint and custom scripts) a senior developer must check the proposed code change before it is merged with the respective `develop` branch. Only upon the approval by the reviewer a code change requests gets merged as no other developers have permission in the software to make such code merges. In case a code change request is not approved the reviewer states the reason for the decision, this may include some tips and requests which will allow the contributor to make improvements so that the code change may get approved. -If the code reviewer only finds minor issues with the proposed code change the reviewer may make small changes to the proposed code change and inform the contributor to speed up the implementation process. Code reviewers are encouraged to do this with new contributors to avoid long iteration processes and to not discourage new developers. However, communication is key and severe issues with code change requests or if the contributor already made multiple code change requests in the past the reviewer should not implement the improvements by himself and rather decline the code change requests with his reasoning. +If the code reviewer only finds minor issues with the proposed code change the reviewer may make small changes to the proposed code change and inform the contributor to speed up the implementation process. Code reviewers are encouraged to do this with new contributors to avoid long iteration processes and to not discourage new developers. However, communication is key and severe issues with code change requests or if the contributor already made multiple code change requests in the past the reviewer should not implement the improvements by himself and rather decline the code change requests with his reasoning. (**R5**+**R8**) + +#### Demo + +Some code changes may also require changes or extensions in the demo setup scripts. The demo setup script try to simulate a real world use case by generating and modifying mostly random data. This is also a good way to setup and “manually” test the code changes in a larger picture. The demo setup script can be found in the [demoSetup](https://github.com/Karaka-Management/demoSetup) repository. The demo setup script takes a long time due to the large amount of user input simulated data which is generated. Therefore it is recommended to run this only sporadically. (**R9**) + +```sh +sudo -u www-data php -dxdebug.remote_enable=1 -dxdebug.start_with_request=yes -dxdebug.mode=coverage,develop,debug demoSetup/setup.php +``` + +#### Documentation + +Occasionally new code or code changes also require new documentation or documentation changes. Developers should make sure that the new code is also reflected in the existing documentation ([Developer-Guide](), [User-Guide]() and/or module documentation) or if additional documentation is necessary. + +#### Improvements, features, bugs + +If a developer (or employee in general) has an idea for an improvement, feature or finds a potential bug it should be reported at https://github.com/Karaka-Management/Karaka/issues. A senior developer has to check these issues and decide how to proceed with them. The decision how to proceed with the issue must be explained by the senior developer as a response in the issue. Possible steps are: + +* Accept the issue and put the task into the [Todos](https://github.com/orgs/Karaka-Management/projects/10) +* Dismiss the issue with an explanation ### Release flow +In case SCSS/CSS or JS files got changed they must get re-built locally before comitting the code change: + +```sh +npx esbuild Web/Backend/js/backend.js --bundle --outfile=Install/Application/Backend/js/backend.min.js --minify +scss cssOMS/styles.scss > cssOMS/styles.css +``` + +For JS you may also use the shorthand command `npm run build`. + Code changes must be performed in a new branch. A new branch can be created with: ```sh @@ -75,8 +127,70 @@ git checkout -b new-branch-name The name of the branch can be chosen freely however it is recommended to follow the following branch naming conventions: * `feature-*` for feature implementations +* `hotfix-*` for security related fixes/improvements * `bug-*` for bug fixes * `security-*` for security related fixes/improvements -* `general-*` for general improvements (i.e. code documentation improvements, code style improvements) +* `general-*` for general improvements (i.e. documentation, code style & performance improvements) -The senior developer who performs the code review merges the change request into the `develop` branch upon approval. \ No newline at end of file +```mermaid +%%{init: { 'gitGraph': {'mainBranchName': 'master'}} }%% + gitGraph + commit + branch hotfix-xxx + commit + checkout master + branch develop + checkout master + merge hotfix-xxx + checkout develop + branch bug-xxx + commit + commit + checkout hotfix-xxx + commit + checkout master + merge hotfix-xxx + checkout develop + merge bug-xxx + commit + checkout develop + branch feature-xxx + commit + commit + commit + checkout develop + merge feature-xxx + checkout master + merge develop + checkout develop + branch general-xxx + commit + checkout develop + merge general-xxx + branch security-xxx + commit + commit + checkout develop + merge security-xxx + checkout master + merge develop + +``` + +The senior developer who performs the code review merges the change request into the `develop` branch after their successful code review. Unsuccessful reviews lead to change requests by the original developer, other developers who can make the requested changes, changes by the senior developer who performed the review, or dismissal of the changed code. (**R10**) + +## Approved dependencies + +### Customer dependencies + +Developers may only rely on the dependencies defined in [Approved Customer Software]() when developing a solution. If new software should be added to this list or a different version is required developers should make a request with their team leader/head of department who forwards this requests if appropriate to the CTO and explain the reasoning for the different dependency needs. The CTO can decide if the dependency will be accepted. (**R11**) + +### Developer dependencies + +Developers may only rely on the dependencies defined in [IT Equipment & Software](). If new software should be added to this list or a different version is required developers should make a request with their team leader/head of department who forwards this requests if appropriate to the CTO and explain the reasoning for the different dependency needs. The CTO can decide if the dependency will be accepted. Changing the package managers such as `composer.json` or `package.json` is not allowed by anyone else than the CTO. (**R12**) + +## Other related documents + +* [Confidentiality Policy](../Policies%20&%20Guidelines/Confidentiality%20Policy.md) +* [Organization Activity Policy](../Policies%20&%20Guidelines/Organization%20Activity%20Policy.md) +* [Tutorials](./Development/Tutorials) \ No newline at end of file diff --git a/Controller/ApiAttributeController.php b/Controller/ApiAttributeController.php new file mode 100644 index 0000000..cd9d66e --- /dev/null +++ b/Controller/ApiAttributeController.php @@ -0,0 +1,550 @@ +validateAttributeCreate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + $type = TaskAttributeTypeMapper::get() + ->with('defaults') + ->where('id', (int) $request->getData('type')) + ->execute(); + + if (!$type->repeatable) { + $attr = TaskAttributeMapper::count() + ->with('type') + ->where('type/id', $type->id) + ->where('ref', (int) $request->getData('ref')) + ->execute(); + + if ($attr > 0) { + $response->header->status = RequestStatusCode::R_409; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + } + + $attribute = $this->createAttributeFromRequest($request, $type); + $this->createModel($request->header->account, $attribute, TaskAttributeMapper::class, 'attribute', $request->getOrigin()); + $this->createStandardCreateResponse($request, $response, $attribute); + } + + /** + * Api method to create task attribute l11n + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeTypeL11nCreate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + $attrL11n = $this->createAttributeTypeL11nFromRequest($request); + $this->createModel($request->header->account, $attrL11n, TaskAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin()); + $this->createStandardCreateResponse($request, $response, $attrL11n); + } + + /** + * Api method to create task attribute type + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeTypeCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeTypeCreate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + $attrType = $this->createAttributeTypeFromRequest($request); + $this->createModel($request->header->account, $attrType, TaskAttributeTypeMapper::class, 'attr_type', $request->getOrigin()); + $this->createStandardCreateResponse($request, $response, $attrType); + } + + /** + * Api method to create task attribute value + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeValueCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeValueCreate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + /** @var \Modules\Attribute\Models\AttributeType $type */ + $type = TaskAttributeTypeMapper::get() + ->where('id', $request->getDataInt('type') ?? 0) + ->execute(); + + if ($type->isInternal) { + $response->header->status = RequestStatusCode::R_403; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + $attrValue = $this->createAttributeValueFromRequest($request, $type); + $this->createModel($request->header->account, $attrValue, TaskAttributeValueMapper::class, 'attr_value', $request->getOrigin()); + + if ($attrValue->isDefault) { + $this->createModelRelation( + $request->header->account, + $type->id, + $attrValue->id, + TaskAttributeTypeMapper::class, 'defaults', '', $request->getOrigin() + ); + } + + $this->createStandardCreateResponse($request, $response, $attrValue); + } + + /** + * Api method to create task attribute l11n + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeValueL11nCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeValueL11nCreate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + $attrL11n = $this->createAttributeValueL11nFromRequest($request); + $this->createModel($request->header->account, $attrL11n, TaskAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin()); + $this->createStandardCreateResponse($request, $response, $attrL11n); + } + + /** + * Api method to update TaskAttribute + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeUpdate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeUpdate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidUpdateResponse($request, $response, $val); + + return; + } + + /** @var Attribute $old */ + $old = TaskAttributeMapper::get() + ->with('type') + ->with('type/defaults') + ->with('value') + ->where('id', (int) $request->getData('id')) + ->execute(); + + $new = $this->updateAttributeFromRequest($request, clone $old); + + if ($new->id === 0) { + // Set response header to invalid request because of invalid data + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidUpdateResponse($request, $response, $new); + + return; + } + + $this->updateModel($request->header->account, $old, $new, TaskAttributeMapper::class, 'task_attribute', $request->getOrigin()); + + if ($new->value->getValue() !== $old->value->getValue() + && $new->type->custom + ) { + $this->updateModel($request->header->account, $old->value, $new->value, TaskAttributeValueMapper::class, 'attribute_value', $request->getOrigin()); + } + + $this->createStandardUpdateResponse($request, $response, $new); + } + + /** + * Api method to delete TaskAttribute + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeDelete(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeDelete($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidDeleteResponse($request, $response, $val); + + return; + } + + $taskAttribute = TaskAttributeMapper::get() + ->with('type') + ->where('id', (int) $request->getData('id')) + ->execute(); + + if ($taskAttribute->type->isRequired) { + $this->createInvalidDeleteResponse($request, $response, []); + + return; + } + + $this->deleteModel($request->header->account, $taskAttribute, TaskAttributeMapper::class, 'task_attribute', $request->getOrigin()); + $this->createStandardDeleteResponse($request, $response, $taskAttribute); + } + + /** + * Api method to update TaskAttributeTypeL11n + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeTypeL11nUpdate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeTypeL11nUpdate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidUpdateResponse($request, $response, $val); + + return; + } + + /** @var BaseStringL11n $old */ + $old = TaskAttributeTypeL11nMapper::get()->where('id', (int) $request->getData('id'))->execute(); + $new = $this->updateAttributeTypeL11nFromRequest($request, clone $old); + + $this->updateModel($request->header->account, $old, $new, TaskAttributeTypeL11nMapper::class, 'task_attribute_type_l11n', $request->getOrigin()); + $this->createStandardUpdateResponse($request, $response, $new); + } + + /** + * Api method to delete TaskAttributeTypeL11n + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeTypeL11nDelete(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeTypeL11nDelete($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidDeleteResponse($request, $response, $val); + + return; + } + + /** @var BaseStringL11n $taskAttributeTypeL11n */ + $taskAttributeTypeL11n = TaskAttributeTypeL11nMapper::get()->where('id', (int) $request->getData('id'))->execute(); + $this->deleteModel($request->header->account, $taskAttributeTypeL11n, TaskAttributeTypeL11nMapper::class, 'task_attribute_type_l11n', $request->getOrigin()); + $this->createStandardDeleteResponse($request, $response, $taskAttributeTypeL11n); + } + + /** + * Api method to update TaskAttributeType + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeTypeUpdate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeTypeUpdate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidUpdateResponse($request, $response, $val); + + return; + } + + /** @var AttributeType $old */ + $old = TaskAttributeTypeMapper::get()->with('defaults')->where('id', (int) $request->getData('id'))->execute(); + $new = $this->updateAttributeTypeFromRequest($request, clone $old); + + $this->updateModel($request->header->account, $old, $new, TaskAttributeTypeMapper::class, 'task_attribute_type', $request->getOrigin()); + $this->createStandardUpdateResponse($request, $response, $new); + } + + /** + * Api method to delete TaskAttributeType + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @todo Implement API function + * + * @since 1.0.0 + */ + public function apiTaskAttributeTypeDelete(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeTypeDelete($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidDeleteResponse($request, $response, $val); + + return; + } + + /** @var AttributeType $taskAttributeType */ + $taskAttributeType = TaskAttributeTypeMapper::get()->with('defaults')->where('id', (int) $request->getData('id'))->execute(); + $this->deleteModel($request->header->account, $taskAttributeType, TaskAttributeTypeMapper::class, 'task_attribute_type', $request->getOrigin()); + $this->createStandardDeleteResponse($request, $response, $taskAttributeType); + } + + /** + * Api method to update TaskAttributeValue + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeValueUpdate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeValueUpdate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidUpdateResponse($request, $response, $val); + + return; + } + + /** @var AttributeValue $old */ + $old = TaskAttributeValueMapper::get()->where('id', (int) $request->getData('id'))->execute(); + + /** @var \Modules\Attribute\Models\Attribute $attr */ + $attr = TaskAttributeMapper::get() + ->with('type') + ->where('id', $request->getDataInt('attribute') ?? 0) + ->execute(); + + $new = $this->updateAttributeValueFromRequest($request, clone $old, $attr); + + $this->updateModel($request->header->account, $old, $new, TaskAttributeValueMapper::class, 'task_attribute_value', $request->getOrigin()); + $this->createStandardUpdateResponse($request, $response, $new); + } + + /** + * Api method to delete TaskAttributeValue + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeValueDelete(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + // @todo I don't think values can be deleted? Only Attributes + // However, It should be possible to remove UNUSED default values + // either here or other function? + // if (!empty($val = $this->validateAttributeValueDelete($request))) { + // $response->header->status = RequestStatusCode::R_400; + // $this->createInvalidDeleteResponse($request, $response, $val); + + // return; + // } + + // /** @var \Modules\Tasks\Models\TaskAttributeValue $taskAttributeValue */ + // $taskAttributeValue = TaskAttributeValueMapper::get()->where('id', (int) $request->getData('id'))->execute(); + // $this->deleteModel($request->header->account, $taskAttributeValue, TaskAttributeValueMapper::class, 'task_attribute_value', $request->getOrigin()); + // $this->createStandardDeleteResponse($request, $response, $taskAttributeValue); + } + + /** + * Api method to update TaskAttributeValueL11n + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeValueL11nUpdate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeValueL11nUpdate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidUpdateResponse($request, $response, $val); + + return; + } + + /** @var BaseStringL11n $old */ + $old = TaskAttributeValueL11nMapper::get()->where('id', (int) $request->getData('id')); + $new = $this->updateAttributeValueL11nFromRequest($request, clone $old); + + $this->updateModel($request->header->account, $old, $new, TaskAttributeValueL11nMapper::class, 'task_attribute_value_l11n', $request->getOrigin()); + $this->createStandardUpdateResponse($request, $response, $new); + } + + /** + * Api method to delete TaskAttributeValueL11n + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiTaskAttributeValueL11nDelete(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateAttributeValueL11nDelete($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidDeleteResponse($request, $response, $val); + + return; + } + + /** @var BaseStringL11n $taskAttributeValueL11n */ + $taskAttributeValueL11n = TaskAttributeValueL11nMapper::get()->where('id', (int) $request->getData('id'))->execute(); + $this->deleteModel($request->header->account, $taskAttributeValueL11n, TaskAttributeValueL11nMapper::class, 'task_attribute_value_l11n', $request->getOrigin()); + $this->createStandardDeleteResponse($request, $response, $taskAttributeValueL11n); + } +} diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 17950f5..aee99a4 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -22,28 +22,15 @@ use Modules\Media\Models\NullMedia; use Modules\Media\Models\PathSettings; use Modules\Media\Models\Reference; use Modules\Media\Models\ReferenceMapper; -use Modules\Tag\Models\NullTag; -use Modules\Tasks\Models\NullTaskAttributeType; -use Modules\Tasks\Models\NullTaskAttributeValue; use Modules\Tasks\Models\Task; -use Modules\Tasks\Models\TaskAttribute; -use Modules\Tasks\Models\TaskAttributeMapper; -use Modules\Tasks\Models\TaskAttributeType; -use Modules\Tasks\Models\TaskAttributeTypeL11nMapper; -use Modules\Tasks\Models\TaskAttributeTypeMapper; -use Modules\Tasks\Models\TaskAttributeValue; -use Modules\Tasks\Models\TaskAttributeValueL11nMapper; -use Modules\Tasks\Models\TaskAttributeValueMapper; use Modules\Tasks\Models\TaskElement; use Modules\Tasks\Models\TaskElementMapper; use Modules\Tasks\Models\TaskMapper; +use Modules\Tasks\Models\TaskPriority; use Modules\Tasks\Models\TaskSeen; use Modules\Tasks\Models\TaskSeenMapper; use Modules\Tasks\Models\TaskStatus; use Modules\Tasks\Models\TaskType; -use phpOMS\Localization\BaseStringL11n; -use phpOMS\Localization\ISO639x1Enum; -use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; @@ -358,45 +345,28 @@ final class ApiController extends Controller $task->title = $request->getDataString('title') ?? ''; $task->description = Markdown::parse($request->getDataString('plain') ?? ''); $task->descriptionRaw = $request->getDataString('plain') ?? ''; - $task->setCreatedBy(new NullAccount($request->header->account)); - $task->setStatus(TaskStatus::OPEN); - $task->setType($request->getDataInt('type') ?? TaskType::SINGLE); - $task->redirect = $request->getDataString('redirect') ?? ''; + $task->createdBy = new NullAccount($request->header->account); + $task->for = $request->hasData('for') ? new NullAccount((int) $request->getData('for')) : null; + $task->status = TaskStatus::OPEN; + $task->type = TaskType::tryFromValue($request->getDataInt('type')) ?? TaskType::SINGLE; + $task->redirect = $request->getDataString('redirect') ?? ''; if ($request->hasData('due')) { $task->due = $request->getDataDateTime('due'); } else { - $task->setPriority((int) $request->getData('priority')); + $task->priority = (int) $request->getData('priority'); } - if (!empty($tags = $request->getDataJson('tags'))) { - foreach ($tags as $tag) { - if (!isset($tag['id'])) { - $request->setData('title', $tag['title'], true); - $request->setData('color', $tag['color'], true); - $request->setData('icon', $tag['icon'] ?? null, true); - $request->setData('language', $tag['language'], true); - - $internalResponse = new HttpResponse(); - $this->app->moduleManager->get('Tag')->apiTagCreate($request, $internalResponse); - - if (!\is_array($data = $internalResponse->getDataArray($request->uri->__toString()))) { - continue; - } - - $task->addTag($data['response']); - } else { - $task->addTag(new NullTag((int) $tag['id'])); - } - } + if ($request->hasData('tags')) { + $task->tags = $this->app->moduleManager->get('Tag', 'Api')->createTagsFromRequest($request); } $element = new TaskElement(); $element->addTo(new NullAccount($request->getDataInt('forward') ?? $request->header->account)); - $element->createdBy = $task->getCreatedBy(); + $element->createdBy = $task->createdBy; $element->due = $task->due; - $element->setPriority($task->getPriority()); - $element->setStatus(TaskStatus::OPEN); + $element->priority = $task->priority; + $element->status = TaskStatus::OPEN; $task->addElement($element); @@ -467,10 +437,10 @@ final class ApiController extends Controller $task->description = Markdown::parse($request->getDataString('plain') ?? $task->descriptionRaw); $task->descriptionRaw = $request->getDataString('plain') ?? $task->descriptionRaw; $task->due = $request->hasData('due') ? new \DateTime($request->getDataString('due') ?? 'now') : $task->due; - $task->setStatus($request->getDataInt('status') ?? $task->getStatus()); - $task->setType($request->getDataInt('type') ?? $task->getType()); - $task->setPriority($request->getDataInt('priority') ?? $task->getPriority()); - $task->completion = $request->getDataInt('completion') ?? $task->completion; + $task->status = TaskStatus::tryFromValue($request->getDataInt('status')) ?? $task->status; + $task->type = TaskType::tryFromValue($request->getDataInt('type')) ?? $task->type; + $task->priority = TaskPriority::tryFromValue($request->getDataInt('priority')) ?? $task->priority; + $task->completion = $request->getDataInt('completion') ?? $task->completion; return $task; } @@ -526,14 +496,14 @@ final class ApiController extends Controller $task->due = $element->due; $task->completion = $request->getDataInt('completion') ?? $task->completion; - $task->setPriority($element->getPriority()); - $task->setStatus($element->getStatus()); + $task->priority = $element->priority; + $task->status = $element->status; - if ($task->getStatus() === TaskStatus::DONE) { + if ($task->status === TaskStatus::DONE) { $task->completion = 100; } - $this->createModel($request->header->account, $element, TaskElementMapper::class, 'taskelement', $request->getOrigin()); + $this->createModel($request->header->account, $element, TaskElementMapper::class, 'task_element', $request->getOrigin()); if (!empty($request->files) || !empty($request->getDataJson('media')) @@ -685,14 +655,15 @@ final class ApiController extends Controller */ public function createTaskElementFromRequest(RequestAbstract $request, Task $task) : TaskElement { - $element = new TaskElement(); - $element->createdBy = new NullAccount($request->header->account); - $element->due = $request->getDataDateTime('due') ?? $task->due; - $element->setPriority($request->getDataInt('priority') ?? $task->getPriority()); - $element->setStatus((int) ($request->getData('status'))); + $element = new TaskElement(); + $element->createdBy = new NullAccount($request->header->account); + $element->due = $request->getDataDateTime('due') ?? $task->due; + $element->priority = TaskPriority::tryFromValue($request->getDataInt('priority')) ?? $task->priority; + $element->status = TaskStatus::tryFromValue($request->getDataInt('status')) ?? TaskStatus::OPEN; $element->task = $task->id; $element->description = Markdown::parse($request->getDataString('plain') ?? ''); $element->descriptionRaw = $request->getDataString('plain') ?? ''; + $element->duration = $request->getDataInt('duration') ?? 0; $tos = $request->getData('to') ?? $request->header->account; if (!\is_array($tos)) { @@ -755,18 +726,18 @@ final class ApiController extends Controller /** @var TaskElement $new */ $new = $this->updateTaskElementFromRequest($request, clone $old); - $this->updateModel($request->header->account, $old, $new, TaskElementMapper::class, 'taskelement', $request->getOrigin()); + $this->updateModel($request->header->account, $old, $new, TaskElementMapper::class, 'task_element', $request->getOrigin()); - if ($old->getStatus() !== $new->getStatus() - || $old->getPriority() !== $new->getPriority() + if ($old->status !== $new->status + || $old->priority !== $new->priority || $old->due !== $new->due ) { /** @var Task $task */ $task = TaskMapper::get()->where('id', $new->task)->execute(); - $task->setStatus($new->getStatus()); - $task->setPriority($new->getPriority()); - $task->due = $new->due; + $task->status = $new->status; + $task->priority = $new->priority; + $task->due = $new->due; $this->updateModel($request->header->account, $task, $task, TaskMapper::class, 'task', $request->getOrigin()); @@ -789,8 +760,8 @@ final class ApiController extends Controller */ private function updateTaskElementFromRequest(RequestAbstract $request, TaskElement $element) : TaskElement { - $element->due = $request->getDataDateTime('due') ?? $element->due; - $element->setStatus($request->getDataInt('status') ?? $element->getStatus()); + $element->due = $request->getDataDateTime('due') ?? $element->due; + $element->status = TaskStatus::tryFromValue($request->getDataInt('status')) ?? $element->status; $element->description = Markdown::parse($request->getDataString('plain') ?? $element->descriptionRaw); $element->descriptionRaw = $request->getDataString('plain') ?? $element->descriptionRaw; @@ -814,377 +785,4 @@ final class ApiController extends Controller return $element; } - - /** - * Api method to create task attribute - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiTaskAttributeCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateTaskAttributeCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $attribute = $this->createTaskAttributeFromRequest($request); - $this->createModel($request->header->account, $attribute, TaskAttributeMapper::class, 'attribute', $request->getOrigin()); - $this->createStandardCreateResponse($request, $response, $attribute); - } - - /** - * Method to create task attribute from request. - * - * @param RequestAbstract $request Request - * - * @return TaskAttribute - * - * @since 1.0.0 - */ - private function createTaskAttributeFromRequest(RequestAbstract $request) : TaskAttribute - { - $attribute = new TaskAttribute(); - $attribute->task = (int) $request->getData('task'); - $attribute->type = new NullTaskAttributeType((int) $request->getData('type')); - - if ($request->hasData('value_id')) { - $attribute->value = new NullTaskAttributeValue((int) $request->getData('value_id')); - } else { - $newRequest = clone $request; - $newRequest->setData('value', $request->getData('value'), true); - - $value = $this->createTaskAttributeValueFromRequest($request); - - $attribute->value = $value; - } - - return $attribute; - } - - /** - * Validate task attribute create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateTaskAttributeCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['type'] = !$request->hasData('type')) - || ($val['value'] = (!$request->hasData('value') && !$request->hasData('custom'))) - || ($val['task'] = !$request->hasData('task')) - ) { - return $val; - } - - return []; - } - - /** - * Api method to create task attribute l11n - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiTaskAttributeTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateTaskAttributeTypeL11nCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $attrL11n = $this->createTaskAttributeTypeL11nFromRequest($request); - $this->createModel($request->header->account, $attrL11n, TaskAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin()); - $this->createStandardCreateResponse($request, $response, $attrL11n); - } - - /** - * Method to create task attribute l11n from request. - * - * @param RequestAbstract $request Request - * - * @return BaseStringL11n - * - * @since 1.0.0 - */ - private function createTaskAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n - { - $attrL11n = new BaseStringL11n(); - $attrL11n->ref = $request->getDataInt('type') ?? 0; - $attrL11n->setLanguage( - $request->getDataString('language') ?? $request->header->l11n->language - ); - $attrL11n->content = $request->getDataString('title') ?? ''; - - return $attrL11n; - } - - /** - * Validate task attribute l11n create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateTaskAttributeTypeL11nCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['title'] = !$request->hasData('title')) - || ($val['type'] = !$request->hasData('type')) - ) { - return $val; - } - - return []; - } - - /** - * Api method to create task attribute type - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiTaskAttributeTypeCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateTaskAttributeTypeCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $attrType = $this->createTaskAttributeTypeFromRequest($request); - $this->createModel($request->header->account, $attrType, TaskAttributeTypeMapper::class, 'attr_type', $request->getOrigin()); - $this->createStandardCreateResponse($request, $response, $attrType); - } - - /** - * Method to create task attribute from request. - * - * @param RequestAbstract $request Request - * - * @return TaskAttributeType - * - * @since 1.0.0 - */ - private function createTaskAttributeTypeFromRequest(RequestAbstract $request) : TaskAttributeType - { - $attrType = new TaskAttributeType($request->getDataString('name') ?? ''); - $attrType->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN); - $attrType->setFields($request->getDataInt('fields') ?? 0); - $attrType->custom = $request->getDataBool('custom') ?? false; - $attrType->isRequired = $request->getDataBool('is_required') ?? false; - $attrType->validationPattern = $request->getDataString('validation_pattern') ?? ''; - - return $attrType; - } - - /** - * Validate task attribute create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateTaskAttributeTypeCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['title'] = !$request->hasData('title')) - || ($val['name'] = !$request->hasData('name')) - ) { - return $val; - } - - return []; - } - - /** - * Api method to create task attribute value - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiTaskAttributeValueCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateTaskAttributeValueCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $attrValue = $this->createTaskAttributeValueFromRequest($request); - $this->createModel($request->header->account, $attrValue, TaskAttributeValueMapper::class, 'attr_value', $request->getOrigin()); - - if ($attrValue->isDefault) { - $this->createModelRelation( - $request->header->account, - (int) $request->getData('attributetype'), - $attrValue->id, - TaskAttributeTypeMapper::class, 'defaults', '', $request->getOrigin() - ); - } - - $this->createStandardCreateResponse($request, $response, $attrValue); - } - - /** - * Method to create task attribute value from request. - * - * @param RequestAbstract $request Request - * - * @return TaskAttributeValue - * - * @since 1.0.0 - */ - private function createTaskAttributeValueFromRequest(RequestAbstract $request) : TaskAttributeValue - { - /** @var TaskAttributeType $type */ - $type = TaskAttributeTypeMapper::get() - ->where('id', $request->getDataInt('type') ?? 0) - ->execute(); - - $attrValue = new TaskAttributeValue(); - $attrValue->isDefault = $request->getDataBool('default') ?? false; - $attrValue->setValue($request->getDataString('value'), $type->datatype); - - if ($request->hasData('title')) { - $attrValue->setL11n( - $request->getDataString('title') ?? '', - $request->getDataString('language') ?? ISO639x1Enum::_EN - ); - } - - return $attrValue; - } - - /** - * Validate task attribute value create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateTaskAttributeValueCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['attributetype'] = !$request->hasData('attributetype')) - || ($val['value'] = !$request->hasData('value')) - ) { - return $val; - } - - return []; - } - - /** - * Api method to create task attribute l11n - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiTaskAttributeValueL11nCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateTaskAttributeValueL11nCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $attrL11n = $this->createTaskAttributeValueL11nFromRequest($request); - $this->createModel($request->header->account, $attrL11n, TaskAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin()); - $this->createStandardCreateResponse($request, $response, $attrL11n); - } - - /** - * Method to create task attribute l11n from request. - * - * @param RequestAbstract $request Request - * - * @return BaseStringL11n - * - * @since 1.0.0 - */ - private function createTaskAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n - { - $attrL11n = new BaseStringL11n(); - $attrL11n->ref = $request->getDataInt('value') ?? 0; - $attrL11n->setLanguage( - $request->getDataString('language') ?? $request->header->l11n->language - ); - $attrL11n->content = $request->getDataString('title') ?? ''; - - return $attrL11n; - } - - /** - * Validate task attribute l11n create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateTaskAttributeValueL11nCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['title'] = !$request->hasData('title')) - || ($val['value'] = !$request->hasData('value')) - ) { - return $val; - } - - return []; - } } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 4f375e5..5b1d3d7 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -95,7 +95,7 @@ final class BackendController extends Controller implements DashboardElementInte $view->data['task_media'] = []; foreach ($view->data['tasks'] as $task) { $view->data['task_media'][$task->id] = TaskMapper::has() - ->with('media') + ->with('files') ->where('id', $task->id) ->where('type', TaskType::SINGLE) ->execute(); @@ -124,7 +124,7 @@ final class BackendController extends Controller implements DashboardElementInte foreach ($view->data['open'] as $task) { $view->data['task_media'][$task->id] = TaskMapper::has() - ->with('media') + ->with('files') ->where('id', $task->id) ->execute(); } @@ -147,7 +147,7 @@ final class BackendController extends Controller implements DashboardElementInte foreach ($view->data['given'] as $task) { $view->data['task_media'][$task->id] = TaskMapper::has() - ->with('media') + ->with('files') ->where('id', $task->id) ->where('type', TaskType::SINGLE) ->execute(); @@ -172,7 +172,7 @@ final class BackendController extends Controller implements DashboardElementInte foreach ($view->data['unread'] as $task) { $view->data['task_media'][$task->id] = TaskMapper::has() - ->with('media') + ->with('files') ->where('id', $task->id) ->where('type', TaskType::SINGLE) ->execute(); @@ -253,7 +253,7 @@ final class BackendController extends Controller implements DashboardElementInte /** @var \Modules\Tasks\Models\Task $task */ $task = TaskMapper::get() ->with('createdBy') - ->with('media') + ->with('files') ->with('tags') ->with('tags/title') ->with('taskElements') @@ -318,7 +318,7 @@ final class BackendController extends Controller implements DashboardElementInte $view->data['reminder'] = $reminderStatus; - $view->setTemplate('/Modules/Tasks/Theme/Backend/task-single'); + $view->setTemplate('/Modules/Tasks/Theme/Backend/task-view'); $view->data['task'] = $task; $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1001101001, $request, $response); diff --git a/LICENSE.txt b/LICENSE.txt index 18d430e..4ba0161 100755 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -27,7 +27,7 @@ Version 2.0 Subject to the terms and conditions of this License, each Contributor grants to You after purchase a perpetual, worldwide, non-exclusive, irrevocable copyright license to prepare Derivative Works of, publicly display, publicly perform the Work and such Derivative Works in Source or Object form. You are not allowed to sublicense, reproduce, or distribute the Work and such Derivative Works in Source or Object form. -3. Redistribution. +3. Redistribution You may not reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form. diff --git a/Models/AccountRelation.php b/Models/AccountRelation.php index 69c56db..266e2fe 100755 --- a/Models/AccountRelation.php +++ b/Models/AccountRelation.php @@ -43,7 +43,7 @@ class AccountRelation extends RelationAbstract * * @since 1.0.0 */ - public function __construct(Account $account = null, int $duty = DutyType::TO) + public function __construct(?Account $account = null, int $duty = DutyType::TO) { $this->relation = $account ?? new NullAccount(); $this->duty = $duty; diff --git a/Models/AccountRelationMapper.php b/Models/AccountRelationMapper.php index 80d98b9..a2339ca 100755 --- a/Models/AccountRelationMapper.php +++ b/Models/AccountRelationMapper.php @@ -51,8 +51,8 @@ final class AccountRelationMapper extends DataMapperFactory */ public const OWNS_ONE = [ 'relation' => [ - 'mapper' => AccountMapper::class, - 'external' => 'task_account_account', + 'mapper' => AccountMapper::class, + 'external' => 'task_account_account', ], ]; diff --git a/Models/TaskAttributeMapper.php b/Models/Attribute/TaskAttributeMapper.php old mode 100755 new mode 100644 similarity index 79% rename from Models/TaskAttributeMapper.php rename to Models/Attribute/TaskAttributeMapper.php index bd70de0..c677350 --- a/Models/TaskAttributeMapper.php +++ b/Models/Attribute/TaskAttributeMapper.php @@ -4,7 +4,7 @@ * * PHP Version 8.1 * - * @package Modules\Tasks\Models + * @package Modules\Tasks\Models\Attribute * @copyright Dennis Eichhorn * @license OMS License 2.0 * @version 1.0.0 @@ -12,19 +12,20 @@ */ declare(strict_types=1); -namespace Modules\Tasks\Models; +namespace Modules\Tasks\Models\Attribute; +use Modules\Attribute\Models\Attribute; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** * Task mapper class. * - * @package Modules\Tasks\Models + * @package Modules\Tasks\Models\Attribute * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 * - * @template T of TaskAttribute + * @template T of Attribute * @extends DataMapperFactory */ final class TaskAttributeMapper extends DataMapperFactory @@ -37,7 +38,7 @@ final class TaskAttributeMapper extends DataMapperFactory */ public const COLUMNS = [ 'task_attr_id' => ['name' => 'task_attr_id', 'type' => 'int', 'internal' => 'id'], - 'task_attr_task' => ['name' => 'task_attr_task', 'type' => 'int', 'internal' => 'task'], + 'task_attr_item' => ['name' => 'task_attr_item', 'type' => 'int', 'internal' => 'ref'], 'task_attr_type' => ['name' => 'task_attr_type', 'type' => 'int', 'internal' => 'type'], 'task_attr_value' => ['name' => 'task_attr_value', 'type' => 'int', 'internal' => 'value'], ]; @@ -59,6 +60,14 @@ final class TaskAttributeMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = Attribute::class; + /** * Primary table. * diff --git a/Models/TaskAttributeTypeL11nMapper.php b/Models/Attribute/TaskAttributeTypeL11nMapper.php old mode 100755 new mode 100644 similarity index 93% rename from Models/TaskAttributeTypeL11nMapper.php rename to Models/Attribute/TaskAttributeTypeL11nMapper.php index 43dee73..133fc96 --- a/Models/TaskAttributeTypeL11nMapper.php +++ b/Models/Attribute/TaskAttributeTypeL11nMapper.php @@ -4,7 +4,7 @@ * * PHP Version 8.1 * - * @package Modules\Tasks\Models + * @package Modules\Tasks\Models\Attribute * @copyright Dennis Eichhorn * @license OMS License 2.0 * @version 1.0.0 @@ -12,7 +12,7 @@ */ declare(strict_types=1); -namespace Modules\Tasks\Models; +namespace Modules\Tasks\Models\Attribute; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; use phpOMS\Localization\BaseStringL11n; @@ -20,7 +20,7 @@ use phpOMS\Localization\BaseStringL11n; /** * Task mapper class. * - * @package Modules\Tasks\Models + * @package Modules\Tasks\Models\Attribute * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 diff --git a/Models/TaskAttributeTypeMapper.php b/Models/Attribute/TaskAttributeTypeMapper.php old mode 100755 new mode 100644 similarity index 53% rename from Models/TaskAttributeTypeMapper.php rename to Models/Attribute/TaskAttributeTypeMapper.php index a39f7cc..3508186 --- a/Models/TaskAttributeTypeMapper.php +++ b/Models/Attribute/TaskAttributeTypeMapper.php @@ -4,7 +4,7 @@ * * PHP Version 8.1 * - * @package Modules\Tasks\Models + * @package Modules\Tasks\Models\Attribute * @copyright Dennis Eichhorn * @license OMS License 2.0 * @version 1.0.0 @@ -12,19 +12,20 @@ */ declare(strict_types=1); -namespace Modules\Tasks\Models; +namespace Modules\Tasks\Models\Attribute; +use Modules\Attribute\Models\AttributeType; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** * Task mapper class. * - * @package Modules\Tasks\Models + * @package Modules\Tasks\Models\Attribute * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 * - * @template T of TaskAttributeType + * @template T of AttributeType * @extends DataMapperFactory */ final class TaskAttributeTypeMapper extends DataMapperFactory @@ -36,12 +37,15 @@ final class TaskAttributeTypeMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'task_attr_type_id' => ['name' => 'task_attr_type_id', 'type' => 'int', 'internal' => 'id'], - 'task_attr_type_name' => ['name' => 'task_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], - 'task_attr_type_fields' => ['name' => 'task_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], - 'task_attr_type_custom' => ['name' => 'task_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'], - 'task_attr_type_pattern' => ['name' => 'task_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'], - 'task_attr_type_required' => ['name' => 'task_attr_type_required', 'type' => 'bool', 'internal' => 'isRequired'], + 'task_attr_type_id' => ['name' => 'task_attr_type_id', 'type' => 'int', 'internal' => 'id'], + 'task_attr_type_name' => ['name' => 'task_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], + 'task_attr_type_datatype' => ['name' => 'task_attr_type_datatype', 'type' => 'int', 'internal' => 'datatype'], + 'task_attr_type_fields' => ['name' => 'task_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], + 'task_attr_type_custom' => ['name' => 'task_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'], + 'task_attr_type_repeatable' => ['name' => 'task_attr_type_repeatable', 'type' => 'bool', 'internal' => 'repeatable'], + 'task_attr_type_internal' => ['name' => 'task_attr_type_internal', 'type' => 'bool', 'internal' => 'isInternal'], + 'task_attr_type_pattern' => ['name' => 'task_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'], + 'task_attr_type_required' => ['name' => 'task_attr_type_required', 'type' => 'bool', 'internal' => 'isRequired'], ]; /** @@ -66,6 +70,14 @@ final class TaskAttributeTypeMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = AttributeType::class; + /** * Primary table. * diff --git a/Models/TaskAttributeValueL11nMapper.php b/Models/Attribute/TaskAttributeValueL11nMapper.php old mode 100755 new mode 100644 similarity index 65% rename from Models/TaskAttributeValueL11nMapper.php rename to Models/Attribute/TaskAttributeValueL11nMapper.php index c3d1094..a596ea8 --- a/Models/TaskAttributeValueL11nMapper.php +++ b/Models/Attribute/TaskAttributeValueL11nMapper.php @@ -4,7 +4,7 @@ * * PHP Version 8.1 * - * @package Modules\Tasks\Models + * @package Modules\Tasks\Models\Attribute * @copyright Dennis Eichhorn * @license OMS License 2.0 * @version 1.0.0 @@ -12,7 +12,7 @@ */ declare(strict_types=1); -namespace Modules\Tasks\Models; +namespace Modules\Tasks\Models\Attribute; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; use phpOMS\Localization\BaseStringL11n; @@ -20,7 +20,7 @@ use phpOMS\Localization\BaseStringL11n; /** * Task mapper class. * - * @package Modules\Tasks\Models + * @package Modules\Tasks\Models\Attribute * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 @@ -37,10 +37,10 @@ final class TaskAttributeValueL11nMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'task_attr_value_l11n_id' => ['name' => 'task_attr_value_l11n_id', 'type' => 'int', 'internal' => 'id'], - 'task_attr_value_l11n_title' => ['name' => 'task_attr_value_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], - 'task_attr_value_l11n_value' => ['name' => 'task_attr_value_l11n_value', 'type' => 'int', 'internal' => 'ref'], - 'task_attr_value_l11n_lang' => ['name' => 'task_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'], + 'task_attr_value_l11n_id' => ['name' => 'task_attr_value_l11n_id', 'type' => 'int', 'internal' => 'id'], + 'task_attr_value_l11n_title' => ['name' => 'task_attr_value_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'task_attr_value_l11n_value' => ['name' => 'task_attr_value_l11n_value', 'type' => 'int', 'internal' => 'ref'], + 'task_attr_value_l11n_lang' => ['name' => 'task_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'], ]; /** diff --git a/Models/Attribute/TaskAttributeValueMapper.php b/Models/Attribute/TaskAttributeValueMapper.php new file mode 100644 index 0000000..91e76fc --- /dev/null +++ b/Models/Attribute/TaskAttributeValueMapper.php @@ -0,0 +1,90 @@ + + */ +final class TaskAttributeValueMapper extends DataMapperFactory +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + public const COLUMNS = [ + 'task_attr_value_id' => ['name' => 'task_attr_value_id', 'type' => 'int', 'internal' => 'id'], + 'task_attr_value_default' => ['name' => 'task_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'], + 'task_attr_value_valueStr' => ['name' => 'task_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'], + 'task_attr_value_valueInt' => ['name' => 'task_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'], + 'task_attr_value_valueDec' => ['name' => 'task_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'], + 'task_attr_value_valueDat' => ['name' => 'task_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'], + 'task_attr_value_unit' => ['name' => 'task_attr_value_unit', 'type' => 'string', 'internal' => 'unit'], + 'task_attr_value_deptype' => ['name' => 'task_attr_value_deptype', 'type' => 'int', 'internal' => 'dependingAttributeType'], + 'task_attr_value_depvalue' => ['name' => 'task_attr_value_depvalue', 'type' => 'int', 'internal' => 'dependingAttributeValue'], + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + public const HAS_MANY = [ + 'l11n' => [ + 'mapper' => TaskAttributeValueL11nMapper::class, + 'table' => 'task_attr_value_l11n', + 'self' => 'task_attr_value_l11n_value', + 'column' => 'content', + 'external' => null, + ], + ]; + + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = AttributeValue::class; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'task_attr_value'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD = 'task_attr_value_id'; +} diff --git a/Models/AttributeValueType.php b/Models/AttributeValueType.php deleted file mode 100755 index 1ad4986..0000000 --- a/Models/AttributeValueType.php +++ /dev/null @@ -1,40 +0,0 @@ -relation = $group ?? new NullGroup(); $this->duty = $duty; diff --git a/Models/GroupRelationMapper.php b/Models/GroupRelationMapper.php index 4742370..283780c 100755 --- a/Models/GroupRelationMapper.php +++ b/Models/GroupRelationMapper.php @@ -51,8 +51,8 @@ final class GroupRelationMapper extends DataMapperFactory */ public const OWNS_ONE = [ 'relation' => [ - 'mapper' => GroupMapper::class, - 'external' => 'task_group_group', + 'mapper' => GroupMapper::class, + 'external' => 'task_group_group', ], ]; diff --git a/Models/NullTaskAttribute.php b/Models/NullTaskAttribute.php deleted file mode 100755 index e07009d..0000000 --- a/Models/NullTaskAttribute.php +++ /dev/null @@ -1,47 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/NullTaskAttributeType.php b/Models/NullTaskAttributeType.php deleted file mode 100755 index 81af091..0000000 --- a/Models/NullTaskAttributeType.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/NullTaskAttributeValue.php b/Models/NullTaskAttributeValue.php deleted file mode 100755 index 0e94bb4..0000000 --- a/Models/NullTaskAttributeValue.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/RelationAbstract.php b/Models/RelationAbstract.php index 0ee53ce..729cbe8 100755 --- a/Models/RelationAbstract.php +++ b/Models/RelationAbstract.php @@ -51,18 +51,6 @@ abstract class RelationAbstract implements \JsonSerializable */ public int $element = 0; - /** - * Get id. - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - /** * Set the duty (TO or CC) * diff --git a/Models/Task.php b/Models/Task.php index 73c62ca..4360877 100755 --- a/Models/Task.php +++ b/Models/Task.php @@ -17,10 +17,7 @@ namespace Modules\Tasks\Models; use Modules\Admin\Models\Account; use Modules\Admin\Models\NullAccount; use Modules\Calendar\Models\Schedule; -use Modules\Media\Models\Media; -use Modules\Tag\Models\NullTag; use Modules\Tag\Models\Tag; -use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; /** * Task class. @@ -124,14 +121,6 @@ class Task implements \JsonSerializable */ public int $completion = -1; - /** - * Attributes. - * - * @var TaskAttribute[] - * @since 1.0.0 - */ - public array $attributes = []; - /** * Task can be closed by user. * @@ -209,12 +198,15 @@ class Task implements \JsonSerializable public int $priority = TaskPriority::NONE; /** - * Media files + * Account this ticket is for * - * @var array + * This is not the person who is working on the ticket but the person who needs help. + * This can be different from the person who created it. + * + * @var null|Account * @since 1.0.0 */ - public array $media = []; + public ?Account $for = null; /** * Constructor. @@ -271,32 +263,6 @@ class Task implements \JsonSerializable return $key; } - /** - * Get all media - * - * @return Media[] - * - * @since 1.0.0 - */ - public function getMedia() : array - { - return $this->media; - } - - /** - * Add media - * - * @param Media $media Media to add - * - * @return void - * - * @since 1.0.0 - */ - public function addMedia(Media $media) : void - { - $this->media[] = $media; - } - /** * Check if user is in to * @@ -404,70 +370,6 @@ class Task implements \JsonSerializable $this->schedule->createdBy = $account; } - /** - * Get status - * - * @return int - * - * @since 1.0.0 - */ - public function getStatus() : int - { - return $this->status; - } - - /** - * Set status - * - * @param int $status Task status - * - * @return void - * - * @throws InvalidEnumValue - * - * @since 1.0.0 - */ - public function setStatus(int $status) : void - { - if (!TaskStatus::isValidValue($status)) { - throw new InvalidEnumValue((string) $status); - } - - $this->status = $status; - } - - /** - * Get priority - * - * @return int - * - * @since 1.0.0 - */ - public function getPriority() : int - { - return $this->priority; - } - - /** - * Set priority - * - * @param int $priority Task priority - * - * @return void - * - * @throws InvalidEnumValue - * - * @since 1.0.0 - */ - public function setPriority(int $priority) : void - { - if (!TaskPriority::isValidValue($priority)) { - throw new InvalidEnumValue((string) $priority); - } - - $this->priority = $priority; - } - /** * Remove Element from list. * @@ -488,52 +390,6 @@ class Task implements \JsonSerializable return false; } - /** - * Remove Tag from list. - * - * @param int $id Tag - * - * @return bool - * - * @since 1.0.0 - */ - public function removeTag($id) : bool - { - if (isset($this->tags[$id])) { - unset($this->tags[$id]); - - return true; - } - - return false; - } - - /** - * Get task elements. - * - * @return Tag[] - * - * @since 1.0.0 - */ - public function getTags() : array - { - return $this->tags; - } - - /** - * Get task elements. - * - * @param int $id Element id - * - * @return Tag - * - * @since 1.0.0 - */ - public function getTag(int $id) : Tag - { - return $this->tags[$id] ?? new NullTag(); - } - /** * Get task elements. * @@ -572,99 +428,6 @@ class Task implements \JsonSerializable return $this->taskElements[$id] ?? new NullTaskElement(); } - /** - * Get task type. - * - * @return int - * - * @since 1.0.0 - */ - public function getType() : int - { - return $this->type; - } - - /** - * Set task type. - * - * @param int $type Task type - * - * @return void - * - * @since 1.0.0 - */ - public function setType(int $type = TaskType::SINGLE) : void - { - $this->type = $type; - } - - /** - * Add attribute to item - * - * @param TaskAttribute $attribute Note - * - * @return void - * - * @since 1.0.0 - */ - public function addAttribute(TaskAttribute $attribute) : void - { - $this->attributes[] = $attribute; - } - - /** - * Get attributes - * - * @return TaskAttribute[] - * - * @since 1.0.0 - */ - public function getAttributes() : array - { - return $this->attributes; - } - - /** - * Has attribute value - * - * @param string $attrName Attribute name - * @param mixed $attrValue Attribute value - * - * @return bool - * - * @since 1.0.0 - */ - public function hasAttributeValue(string $attrName, mixed $attrValue) : bool - { - foreach ($this->attributes as $attribute) { - if ($attribute->type->name === $attrName && $attribute->value->getValue() === $attrValue) { - return true; - } - } - - return false; - } - - /** - * Get attribute - * - * @param string $attrName Attribute name - * - * @return null|TaskAttributeValue - * - * @since 1.0.0 - */ - public function getAttribute(string $attrName) : ?TaskAttributeValue - { - foreach ($this->attributes as $attribute) { - if ($attribute->type->name === $attrName) { - return $attribute->value; - } - } - - return null; - } - /** * {@inheritdoc} */ @@ -693,4 +456,7 @@ class Task implements \JsonSerializable { return $this->toArray(); } + + use \Modules\Media\Models\MediaListTrait; + use \Modules\Attribute\Models\AttributeHolderTrait; } diff --git a/Models/TaskAttribute.php b/Models/TaskAttribute.php deleted file mode 100755 index c16e7dc..0000000 --- a/Models/TaskAttribute.php +++ /dev/null @@ -1,90 +0,0 @@ -type = new NullTaskAttributeType(); - $this->value = new NullTaskAttributeValue(); - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'task' => $this->task, - 'type' => $this->type, - 'value' => $this->value, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/TaskAttributeType.php b/Models/TaskAttributeType.php deleted file mode 100755 index 25e3551..0000000 --- a/Models/TaskAttributeType.php +++ /dev/null @@ -1,193 +0,0 @@ -name = $name; - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getL11n() : string - { - if (!isset($this->l11n)) { - return ''; - } - - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * Set fields - * - * @param int $fields Fields - * - * @return void - * - * @since 1.0.0 - */ - public function setFields(int $fields) : void - { - $this->fields = $fields; - } - - /** - * Get default values - * - * @return array - * - * @sicne 1.0.0 - */ - public function getDefaults() : array - { - return $this->defaults; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'validationPattern' => $this->validationPattern, - 'custom' => $this->custom, - 'isRequired' => $this->isRequired, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/TaskAttributeValue.php b/Models/TaskAttributeValue.php deleted file mode 100755 index e83bdc3..0000000 --- a/Models/TaskAttributeValue.php +++ /dev/null @@ -1,217 +0,0 @@ -l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->ref = $this->id; - $this->l11n->setLanguage($lang); - } - } - - /** - * Get localization - * - * @return null|string - * - * @since 1.0.0 - */ - public function getL11n() : ?string - { - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * Set value - * - * @param null|int|string|float $value Value - * - * @return void - * - * @since 1.0.0 - */ - public function setValue(mixed $value, int $datatype) : void - { - if ($datatype === AttributeValueType::_STRING) { - $this->valueStr = (string) $value; - } elseif ($datatype === AttributeValueType::_INT - || $datatype === AttributeValueType::_FLOAT_INT - || $datatype === AttributeValueType::_BOOL - ) { - $this->valueInt = (int) $value; - } elseif ($datatype === AttributeValueType::_FLOAT) { - $this->valueDec = (float) $value; - } elseif ($datatype === AttributeValueType::_DATETIME) { - $this->valueDat = new \DateTime((string) $value); - } - } - - /** - * Get value - * - * @return null|int|string|float|\DateTimeInterface - * - * @since 1.0.0 - */ - public function getValue() : mixed - { - if (!empty($this->valueStr)) { - return $this->valueStr; - } elseif (!empty($this->valueInt)) { - return $this->valueInt; - } elseif (!empty($this->valueDec)) { - return $this->valueDec; - } elseif ($this->valueDat instanceof \DateTimeInterface) { - return $this->valueDat; - } - - return null; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'valueInt' => $this->valueInt, - 'valueStr' => $this->valueStr, - 'valueDec' => $this->valueDec, - 'valueDat' => $this->valueDat, - 'isDefault' => $this->isDefault, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/TaskAttributeValueMapper.php b/Models/TaskAttributeValueMapper.php deleted file mode 100755 index ab27430..0000000 --- a/Models/TaskAttributeValueMapper.php +++ /dev/null @@ -1,79 +0,0 @@ - - */ -final class TaskAttributeValueMapper extends DataMapperFactory -{ - /** - * Columns. - * - * @var array - * @since 1.0.0 - */ - public const COLUMNS = [ - 'task_attr_value_id' => ['name' => 'task_attr_value_id', 'type' => 'int', 'internal' => 'id'], - 'task_attr_value_default' => ['name' => 'task_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'], - 'task_attr_value_valueStr' => ['name' => 'task_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'], - 'task_attr_value_valueInt' => ['name' => 'task_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'], - 'task_attr_value_valueDec' => ['name' => 'task_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'], - 'task_attr_value_valueDat' => ['name' => 'task_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'], - 'task_attr_value_unit' => ['name' => 'task_attr_value_unit', 'type' => 'string', 'internal' => 'unit'], - ]; - - /** - * Has many relation. - * - * @var array - * @since 1.0.0 - */ - public const HAS_MANY = [ - 'l11n' => [ - 'mapper' => TaskAttributeValueL11nMapper::class, - 'table' => 'task_attr_value_l11n', - 'self' => 'task_attr_value_l11n_value', - 'column' => 'content', - 'external' => null, - ], - ]; - - /** - * Primary table. - * - * @var string - * @since 1.0.0 - */ - public const TABLE = 'task_attr_value'; - - /** - * Primary field name. - * - * @var string - * @since 1.0.0 - */ - public const PRIMARYFIELD = 'task_attr_value_id'; -} diff --git a/Models/TaskElement.php b/Models/TaskElement.php index 4a41c6b..c21fbc9 100755 --- a/Models/TaskElement.php +++ b/Models/TaskElement.php @@ -17,8 +17,6 @@ namespace Modules\Tasks\Models; use Modules\Admin\Models\Account; use Modules\Admin\Models\Group; use Modules\Admin\Models\NullAccount; -use Modules\Media\Models\Media; -use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; /** * Task element class. @@ -102,14 +100,6 @@ class TaskElement implements \JsonSerializable */ public int $priority = TaskPriority::NONE; - /** - * Media. - * - * @var Media[] - * @since 1.0.0 - */ - public array $media = []; - /** * Accounts who received this task element. * @@ -126,6 +116,8 @@ class TaskElement implements \JsonSerializable */ public array $grpRelation = []; + public int $duration = 0; + /** * Constructor. * @@ -139,64 +131,6 @@ class TaskElement implements \JsonSerializable $this->createdBy = new NullAccount(); } - /** - * Get all media - * - * @return Media[] - * - * @since 1.0.0 - */ - public function getMedia() : array - { - return $this->media; - } - - /** - * Add media - * - * @param Media $media Media to add - * - * @return void - * - * @since 1.0.0 - */ - public function addMedia(Media $media) : void - { - $this->media[] = $media; - } - - /** - * Get priority - * - * @return int - * - * @since 1.0.0 - */ - public function getPriority() : int - { - return $this->priority; - } - - /** - * Set priority - * - * @param int $priority Task priority - * - * @return void - * - * @throws InvalidEnumValue - * - * @since 1.0.0 - */ - public function setPriority(int $priority) : void - { - if (!TaskPriority::isValidValue($priority)) { - throw new InvalidEnumValue((string) $priority); - } - - $this->priority = $priority; - } - /** * Get to * @@ -469,38 +403,6 @@ class TaskElement implements \JsonSerializable $this->accRelation[] = new AccountRelation($account, DutyType::CC); } - /** - * Get status - * - * @return int - * - * @since 1.0.0 - */ - public function getStatus() : int - { - return $this->status; - } - - /** - * Set Status - * - * @param int $status Task element status - * - * @return void - * - * @throws InvalidEnumValue - * - * @since 1.0.0 - */ - public function setStatus(int $status) : void - { - if (!TaskStatus::isValidValue($status)) { - throw new InvalidEnumValue((string) $status); - } - - $this->status = $status; - } - /** * {@inheritdoc} */ @@ -527,4 +429,6 @@ class TaskElement implements \JsonSerializable { return $this->toArray(); } + + use \Modules\Media\Models\MediaListTrait; } diff --git a/Models/TaskElementMapper.php b/Models/TaskElementMapper.php index 76c3ead..69bfb07 100755 --- a/Models/TaskElementMapper.php +++ b/Models/TaskElementMapper.php @@ -56,23 +56,23 @@ final class TaskElementMapper extends DataMapperFactory * @since 1.0.0 */ public const HAS_MANY = [ - 'media' => [ + 'files' => [ 'mapper' => MediaMapper::class, 'table' => 'task_element_media', 'external' => 'task_element_media_dst', 'self' => 'task_element_media_src', ], - 'accRelation' => [ - 'mapper' => AccountRelationMapper::class, - 'table' => 'task_account', - 'self' => 'task_account_task_element', - 'external' => null, + 'accRelation' => [ + 'mapper' => AccountRelationMapper::class, + 'table' => 'task_account', + 'self' => 'task_account_task_element', + 'external' => null, ], - 'grpRelation' => [ - 'mapper' => GroupRelationMapper::class, - 'table' => 'task_group', - 'self' => 'task_group_task_element', - 'external' => null, + 'grpRelation' => [ + 'mapper' => GroupRelationMapper::class, + 'table' => 'task_group', + 'self' => 'task_group_task_element', + 'external' => null, ], ]; @@ -84,8 +84,8 @@ final class TaskElementMapper extends DataMapperFactory */ public const BELONGS_TO = [ 'createdBy' => [ - 'mapper' => AccountMapper::class, - 'external' => 'task_element_created_by', + 'mapper' => AccountMapper::class, + 'external' => 'task_element_created_by', ], ]; diff --git a/Models/TaskMapper.php b/Models/TaskMapper.php index 5153642..d2cdc3c 100755 --- a/Models/TaskMapper.php +++ b/Models/TaskMapper.php @@ -18,6 +18,7 @@ use Modules\Admin\Models\AccountMapper; use Modules\Calendar\Models\ScheduleMapper; use Modules\Media\Models\MediaMapper; use Modules\Tag\Models\TagMapper; +use Modules\Tasks\Models\Attribute\TaskAttributeMapper; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; use phpOMS\DataStorage\Database\Mapper\ReadMapper; use phpOMS\DataStorage\Database\Query\Builder; @@ -43,24 +44,25 @@ final class TaskMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'task_id' => ['name' => 'task_id', 'type' => 'int', 'internal' => 'id'], - 'task_title' => ['name' => 'task_title', 'type' => 'string', 'internal' => 'title'], - 'task_desc' => ['name' => 'task_desc', 'type' => 'string', 'internal' => 'description'], - 'task_desc_raw' => ['name' => 'task_desc_raw', 'type' => 'string', 'internal' => 'descriptionRaw'], - 'task_type' => ['name' => 'task_type', 'type' => 'int', 'internal' => 'type'], - 'task_status' => ['name' => 'task_status', 'type' => 'int', 'internal' => 'status'], - 'task_completion' => ['name' => 'task_completion', 'type' => 'int', 'internal' => 'completion'], - 'task_closable' => ['name' => 'task_closable', 'type' => 'bool', 'internal' => 'isClosable'], - 'task_editable' => ['name' => 'task_editable', 'type' => 'bool', 'internal' => 'isEditable'], - 'task_priority' => ['name' => 'task_priority', 'type' => 'int', 'internal' => 'priority'], - 'task_due' => ['name' => 'task_due', 'type' => 'DateTime', 'internal' => 'due'], - 'task_done' => ['name' => 'task_done', 'type' => 'DateTime', 'internal' => 'done'], - 'task_schedule' => ['name' => 'task_schedule', 'type' => 'int', 'internal' => 'schedule'], - 'task_start' => ['name' => 'task_start', 'type' => 'DateTime', 'internal' => 'start'], - 'task_redirect' => ['name' => 'task_redirect', 'type' => 'string', 'internal' => 'redirect'], - 'task_trigger' => ['name' => 'task_trigger', 'type' => 'string', 'internal' => 'trigger'], - 'task_created_by' => ['name' => 'task_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], - 'task_created_at' => ['name' => 'task_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], + 'task_id' => ['name' => 'task_id', 'type' => 'int', 'internal' => 'id'], + 'task_title' => ['name' => 'task_title', 'type' => 'string', 'internal' => 'title'], + 'task_desc' => ['name' => 'task_desc', 'type' => 'string', 'internal' => 'description'], + 'task_desc_raw' => ['name' => 'task_desc_raw', 'type' => 'string', 'internal' => 'descriptionRaw'], + 'task_type' => ['name' => 'task_type', 'type' => 'int', 'internal' => 'type'], + 'task_status' => ['name' => 'task_status', 'type' => 'int', 'internal' => 'status'], + 'task_completion' => ['name' => 'task_completion', 'type' => 'int', 'internal' => 'completion'], + 'task_closable' => ['name' => 'task_closable', 'type' => 'bool', 'internal' => 'isClosable'], + 'task_editable' => ['name' => 'task_editable', 'type' => 'bool', 'internal' => 'isEditable'], + 'task_priority' => ['name' => 'task_priority', 'type' => 'int', 'internal' => 'priority'], + 'task_due' => ['name' => 'task_due', 'type' => 'DateTime', 'internal' => 'due'], + 'task_done' => ['name' => 'task_done', 'type' => 'DateTime', 'internal' => 'done'], + 'task_schedule' => ['name' => 'task_schedule', 'type' => 'int', 'internal' => 'schedule'], + 'task_start' => ['name' => 'task_start', 'type' => 'DateTime', 'internal' => 'start'], + 'task_redirect' => ['name' => 'task_redirect', 'type' => 'string', 'internal' => 'redirect'], + 'task_trigger' => ['name' => 'task_trigger', 'type' => 'string', 'internal' => 'trigger'], + 'task_created_by' => ['name' => 'task_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], + 'task_for' => ['name' => 'task_for', 'type' => 'int', 'internal' => 'for'], + 'task_created_at' => ['name' => 'task_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true], ]; /** @@ -71,18 +73,18 @@ final class TaskMapper extends DataMapperFactory */ public const HAS_MANY = [ 'taskElements' => [ - 'mapper' => TaskElementMapper::class, - 'table' => 'task_element', - 'self' => 'task_element_task', - 'external' => null, + 'mapper' => TaskElementMapper::class, + 'table' => 'task_element', + 'self' => 'task_element_task', + 'external' => null, ], - 'media' => [ + 'files' => [ 'mapper' => MediaMapper::class, 'table' => 'task_media', 'external' => 'task_media_dst', 'self' => 'task_media_src', ], - 'tags' => [ + 'tags' => [ 'mapper' => TagMapper::class, 'table' => 'task_tag', 'external' => 'task_tag_dst', @@ -104,8 +106,8 @@ final class TaskMapper extends DataMapperFactory */ public const BELONGS_TO = [ 'createdBy' => [ - 'mapper' => AccountMapper::class, - 'external' => 'task_created_by', + 'mapper' => AccountMapper::class, + 'external' => 'task_created_by', ], ]; @@ -117,8 +119,12 @@ final class TaskMapper extends DataMapperFactory */ public const OWNS_ONE = [ 'schedule' => [ - 'mapper' => ScheduleMapper::class, - 'external' => 'task_schedule', + 'mapper' => ScheduleMapper::class, + 'external' => 'task_schedule', + ], + 'for' => [ + 'mapper' => AccountMapper::class, + 'external' => 'task_for', ], ]; diff --git a/Models/TaskSeenMapper.php b/Models/TaskSeenMapper.php index 3b39c19..c38c2ca 100755 --- a/Models/TaskSeenMapper.php +++ b/Models/TaskSeenMapper.php @@ -40,13 +40,13 @@ final class TaskSeenMapper extends DataMapperFactory * @since 1.0.0 */ public const COLUMNS = [ - 'task_seen_id' => ['name' => 'task_seen_id', 'type' => 'int', 'internal' => 'id'], - 'task_seen_at' => ['name' => 'task_seen_at', 'type' => 'DateTime', 'internal' => 'seenAt'], - 'task_seen_task' => ['name' => 'task_seen_task', 'type' => 'int', 'internal' => 'task'], - 'task_seen_by' => ['name' => 'task_seen_by', 'type' => 'int', 'internal' => 'seenBy'], - 'task_seen_reminder' => ['name' => 'task_seen_reminder', 'type' => 'bool', 'internal' => 'isRemindered'], - 'task_seen_reminder_at' => ['name' => 'task_seen_reminder_at', 'type' => 'DateTime', 'internal' => 'reminderAt'], - 'task_seen_reminder_by' => ['name' => 'task_seen_reminder_by', 'type' => 'int', 'internal' => 'reminderBy'], + 'task_seen_id' => ['name' => 'task_seen_id', 'type' => 'int', 'internal' => 'id'], + 'task_seen_at' => ['name' => 'task_seen_at', 'type' => 'DateTime', 'internal' => 'seenAt'], + 'task_seen_task' => ['name' => 'task_seen_task', 'type' => 'int', 'internal' => 'task'], + 'task_seen_by' => ['name' => 'task_seen_by', 'type' => 'int', 'internal' => 'seenBy'], + 'task_seen_reminder' => ['name' => 'task_seen_reminder', 'type' => 'bool', 'internal' => 'isRemindered'], + 'task_seen_reminder_at' => ['name' => 'task_seen_reminder_at', 'type' => 'DateTime', 'internal' => 'reminderAt'], + 'task_seen_reminder_by' => ['name' => 'task_seen_reminder_by', 'type' => 'int', 'internal' => 'reminderBy'], ]; /** @@ -57,8 +57,8 @@ final class TaskSeenMapper extends DataMapperFactory */ public const BELONGS_TO = [ 'reminderBy' => [ - 'mapper' => AccountMapper::class, - 'external' => 'task_seen_reminder_by', + 'mapper' => AccountMapper::class, + 'external' => 'task_seen_reminder_by', ], ]; diff --git a/Theme/Backend/Components/Tasks/list.tpl.php b/Theme/Backend/Components/Tasks/list.tpl.php index 338c309..da41d43 100755 --- a/Theme/Backend/Components/Tasks/list.tpl.php +++ b/Theme/Backend/Components/Tasks/list.tpl.php @@ -31,21 +31,21 @@ use phpOMS\Uri\UriFactory; tasks as $key => $task) : ++$c; - $url = UriFactory::build(empty($task->redirect) ? 'task/single?{?}&id=' . $task->id : ($task->redirect)); + $url = UriFactory::build(empty($task->redirect) ? 'task/view?{?}&id=' . $task->id : ($task->redirect)); - $color = 'darkred'; - if ($task->getStatus() === TaskStatus::DONE) { $color = 'green'; } - elseif ($task->getStatus() === TaskStatus::OPEN) { $color = 'darkblue'; } - elseif ($task->getStatus() === TaskStatus::WORKING) { $color = 'purple'; } - elseif ($task->getStatus() === TaskStatus::CANCELED) { $color = 'red'; } - elseif ($task->getStatus() === TaskStatus::SUSPENDED) { $color = 'yellow'; } ?> + $color = 'darkred'; + if ($task->status === TaskStatus::DONE) { $color = 'green'; } + elseif ($task->status === TaskStatus::OPEN) { $color = 'darkblue'; } + elseif ($task->status === TaskStatus::WORKING) { $color = 'purple'; } + elseif ($task->status === TaskStatus::CANCELED) { $color = 'red'; } + elseif ($task->status === TaskStatus::SUSPENDED) { $color = 'yellow'; } ?> - getHtml('S' . $task->getStatus(), 'Tasks'); ?> + getHtml('S' . $task->status, 'Tasks'); ?> - getPriority() === TaskPriority::NONE) : ?> + priority === TaskPriority::NONE) : ?> printHtml($task->due->format('Y-m-d H:i')); ?> - getHtml('P' . $task->getPriority()); ?> + getHtml('P' . $task->priority); ?> printHtml($task->title); ?> @@ -56,4 +56,4 @@ use phpOMS\Uri\UriFactory;
- \ No newline at end of file + diff --git a/Theme/Backend/Components/Tasks/status.tpl.php b/Theme/Backend/Components/Tasks/status.tpl.php index a070222..a0697b1 100755 --- a/Theme/Backend/Components/Tasks/status.tpl.php +++ b/Theme/Backend/Components/Tasks/status.tpl.php @@ -1,3 +1,8 @@ +
@@ -7,7 +12,7 @@ data-src="api/admin/find/accgrp?search={!#iid; ?>}">
-