From 52a59e002f44f184ca87a6c364de23afebc7d825 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Sat, 15 Apr 2023 17:01:55 +0200 Subject: [PATCH] first commit --- README.md | 435 ++++++++++++++++++ .../README.md | 54 +++ .../code.php | 83 ++++ .../code.power | 51 ++ .../settings.json | 37 ++ .../README.md | 85 ++++ .../code.php | 137 ++++++ .../code.power | 106 +++++ .../settings.json | 33 ++ .../README.md | 163 +++++++ .../code.php | 425 +++++++++++++++++ .../code.power | 389 ++++++++++++++++ .../settings.json | 55 +++ .../README.md | 59 +++ .../code.php | 56 +++ .../code.power | 32 ++ .../settings.json | 18 + .../README.md | 45 ++ .../code.php | 43 ++ .../code.power | 19 + .../settings.json | 18 + .../README.md | 76 +++ .../code.php | 180 ++++++++ .../code.power | 148 ++++++ .../settings.json | 41 ++ .../README.md | 61 +++ .../code.php | 60 +++ .../code.power | 36 ++ .../settings.json | 18 + .../README.md | 108 +++++ .../code.php | 305 ++++++++++++ .../code.power | 272 +++++++++++ .../settings.json | 41 ++ .../README.md | 76 +++ .../code.php | 236 ++++++++++ .../code.power | 206 +++++++++ .../settings.json | 35 ++ .../README.md | 62 +++ .../code.php | 60 +++ .../code.power | 37 ++ .../settings.json | 18 + .../README.md | 66 +++ .../code.php | 66 +++ .../code.power | 42 ++ .../settings.json | 18 + .../README.md | 79 ++++ .../code.php | 188 ++++++++ .../code.power | 155 +++++++ .../settings.json | 41 ++ .../README.md | 141 ++++++ .../code.php | 180 ++++++++ .../code.power | 153 ++++++ .../settings.json | 18 + .../README.md | 53 +++ .../code.php | 77 ++++ .../code.power | 47 ++ .../settings.json | 30 ++ .../README.md | 61 +++ .../code.php | 128 ++++++ .../code.power | 97 ++++ .../settings.json | 33 ++ .../README.md | 50 ++ .../code.php | 123 +++++ .../code.power | 96 ++++ .../settings.json | 27 ++ .../README.md | 76 +++ .../code.php | 181 ++++++++ .../code.power | 149 ++++++ .../settings.json | 41 ++ .../README.md | 66 +++ .../code.php | 66 +++ .../code.power | 42 ++ .../settings.json | 18 + .../README.md | 77 ++++ .../code.php | 143 ++++++ .../code.power | 110 +++++ .../settings.json | 42 ++ .../README.md | 61 +++ .../code.php | 98 ++++ .../code.power | 67 +++ .../settings.json | 34 ++ .../README.md | 78 ++++ .../code.php | 149 ++++++ .../code.power | 116 +++++ .../settings.json | 42 ++ .../README.md | 93 ++++ .../code.php | 271 +++++++++++ .../code.power | 240 ++++++++++ .../settings.json | 33 ++ .../README.md | 105 +++++ .../code.php | 302 ++++++++++++ .../code.power | 271 +++++++++++ .../settings.json | 41 ++ .../README.md | 85 ++++ .../code.php | 142 ++++++ .../code.power | 109 +++++ .../settings.json | 41 ++ super-powers.json | 242 ++++++++++ 98 files changed, 10019 insertions(+) create mode 100644 README.md create mode 100644 src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/README.md create mode 100644 src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/code.php create mode 100644 src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/code.power create mode 100644 src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/settings.json create mode 100644 src/02efe40a-7792-4c82-9444-7d0377243483/README.md create mode 100644 src/02efe40a-7792-4c82-9444-7d0377243483/code.php create mode 100644 src/02efe40a-7792-4c82-9444-7d0377243483/code.power create mode 100644 src/02efe40a-7792-4c82-9444-7d0377243483/settings.json create mode 100644 src/0b658434-3767-401e-addc-eabfd1d0e94a/README.md create mode 100644 src/0b658434-3767-401e-addc-eabfd1d0e94a/code.php create mode 100644 src/0b658434-3767-401e-addc-eabfd1d0e94a/code.power create mode 100644 src/0b658434-3767-401e-addc-eabfd1d0e94a/settings.json create mode 100644 src/0d9442ab-54d9-4947-a219-244cfaea3084/README.md create mode 100644 src/0d9442ab-54d9-4947-a219-244cfaea3084/code.php create mode 100644 src/0d9442ab-54d9-4947-a219-244cfaea3084/code.power create mode 100644 src/0d9442ab-54d9-4947-a219-244cfaea3084/settings.json create mode 100644 src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/README.md create mode 100644 src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/code.php create mode 100644 src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/code.power create mode 100644 src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/settings.json create mode 100644 src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/README.md create mode 100644 src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/code.php create mode 100644 src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/code.power create mode 100644 src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/settings.json create mode 100644 src/2bd1a32c-3d90-4646-9314-28d44d164f76/README.md create mode 100644 src/2bd1a32c-3d90-4646-9314-28d44d164f76/code.php create mode 100644 src/2bd1a32c-3d90-4646-9314-28d44d164f76/code.power create mode 100644 src/2bd1a32c-3d90-4646-9314-28d44d164f76/settings.json create mode 100644 src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/README.md create mode 100644 src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/code.php create mode 100644 src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/code.power create mode 100644 src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/settings.json create mode 100644 src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/README.md create mode 100644 src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/code.php create mode 100644 src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/code.power create mode 100644 src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/settings.json create mode 100644 src/4c44e5d3-750c-4609-88c8-aa441838b8fe/README.md create mode 100644 src/4c44e5d3-750c-4609-88c8-aa441838b8fe/code.php create mode 100644 src/4c44e5d3-750c-4609-88c8-aa441838b8fe/code.power create mode 100644 src/4c44e5d3-750c-4609-88c8-aa441838b8fe/settings.json create mode 100644 src/55280ec7-e48d-431b-af25-10308dd30636/README.md create mode 100644 src/55280ec7-e48d-431b-af25-10308dd30636/code.php create mode 100644 src/55280ec7-e48d-431b-af25-10308dd30636/code.power create mode 100644 src/55280ec7-e48d-431b-af25-10308dd30636/settings.json create mode 100644 src/6caf9473-133c-49a9-afa0-9f84151b5155/README.md create mode 100644 src/6caf9473-133c-49a9-afa0-9f84151b5155/code.php create mode 100644 src/6caf9473-133c-49a9-afa0-9f84151b5155/code.power create mode 100644 src/6caf9473-133c-49a9-afa0-9f84151b5155/settings.json create mode 100644 src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/README.md create mode 100644 src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/code.php create mode 100644 src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/code.power create mode 100644 src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/settings.json create mode 100644 src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/README.md create mode 100644 src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/code.php create mode 100644 src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/code.power create mode 100644 src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/settings.json create mode 100644 src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/README.md create mode 100644 src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/code.php create mode 100644 src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/code.power create mode 100644 src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/settings.json create mode 100644 src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/README.md create mode 100644 src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/code.php create mode 100644 src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/code.power create mode 100644 src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/settings.json create mode 100644 src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/README.md create mode 100644 src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/code.php create mode 100644 src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/code.power create mode 100644 src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/settings.json create mode 100644 src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/README.md create mode 100644 src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/code.php create mode 100644 src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/code.power create mode 100644 src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/settings.json create mode 100644 src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/README.md create mode 100644 src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/code.php create mode 100644 src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/code.power create mode 100644 src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/settings.json create mode 100644 src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/README.md create mode 100644 src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/code.php create mode 100644 src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/code.power create mode 100644 src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/settings.json create mode 100644 src/da714ea5-96bb-4eb1-959b-39b457be9cd1/README.md create mode 100644 src/da714ea5-96bb-4eb1-959b-39b457be9cd1/code.php create mode 100644 src/da714ea5-96bb-4eb1-959b-39b457be9cd1/code.power create mode 100644 src/da714ea5-96bb-4eb1-959b-39b457be9cd1/settings.json create mode 100644 src/db093eca-63b3-4d6c-9232-3ceb058121c0/README.md create mode 100644 src/db093eca-63b3-4d6c-9232-3ceb058121c0/code.php create mode 100644 src/db093eca-63b3-4d6c-9232-3ceb058121c0/code.power create mode 100644 src/db093eca-63b3-4d6c-9232-3ceb058121c0/settings.json create mode 100644 src/e544a248-4b6a-46cb-9926-a3ac9937807c/README.md create mode 100644 src/e544a248-4b6a-46cb-9926-a3ac9937807c/code.php create mode 100644 src/e544a248-4b6a-46cb-9926-a3ac9937807c/code.power create mode 100644 src/e544a248-4b6a-46cb-9926-a3ac9937807c/settings.json create mode 100644 src/f523ab49-907a-4356-b064-51c85a187fbd/README.md create mode 100644 src/f523ab49-907a-4356-b064-51c85a187fbd/code.php create mode 100644 src/f523ab49-907a-4356-b064-51c85a187fbd/code.power create mode 100644 src/f523ab49-907a-4356-b064-51c85a187fbd/settings.json create mode 100644 super-powers.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..88fe04a --- /dev/null +++ b/README.md @@ -0,0 +1,435 @@ +``` +███████╗██╗ ██╗██████╗ ███████╗██████╗ +██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗ +███████╗██║ ██║██████╔╝█████╗ ██████╔╝ +╚════██║██║ ██║██╔═══╝ ██╔══╝ ██╔══██╗ +███████║╚██████╔╝██║ ███████╗██║ ██║ +╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ ███████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗██╔════╝ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝███████╗ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗╚════██║ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║███████║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝╚══════╝ +``` + +### What is JCB Super Powers? +The Joomla Component Builder (JCB) Super Power features are designed to enhance JCB's functionality and streamline the development process. These Super Powers enable developers to efficiently manage and share their custom powers across multiple JCB instances through repositories hosted on [https://git.vdm.dev/[username]/[repository-name]](https://git.vdm.dev). JCB Super Powers are managed using a combination of layers, events, tasks, methods, switches, and algorithms, which work together to provide powerful customization and extensibility options. More details on JCB Super Powers can be found in the [Super Powers Documentation](https://git.vdm.dev/joomla/super-powers/wiki). + +In summary, JCB Super Powers offer a flexible and efficient way to manage and share functionalities between JCB instances. By utilizing a sophisticated system of layers, events, tasks, methods, switches, and algorithms, developers can seamlessly integrate JCB core powers and their custom powers. For more information on how to work with JCB Super Powers, refer to the [Super Powers User Guide](https://git.vdm.dev/joomla/super-powers/wiki). + +### What can I find here? +This repository contains an index (see below) of all the approved powers within the JCB GUI. During the compilation of a component, these powers are automatically added to the repository, ensuring a well-organized and accessible collection of functionalities. + +# Index of powers + +- **Namespace**: [VDM\Joomla\Componentbuilder\Search](#vdm-joomla-componentbuilder-search) + + - **abstract class Factory** | [Details](src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a) | [Code](src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/code.php) | [Settings](src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/settings.json) | [01a89ba8-f8bb-435c-93de-0a8f3fa9432a](src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a) + - **class Agent** | [Details](src/0b658434-3767-401e-addc-eabfd1d0e94a) | [Code](src/0b658434-3767-401e-addc-eabfd1d0e94a/code.php) | [Settings](src/0b658434-3767-401e-addc-eabfd1d0e94a/settings.json) | [0b658434-3767-401e-addc-eabfd1d0e94a](src/0b658434-3767-401e-addc-eabfd1d0e94a) + - **class Config** | [Details](src/6e2ca779-f70e-4871-a138-0ee5eaec6a97) | [Code](src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/code.php) | [Settings](src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/settings.json) | [6e2ca779-f70e-4871-a138-0ee5eaec6a97](src/6e2ca779-f70e-4871-a138-0ee5eaec6a97) +- **Namespace**: [VDM\Joomla\Componentbuilder\Search\Abstraction](#vdm-joomla-componentbuilder-search-abstraction) + + - **abstract class Engine** | [Details](src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf) | [Code](src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/code.php) | [Settings](src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/settings.json) | [8f9449fc-bfbc-49a5-b146-d58c8c17dfdf](src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf) +- **Namespace**: [VDM\Joomla\Componentbuilder\Search\Agent](#vdm-joomla-componentbuilder-search-agent) + + - **class Find** | [Details](src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c) | [Code](src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/code.php) | [Settings](src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/settings.json) | [15d9e1a9-3364-4d69-9d9f-9b87db820e5c](src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c) + - **class Replace** | [Details](src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7) | [Code](src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/code.php) | [Settings](src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/settings.json) | [abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7](src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7) + - **class Search** | [Details](src/e544a248-4b6a-46cb-9926-a3ac9937807c) | [Code](src/e544a248-4b6a-46cb-9926-a3ac9937807c/code.php) | [Settings](src/e544a248-4b6a-46cb-9926-a3ac9937807c/settings.json) | [e544a248-4b6a-46cb-9926-a3ac9937807c](src/e544a248-4b6a-46cb-9926-a3ac9937807c) + - **class Update** | [Details](src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7) | [Code](src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/code.php) | [Settings](src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/settings.json) | [3ac29912-0681-4ca9-8197-d5a8f6a49ac7](src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7) +- **Namespace**: [VDM\Joomla\Componentbuilder\Search\Database](#vdm-joomla-componentbuilder-search-database) + + - **class Insert** | [Details](src/6caf9473-133c-49a9-afa0-9f84151b5155) | [Code](src/6caf9473-133c-49a9-afa0-9f84151b5155/code.php) | [Settings](src/6caf9473-133c-49a9-afa0-9f84151b5155/settings.json) | [6caf9473-133c-49a9-afa0-9f84151b5155](src/6caf9473-133c-49a9-afa0-9f84151b5155) + - **class Load** | [Details](src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710) | [Code](src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/code.php) | [Settings](src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/settings.json) | [2dabfb4a-64cd-4c04-9772-4a75f9f3b710](src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710) +- **Namespace**: [VDM\Joomla\Componentbuilder\Search\Engine](#vdm-joomla-componentbuilder-search-engine) + + - **class Basic** | [Details](src/db093eca-63b3-4d6c-9232-3ceb058121c0) | [Code](src/db093eca-63b3-4d6c-9232-3ceb058121c0/code.php) | [Settings](src/db093eca-63b3-4d6c-9232-3ceb058121c0/settings.json) | [db093eca-63b3-4d6c-9232-3ceb058121c0](src/db093eca-63b3-4d6c-9232-3ceb058121c0) + - **class Regex** | [Details](src/83efa9a0-4aec-41f8-9c05-b1ac9617746e) | [Code](src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/code.php) | [Settings](src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/settings.json) | [83efa9a0-4aec-41f8-9c05-b1ac9617746e](src/83efa9a0-4aec-41f8-9c05-b1ac9617746e) +- **Namespace**: [VDM\Joomla\Componentbuilder\Search\Interfaces](#vdm-joomla-componentbuilder-search-interfaces) + + - **interface FindInterface** | [Details](src/55280ec7-e48d-431b-af25-10308dd30636) | [Code](src/55280ec7-e48d-431b-af25-10308dd30636/code.php) | [Settings](src/55280ec7-e48d-431b-af25-10308dd30636/settings.json) | [55280ec7-e48d-431b-af25-10308dd30636](src/55280ec7-e48d-431b-af25-10308dd30636) + - **interface InsertInterface** | [Details](src/4c44e5d3-750c-4609-88c8-aa441838b8fe) | [Code](src/4c44e5d3-750c-4609-88c8-aa441838b8fe/code.php) | [Settings](src/4c44e5d3-750c-4609-88c8-aa441838b8fe/settings.json) | [4c44e5d3-750c-4609-88c8-aa441838b8fe](src/4c44e5d3-750c-4609-88c8-aa441838b8fe) + - **interface LoadInterface** | [Details](src/2bd1a32c-3d90-4646-9314-28d44d164f76) | [Code](src/2bd1a32c-3d90-4646-9314-28d44d164f76/code.php) | [Settings](src/2bd1a32c-3d90-4646-9314-28d44d164f76/settings.json) | [2bd1a32c-3d90-4646-9314-28d44d164f76](src/2bd1a32c-3d90-4646-9314-28d44d164f76) + - **interface ReplaceInterface** | [Details](src/afdae35d-fe7f-4055-99ea-afd8ff8349b6) | [Code](src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/code.php) | [Settings](src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/settings.json) | [afdae35d-fe7f-4055-99ea-afd8ff8349b6](src/afdae35d-fe7f-4055-99ea-afd8ff8349b6) + - **interface SearchInterface** | [Details](src/0d9442ab-54d9-4947-a219-244cfaea3084) | [Code](src/0d9442ab-54d9-4947-a219-244cfaea3084/code.php) | [Settings](src/0d9442ab-54d9-4947-a219-244cfaea3084/settings.json) | [0d9442ab-54d9-4947-a219-244cfaea3084](src/0d9442ab-54d9-4947-a219-244cfaea3084) + - **interface SearchTypeInterface** | [Details](src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a) | [Code](src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/code.php) | [Settings](src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/settings.json) | [117d8c9e-3f8d-40ae-b375-1efa2fe5538a](src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a) +- **Namespace**: [VDM\Joomla\Componentbuilder\Search\Model](#vdm-joomla-componentbuilder-search-model) + + - **class Insert** | [Details](src/02efe40a-7792-4c82-9444-7d0377243483) | [Code](src/02efe40a-7792-4c82-9444-7d0377243483/code.php) | [Settings](src/02efe40a-7792-4c82-9444-7d0377243483/settings.json) | [02efe40a-7792-4c82-9444-7d0377243483](src/02efe40a-7792-4c82-9444-7d0377243483) + - **class Load** | [Details](src/f523ab49-907a-4356-b064-51c85a187fbd) | [Code](src/f523ab49-907a-4356-b064-51c85a187fbd/code.php) | [Settings](src/f523ab49-907a-4356-b064-51c85a187fbd/settings.json) | [f523ab49-907a-4356-b064-51c85a187fbd](src/f523ab49-907a-4356-b064-51c85a187fbd) +- **Namespace**: [VDM\Joomla\Componentbuilder\Search\Service](#vdm-joomla-componentbuilder-search-service) + + - **class Agent** | [Details](src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7) | [Code](src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/code.php) | [Settings](src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/settings.json) | [cc6972a7-1574-4ae0-92a8-7f1012aac6f7](src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7) + - **class Database** | [Details](src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3) | [Code](src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/code.php) | [Settings](src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/settings.json) | [d5de47ce-9a9e-4e76-a5c6-61ed74842ea3](src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3) + - **class Model** | [Details](src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a) | [Code](src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/code.php) | [Settings](src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/settings.json) | [7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a](src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a) + - **class Search** | [Details](src/da714ea5-96bb-4eb1-959b-39b457be9cd1) | [Code](src/da714ea5-96bb-4eb1-959b-39b457be9cd1/code.php) | [Settings](src/da714ea5-96bb-4eb1-959b-39b457be9cd1/settings.json) | [da714ea5-96bb-4eb1-959b-39b457be9cd1](src/da714ea5-96bb-4eb1-959b-39b457be9cd1) + +# Class Diagrams + +## VDM Joomla Componentbuilder Search +> namespace VDM\Joomla\Componentbuilder\Search +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Search #Olive { + + + abstract Factory #Orange { + # static $container + + {static} _() : Mixed + + {static} getContainer() : Container + # {static} createContainer() : Container + } + + class Agent #Gold { + # Config $config + # Load $load + # Insert $insert + # Find $find + # Replace $replace + # Search $search + # Update $update + # Table $table + # string $return + # array $marker + # array $markerHtml + + __construct() + + getValue() : ?string + + setValue() : bool + + table() : ?array + + find() : ?array + + replace() : int + # getRow() : array + # getRowCode() : string + # getRowEditButton() : string + # setReturnValue() : void + # setMarkers() : void + } + + class Config #Gold { + # getTypesearch() : ?int + # getSearchvalue() : ?string + # getReplacevalue() : string + # getMatchcase() : int + # getWholeword() : int + # getRegexsearch() : int + # getComponentid() : int + # getTablename() : ?string + # getFieldname() : ?string + # getItemid() : int + # getFieldcounter() : int + # getLinecounter() : int + # getMarkerstart() : string + # getMarkerend() : string + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Search Abstraction +> namespace VDM\Joomla\Componentbuilder\Search\Abstraction +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Search\Abstraction #LightGreen { + + + abstract Engine #Orange { + # Config $config + # ?string $searchValue + # string $replaceValue + # int $matchCase + # int $wholeWord + # string $start + # string $end + + __construct() + # lineCounter() + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Search Agent +> namespace VDM\Joomla\Componentbuilder\Search\Agent +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Search\Agent #LightGreen { + + + class Find #Gold { + # array $found + # Config $config + # Search $search + + __construct() + + get() : ?array + + item() : void + + items() : void + + reset() : void + } + + class Replace #Gold { + # array $updated + # Config $config + # Update $update + + __construct() + + get() : ?array + + item() : void + + items() : void + + reset() : void + } + + class Search #Gold { + # array $found + # Config $config + # SearchEngine $search + + __construct() + + get() : ?array + + value() : bool + + reset() : void + # searchValue() : ?array + # string() : ?array + # prep() : void + # fieldCounter() + } + + class Update #Gold { + # SearchEngine $search + + __construct() + + value() : mixed + # updateValue() : mixed + # validateUpdateKey() : bool + # string() : string + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Search Database +> namespace VDM\Joomla\Componentbuilder\Search\Database +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Search\Database #LightGreen { + + + class Insert #Gold { + # Config $config + # Table $table + # Model $model + # \JDatabaseDriver $db + + __construct() + + value() : bool + + item() : bool + + items() : bool + } + + class Load #Gold { + # int $bundle + # Config $config + # Table $table + # Model $model + # Database $load + + __construct() + + value() : mixed + + item() : ?object + + items() : ?array + # next() : int + # incremental() : int + # setDatabaseFields() : ?array + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Search Engine +> namespace VDM\Joomla\Componentbuilder\Search\Engine +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Search\Engine #LightGreen { + + + class Basic #Gold { + # string $regexValue + + __construct() + + string() : ?string + + replace() : string + # replaceWhole() : string + # searchWhole() : ?string + + match() : bool + # searchAll() : ?string + # replaceAll() : string + } + + class Regex #Gold { + # string $regexValue + + __construct() + + string() : ?string + + replace() : string + + match() : bool + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Search Interfaces +> namespace VDM\Joomla\Componentbuilder\Search\Interfaces +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Search\Interfaces #LightGreen { + + + interface FindInterface #Lavender { + + get() : ?array + + item() : void + + items() : void + + reset() : void + } + + interface InsertInterface #Lavender { + + value() : bool + + item() : bool + + items() : bool + } + + interface LoadInterface #Lavender { + + value() : mixed + + item() : ?object + + items() : ?array + } + + interface ReplaceInterface #Lavender { + + get() : ?array + + item() : void + + items() : void + + reset() : void + } + + interface SearchInterface #Lavender { + + get() : ?array + + value() : bool + + reset() : void + } + + interface SearchTypeInterface #Lavender { + + string() : ?string + + replace() : string + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Search Model +> namespace VDM\Joomla\Componentbuilder\Search\Model +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Search\Model #LightGreen { + + + class Insert #Gold { + # Config $config + + __construct() + + value() : mixed + # validateBefore() : bool + # validateAfter() : bool + # getTable() : string + } + + class Load #Gold { + # Config $config + + __construct() + + value() : mixed + # validateBefore() : bool + # validateAfter() : bool + # getTable() : string + } +} + + +@enduml +``` + +## VDM Joomla Componentbuilder Search Service +> namespace VDM\Joomla\Componentbuilder\Search\Service +```uml +@startuml + +namespace VDM\Joomla\Componentbuilder\Search\Service #LightGreen { + + + class Agent #Gold { + + register() : void + + getAgent() : SearchAgent + + getFind() : Find + + getReplace() : Replace + + getSearch() : Search + + getUpdate() : Update + } + + class Database #Gold { + + register() : void + + getLoad() : Load + + getDatabaseLoad() : LoadDatabase + + getDatabaseInsert() : InsertDatabase + } + + class Model #Gold { + + register() : void + + getModelLoad() : Load + + getModelInsert() : Insert + } + + class Search #Gold { + # $searchEngine + + register() : void + + getConfig() : Config + + getTable() : Table + + getRegex() : Regex + + getBasic() : Basic + + getSearch() : SearchEngine + } +} + + +@enduml +``` + + +--- +``` + ██╗ ██████╗ ██████╗ ███╗ ███╗██╗ █████╗ + ██║██╔═══██╗██╔═══██╗████╗ ████║██║ ██╔══██╗ + ██║██║ ██║██║ ██║██╔████╔██║██║ ███████║ +██ ██║██║ ██║██║ ██║██║╚██╔╝██║██║ ██╔══██║ +╚█████╔╝╚██████╔╝╚██████╔╝██║ ╚═╝ ██║███████╗██║ ██║ + ╚════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ + ██████╗ ██████╗ ███╗ ███╗██████╗ ██████╗ ███╗ ██╗███████╗███╗ ██╗████████╗ +██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔═══██╗████╗ ██║██╔════╝████╗ ██║╚══██╔══╝ +██║ ██║ ██║██╔████╔██║██████╔╝██║ ██║██╔██╗ ██║█████╗ ██╔██╗ ██║ ██║ +██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ██║██║╚██╗██║██╔══╝ ██║╚██╗██║ ██║ +╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚██████╔╝██║ ╚████║███████╗██║ ╚████║ ██║ + ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═══╝ ╚═╝ +██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗ +██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗ +██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝ +██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗ +██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║ +╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/README.md b/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/README.md new file mode 100644 index 0000000..f0ea246 --- /dev/null +++ b/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/README.md @@ -0,0 +1,54 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class Factory (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search** +```uml +@startuml +abstract Factory #Orange { + # static $container + + {static} _(string $key) : Mixed + + {static} getContainer() : Container + # {static} createContainer() : Container +} + +note right of Factory::_ + Get any class from the search container + + since: 3.2.0 + return: Mixed +end note + +note right of Factory::getContainer + Get the global search container + + since: 3.2.0 + return: Container +end note + +note right of Factory::createContainer + Create a container object + + since: 3.2.0 + return: Container +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/code.php b/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/code.php new file mode 100644 index 0000000..8d02dd6 --- /dev/null +++ b/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/code.php @@ -0,0 +1,83 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search; + + +use Joomla\DI\Container; +use VDM\Joomla\Componentbuilder\Search\Service\Search; +use VDM\Joomla\Componentbuilder\Search\Service\Model; +use VDM\Joomla\Componentbuilder\Search\Service\Database; +use VDM\Joomla\Componentbuilder\Search\Service\Agent; +use VDM\Joomla\Componentbuilder\Interfaces\FactoryInterface; + + +/** + * Search Factory + * + * @since 3.2.0 + */ +abstract class Factory implements FactoryInterface +{ + /** + * Global Search Container + * + * @var Container + * @since 3.2.0 + **/ + protected static $container = null; + + /** + * Get any class from the search container + * + * @param string $key The container class key + * + * @return Mixed + * @since 3.2.0 + */ + public static function _(string $key) + { + return self::getContainer()->get($key); + } + + /** + * Get the global search container + * + * @return Container + * @since 3.2.0 + */ + public static function getContainer(): Container + { + if (!self::$container) + { + self::$container = self::createContainer(); + } + + return self::$container; + } + + /** + * Create a container object + * + * @return Container + * @since 3.2.0 + */ + protected static function createContainer(): Container + { + return (new Container()) + ->registerServiceProvider(new Search()) + ->registerServiceProvider(new Model()) + ->registerServiceProvider(new Database()) + ->registerServiceProvider(new Agent()); + } + +} + diff --git a/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/code.power b/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/code.power new file mode 100644 index 0000000..b6b6619 --- /dev/null +++ b/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/code.power @@ -0,0 +1,51 @@ + /** + * Global Search Container + * + * @var Container + * @since 3.2.0 + **/ + protected static $container = null; + + /** + * Get any class from the search container + * + * @param string $key The container class key + * + * @return Mixed + * @since 3.2.0 + */ + public static function _(string $key) + { + return self::getContainer()->get($key); + } + + /** + * Get the global search container + * + * @return Container + * @since 3.2.0 + */ + public static function getContainer(): Container + { + if (!self::$container) + { + self::$container = self::createContainer(); + } + + return self::$container; + } + + /** + * Create a container object + * + * @return Container + * @since 3.2.0 + */ + protected static function createContainer(): Container + { + return (new Container()) + ->registerServiceProvider(new Search()) + ->registerServiceProvider(new Model()) + ->registerServiceProvider(new Database()) + ->registerServiceProvider(new Agent()); + } diff --git a/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/settings.json b/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/settings.json new file mode 100644 index 0000000..8cf986e --- /dev/null +++ b/src/01a89ba8-f8bb-435c-93de-0a8f3fa9432a/settings.json @@ -0,0 +1,37 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "implements": [ + "caf33c5d-858c-4f9a-894f-ab302ec5445a" + ], + "load_selection": null, + "name": "Factory", + "power_version": "1.0.0", + "system_name": "JCB.Search.Factory", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "da714ea5-96bb-4eb1-959b-39b457be9cd1", + "as": "default" + }, + "use_selection1": { + "use": "7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a", + "as": "default" + }, + "use_selection2": { + "use": "d5de47ce-9a9e-4e76-a5c6-61ed74842ea3", + "as": "default" + }, + "use_selection3": { + "use": "cc6972a7-1574-4ae0-92a8-7f1012aac6f7", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Factory", + "description": "Search Factory\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\DI\\Container;", + "composer": "" +} \ No newline at end of file diff --git a/src/02efe40a-7792-4c82-9444-7d0377243483/README.md b/src/02efe40a-7792-4c82-9444-7d0377243483/README.md new file mode 100644 index 0000000..f34f0a1 --- /dev/null +++ b/src/02efe40a-7792-4c82-9444-7d0377243483/README.md @@ -0,0 +1,85 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Insert (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Model** +```uml +@startuml +class Insert #Gold { + # Config $config + + __construct(?Config $config = null, ?Table $table = null) + + value(mixed $value, string $field, ...) : mixed + # validateBefore(mixed $value, ?string $field = null, ...) : bool + # validateAfter(mixed $value, ?string $field = null, ...) : bool + # getTable() : string +} + +note right of Insert::__construct + Constructor + + since: 3.2.0 +end note + +note right of Insert::value + Model the value +Example: $this->value(value, 'field_key', 'table_name'); + + since: 3.2.0 + return: mixed + + arguments: + mixed $value + string $field + ?string $table = null +end note + +note right of Insert::validateBefore + Validate before the value is modelled (basic, override in child class) + + since: 3.2.0 + return: bool + + arguments: + mixed $value + ?string $field = null + ?string $table = null +end note + +note right of Insert::validateAfter + Validate after the value is modelled (basic, override in child class) + + since: 3.2.0 + return: bool + + arguments: + mixed $value + ?string $field = null + ?string $table = null +end note + +note right of Insert::getTable + Get the current active table + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/02efe40a-7792-4c82-9444-7d0377243483/code.php b/src/02efe40a-7792-4c82-9444-7d0377243483/code.php new file mode 100644 index 0000000..181b208 --- /dev/null +++ b/src/02efe40a-7792-4c82-9444-7d0377243483/code.php @@ -0,0 +1,137 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Model; + + +use VDM\Joomla\Componentbuilder\Search\Factory; +use VDM\Joomla\Componentbuilder\Table; +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Componentbuilder\Interfaces\ModelInterface; +use VDM\Joomla\Componentbuilder\Abstraction\Model; + + +/** + * Search Insert Model + * + * @since 3.2.0 + */ +class Insert extends Model implements ModelInterface +{ + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Table|null $table The search table object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Table $table = null) + { + parent::__construct($table ?? Factory::_('Table')); + + $this->config = $config ?: Factory::_('Config'); + } + + /** + * Model the value + * Example: $this->value(value, 'field_key', 'table_name'); + * + * @param mixed $value The value to model + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value($value, string $field, ?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + // check if this is a valid table + if (($store = $this->table->get($table, $field, 'store')) !== null) + { + // open the value based on the store method + switch($store) + { + case 'base64': + $value = base64_encode((string) $value); + break; + case 'json': + $value = json_encode($value, JSON_FORCE_OBJECT); + break; + } + } + + return $value; + } + + /** + * Validate before the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool + { + // check values + if (StringHelper::check($value) || ArrayHelper::check($value, true)) + { + return true; + } + // remove empty values + return false; + } + + /** + * Validate after the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool + { + return true; + } + + /** + * Get the current active table + * + * @return string + * @since 3.2.0 + */ + protected function getTable(): string + { + return $this->config->table_name; + } + +} + diff --git a/src/02efe40a-7792-4c82-9444-7d0377243483/code.power b/src/02efe40a-7792-4c82-9444-7d0377243483/code.power new file mode 100644 index 0000000..8ba0186 --- /dev/null +++ b/src/02efe40a-7792-4c82-9444-7d0377243483/code.power @@ -0,0 +1,106 @@ + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Table|null $table The search table object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Table $table = null) + { + parent::__construct($table ?? Factory::_('Table')); + + $this->config = $config ?: Factory::_('Config'); + } + + /** + * Model the value + * Example: $this->value(value, 'field_key', 'table_name'); + * + * @param mixed $value The value to model + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value($value, string $field, ?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->getTable(); + } + + // check if this is a valid table + if (($store = $this->table->get($table, $field, 'store')) !== null) + { + // open the value based on the store method + switch($store) + { + case 'base64': + $value = base64_encode((string) $value); + break; + case 'json': + $value = json_encode($value, JSON_FORCE_OBJECT); + break; + } + } + + return $value; + } + + /** + * Validate before the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool + { + // check values + if (StringHelper::check($value) || ArrayHelper::check($value, true)) + { + return true; + } + // remove empty values + return false; + } + + /** + * Validate after the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool + { + return true; + } + + /** + * Get the current active table + * + * @return string + * @since 3.2.0 + */ + protected function getTable(): string + { + return $this->config->table_name; + } diff --git a/src/02efe40a-7792-4c82-9444-7d0377243483/settings.json b/src/02efe40a-7792-4c82-9444-7d0377243483/settings.json new file mode 100644 index 0000000..dd5b915 --- /dev/null +++ b/src/02efe40a-7792-4c82-9444-7d0377243483/settings.json @@ -0,0 +1,33 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "584747d1-3a86-453d-b7a3-a2219de8d777", + "guid": "02efe40a-7792-4c82-9444-7d0377243483", + "implements": [ + "8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff" + ], + "load_selection": null, + "name": "Insert", + "power_version": "1.0.0", + "system_name": "JCB.Search.Model.Insert", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "as": "default" + }, + "use_selection1": { + "use": "bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8", + "as": "default" + }, + "use_selection2": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Model.Insert", + "description": "Search Insert Model\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/0b658434-3767-401e-addc-eabfd1d0e94a/README.md b/src/0b658434-3767-401e-addc-eabfd1d0e94a/README.md new file mode 100644 index 0000000..96d2354 --- /dev/null +++ b/src/0b658434-3767-401e-addc-eabfd1d0e94a/README.md @@ -0,0 +1,163 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Agent (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search** +```uml +@startuml +class Agent #Gold { + # Config $config + # Load $load + # Insert $insert + # Find $find + # Replace $replace + # Search $search + # Update $update + # Table $table + # string $return + # array $marker + # array $markerHtml + + __construct(?Config $config = null, ?Load $load = null, ...) + + getValue(int $id, string $field, ...) : ?string + + setValue(mixed $value, int $id, ...) : bool + + table(?string $table = null) : ?array + + find(?string $table = null) : ?array + + replace(?string $table = null) : int + # getRow(string $code, string $table, ...) : array + # getRowCode(string $code) : string + # getRowEditButton(string $view, string $field, ...) : string + # setReturnValue() : void + # setMarkers() : void +} + +note right of Agent::__construct + Constructor + + since: 3.2.0 + + arguments: + ?Config $config = null + ?Load $load = null + ?Insert $insert = null + ?Find $find = null + ?Replace $replace = null + ?Search $search = null + ?Update $update = null + ?Table $table = null +end note + +note left of Agent::getValue + Get the value of a field in a row and table + + since: 3.2.0 + return: ?string + + arguments: + int $id + string $field + mixed $line = null + ?string $table = null + bool $update = false +end note + +note right of Agent::setValue + Set the value of a field in a row and table + + since: 3.2.0 + return: bool + + arguments: + mixed $value + int $id + string $field + ?string $table = null +end note + +note left of Agent::table + Return Table Ready Search Results + + since: 3.2.0 + return: ?array +end note + +note right of Agent::find + Search the posted table for the search value and return all + + since: 3.2.0 + return: ?array +end note + +note left of Agent::replace + Search the posted table for the search value, and replace all + + since: 3.2.0 + return: int +end note + +note right of Agent::getRow + Return prepared code string for table + + since: 3.2.0 + return: array + + arguments: + string $code + string $table + string $field + int $id + mixed $line +end note + +note left of Agent::getRowCode + Return prepared code string for table + + since: 3.2.0 + return: string +end note + +note right of Agent::getRowEditButton + Get the Item button to edit an item + + since: 3.2.0 + return: string + + arguments: + string $view + string $field + int $id + mixed $line +end note + +note left of Agent::setReturnValue + Set the return value for this search + + since: 3.2.0 + return: void +end note + +note right of Agent::setMarkers + Set the markers of the found code + + since: 3.2.0 + return: void +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/0b658434-3767-401e-addc-eabfd1d0e94a/code.php b/src/0b658434-3767-401e-addc-eabfd1d0e94a/code.php new file mode 100644 index 0000000..b33c55d --- /dev/null +++ b/src/0b658434-3767-401e-addc-eabfd1d0e94a/code.php @@ -0,0 +1,425 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search; + + +use Joomla\CMS\Language\Text; +use VDM\Joomla\Componentbuilder\Search\Factory; +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Componentbuilder\Search\Database\Load; +use VDM\Joomla\Componentbuilder\Search\Database\Insert; +use VDM\Joomla\Componentbuilder\Search\Agent\Find; +use VDM\Joomla\Componentbuilder\Search\Agent\Replace; +use VDM\Joomla\Componentbuilder\Search\Agent\Search; +use VDM\Joomla\Componentbuilder\Search\Agent\Update; +use VDM\Joomla\Componentbuilder\Table; + + +/** + * Search Agent + * + * @since 3.2.0 + */ +class Agent +{ + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search Load Database + * + * @var Load + * @since 3.2.0 + */ + protected Load $load; + + /** + * Search Insert Database + * + * @var Insert + * @since 3.2.0 + */ + protected Insert $insert; + + /** + * Search Find + * + * @var Find + * @since 3.2.0 + */ + protected Find $find; + + /** + * Search Replace + * + * @var Replace + * @since 3.2.0 + */ + protected Replace $replace; + + /** + * Search + * + * @var Search + * @since 3.2.0 + */ + protected Search $search; + + /** + * Update + * + * @var Update + * @since 3.2.0 + */ + protected Update $update; + + /** + * Table + * + * @var Table + * @since 3.2.0 + */ + protected Table $table; + + /** + * Return value to search view + * + * @var string + * @since 3.2.0 + */ + protected string $return; + + /** + * Marker start and end values + * + * @var array + * @since 3.2.0 + */ + protected array $marker; + + /** + * Marker start and end html values + * + * @var array + * @since 3.2.0 + */ + protected array $markerHtml; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Load|null $load The search load database object. + * @param Insert|null $insert The search insert database object. + * @param Find|null $find The search find object. + * @param Replace|null $replace The search replace object. + * @param Search|null $search The search object. + * @param Update|null $update The update object. + * @param Table|null $table The table object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Load $load = null, + ?Insert $insert = null, ?Find $find = null, ?Replace $replace = null, + ?Search $search = null, ?Update $update = null, ?Table $table = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->load = $load ?: Factory::_('Load.Database'); + $this->insert = $insert ?: Factory::_('Insert.Database'); + $this->find = $find ?: Factory::_('Agent.Find'); + $this->replace = $replace ?: Factory::_('Agent.Replace'); + $this->search = $search ?: Factory::_('Agent.Search'); + $this->update = $update ?: Factory::_('Agent.Update'); + $this->table = $table ?: Factory::_('Table'); + } + + /** + * Get the value of a field in a row and table + * + * @param int $id The item ID + * @param string $field The field key + * @param mixed $line The field line + * @param string|null $table The table + * @param bool $update The switch to triger an update (default is false) + * + * @return string|null + * @since 3.2.0 + */ + public function getValue(int $id, string $field, $line = null, + ?string $table = null, bool $update = false): ?string + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if (($value = $this->load->value($id, $field, $table)) !== null) + { + // we only return strings that can load in an editor + if (is_string($value)) + { + // try to update the value if required + if ($update && ($updated_value = $this->update->value($value, $line)) !== null) + { + return $updated_value; + } + + return $value; + } + + return '// VALUE CAN NOT BE LOADED (AT THIS TIME) SINCE ITS NOT A STRING'; + } + + return null; + } + + /** + * Set the value of a field in a row and table + * + * @param mixed $value The field value + * @param int $id The item ID + * @param string $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function setValue($value, int $id, string $field, ?string $table = null): bool + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + return $this->insert->value($value, $id, $field, $table); + } + + /** + * Return Table Ready Search Results + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function table(?string $table = null): ?array + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if(($values = $this->find($table)) !== null) + { + // build return value + $this->setReturnValue(); + + // set the markers + $this->setMarkers(); + + // start table bucket + $table_rows = []; + + foreach ($values as $id => $fields) + { + foreach ($fields as $field => $lines) + { + foreach ($lines as $line => $code) + { + $table_rows[] = $this->getRow($code, $table, $field, $id, $line); + } + } + } + return $table_rows; + } + return null; + } + + /** + * Search the posted table for the search value and return all + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function find(?string $table = null): ?array + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + $set = 1; + + // continue loading items until all are searched + while(($items = $this->load->items($table, $set)) !== null) + { + $this->find->items($items, $table); + $set++; + } + + return $this->search->get($table); + } + + /** + * Search the posted table for the search value, and replace all + * + * @param string|null $table The table being searched + * + * @return int + * @since 3.2.0 + */ + public function replace(?string $table = null): int + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + $set = 1; + $replaced = 0; + + // continue loading items until all was loaded + while(($items = $this->load->items($table, $set)) !== null) + { + // search for items + $this->find->items($items, $table); + + // update those found + $this->replace->items($this->find->get($table), $table); + + // update the database + if ($this->insert->items($this->replace->get($table), $table)) + { + $replaced++; + } + + // reset found items + $this->find->reset($table); + $this->replace->reset($table); + + $set++; + } + + // we return the number of times we replaced + return $replaced; + } + + /** + * Return prepared code string for table + * + * @param string $code The code value fro the table + * @param string|null $table The table + * @param string $field The field key + * @param int $id The the row id + * @param mixed $line The code line where found + * + * @return array + * @since 3.2.0 + */ + protected function getRow(string $code, string $table, string $field, int $id, $line): array + { + return [ + 'edit' => $this->getRowEditButton($table, $field, $id, $line), + 'code' => $this->getRowCode($code), + 'table' => $table, + 'field' => $field, + 'id' => $id, + 'line' => $line + ]; + } + + /** + * Return prepared code string for table + * + * @param string $code The code value fro the table + * + * @return string + * @since 3.2.0 + */ + protected function getRowCode(string $code): string + { + return str_replace($this->marker, $this->markerHtml, htmlentities($code)); + } + + /** + * Get the Item button to edit an item + * + * @param string|null $view The single view + * @param string $field The field key + * @param int $id The the row id + * @param mixed $line The code line where found + * + * @return string + * @since 3.2.0 + */ + protected function getRowEditButton(string $view, string $field, int $id, $line): string + { + // get list view + $views = $this->table->get($view, $field, 'list'); + $tab = $this->table->get($view, $field, 'tab_name'); + + // return edit link + return ''; + } + + /** + * Set the return value for this search + * + * @return void + * @since 3.2.0 + */ + protected function setReturnValue() + { + // set the return value so the search auto load on return + $this->return = urlencode(base64_encode('index.php?option=com_componentbuilder&view=search' . + '&type_search=' . (int) $this->config->type_search . + '&match_case=' . (int) $this->config->match_case . + '&whole_word=' . (int) $this->config->whole_word . + '®ex_search=' . (int) $this->config->regex_search . + '&search_value=' . (string) urlencode((string) $this->config->search_value) . + '&replace_value=' . (string) urlencode((string) $this->config->replace_value))); + } + + /** + * Set the markers of the found code + * + * @return void + * @since 3.2.0 + */ + protected function setMarkers() + { + // set the markers + $this->marker = [$this->config->marker_start, $this->config->marker_end]; + $this->markerHtml = ['','']; + } + +} + diff --git a/src/0b658434-3767-401e-addc-eabfd1d0e94a/code.power b/src/0b658434-3767-401e-addc-eabfd1d0e94a/code.power new file mode 100644 index 0000000..cabbec1 --- /dev/null +++ b/src/0b658434-3767-401e-addc-eabfd1d0e94a/code.power @@ -0,0 +1,389 @@ + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search Load Database + * + * @var Load + * @since 3.2.0 + */ + protected Load $load; + + /** + * Search Insert Database + * + * @var Insert + * @since 3.2.0 + */ + protected Insert $insert; + + /** + * Search Find + * + * @var Find + * @since 3.2.0 + */ + protected Find $find; + + /** + * Search Replace + * + * @var Replace + * @since 3.2.0 + */ + protected Replace $replace; + + /** + * Search + * + * @var Search + * @since 3.2.0 + */ + protected Search $search; + + /** + * Update + * + * @var Update + * @since 3.2.0 + */ + protected Update $update; + + /** + * Table + * + * @var Table + * @since 3.2.0 + */ + protected Table $table; + + /** + * Return value to search view + * + * @var string + * @since 3.2.0 + */ + protected string $return; + + /** + * Marker start and end values + * + * @var array + * @since 3.2.0 + */ + protected array $marker; + + /** + * Marker start and end html values + * + * @var array + * @since 3.2.0 + */ + protected array $markerHtml; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Load|null $load The search load database object. + * @param Insert|null $insert The search insert database object. + * @param Find|null $find The search find object. + * @param Replace|null $replace The search replace object. + * @param Search|null $search The search object. + * @param Update|null $update The update object. + * @param Table|null $table The table object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Load $load = null, + ?Insert $insert = null, ?Find $find = null, ?Replace $replace = null, + ?Search $search = null, ?Update $update = null, ?Table $table = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->load = $load ?: Factory::_('Load.Database'); + $this->insert = $insert ?: Factory::_('Insert.Database'); + $this->find = $find ?: Factory::_('Agent.Find'); + $this->replace = $replace ?: Factory::_('Agent.Replace'); + $this->search = $search ?: Factory::_('Agent.Search'); + $this->update = $update ?: Factory::_('Agent.Update'); + $this->table = $table ?: Factory::_('Table'); + } + + /** + * Get the value of a field in a row and table + * + * @param int $id The item ID + * @param string $field The field key + * @param mixed $line The field line + * @param string|null $table The table + * @param bool $update The switch to triger an update (default is false) + * + * @return string|null + * @since 3.2.0 + */ + public function getValue(int $id, string $field, $line = null, + ?string $table = null, bool $update = false): ?string + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if (($value = $this->load->value($id, $field, $table)) !== null) + { + // we only return strings that can load in an editor + if (is_string($value)) + { + // try to update the value if required + if ($update && ($updated_value = $this->update->value($value, $line)) !== null) + { + return $updated_value; + } + + return $value; + } + + return '// VALUE CAN NOT BE LOADED (AT THIS TIME) SINCE ITS NOT A STRING'; + } + + return null; + } + + /** + * Set the value of a field in a row and table + * + * @param mixed $value The field value + * @param int $id The item ID + * @param string $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function setValue($value, int $id, string $field, ?string $table = null): bool + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + return $this->insert->value($value, $id, $field, $table); + } + + /** + * Return Table Ready Search Results + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function table(?string $table = null): ?array + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if(($values = $this->find($table)) !== null) + { + // build return value + $this->setReturnValue(); + + // set the markers + $this->setMarkers(); + + // start table bucket + $table_rows = []; + + foreach ($values as $id => $fields) + { + foreach ($fields as $field => $lines) + { + foreach ($lines as $line => $code) + { + $table_rows[] = $this->getRow($code, $table, $field, $id, $line); + } + } + } + return $table_rows; + } + return null; + } + + /** + * Search the posted table for the search value and return all + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function find(?string $table = null): ?array + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + $set = 1; + + // continue loading items until all are searched + while(($items = $this->load->items($table, $set)) !== null) + { + $this->find->items($items, $table); + $set++; + } + + return $this->search->get($table); + } + + /** + * Search the posted table for the search value, and replace all + * + * @param string|null $table The table being searched + * + * @return int + * @since 3.2.0 + */ + public function replace(?string $table = null): int + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + $set = 1; + $replaced = 0; + + // continue loading items until all was loaded + while(($items = $this->load->items($table, $set)) !== null) + { + // search for items + $this->find->items($items, $table); + + // update those found + $this->replace->items($this->find->get($table), $table); + + // update the database + if ($this->insert->items($this->replace->get($table), $table)) + { + $replaced++; + } + + // reset found items + $this->find->reset($table); + $this->replace->reset($table); + + $set++; + } + + // we return the number of times we replaced + return $replaced; + } + + /** + * Return prepared code string for table + * + * @param string $code The code value fro the table + * @param string|null $table The table + * @param string $field The field key + * @param int $id The the row id + * @param mixed $line The code line where found + * + * @return array + * @since 3.2.0 + */ + protected function getRow(string $code, string $table, string $field, int $id, $line): array + { + return [ + 'edit' => $this->getRowEditButton($table, $field, $id, $line), + 'code' => $this->getRowCode($code), + 'table' => $table, + 'field' => $field, + 'id' => $id, + 'line' => $line + ]; + } + + /** + * Return prepared code string for table + * + * @param string $code The code value fro the table + * + * @return string + * @since 3.2.0 + */ + protected function getRowCode(string $code): string + { + return str_replace($this->marker, $this->markerHtml, htmlentities($code)); + } + + /** + * Get the Item button to edit an item + * + * @param string|null $view The single view + * @param string $field The field key + * @param int $id The the row id + * @param mixed $line The code line where found + * + * @return string + * @since 3.2.0 + */ + protected function getRowEditButton(string $view, string $field, int $id, $line): string + { + // get list view + $views = $this->table->get($view, $field, 'list'); + $tab = $this->table->get($view, $field, 'tab_name'); + + // return edit link + return ''; + } + + /** + * Set the return value for this search + * + * @return void + * @since 3.2.0 + */ + protected function setReturnValue() + { + // set the return value so the search auto load on return + $this->return = urlencode(base64_encode('index.php?option=com_componentbuilder&view=search' . + '&type_search=' . (int) $this->config->type_search . + '&match_case=' . (int) $this->config->match_case . + '&whole_word=' . (int) $this->config->whole_word . + '®ex_search=' . (int) $this->config->regex_search . + '&search_value=' . (string) urlencode((string) $this->config->search_value) . + '&replace_value=' . (string) urlencode((string) $this->config->replace_value))); + } + + /** + * Set the markers of the found code + * + * @return void + * @since 3.2.0 + */ + protected function setMarkers() + { + // set the markers + $this->marker = [$this->config->marker_start, $this->config->marker_end]; + $this->markerHtml = ['','']; + } diff --git a/src/0b658434-3767-401e-addc-eabfd1d0e94a/settings.json b/src/0b658434-3767-401e-addc-eabfd1d0e94a/settings.json new file mode 100644 index 0000000..44b757a --- /dev/null +++ b/src/0b658434-3767-401e-addc-eabfd1d0e94a/settings.json @@ -0,0 +1,55 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "0b658434-3767-401e-addc-eabfd1d0e94a", + "implements": null, + "load_selection": null, + "name": "Agent", + "power_version": "1.0.0", + "system_name": "JCB.Search.Agent", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "as": "default" + }, + "use_selection1": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + }, + "use_selection2": { + "use": "2dabfb4a-64cd-4c04-9772-4a75f9f3b710", + "as": "default" + }, + "use_selection3": { + "use": "6caf9473-133c-49a9-afa0-9f84151b5155", + "as": "default" + }, + "use_selection4": { + "use": "15d9e1a9-3364-4d69-9d9f-9b87db820e5c", + "as": "default" + }, + "use_selection5": { + "use": "abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7", + "as": "default" + }, + "use_selection6": { + "use": "e544a248-4b6a-46cb-9926-a3ac9937807c", + "as": "default" + }, + "use_selection7": { + "use": "3ac29912-0681-4ca9-8197-d5a8f6a49ac7", + "as": "default" + }, + "use_selection8": { + "use": "bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Agent", + "description": "Search Agent\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\CMS\\Language\\Text;", + "composer": "" +} \ No newline at end of file diff --git a/src/0d9442ab-54d9-4947-a219-244cfaea3084/README.md b/src/0d9442ab-54d9-4947-a219-244cfaea3084/README.md new file mode 100644 index 0000000..b961b9d --- /dev/null +++ b/src/0d9442ab-54d9-4947-a219-244cfaea3084/README.md @@ -0,0 +1,59 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# interface SearchInterface (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Interfaces** +```uml +@startuml +interface SearchInterface #Lavender { + + get(string $table) : ?array + + value(mixed $value, int $id, ...) : bool + + reset(string $table) : void +} + +note right of SearchInterface::get + Get found values + + since: 3.2.0 + return: ?array +end note + +note right of SearchInterface::value + Search inside a value + + since: 3.2.0 + return: bool + + arguments: + mixed $value + int $id + string $field + string $table +end note + +note right of SearchInterface::reset + Empty the found values + + since: 3.2.0 + return: void +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/0d9442ab-54d9-4947-a219-244cfaea3084/code.php b/src/0d9442ab-54d9-4947-a219-244cfaea3084/code.php new file mode 100644 index 0000000..29e944e --- /dev/null +++ b/src/0d9442ab-54d9-4947-a219-244cfaea3084/code.php @@ -0,0 +1,56 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Interfaces; + + +/** + * Search Interface + * + * @since 3.2.0 + */ +interface SearchInterface +{ + /** + * Get found values + * + * @param string $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(string $table): ?array; + + /** + * Search inside a value + * + * @param mixed $value The field value + * @param int $id The item ID + * @param string $field The field key + * @param string $table The table + * + * @return bool + * @since 3.2.0 + */ + public function value($value, int $id, string $field, string $table): bool; + + /** + * Empty the found values + * + * @param string $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(string $table); + +} + diff --git a/src/0d9442ab-54d9-4947-a219-244cfaea3084/code.power b/src/0d9442ab-54d9-4947-a219-244cfaea3084/code.power new file mode 100644 index 0000000..ea59936 --- /dev/null +++ b/src/0d9442ab-54d9-4947-a219-244cfaea3084/code.power @@ -0,0 +1,32 @@ + /** + * Get found values + * + * @param string $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(string $table): ?array; + + /** + * Search inside a value + * + * @param mixed $value The field value + * @param int $id The item ID + * @param string $field The field key + * @param string $table The table + * + * @return bool + * @since 3.2.0 + */ + public function value($value, int $id, string $field, string $table): bool; + + /** + * Empty the found values + * + * @param string $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(string $table); diff --git a/src/0d9442ab-54d9-4947-a219-244cfaea3084/settings.json b/src/0d9442ab-54d9-4947-a219-244cfaea3084/settings.json new file mode 100644 index 0000000..5bcfbe6 --- /dev/null +++ b/src/0d9442ab-54d9-4947-a219-244cfaea3084/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "0d9442ab-54d9-4947-a219-244cfaea3084", + "implements": null, + "load_selection": null, + "name": "SearchInterface", + "power_version": "1.0.0", + "system_name": "JCB.Search.Interfaces.SearchInterface", + "type": "interface", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Interfaces.SearchInterface", + "description": "Search Interface\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/README.md b/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/README.md new file mode 100644 index 0000000..45c0008 --- /dev/null +++ b/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/README.md @@ -0,0 +1,45 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# interface SearchTypeInterface (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Interfaces** +```uml +@startuml +interface SearchTypeInterface #Lavender { + + string(string $value) : ?string + + replace(string $value) : string +} + +note right of SearchTypeInterface::string + Search inside a string + + since: 3.2.0 + return: ?string +end note + +note right of SearchTypeInterface::replace + Replace found instances inside string value + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/code.php b/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/code.php new file mode 100644 index 0000000..d120860 --- /dev/null +++ b/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/code.php @@ -0,0 +1,43 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Interfaces; + + +/** + * Search Type Interface + * + * @since 3.2.0 + */ +interface SearchTypeInterface +{ + /** + * Search inside a string + * + * @param string $value The string value + * + * @return string|null The marked string if found, else null + * @since 3.2.0 + */ + public function string(string $value): ?string; + + /** + * Replace found instances inside string value + * + * @param string $value The string value to update + * + * @return string The updated string + * @since 3.2.0 + */ + public function replace(string $value): string; + +} + diff --git a/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/code.power b/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/code.power new file mode 100644 index 0000000..a909cd9 --- /dev/null +++ b/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/code.power @@ -0,0 +1,19 @@ + /** + * Search inside a string + * + * @param string $value The string value + * + * @return string|null The marked string if found, else null + * @since 3.2.0 + */ + public function string(string $value): ?string; + + /** + * Replace found instances inside string value + * + * @param string $value The string value to update + * + * @return string The updated string + * @since 3.2.0 + */ + public function replace(string $value): string; diff --git a/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/settings.json b/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/settings.json new file mode 100644 index 0000000..a856a03 --- /dev/null +++ b/src/117d8c9e-3f8d-40ae-b375-1efa2fe5538a/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "117d8c9e-3f8d-40ae-b375-1efa2fe5538a", + "implements": null, + "load_selection": null, + "name": "SearchTypeInterface", + "power_version": "1.0.0", + "system_name": "JCB.Search.Interfaces.SearchTypeInterface", + "type": "interface", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Interfaces.SearchTypeInterface", + "description": "Search Type Interface\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/README.md b/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/README.md new file mode 100644 index 0000000..2a4e405 --- /dev/null +++ b/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/README.md @@ -0,0 +1,76 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Find (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Agent** +```uml +@startuml +class Find #Gold { + # array $found + # Config $config + # Search $search + + __construct(?Config $config = null, ?Search $search = null) + + get(?string $table = null) : ?array + + item(object $item, ?int $id = null, ...) : void + + items(?array $items = null, ?string $table = null) : void + + reset(?string $table = null) : void +} + +note right of Find::__construct + Constructor + + since: 3.2.0 +end note + +note right of Find::get + Get found values + + since: 3.2.0 + return: ?array +end note + +note right of Find::item + Search over an item fields + + since: 3.2.0 + return: void + + arguments: + object $item + ?int $id = null + ?string $table = null +end note + +note right of Find::items + Search over an array of items + + since: 3.2.0 + return: void +end note + +note right of Find::reset + Reset all found values of a table + + since: 3.2.0 + return: void +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/code.php b/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/code.php new file mode 100644 index 0000000..dda386d --- /dev/null +++ b/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/code.php @@ -0,0 +1,180 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Agent; + + +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Utilities\ObjectHelper; +use VDM\Joomla\Componentbuilder\Search\Factory; +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Componentbuilder\Search\Agent\Search; +use VDM\Joomla\Componentbuilder\Search\Interfaces\FindInterface; + + +/** + * Search Agent Find + * + * @since 3.2.0 + */ +class Find implements FindInterface +{ + /** + * Found Values + * + * @var array + * @since 3.2.0 + */ + protected array $found = []; + + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search + * + * @var Search + * @since 3.2.0 + */ + protected Search $search; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Search|null $search The search object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Search $search = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->search = $search ?: Factory::_('Agent.Search'); + } + + /** + * Get found values + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(?string $table = null): ?array + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if (isset($this->found[$table])) + { + return $this->found[$table]; + } + + return null; + } + + /** + * Search over an item fields + * + * @param object $item The item object of fields to search through + * @param int|null $id The item id + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function item(object $item, ?int $id =null, ?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + // set the item id + if (empty($id)) + { + $id = $item->id; + } + + if (ObjectHelper::check($item)) + { + foreach ($item as $field => $value) + { + if ($field !== 'id' && $this->search->value($value, $id, $field, $table)) + { + if (empty($this->found[$table][$id])) + { + $this->found[$table][$id] = new \stdClass(); + $this->found[$table][$id]->id = $id; + } + $this->found[$table][$id]->{$field} = $value; + } + } + } + } + + /** + * Search over an array of items + * + * @param array|null $items The array of items to search through + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if (ArrayHelper::check($items)) + { + foreach ($items as $id => $item) + { + $this->item($item, $id, $table); + } + } + } + + /** + * Reset all found values of a table + * + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + // empty or unset the table active values + unset($this->found[$table]); + } + +} + diff --git a/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/code.power b/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/code.power new file mode 100644 index 0000000..1917a60 --- /dev/null +++ b/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/code.power @@ -0,0 +1,148 @@ + /** + * Found Values + * + * @var array + * @since 3.2.0 + */ + protected array $found = []; + + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search + * + * @var Search + * @since 3.2.0 + */ + protected Search $search; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Search|null $search The search object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Search $search = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->search = $search ?: Factory::_('Agent.Search'); + } + + /** + * Get found values + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(?string $table = null): ?array + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if (isset($this->found[$table])) + { + return $this->found[$table]; + } + + return null; + } + + /** + * Search over an item fields + * + * @param object $item The item object of fields to search through + * @param int|null $id The item id + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function item(object $item, ?int $id =null, ?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + // set the item id + if (empty($id)) + { + $id = $item->id; + } + + if (ObjectHelper::check($item)) + { + foreach ($item as $field => $value) + { + if ($field !== 'id' && $this->search->value($value, $id, $field, $table)) + { + if (empty($this->found[$table][$id])) + { + $this->found[$table][$id] = new \stdClass(); + $this->found[$table][$id]->id = $id; + } + $this->found[$table][$id]->{$field} = $value; + } + } + } + } + + /** + * Search over an array of items + * + * @param array|null $items The array of items to search through + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if (ArrayHelper::check($items)) + { + foreach ($items as $id => $item) + { + $this->item($item, $id, $table); + } + } + } + + /** + * Reset all found values of a table + * + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + // empty or unset the table active values + unset($this->found[$table]); + } diff --git a/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/settings.json b/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/settings.json new file mode 100644 index 0000000..fd4f4f0 --- /dev/null +++ b/src/15d9e1a9-3364-4d69-9d9f-9b87db820e5c/settings.json @@ -0,0 +1,41 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "15d9e1a9-3364-4d69-9d9f-9b87db820e5c", + "implements": [ + "55280ec7-e48d-431b-af25-10308dd30636" + ], + "load_selection": null, + "name": "Find", + "power_version": "1.0.0", + "system_name": "JCB.Search.Agent.Find", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + }, + "use_selection1": { + "use": "91004529-94a9-4590-b842-e7c6b624ecf5", + "as": "default" + }, + "use_selection2": { + "use": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "as": "default" + }, + "use_selection3": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + }, + "use_selection4": { + "use": "e544a248-4b6a-46cb-9926-a3ac9937807c", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Agent.Find", + "description": "Search Agent Find\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/2bd1a32c-3d90-4646-9314-28d44d164f76/README.md b/src/2bd1a32c-3d90-4646-9314-28d44d164f76/README.md new file mode 100644 index 0000000..a71325e --- /dev/null +++ b/src/2bd1a32c-3d90-4646-9314-28d44d164f76/README.md @@ -0,0 +1,61 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# interface LoadInterface (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Interfaces** +```uml +@startuml +interface LoadInterface #Lavender { + + value(int $id, string $field, ...) : mixed + + item(int $id, string $table = null) : ?object + + items(string $table = null, int $bundle) : ?array +} + +note right of LoadInterface::value + Get a value from a given table +Example: $this->value(23, 'value_key', 'table_name'); + + since: 3.2.0 + return: mixed + + arguments: + int $id + string $field + string $table = null +end note + +note right of LoadInterface::item + Get values from a given table +Example: $this->item(23, 'table_name'); + + since: 3.2.0 + return: ?object +end note + +note right of LoadInterface::items + Get values from a given table +Example: $this->items('table_name'); + + since: 3.2.0 + return: ?array +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/2bd1a32c-3d90-4646-9314-28d44d164f76/code.php b/src/2bd1a32c-3d90-4646-9314-28d44d164f76/code.php new file mode 100644 index 0000000..6c38fcc --- /dev/null +++ b/src/2bd1a32c-3d90-4646-9314-28d44d164f76/code.php @@ -0,0 +1,60 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Interfaces; + + +/** + * Search Database Load Interface + * + * @since 3.2.0 + */ +interface LoadInterface +{ + /** + * Get a value from a given table + * Example: $this->value(23, 'value_key', 'table_name'); + * + * @param int $id The item ID + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value(int $id, string $field, string $table = null); + + /** + * Get values from a given table + * Example: $this->item(23, 'table_name'); + * + * @param int $id The item ID + * @param string| null $table The table + * + * @return object|null + * @since 3.2.0 + */ + public function item(int $id, string $table = null): ?object; + + /** + * Get values from a given table + * Example: $this->items('table_name'); + * + * @param string|null $table The table + * @param int $bundle The bundle to return (0 = all) + * + * @return array|null + * @since 3.2.0 + */ + public function items(string $table = null, int $bundle = 0): ?array; + +} + diff --git a/src/2bd1a32c-3d90-4646-9314-28d44d164f76/code.power b/src/2bd1a32c-3d90-4646-9314-28d44d164f76/code.power new file mode 100644 index 0000000..a1318b9 --- /dev/null +++ b/src/2bd1a32c-3d90-4646-9314-28d44d164f76/code.power @@ -0,0 +1,36 @@ + /** + * Get a value from a given table + * Example: $this->value(23, 'value_key', 'table_name'); + * + * @param int $id The item ID + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value(int $id, string $field, string $table = null); + + /** + * Get values from a given table + * Example: $this->item(23, 'table_name'); + * + * @param int $id The item ID + * @param string| null $table The table + * + * @return object|null + * @since 3.2.0 + */ + public function item(int $id, string $table = null): ?object; + + /** + * Get values from a given table + * Example: $this->items('table_name'); + * + * @param string|null $table The table + * @param int $bundle The bundle to return (0 = all) + * + * @return array|null + * @since 3.2.0 + */ + public function items(string $table = null, int $bundle = 0): ?array; diff --git a/src/2bd1a32c-3d90-4646-9314-28d44d164f76/settings.json b/src/2bd1a32c-3d90-4646-9314-28d44d164f76/settings.json new file mode 100644 index 0000000..63b7d1b --- /dev/null +++ b/src/2bd1a32c-3d90-4646-9314-28d44d164f76/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "2bd1a32c-3d90-4646-9314-28d44d164f76", + "implements": null, + "load_selection": null, + "name": "LoadInterface", + "power_version": "1.0.0", + "system_name": "JCB.Search.Interfaces.LoadInterface", + "type": "interface", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Interfaces.LoadInterface", + "description": "Search Database Load Interface\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/README.md b/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/README.md new file mode 100644 index 0000000..7e5ca29 --- /dev/null +++ b/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/README.md @@ -0,0 +1,108 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Load (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Database** +```uml +@startuml +class Load #Gold { + # int $bundle + # Config $config + # Table $table + # Model $model + # Database $load + + __construct(?Config $config = null, ?Table $table = null, ...) + + value(int $id, string $field, ...) : mixed + + item(int $id, string $table = null) : ?object + + items(string $table = null, int $bundle) : ?array + # next(string $table, int $bundle) : int + # incremental(int $bundle) : int + # setDatabaseFields(string $table, string $key = 'a', ...) : ?array +} + +note right of Load::__construct + Constructor + + since: 3.2.0 + + arguments: + ?Config $config = null + ?Table $table = null + ?Model $model = null + ?Database $load = null +end note + +note right of Load::value + Get a value from a given table +Example: $this->value(23, 'value_key', 'table_name'); + + since: 3.2.0 + return: mixed + + arguments: + int $id + string $field + string $table = null +end note + +note right of Load::item + Get values from a given table +Example: $this->item(23, 'table_name'); + + since: 3.2.0 + return: ?object +end note + +note right of Load::items + Get values from a given table +Example: $this->items('table_name'); + + since: 3.2.0 + return: ?array +end note + +note right of Load::next + Get next id to call + + since: 3.2.0 + return: int +end note + +note right of Load::incremental + Get Incremental number where the set starts + + since: 3.2.0 + return: int +end note + +note right of Load::setDatabaseFields + Get Fields ready to use in database call + + since: 3.2.0 + return: ?array + + arguments: + string $table + string $key = 'a' + bool $addId = true +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/code.php b/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/code.php new file mode 100644 index 0000000..4dbefc3 --- /dev/null +++ b/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/code.php @@ -0,0 +1,305 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Database; + + +use Joomla\CMS\Factory as JoomlaFactory; +use VDM\Joomla\Componentbuilder\Search\Factory; +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Componentbuilder\Table; +use VDM\Joomla\Componentbuilder\Search\Model\Load as Model; +use VDM\Joomla\Componentbuilder\Database\Load as Database; +use VDM\Joomla\Componentbuilder\Search\Interfaces\LoadInterface; + + +/** + * Search Database Load + * + * @since 3.2.0 + */ +class Load implements LoadInterface +{ + /** + * Bundle Size + * + * @var int + * @since 3.2.0 + */ + protected int $bundle = 300; + + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search Table + * + * @var Table + * @since 3.2.0 + */ + protected Table $table; + + /** + * Search Model + * + * @var Model + * @since 3.2.0 + */ + protected Model $model; + + /** + * Database load class + * + * @var Database + * @since 3.2.0 + **/ + protected Database $load; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Table|null $table The search table object. + * @param Model|null $model The search get model object. + * @param Database|null $load The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Table $table = null, + ?Model $model = null, ?Database $load = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->table = $table ?: Factory::_('Table'); + $this->model = $model ?: Factory::_('Load.Model'); + $this->load = $load ?: Factory::_('Load'); + } + + /** + * Get a value from a given table + * Example: $this->value(23, 'value_key', 'table_name'); + * + * @param int $id The item ID + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value(int $id, string $field, string $table = null) + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid table + if ($id > 0 && $this->table->exist($table, $field) && + ($value = $this->load->value( + ["a.${field}" => $field], // select + ['a' => $table], // tables + ['a.id' => $id] // where + )) !== null) + { + return $this->model->value( + $value, $field, $table + ); + } + + return null; + } + + /** + * Get values from a given table + * Example: $this->item(23, 'table_name'); + * + * @param int $id The item ID + * @param string| null $table The table + * + * @return object|null + * @since 3.2.0 + */ + public function item(int $id, string $table = null): ?object + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid table + if ($id > 0 && ($fields = $this->setDatabaseFields($table)) !== null && + ($item = $this->load->item( + $fields, // select + ['a' => $table], // tables + ['a.id' => $id] // where + )) !== null) + { + // return found values + return $this->model->item($item, $table); + } + + return null; + } + + /** + * Get values from a given table + * Example: $this->items('table_name'); + * + * @param string|null $table The table + * @param int $bundle The bundle to return (0 = all) + * + * @return array|null + * @since 3.2.0 + */ + public function items(string $table = null, int $bundle = 0): ?array + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid table + if ( ($fields = $this->setDatabaseFields($table)) !== null) + { + // add a key to the selection return set + $fields['key'] = 'id'; + // get the title value + $title = $this->table->titleName($table); + // set order + $order = ['a.' . $title => 'ASC']; + // select all + $where = null; + // no limit + $limit = null; + + // add limitation and pagination + if ($bundle > 0) + { + // get the incremental number + $where = ['a.id' => [ + 'operator' => '>=', + 'value' => $this->next($table, $bundle) + ] + ]; + + // only return a limited number + $limit = $this->bundle; + } + + if (($items = $this->load->items( + $fields, // select + ['a' => $table], // tables + $where, + $order, + $limit + )) !== null) + { + // return found values + return $this->model->items($items, $table); + } + } + + return null; + } + + /** + * Get next id to call + * + * @param string $table The table + * @param int $bundle The bundle to return + * + * @return int + * @since 3.2.0 + */ + protected function next(string $table, int $bundle): int + { + if ($bundle == 1 || $bundle == 0) + { + return 1; + } + + if (($number = $this->model->last($table)) !== null) + { + return $number + 1; + } + + return $this->incremental($bundle); + } + + /** + * Get Incremental number where the set starts + * + * @param int $bundle The bundle to return + * + * @return int + * @since 3.2.0 + */ + protected function incremental(int $bundle): int + { + // just in case + if ($bundle == 1 || $bundle == 0) + { + return 1; + } + + /** Number two set starts at 301 + * 2 x 300 = 600 + * 600 - 300 = 300 + * 300 + 1 = 301 <-- + * Number five set starts at 1201 + * 5 x 300 = 1500 + * 1500 - 300 = 1200 + * 1200 + 1 = 1201 <-- + **/ + return (($bundle * $this->bundle) - $this->bundle) + 1; + } + + /** + * Get Fields ready to use in database call + * + * @param string $table The table which fields we want to get + * @param string $key The table key to which the fields belong + * @param bool $addId The switch to add ID + * + * @return array|null + * @since 3.2.0 + */ + protected function setDatabaseFields(string $table, string $key = 'a', bool $addId = true): ?array + { + if (($fields = $this->table->fields($table)) !== null) + { + // add the ID + if ($addId) + { + array_unshift($fields , 'id'); + } + + $bucket = []; + foreach ($fields as $field) + { + $bucket[$key . '.' . $field] = $field; + } + + return $bucket; + } + + return null; + } + +} + diff --git a/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/code.power b/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/code.power new file mode 100644 index 0000000..7be301b --- /dev/null +++ b/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/code.power @@ -0,0 +1,272 @@ + /** + * Bundle Size + * + * @var int + * @since 3.2.0 + */ + protected int $bundle = 300; + + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search Table + * + * @var Table + * @since 3.2.0 + */ + protected Table $table; + + /** + * Search Model + * + * @var Model + * @since 3.2.0 + */ + protected Model $model; + + /** + * Database load class + * + * @var Database + * @since 3.2.0 + **/ + protected Database $load; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Table|null $table The search table object. + * @param Model|null $model The search get model object. + * @param Database|null $load The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Table $table = null, + ?Model $model = null, ?Database $load = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->table = $table ?: Factory::_('Table'); + $this->model = $model ?: Factory::_('Load.Model'); + $this->load = $load ?: Factory::_('Load'); + } + + /** + * Get a value from a given table + * Example: $this->value(23, 'value_key', 'table_name'); + * + * @param int $id The item ID + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value(int $id, string $field, string $table = null) + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid table + if ($id > 0 && $this->table->exist($table, $field) && + ($value = $this->load->value( + ["a.${field}" => $field], // select + ['a' => $table], // tables + ['a.id' => $id] // where + )) !== null) + { + return $this->model->value( + $value, $field, $table + ); + } + + return null; + } + + /** + * Get values from a given table + * Example: $this->item(23, 'table_name'); + * + * @param int $id The item ID + * @param string| null $table The table + * + * @return object|null + * @since 3.2.0 + */ + public function item(int $id, string $table = null): ?object + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid table + if ($id > 0 && ($fields = $this->setDatabaseFields($table)) !== null && + ($item = $this->load->item( + $fields, // select + ['a' => $table], // tables + ['a.id' => $id] // where + )) !== null) + { + // return found values + return $this->model->item($item, $table); + } + + return null; + } + + /** + * Get values from a given table + * Example: $this->items('table_name'); + * + * @param string|null $table The table + * @param int $bundle The bundle to return (0 = all) + * + * @return array|null + * @since 3.2.0 + */ + public function items(string $table = null, int $bundle = 0): ?array + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid table + if ( ($fields = $this->setDatabaseFields($table)) !== null) + { + // add a key to the selection return set + $fields['key'] = 'id'; + // get the title value + $title = $this->table->titleName($table); + // set order + $order = ['a.' . $title => 'ASC']; + // select all + $where = null; + // no limit + $limit = null; + + // add limitation and pagination + if ($bundle > 0) + { + // get the incremental number + $where = ['a.id' => [ + 'operator' => '>=', + 'value' => $this->next($table, $bundle) + ] + ]; + + // only return a limited number + $limit = $this->bundle; + } + + if (($items = $this->load->items( + $fields, // select + ['a' => $table], // tables + $where, + $order, + $limit + )) !== null) + { + // return found values + return $this->model->items($items, $table); + } + } + + return null; + } + + /** + * Get next id to call + * + * @param string $table The table + * @param int $bundle The bundle to return + * + * @return int + * @since 3.2.0 + */ + protected function next(string $table, int $bundle): int + { + if ($bundle == 1 || $bundle == 0) + { + return 1; + } + + if (($number = $this->model->last($table)) !== null) + { + return $number + 1; + } + + return $this->incremental($bundle); + } + + /** + * Get Incremental number where the set starts + * + * @param int $bundle The bundle to return + * + * @return int + * @since 3.2.0 + */ + protected function incremental(int $bundle): int + { + // just in case + if ($bundle == 1 || $bundle == 0) + { + return 1; + } + + /** Number two set starts at 301 + * 2 x 300 = 600 + * 600 - 300 = 300 + * 300 + 1 = 301 <-- + * Number five set starts at 1201 + * 5 x 300 = 1500 + * 1500 - 300 = 1200 + * 1200 + 1 = 1201 <-- + **/ + return (($bundle * $this->bundle) - $this->bundle) + 1; + } + + /** + * Get Fields ready to use in database call + * + * @param string $table The table which fields we want to get + * @param string $key The table key to which the fields belong + * @param bool $addId The switch to add ID + * + * @return array|null + * @since 3.2.0 + */ + protected function setDatabaseFields(string $table, string $key = 'a', bool $addId = true): ?array + { + if (($fields = $this->table->fields($table)) !== null) + { + // add the ID + if ($addId) + { + array_unshift($fields , 'id'); + } + + $bucket = []; + foreach ($fields as $field) + { + $bucket[$key . '.' . $field] = $field; + } + + return $bucket; + } + + return null; + } diff --git a/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/settings.json b/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/settings.json new file mode 100644 index 0000000..ff379a7 --- /dev/null +++ b/src/2dabfb4a-64cd-4c04-9772-4a75f9f3b710/settings.json @@ -0,0 +1,41 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "2dabfb4a-64cd-4c04-9772-4a75f9f3b710", + "implements": [ + "2bd1a32c-3d90-4646-9314-28d44d164f76" + ], + "load_selection": null, + "name": "Load", + "power_version": "1.0.0", + "system_name": "JCB.Search.Database.Load", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "as": "default" + }, + "use_selection1": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + }, + "use_selection2": { + "use": "bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8", + "as": "default" + }, + "use_selection3": { + "use": "f523ab49-907a-4356-b064-51c85a187fbd", + "as": "Model" + }, + "use_selection4": { + "use": "06f8eada-d59b-441c-b287-0aea1793da5a", + "as": "Database" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Database.Load", + "description": "Search Database Load\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\CMS\\Factory as JoomlaFactory;", + "composer": "" +} \ No newline at end of file diff --git a/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/README.md b/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/README.md new file mode 100644 index 0000000..6595e9c --- /dev/null +++ b/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/README.md @@ -0,0 +1,76 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Update (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Agent** +```uml +@startuml +class Update #Gold { + # SearchEngine $search + + __construct(?SearchEngine $search = null) + + value(mixed $value, mixed $line) : mixed + # updateValue(mixed $value, mixed $line) : mixed + # validateUpdateKey(int $line, mixed $keys = null, ...) : bool + # string(string $value, int $line) : string +} + +note right of Update::__construct + Constructor + + since: 3.2.0 +end note + +note right of Update::value + Update the value + + since: 3.2.0 + return: mixed +end note + +note right of Update::updateValue + Update all search-replace instances inside a value + + since: 3.2.0 + return: mixed +end note + +note right of Update::validateUpdateKey + Check if the keys are valid for search when working with arrays + + since: 3.2.0 + return: bool + + arguments: + int $line + mixed $keys = null + mixed $key = null + $ke = null + mixed $k = null +end note + +note right of Update::string + Update all search-replace instances inside a string + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/code.php b/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/code.php new file mode 100644 index 0000000..410366a --- /dev/null +++ b/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/code.php @@ -0,0 +1,236 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Agent; + + +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Componentbuilder\Search\Factory; +use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface as SearchEngine; + + +/** + * Search Agent Update + * + * @since 3.2.0 + */ +class Update +{ + /** + * Search Engine + * + * @var SearchEngine + * @since 3.2.0 + */ + protected SearchEngine $search; + + /** + * Constructor + * + * @param SearchEngine|null $search The search engine object. + * + * @since 3.2.0 + */ + public function __construct(?SearchEngine $search = null) + { + $this->search = $search ?: Factory::_('Search'); + } + + /** + * Update the value + * + * @param mixed $value The field value + * @param mixed $line The line to update (0 = all) + * + * @return mixed + * @since 3.2.0 + */ + public function value($value, $line = 0) + { + // update the value + $update = $this->updateValue($value, $line); + + // was anything updated + if ($value === $update) + { + return null; + } + + return $update; + } + + /** + * Update all search-replace instances inside a value + * + * @param mixed $value The field value + * @param mixed $line The line to update (0 = all) + * + * @return mixed + * @since 3.2.0 + */ + protected function updateValue($value, $line = 0) + { + // I know this is a little crazy... TODO refactor into recursion functions + // the possibility of updating sub-forms in sub-forms + if (ArrayHelper::check($value)) + { + if (strpos((string) $line, '.') !== false) + { + $line = explode('.', (string) $line); + } + // first layer + foreach ($value as $keys => &$rows) + { + if (ArrayHelper::check($rows)) + { + // second layer + foreach ($rows as $key => &$row) + { + if (ArrayHelper::check($row)) + { + // third layer + foreach ($row as $ke => &$ro) + { + if (ArrayHelper::check($ro)) + { + // forth layer + foreach ($ro as $k => &$r) + { + if (StringHelper::check($r) && + $this->validateUpdateKey($line, $keys, $key, $ke, $k)) + { + $_line = (isset($line[4])) ? $line[4] : 0; + $r = $this->string($r, $_line); + } + } + } + elseif (StringHelper::check($ro) && + $this->validateUpdateKey($line, $keys, $key, $ke)) + { + $_line = (isset($line[3])) ? $line[3] : 0; + $ro = $this->string($ro, $_line); + } + + } + } + elseif (StringHelper::check($row) && + $this->validateUpdateKey($line, $keys, $key)) + { + $_line = (isset($line[2])) ? $line[2] : 0; + $row = $this->string($row, $_line); + } + } + } + elseif (StringHelper::check($rows) && + $this->validateUpdateKey($line, $keys)) + { + $_line = (isset($line[1])) ? $line[1] : 0; + $rows = $this->string($rows, $_line); + } + } + } + elseif (StringHelper::check($value)) + { + $value = $this->string($value, $line); + } + + return $value; + } + + /** + * Check if the keys are valid for search when working with arrays + * + * @param int $line The lines array + * @param mixed $keys The line keys + * @param mixed $key The line key + * @param mixed $k The line ke + * @param mixed $k The line k + * + * @return bool + * @since 3.2.0 + */ + protected function validateUpdateKey($line, $keys = null, $key = null, $ke = null, $k = null): bool + { + if (ArrayHelper::check($line)) + { + $_keys = (isset($line[0])) ? $line[0] : null; + $_key = (isset($line[1])) ? $line[1] : null; + $_ke = (isset($line[2])) ? $line[2] : null; + $_k = (isset($line[3])) ? $line[3] : null; + + if ($keys && $_keys && $_keys !== $keys) + { + return false; + } + + if ($key && $_key && $_key !== $key) + { + return false; + } + + if ($ke && $_ke && $_ke !== $ke) + { + return false; + } + + if ($k && $_k && $_k !== $k) + { + return false; + } + } + + return true; + } + + /** + * Update all search-replace instances inside a string + * + * @param string $value The field value + * @param int $line The line to update (0 = all) + * + * @return string + * @since 3.2.0 + */ + protected function string(string $value, int $line = 0): string + { + // check if string has a new line + if (\preg_match('/\R/', $value) && $line > 0) + { + // line counter + $line_number = 1; + + $search_array = \preg_split('/\R/', $value); + + // loop over the lines + foreach ($search_array as $nr => $line_value) + { + if ($line_number == $line) + { + $search_array[$nr] = $this->search->replace($line_value); + + // since we are targeting on line (and possibly one number) + // this can only happen once, and so we return at this point + return implode(PHP_EOL, $search_array); + } + // next line + $line_number++; + } + + // no update took place so we just return the original value + return $value; + } + + return $this->search->replace($value); + } + +} + diff --git a/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/code.power b/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/code.power new file mode 100644 index 0000000..f85f407 --- /dev/null +++ b/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/code.power @@ -0,0 +1,206 @@ + /** + * Search Engine + * + * @var SearchEngine + * @since 3.2.0 + */ + protected SearchEngine $search; + + /** + * Constructor + * + * @param SearchEngine|null $search The search engine object. + * + * @since 3.2.0 + */ + public function __construct(?SearchEngine $search = null) + { + $this->search = $search ?: Factory::_('Search'); + } + + /** + * Update the value + * + * @param mixed $value The field value + * @param mixed $line The line to update (0 = all) + * + * @return mixed + * @since 3.2.0 + */ + public function value($value, $line = 0) + { + // update the value + $update = $this->updateValue($value, $line); + + // was anything updated + if ($value === $update) + { + return null; + } + + return $update; + } + + /** + * Update all search-replace instances inside a value + * + * @param mixed $value The field value + * @param mixed $line The line to update (0 = all) + * + * @return mixed + * @since 3.2.0 + */ + protected function updateValue($value, $line = 0) + { + // I know this is a little crazy... TODO refactor into recursion functions + // the possibility of updating sub-forms in sub-forms + if (ArrayHelper::check($value)) + { + if (strpos((string) $line, '.') !== false) + { + $line = explode('.', (string) $line); + } + // first layer + foreach ($value as $keys => &$rows) + { + if (ArrayHelper::check($rows)) + { + // second layer + foreach ($rows as $key => &$row) + { + if (ArrayHelper::check($row)) + { + // third layer + foreach ($row as $ke => &$ro) + { + if (ArrayHelper::check($ro)) + { + // forth layer + foreach ($ro as $k => &$r) + { + if (StringHelper::check($r) && + $this->validateUpdateKey($line, $keys, $key, $ke, $k)) + { + $_line = (isset($line[4])) ? $line[4] : 0; + $r = $this->string($r, $_line); + } + } + } + elseif (StringHelper::check($ro) && + $this->validateUpdateKey($line, $keys, $key, $ke)) + { + $_line = (isset($line[3])) ? $line[3] : 0; + $ro = $this->string($ro, $_line); + } + + } + } + elseif (StringHelper::check($row) && + $this->validateUpdateKey($line, $keys, $key)) + { + $_line = (isset($line[2])) ? $line[2] : 0; + $row = $this->string($row, $_line); + } + } + } + elseif (StringHelper::check($rows) && + $this->validateUpdateKey($line, $keys)) + { + $_line = (isset($line[1])) ? $line[1] : 0; + $rows = $this->string($rows, $_line); + } + } + } + elseif (StringHelper::check($value)) + { + $value = $this->string($value, $line); + } + + return $value; + } + + /** + * Check if the keys are valid for search when working with arrays + * + * @param int $line The lines array + * @param mixed $keys The line keys + * @param mixed $key The line key + * @param mixed $k The line ke + * @param mixed $k The line k + * + * @return bool + * @since 3.2.0 + */ + protected function validateUpdateKey($line, $keys = null, $key = null, $ke = null, $k = null): bool + { + if (ArrayHelper::check($line)) + { + $_keys = (isset($line[0])) ? $line[0] : null; + $_key = (isset($line[1])) ? $line[1] : null; + $_ke = (isset($line[2])) ? $line[2] : null; + $_k = (isset($line[3])) ? $line[3] : null; + + if ($keys && $_keys && $_keys !== $keys) + { + return false; + } + + if ($key && $_key && $_key !== $key) + { + return false; + } + + if ($ke && $_ke && $_ke !== $ke) + { + return false; + } + + if ($k && $_k && $_k !== $k) + { + return false; + } + } + + return true; + } + + /** + * Update all search-replace instances inside a string + * + * @param string $value The field value + * @param int $line The line to update (0 = all) + * + * @return string + * @since 3.2.0 + */ + protected function string(string $value, int $line = 0): string + { + // check if string has a new line + if (\preg_match('/\R/', $value) && $line > 0) + { + // line counter + $line_number = 1; + + $search_array = \preg_split('/\R/', $value); + + // loop over the lines + foreach ($search_array as $nr => $line_value) + { + if ($line_number == $line) + { + $search_array[$nr] = $this->search->replace($line_value); + + // since we are targeting on line (and possibly one number) + // this can only happen once, and so we return at this point + return implode(PHP_EOL, $search_array); + } + // next line + $line_number++; + } + + // no update took place so we just return the original value + return $value; + } + + return $this->search->replace($value); + } diff --git a/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/settings.json b/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/settings.json new file mode 100644 index 0000000..3040dea --- /dev/null +++ b/src/3ac29912-0681-4ca9-8197-d5a8f6a49ac7/settings.json @@ -0,0 +1,35 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "3ac29912-0681-4ca9-8197-d5a8f6a49ac7", + "implements": null, + "load_selection": null, + "name": "Update", + "power_version": "1.0.0", + "system_name": "JCB.Search.Agent.Update", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + }, + "use_selection1": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + }, + "use_selection2": { + "use": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "as": "default" + }, + "use_selection3": { + "use": "117d8c9e-3f8d-40ae-b375-1efa2fe5538a", + "as": "SearchEngine" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Agent.Update", + "description": "Search Agent Update\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/README.md b/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/README.md new file mode 100644 index 0000000..30fac5e --- /dev/null +++ b/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/README.md @@ -0,0 +1,62 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# interface InsertInterface (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Interfaces** +```uml +@startuml +interface InsertInterface #Lavender { + + value(mixed $value, int $id, ...) : bool + + item(object $item, ?string $table = null) : bool + + items(array $items, string $table = null) : bool +} + +note right of InsertInterface::value + Set values to a given table +Example: $this->value(Value, 23, 'value_key', 'table_name'); + + since: 3.2.0 + return: bool + + arguments: + mixed $value + int $id + string $field + ?string $table = null +end note + +note right of InsertInterface::item + Set values to a given table +Example: $this->item(Object, 23, 'table_name'); + + since: 3.2.0 + return: bool +end note + +note right of InsertInterface::items + Set values to a given table +Example: $this->items(Array, 'table_name'); + + since: 3.2.0 + return: bool +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/code.php b/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/code.php new file mode 100644 index 0000000..171b1e5 --- /dev/null +++ b/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/code.php @@ -0,0 +1,60 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Interfaces; + + +/** + * Search Database Insert Interface + * + * @since 3.2.0 + */ +interface InsertInterface +{ + /** + * Set values to a given table + * Example: $this->value(Value, 23, 'value_key', 'table_name'); + * + * @param mixed $value The field value + * @param int $id The item ID + * @param string $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function value($value, int $id, string $field, ?string $table = null): bool; + + /** + * Set values to a given table + * Example: $this->item(Object, 23, 'table_name'); + * + * @param object $item The item to save + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function item(object $item, ?string $table = null): bool; + + /** + * Set values to a given table + * Example: $this->items(Array, 'table_name'); + * + * @param array $items The items being saved + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function items(array $items, string $table = null): bool; +} + diff --git a/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/code.power b/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/code.power new file mode 100644 index 0000000..480eeaa --- /dev/null +++ b/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/code.power @@ -0,0 +1,37 @@ + /** + * Set values to a given table + * Example: $this->value(Value, 23, 'value_key', 'table_name'); + * + * @param mixed $value The field value + * @param int $id The item ID + * @param string $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function value($value, int $id, string $field, ?string $table = null): bool; + + /** + * Set values to a given table + * Example: $this->item(Object, 23, 'table_name'); + * + * @param object $item The item to save + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function item(object $item, ?string $table = null): bool; + + /** + * Set values to a given table + * Example: $this->items(Array, 'table_name'); + * + * @param array $items The items being saved + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function items(array $items, string $table = null): bool; \ No newline at end of file diff --git a/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/settings.json b/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/settings.json new file mode 100644 index 0000000..ae05314 --- /dev/null +++ b/src/4c44e5d3-750c-4609-88c8-aa441838b8fe/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "4c44e5d3-750c-4609-88c8-aa441838b8fe", + "implements": null, + "load_selection": null, + "name": "InsertInterface", + "power_version": "1.0.0", + "system_name": "JCB.Search.Interfaces.InsertInterface", + "type": "interface", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Interfaces.InsertInterface", + "description": "Search Database Insert Interface\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/55280ec7-e48d-431b-af25-10308dd30636/README.md b/src/55280ec7-e48d-431b-af25-10308dd30636/README.md new file mode 100644 index 0000000..fdecce7 --- /dev/null +++ b/src/55280ec7-e48d-431b-af25-10308dd30636/README.md @@ -0,0 +1,66 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# interface FindInterface (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Interfaces** +```uml +@startuml +interface FindInterface #Lavender { + + get(?string $table = null) : ?array + + item(object $item, ?int $id = null, ...) : void + + items(?array $items = null, ?string $table = null) : void + + reset(?string $table = null) : void +} + +note right of FindInterface::get + Get found values + + since: 3.2.0 + return: ?array +end note + +note right of FindInterface::item + Search over an item fields + + since: 3.2.0 + return: void + + arguments: + object $item + ?int $id = null + ?string $table = null +end note + +note right of FindInterface::items + Search over an array of items + + since: 3.2.0 + return: void +end note + +note right of FindInterface::reset + Reset all found values of a table + + since: 3.2.0 + return: void +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/55280ec7-e48d-431b-af25-10308dd30636/code.php b/src/55280ec7-e48d-431b-af25-10308dd30636/code.php new file mode 100644 index 0000000..ea34b2d --- /dev/null +++ b/src/55280ec7-e48d-431b-af25-10308dd30636/code.php @@ -0,0 +1,66 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Interfaces; + + +/** + * Search Find Interface + * + * @since 3.2.0 + */ +interface FindInterface +{ + /** + * Get found values + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(?string $table = null): ?array; + + /** + * Search over an item fields + * + * @param object $item The item object of fields to search through + * @param int|null $id The item id + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function item(object $item, ?int $id =null, ?string $table = null); + + /** + * Search over an array of items + * + * @param array|null $items The array of items to search through + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null); + + /** + * Reset all found values of a table + * + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(?string $table = null); + +} + diff --git a/src/55280ec7-e48d-431b-af25-10308dd30636/code.power b/src/55280ec7-e48d-431b-af25-10308dd30636/code.power new file mode 100644 index 0000000..6558207 --- /dev/null +++ b/src/55280ec7-e48d-431b-af25-10308dd30636/code.power @@ -0,0 +1,42 @@ + /** + * Get found values + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(?string $table = null): ?array; + + /** + * Search over an item fields + * + * @param object $item The item object of fields to search through + * @param int|null $id The item id + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function item(object $item, ?int $id =null, ?string $table = null); + + /** + * Search over an array of items + * + * @param array|null $items The array of items to search through + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null); + + /** + * Reset all found values of a table + * + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(?string $table = null); diff --git a/src/55280ec7-e48d-431b-af25-10308dd30636/settings.json b/src/55280ec7-e48d-431b-af25-10308dd30636/settings.json new file mode 100644 index 0000000..f662176 --- /dev/null +++ b/src/55280ec7-e48d-431b-af25-10308dd30636/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "55280ec7-e48d-431b-af25-10308dd30636", + "implements": null, + "load_selection": null, + "name": "FindInterface", + "power_version": "1.0.0", + "system_name": "JCB.Search.Interfaces.FindInterface", + "type": "interface", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Interfaces.FindInterface", + "description": "Search Find Interface\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/6caf9473-133c-49a9-afa0-9f84151b5155/README.md b/src/6caf9473-133c-49a9-afa0-9f84151b5155/README.md new file mode 100644 index 0000000..5b44fa8 --- /dev/null +++ b/src/6caf9473-133c-49a9-afa0-9f84151b5155/README.md @@ -0,0 +1,79 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Insert (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Database** +```uml +@startuml +class Insert #Gold { + # Config $config + # Table $table + # Model $model + # \JDatabaseDriver $db + + __construct(?Config $config = null, ?Table $table = null, ...) + + value(mixed $value, int $id, ...) : bool + + item(object $item, ?string $table = null) : bool + + items(?array $items, string $table = null) : bool +} + +note right of Insert::__construct + Constructor + + since: 3.2.0 + + arguments: + ?Config $config = null + ?Table $table = null + ?Model $model = null + ?\JDatabaseDriver $db = null +end note + +note right of Insert::value + Set values to a given table +Example: $this->value(Value, 23, 'value_key', 'table_name'); + + since: 3.2.0 + return: bool + + arguments: + mixed $value + int $id + string $field + ?string $table = null +end note + +note right of Insert::item + Set values to a given table +Example: $this->item(Object, 'table_name'); + + since: 3.2.0 + return: bool +end note + +note right of Insert::items + Set values to a given table +Example: $this->items(Array, 'table_name'); + + since: 3.2.0 + return: bool +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/6caf9473-133c-49a9-afa0-9f84151b5155/code.php b/src/6caf9473-133c-49a9-afa0-9f84151b5155/code.php new file mode 100644 index 0000000..afce63c --- /dev/null +++ b/src/6caf9473-133c-49a9-afa0-9f84151b5155/code.php @@ -0,0 +1,188 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Database; + + +use Joomla\CMS\Factory as JoomlaFactory; +use VDM\Joomla\Componentbuilder\Search\Factory; +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Componentbuilder\Table; +use VDM\Joomla\Componentbuilder\Search\Model\Insert as Model; +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Componentbuilder\Search\Interfaces\InsertInterface; + + +/** + * Search Database Set + * + * @since 3.2.0 + */ +class Insert implements InsertInterface +{ + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search Table + * + * @var Table + * @since 3.2.0 + */ + protected Table $table; + + /** + * Search Model + * + * @var Model + * @since 3.2.0 + */ + protected Model $model; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Table|null $table The search table object. + * @param Model|null $model The search get model object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Table $table = null, + ?Model $model = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->table = $table ?: Factory::_('Table'); + $this->model = $model ?: Factory::_('Insert.Model'); + $this->db = $db ?: JoomlaFactory::getDbo(); + } + + /** + * Set values to a given table + * Example: $this->value(Value, 23, 'value_key', 'table_name'); + * + * @param mixed $value The field value + * @param int $id The item ID + * @param string $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function value($value, int $id, string $field, ?string $table = null): bool + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid field and table + if ($id > 0 && ($name = $this->table->get($table, $field, 'name')) !== null) + { + // build the object + $item = new \stdClass(); + $item->id = $id; + $item->{$name} = $this->model->value($value, $name, $table); + + // Update the column of this table using id as the primary key. + return $this->db->updateObject('#__componentbuilder_' . $table, $item, 'id'); + } + return false; + } + + /** + * Set values to a given table + * Example: $this->item(Object, 'table_name'); + * + * @param object $item The item to save + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function item(object $item, ?string $table = null): bool + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid table + if (($fields = $this->table->fields($table)) !== null) + { + // model the item values + foreach ($fields as $field) + { + if (isset($item->{$field})) + { + $item->{$field} = $this->model->value($item->{$field}, $field, $table); + } + } + + // Update the column of this table using id as the primary key. + return $this->db->updateObject('#__componentbuilder_' . $table, $item, 'id'); + } + return false; + } + + /** + * Set values to a given table + * Example: $this->items(Array, 'table_name'); + * + * @param array|null $items The items being saved + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function items(?array $items, string $table = null): bool + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid table + if (ArrayHelper::check($items)) + { + $success = true; + foreach ($items as $item) + { + if (!$this->item($item, $table)) + { + $success = false; + break; + } + } + return $success; + } + return false; + } + +} + diff --git a/src/6caf9473-133c-49a9-afa0-9f84151b5155/code.power b/src/6caf9473-133c-49a9-afa0-9f84151b5155/code.power new file mode 100644 index 0000000..4005126 --- /dev/null +++ b/src/6caf9473-133c-49a9-afa0-9f84151b5155/code.power @@ -0,0 +1,155 @@ + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search Table + * + * @var Table + * @since 3.2.0 + */ + protected Table $table; + + /** + * Search Model + * + * @var Model + * @since 3.2.0 + */ + protected Model $model; + + /** + * Database object to query local DB + * + * @var \JDatabaseDriver + * @since 3.2.0 + **/ + protected \JDatabaseDriver $db; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Table|null $table The search table object. + * @param Model|null $model The search get model object. + * @param \JDatabaseDriver|null $db The database object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Table $table = null, + ?Model $model = null, ?\JDatabaseDriver $db = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->table = $table ?: Factory::_('Table'); + $this->model = $model ?: Factory::_('Insert.Model'); + $this->db = $db ?: JoomlaFactory::getDbo(); + } + + /** + * Set values to a given table + * Example: $this->value(Value, 23, 'value_key', 'table_name'); + * + * @param mixed $value The field value + * @param int $id The item ID + * @param string $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function value($value, int $id, string $field, ?string $table = null): bool + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid field and table + if ($id > 0 && ($name = $this->table->get($table, $field, 'name')) !== null) + { + // build the object + $item = new \stdClass(); + $item->id = $id; + $item->{$name} = $this->model->value($value, $name, $table); + + // Update the column of this table using id as the primary key. + return $this->db->updateObject('#__componentbuilder_' . $table, $item, 'id'); + } + return false; + } + + /** + * Set values to a given table + * Example: $this->item(Object, 'table_name'); + * + * @param object $item The item to save + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function item(object $item, ?string $table = null): bool + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid table + if (($fields = $this->table->fields($table)) !== null) + { + // model the item values + foreach ($fields as $field) + { + if (isset($item->{$field})) + { + $item->{$field} = $this->model->value($item->{$field}, $field, $table); + } + } + + // Update the column of this table using id as the primary key. + return $this->db->updateObject('#__componentbuilder_' . $table, $item, 'id'); + } + return false; + } + + /** + * Set values to a given table + * Example: $this->items(Array, 'table_name'); + * + * @param array|null $items The items being saved + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + public function items(?array $items, string $table = null): bool + { + // load the table + if (empty($table)) + { + $table = $this->config->table_name; + } + + // check if this is a valid table + if (ArrayHelper::check($items)) + { + $success = true; + foreach ($items as $item) + { + if (!$this->item($item, $table)) + { + $success = false; + break; + } + } + return $success; + } + return false; + } diff --git a/src/6caf9473-133c-49a9-afa0-9f84151b5155/settings.json b/src/6caf9473-133c-49a9-afa0-9f84151b5155/settings.json new file mode 100644 index 0000000..7f51664 --- /dev/null +++ b/src/6caf9473-133c-49a9-afa0-9f84151b5155/settings.json @@ -0,0 +1,41 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "6caf9473-133c-49a9-afa0-9f84151b5155", + "implements": [ + "4c44e5d3-750c-4609-88c8-aa441838b8fe" + ], + "load_selection": null, + "name": "Insert", + "power_version": "1.0.0", + "system_name": "JCB.Search.Database.Insert", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "as": "default" + }, + "use_selection1": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + }, + "use_selection2": { + "use": "bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8", + "as": "default" + }, + "use_selection3": { + "use": "02efe40a-7792-4c82-9444-7d0377243483", + "as": "Model" + }, + "use_selection4": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Database.Insert", + "description": "Search Database Set\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\CMS\\Factory as JoomlaFactory;", + "composer": "" +} \ No newline at end of file diff --git a/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/README.md b/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/README.md new file mode 100644 index 0000000..0700b36 --- /dev/null +++ b/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/README.md @@ -0,0 +1,141 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Config (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search** +```uml +@startuml +class Config #Gold { + # getTypesearch() : ?int + # getSearchvalue() : ?string + # getReplacevalue() : string + # getMatchcase() : int + # getWholeword() : int + # getRegexsearch() : int + # getComponentid() : int + # getTablename() : ?string + # getFieldname() : ?string + # getItemid() : int + # getFieldcounter() : int + # getLinecounter() : int + # getMarkerstart() : string + # getMarkerend() : string +} + +note right of Config::getTypesearch + get type search being preformed + + since: 3.2.0 + return: ?int +end note + +note left of Config::getSearchvalue + get posted search value + + since: 3.2.0 + return: ?string +end note + +note right of Config::getReplacevalue + get posted replace value + + since: 3.2.0 + return: string +end note + +note left of Config::getMatchcase + get posted search match case + + since: 3.2.0 + return: int +end note + +note right of Config::getWholeword + get posted search whole word + + since: 3.2.0 + return: int +end note + +note left of Config::getRegexsearch + get posted search regex + + since: 3.2.0 + return: int +end note + +note right of Config::getComponentid + get posted component + + since: 3.2.0 + return: int +end note + +note left of Config::getTablename + get posted area/table + + since: 3.2.0 + return: ?string +end note + +note right of Config::getFieldname + get posted field + + since: 3.2.0 + return: ?string +end note + +note left of Config::getItemid + get posted item id + + since: 3.2.0 + return: int +end note + +note right of Config::getFieldcounter + get field counter + + since: 3.2.0 + return: int +end note + +note left of Config::getLinecounter + get line counter + + since: 3.2.0 + return: int +end note + +note right of Config::getMarkerstart + get the start marker + + since: 3.2.0 + return: string +end note + +note left of Config::getMarkerend + get the end marker + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/code.php b/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/code.php new file mode 100644 index 0000000..004d4c7 --- /dev/null +++ b/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/code.php @@ -0,0 +1,180 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search; + + +use VDM\Joomla\Componentbuilder\Abstraction\BaseConfig; + + +/** + * Search Configurations + * + * @since 3.2.0 + */ +class Config extends BaseConfig +{ + /** + * get type search being preformed + * + * @return int the search type 1 = search, 2 = search & replace + * @since 3.2.0 + */ + protected function getTypesearch(): ?int + { + return $this->input->get('type_search', 1, 'INT'); + } + + /** + * get posted search value + * + * @return string|null Raw search value + * @since 3.2.0 + */ + protected function getSearchvalue(): ?string + { + return $this->input->get('search_value', null, 'RAW'); + } + + /** + * get posted replace value + * + * @return string Raw replace value + * @since 3.2.0 + */ + protected function getReplacevalue(): string + { + return $this->input->get('replace_value', '', 'RAW'); + } + + /** + * get posted search match case + * + * @return int Match case + * @since 3.2.0 + */ + protected function getMatchcase(): int + { + return $this->input->get('match_case', 0, 'INT'); + } + + /** + * get posted search whole word + * + * @return int Whole word + * @since 3.2.0 + */ + protected function getWholeword(): int + { + return $this->input->get('whole_word', 0, 'INT'); + } + + /** + * get posted search regex + * + * @return int Regex + * @since 3.2.0 + */ + protected function getRegexsearch(): int + { + return $this->input->get('regex_search', 0, 'INT'); + } + + /** + * get posted component + * + * @return int Component ID + * @since 3.2.0 + */ + protected function getComponentid(): int + { + return $this->input->get('component_id', 0, 'INT'); + } + + /** + * get posted area/table + * + * @return string|null Table name + * @since 3.2.0 + */ + protected function getTablename(): ?string + { + return $this->input->get('table_name', null, 'word'); + } + + /** + * get posted field + * + * @return string|null Field name + * @since 3.2.0 + */ + protected function getFieldname(): ?string + { + return $this->input->get('field_name', null, 'word'); + } + + /** + * get posted item id + * + * @return int Item id + * @since 3.2.0 + */ + protected function getItemid(): int + { + return $this->input->get('item_id', 0, 'INT'); + } + + /** + * get field counter + * + * @return int we start at 0 + * @since 3.2.0 + */ + protected function getFieldcounter(): int + { + return 0; + } + + /** + * get line counter + * + * @return int we start at 0 + * @since 3.2.0 + */ + protected function getLinecounter(): int + { + return 0; + } + + /** + * get the start marker + * + * @return string The string to use as the start marker + * @since 3.2.0 + */ + protected function getMarkerstart(): string + { + return '{+' . '|' . '=['; + } + + /** + * get the end marker + * + * @return string The string to use as the end marker + * @since 3.2.0 + */ + protected function getMarkerend(): string + { + return ']=' . '|' . '+}'; + } + +} + diff --git a/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/code.power b/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/code.power new file mode 100644 index 0000000..6275792 --- /dev/null +++ b/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/code.power @@ -0,0 +1,153 @@ + /** + * get type search being preformed + * + * @return int the search type 1 = search, 2 = search & replace + * @since 3.2.0 + */ + protected function getTypesearch(): ?int + { + return $this->input->get('type_search', 1, 'INT'); + } + + /** + * get posted search value + * + * @return string|null Raw search value + * @since 3.2.0 + */ + protected function getSearchvalue(): ?string + { + return $this->input->get('search_value', null, 'RAW'); + } + + /** + * get posted replace value + * + * @return string Raw replace value + * @since 3.2.0 + */ + protected function getReplacevalue(): string + { + return $this->input->get('replace_value', '', 'RAW'); + } + + /** + * get posted search match case + * + * @return int Match case + * @since 3.2.0 + */ + protected function getMatchcase(): int + { + return $this->input->get('match_case', 0, 'INT'); + } + + /** + * get posted search whole word + * + * @return int Whole word + * @since 3.2.0 + */ + protected function getWholeword(): int + { + return $this->input->get('whole_word', 0, 'INT'); + } + + /** + * get posted search regex + * + * @return int Regex + * @since 3.2.0 + */ + protected function getRegexsearch(): int + { + return $this->input->get('regex_search', 0, 'INT'); + } + + /** + * get posted component + * + * @return int Component ID + * @since 3.2.0 + */ + protected function getComponentid(): int + { + return $this->input->get('component_id', 0, 'INT'); + } + + /** + * get posted area/table + * + * @return string|null Table name + * @since 3.2.0 + */ + protected function getTablename(): ?string + { + return $this->input->get('table_name', null, 'word'); + } + + /** + * get posted field + * + * @return string|null Field name + * @since 3.2.0 + */ + protected function getFieldname(): ?string + { + return $this->input->get('field_name', null, 'word'); + } + + /** + * get posted item id + * + * @return int Item id + * @since 3.2.0 + */ + protected function getItemid(): int + { + return $this->input->get('item_id', 0, 'INT'); + } + + /** + * get field counter + * + * @return int we start at 0 + * @since 3.2.0 + */ + protected function getFieldcounter(): int + { + return 0; + } + + /** + * get line counter + * + * @return int we start at 0 + * @since 3.2.0 + */ + protected function getLinecounter(): int + { + return 0; + } + + /** + * get the start marker + * + * @return string The string to use as the start marker + * @since 3.2.0 + */ + protected function getMarkerstart(): string + { + return '{+' . '|' . '=['; + } + + /** + * get the end marker + * + * @return string The string to use as the end marker + * @since 3.2.0 + */ + protected function getMarkerend(): string + { + return ']=' . '|' . '+}'; + } diff --git a/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/settings.json b/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/settings.json new file mode 100644 index 0000000..3faf8e7 --- /dev/null +++ b/src/6e2ca779-f70e-4871-a138-0ee5eaec6a97/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "9769f3b2-17bf-4f20-b54b-3a4ebe572b36", + "guid": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "implements": null, + "load_selection": null, + "name": "Config", + "power_version": "1.0.0", + "system_name": "JCB.Search.Config", + "type": "class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Config", + "description": "Search Configurations\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/README.md b/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/README.md new file mode 100644 index 0000000..9e914b0 --- /dev/null +++ b/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/README.md @@ -0,0 +1,53 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Model (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Service** +```uml +@startuml +class Model #Gold { + + register(Container $container) : void + + getModelLoad(Container $container) : Load + + getModelInsert(Container $container) : Insert +} + +note right of Model::register + Registers the service provider with a DI container. + + since: 3.2.0 + return: void +end note + +note right of Model::getModelLoad + Get the Load Model + + since: 3.2.0 + return: Load +end note + +note right of Model::getModelInsert + Get the Insert Model + + since: 3.2.0 + return: Insert +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/code.php b/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/code.php new file mode 100644 index 0000000..968001f --- /dev/null +++ b/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/code.php @@ -0,0 +1,77 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Service; + + +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use VDM\Joomla\Componentbuilder\Search\Model\Load; +use VDM\Joomla\Componentbuilder\Search\Model\Insert; + + +/** + * Model Service Provider + * + * @since 3.2.0 + */ +class Model implements ServiceProviderInterface +{ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Load::class, 'Load.Model') + ->share('Load.Model', [$this, 'getModelLoad'], true); + $container->alias(Insert::class, 'Insert.Model') + ->share('Insert.Model', [$this, 'getModelInsert'], true); + } + + /** + * Get the Load Model + * + * @param Container $container The DI container. + * + * @return Load + * @since 3.2.0 + */ + public function getModelLoad(Container $container): Load + { + return new Load( + $container->get('Config'), + $container->get('Table') + ); + } + + /** + * Get the Insert Model + * + * @param Container $container The DI container. + * + * @return Insert + * @since 3.2.0 + */ + public function getModelInsert(Container $container): Insert + { + return new Insert( + $container->get('Config'), + $container->get('Table') + ); + } + +} + diff --git a/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/code.power b/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/code.power new file mode 100644 index 0000000..5da921a --- /dev/null +++ b/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/code.power @@ -0,0 +1,47 @@ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Load::class, 'Load.Model') + ->share('Load.Model', [$this, 'getModelLoad'], true); + $container->alias(Insert::class, 'Insert.Model') + ->share('Insert.Model', [$this, 'getModelInsert'], true); + } + + /** + * Get the Load Model + * + * @param Container $container The DI container. + * + * @return Load + * @since 3.2.0 + */ + public function getModelLoad(Container $container): Load + { + return new Load( + $container->get('Config'), + $container->get('Table') + ); + } + + /** + * Get the Insert Model + * + * @param Container $container The DI container. + * + * @return Insert + * @since 3.2.0 + */ + public function getModelInsert(Container $container): Insert + { + return new Insert( + $container->get('Config'), + $container->get('Table') + ); + } diff --git a/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/settings.json b/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/settings.json new file mode 100644 index 0000000..c31c7ae --- /dev/null +++ b/src/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a/settings.json @@ -0,0 +1,30 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a", + "implements": [ + "-1" + ], + "load_selection": null, + "name": "Model", + "power_version": "1.0.0", + "system_name": "JCB.Search.Service.Model", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "f523ab49-907a-4356-b064-51c85a187fbd", + "as": "default" + }, + "use_selection1": { + "use": "02efe40a-7792-4c82-9444-7d0377243483", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Service.Model", + "description": "Model Service Provider\r\n\r\n@since 3.2.0", + "implements_custom": "ServiceProviderInterface", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\DI\\Container;\r\nuse Joomla\\DI\\ServiceProviderInterface;", + "composer": "" +} \ No newline at end of file diff --git a/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/README.md b/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/README.md new file mode 100644 index 0000000..1460abe --- /dev/null +++ b/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/README.md @@ -0,0 +1,61 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Regex (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Engine** +```uml +@startuml +class Regex #Gold { + # string $regexValue + + __construct(?Config $config = null) + + string(string $value) : ?string + + replace(string $value) : string + + match(string $value) : bool +} + +note right of Regex::__construct + Constructor + + since: 3.2.0 +end note + +note right of Regex::string + Search inside a string + + since: 3.2.0 + return: ?string +end note + +note right of Regex::replace + Replace found instances inside string value + + since: 3.2.0 + return: string +end note + +note right of Regex::match + Math the Regular Expression + + since: 3.0.9 + return: bool +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/code.php b/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/code.php new file mode 100644 index 0000000..58c07c9 --- /dev/null +++ b/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/code.php @@ -0,0 +1,128 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Engine; + + +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface; +use VDM\Joomla\Componentbuilder\Search\Abstraction\Engine; + + +/** + * Search Type Regex + * + * @since 3.2.0 + */ +class Regex extends Engine implements SearchTypeInterface +{ + /** + * Regex Search Value + * + * @var string + * @since 3.2.0 + */ + protected string $regexValue = ''; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null) + { + parent::__construct($config); + + // set search based on match case + $case = ''; + if ($this->matchCase == 0) + { + $case = 'i'; + } + + $this->regexValue = "/(" . $this->searchValue . ")/" . $case; + } + + /** + * Search inside a string + * + * @param string $value The string value + * + * @return string|null The marked string if found, else null + * @since 3.2.0 + */ + public function string(string $value): ?string + { + // we count every line + $this->lineCounter(); + + if (StringHelper::check($this->searchValue) && $this->match($value)) + { + return trim(preg_replace( + $this->regexValue . 'm', + $this->start . "$1" . $this->end, + $value + )); + } + + return null; + } + + /** + * Replace found instances inside string value + * + * @param string $value The string value to update + * + * @return string The updated string + * @since 3.2.0 + */ + public function replace(string $value): string + { + if (StringHelper::check($this->searchValue) && $this->match($value)) + { + return preg_replace( + $this->regexValue . 'm', + (string) $this->replaceValue, + $value + ); + } + + return $value; + } + + /** + * Math the Regular Expression + * + * @param string $value The string value + * + * @return bool true if match is found + * @since 3.0.9 + */ + public function match(string $value): bool + { + $match = []; + + preg_match($this->regexValue, $value, $match); + + $match = array_filter( + $match, + fn($found) => !empty($found) + ); + + return (bool) ArrayHelper::check($match); + } + +} + diff --git a/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/code.power b/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/code.power new file mode 100644 index 0000000..3bccf29 --- /dev/null +++ b/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/code.power @@ -0,0 +1,97 @@ + /** + * Regex Search Value + * + * @var string + * @since 3.2.0 + */ + protected string $regexValue = ''; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null) + { + parent::__construct($config); + + // set search based on match case + $case = ''; + if ($this->matchCase == 0) + { + $case = 'i'; + } + + $this->regexValue = "/(" . $this->searchValue . ")/" . $case; + } + + /** + * Search inside a string + * + * @param string $value The string value + * + * @return string|null The marked string if found, else null + * @since 3.2.0 + */ + public function string(string $value): ?string + { + // we count every line + $this->lineCounter(); + + if (StringHelper::check($this->searchValue) && $this->match($value)) + { + return trim(preg_replace( + $this->regexValue . 'm', + $this->start . "$1" . $this->end, + $value + )); + } + + return null; + } + + /** + * Replace found instances inside string value + * + * @param string $value The string value to update + * + * @return string The updated string + * @since 3.2.0 + */ + public function replace(string $value): string + { + if (StringHelper::check($this->searchValue) && $this->match($value)) + { + return preg_replace( + $this->regexValue . 'm', + (string) $this->replaceValue, + $value + ); + } + + return $value; + } + + /** + * Math the Regular Expression + * + * @param string $value The string value + * + * @return bool true if match is found + * @since 3.0.9 + */ + public function match(string $value): bool + { + $match = []; + + preg_match($this->regexValue, $value, $match); + + $match = array_filter( + $match, + fn($found) => !empty($found) + ); + + return (bool) ArrayHelper::check($match); + } diff --git a/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/settings.json b/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/settings.json new file mode 100644 index 0000000..225c21b --- /dev/null +++ b/src/83efa9a0-4aec-41f8-9c05-b1ac9617746e/settings.json @@ -0,0 +1,33 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "8f9449fc-bfbc-49a5-b146-d58c8c17dfdf", + "guid": "83efa9a0-4aec-41f8-9c05-b1ac9617746e", + "implements": [ + "117d8c9e-3f8d-40ae-b375-1efa2fe5538a" + ], + "load_selection": null, + "name": "Regex", + "power_version": "1.0.0", + "system_name": "JCB.Search.Engine.Regex", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + }, + "use_selection1": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + }, + "use_selection2": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Engine.Regex", + "description": "Search Type Regex\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/README.md b/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/README.md new file mode 100644 index 0000000..44e107a --- /dev/null +++ b/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/README.md @@ -0,0 +1,50 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class Engine (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Abstraction** +```uml +@startuml +abstract Engine #Orange { + # Config $config + # ?string $searchValue + # string $replaceValue + # int $matchCase + # int $wholeWord + # string $start + # string $end + + __construct(?Config $config = null) + # lineCounter() +} + +note right of Engine::__construct + Constructor + + since: 3.2.0 +end note + +note right of Engine::lineCounter + we count every line being searched + + since: 3.2.0 +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/code.php b/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/code.php new file mode 100644 index 0000000..a15b48d --- /dev/null +++ b/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/code.php @@ -0,0 +1,123 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Abstraction; + + +use VDM\Joomla\Componentbuilder\Search\Factory; +use VDM\Joomla\Componentbuilder\Search\Config; + + +/** + * Search Engine + * + * @since 3.2.0 + */ +abstract class Engine +{ + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search Value + * + * @var string|null + * @since 3.2.0 + */ + protected ?string $searchValue; + + /** + * Replace Value + * + * @var string + * @since 3.2.0 + */ + protected string $replaceValue; + + /** + * Search Should Match Case + * + * @var int + * @since 3.2.0 + */ + protected int $matchCase = 0; + + /** + * Search Should Match Whole Word + * + * @var int + * @since 3.2.0 + */ + protected int $wholeWord = 0; + + /** + * Start marker + * + * @var string + * @since 3.2.0 + */ + protected string $start = ''; + + /** + * End marker + * + * @var string + * @since 3.2.0 + */ + protected string $end = ''; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null) + { + $this->config = $config ?: Factory::_('Config'); + + // set search value + $this->searchValue = $this->config->search_value; + + // set replace value + $this->replaceValue = $this->config->replace_value; + + // set match case + $this->matchCase = $this->config->match_case; + + // set whole word + $this->wholeWord = $this->config->whole_word; + + // set start marker + $this->start = $this->config->marker_start; + + // set end marker + $this->end = $this->config->marker_end; + } + + /** + * we count every line being searched + * + * @since 3.2.0 + */ + protected function lineCounter() + { + // we count every line we search + $this->config->line_counter += 1; + } +} + diff --git a/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/code.power b/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/code.power new file mode 100644 index 0000000..03b7296 --- /dev/null +++ b/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/code.power @@ -0,0 +1,96 @@ + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search Value + * + * @var string|null + * @since 3.2.0 + */ + protected ?string $searchValue; + + /** + * Replace Value + * + * @var string + * @since 3.2.0 + */ + protected string $replaceValue; + + /** + * Search Should Match Case + * + * @var int + * @since 3.2.0 + */ + protected int $matchCase = 0; + + /** + * Search Should Match Whole Word + * + * @var int + * @since 3.2.0 + */ + protected int $wholeWord = 0; + + /** + * Start marker + * + * @var string + * @since 3.2.0 + */ + protected string $start = ''; + + /** + * End marker + * + * @var string + * @since 3.2.0 + */ + protected string $end = ''; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null) + { + $this->config = $config ?: Factory::_('Config'); + + // set search value + $this->searchValue = $this->config->search_value; + + // set replace value + $this->replaceValue = $this->config->replace_value; + + // set match case + $this->matchCase = $this->config->match_case; + + // set whole word + $this->wholeWord = $this->config->whole_word; + + // set start marker + $this->start = $this->config->marker_start; + + // set end marker + $this->end = $this->config->marker_end; + } + + /** + * we count every line being searched + * + * @since 3.2.0 + */ + protected function lineCounter() + { + // we count every line we search + $this->config->line_counter += 1; + } \ No newline at end of file diff --git a/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/settings.json b/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/settings.json new file mode 100644 index 0000000..216441e --- /dev/null +++ b/src/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf/settings.json @@ -0,0 +1,27 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "8f9449fc-bfbc-49a5-b146-d58c8c17dfdf", + "implements": null, + "load_selection": null, + "name": "Engine", + "power_version": "1.0.0", + "system_name": "JCB.Search.Abstraction.Engine", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "as": "default" + }, + "use_selection1": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Abstraction.Engine", + "description": "Search Engine\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/README.md b/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/README.md new file mode 100644 index 0000000..f2179df --- /dev/null +++ b/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/README.md @@ -0,0 +1,76 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Replace (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Agent** +```uml +@startuml +class Replace #Gold { + # array $updated + # Config $config + # Update $update + + __construct(?Config $config = null, ?Update $update = null) + + get(?string $table = null) : ?array + + item(object $item, ?int $id = null, ...) : void + + items(?array $items = null, ?string $table = null) : void + + reset(?string $table = null) : void +} + +note right of Replace::__construct + Constructor + + since: 3.2.0 +end note + +note right of Replace::get + Get updated values + + since: 3.2.0 + return: ?array +end note + +note right of Replace::item + Search over an item fields + + since: 3.2.0 + return: void + + arguments: + object $item + ?int $id = null + ?string $table = null +end note + +note right of Replace::items + Search over an array of items + + since: 3.2.0 + return: void +end note + +note right of Replace::reset + Reset all updated values of a table + + since: 3.2.0 + return: void +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/code.php b/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/code.php new file mode 100644 index 0000000..2fd4bae --- /dev/null +++ b/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/code.php @@ -0,0 +1,181 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Agent; + + +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Utilities\ObjectHelper; +use VDM\Joomla\Componentbuilder\Search\Factory; +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Componentbuilder\Search\Agent\Update; +use VDM\Joomla\Componentbuilder\Search\Interfaces\ReplaceInterface; + + +/** + * Search Agent Replace + * + * @since 3.2.0 + */ +class Replace implements ReplaceInterface +{ + /** + * Updated Values + * + * @var array + * @since 3.2.0 + */ + protected array $updated = []; + + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Update + * + * @var Update + * @since 3.2.0 + */ + protected Update $update; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Update|null $update The update object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Update $update = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->update = $update ?: Factory::_('Agent.Update'); + } + + /** + * Get updated values + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(?string $table = null): ?array + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if (isset($this->updated[$table])) + { + return $this->updated[$table]; + } + + return null; + } + + /** + * Search over an item fields + * + * @param object $item The item object of fields to search through + * @param int|null $id The item id + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function item(object $item, ?int $id =null, ?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + // set the item id + if (empty($id)) + { + $id = $item->id; + } + + if (ObjectHelper::check($item)) + { + foreach ($item as $field => $value) + { + if ($field !== 'id' && ($_value = $this->update->value($value)) !== null) + { + if (empty($this->updated[$table][$id])) + { + $this->updated[$table][$id] = new \stdClass(); + $this->updated[$table][$id]->id = $id; + } + // add updated value + $this->updated[$table][$id]->{$field} = $_value; + } + } + } + } + + /** + * Search over an array of items + * + * @param array|null $items The array of items to search through + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if (ArrayHelper::check($items)) + { + foreach ($items as $id => $item) + { + $this->item($item, $id, $table); + } + } + } + + /** + * Reset all updated values of a table + * + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + // empty or unset the table active values + unset($this->updated[$table]); + } + +} + diff --git a/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/code.power b/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/code.power new file mode 100644 index 0000000..f3ff1a3 --- /dev/null +++ b/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/code.power @@ -0,0 +1,149 @@ + /** + * Updated Values + * + * @var array + * @since 3.2.0 + */ + protected array $updated = []; + + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Update + * + * @var Update + * @since 3.2.0 + */ + protected Update $update; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Update|null $update The update object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Update $update = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->update = $update ?: Factory::_('Agent.Update'); + } + + /** + * Get updated values + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(?string $table = null): ?array + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if (isset($this->updated[$table])) + { + return $this->updated[$table]; + } + + return null; + } + + /** + * Search over an item fields + * + * @param object $item The item object of fields to search through + * @param int|null $id The item id + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function item(object $item, ?int $id =null, ?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + // set the item id + if (empty($id)) + { + $id = $item->id; + } + + if (ObjectHelper::check($item)) + { + foreach ($item as $field => $value) + { + if ($field !== 'id' && ($_value = $this->update->value($value)) !== null) + { + if (empty($this->updated[$table][$id])) + { + $this->updated[$table][$id] = new \stdClass(); + $this->updated[$table][$id]->id = $id; + } + // add updated value + $this->updated[$table][$id]->{$field} = $_value; + } + } + } + } + + /** + * Search over an array of items + * + * @param array|null $items The array of items to search through + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + if (ArrayHelper::check($items)) + { + foreach ($items as $id => $item) + { + $this->item($item, $id, $table); + } + } + } + + /** + * Reset all updated values of a table + * + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(?string $table = null) + { + // set the table name + if (empty($table)) + { + $table = $this->config->table_name; + } + + // empty or unset the table active values + unset($this->updated[$table]); + } diff --git a/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/settings.json b/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/settings.json new file mode 100644 index 0000000..4061b1e --- /dev/null +++ b/src/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7/settings.json @@ -0,0 +1,41 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7", + "implements": [ + "afdae35d-fe7f-4055-99ea-afd8ff8349b6" + ], + "load_selection": null, + "name": "Replace", + "power_version": "1.0.0", + "system_name": "JCB.Search.Agent.Replace", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + }, + "use_selection1": { + "use": "91004529-94a9-4590-b842-e7c6b624ecf5", + "as": "default" + }, + "use_selection2": { + "use": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "as": "default" + }, + "use_selection3": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + }, + "use_selection4": { + "use": "3ac29912-0681-4ca9-8197-d5a8f6a49ac7", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Agent.Replace", + "description": "Search Agent Replace\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/README.md b/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/README.md new file mode 100644 index 0000000..60f79ec --- /dev/null +++ b/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/README.md @@ -0,0 +1,66 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# interface ReplaceInterface (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Interfaces** +```uml +@startuml +interface ReplaceInterface #Lavender { + + get(?string $table = null) : ?array + + item(object $item, ?int $id = null, ...) : void + + items(?array $items = null, ?string $table = null) : void + + reset(?string $table = null) : void +} + +note right of ReplaceInterface::get + Get updated values + + since: 3.2.0 + return: ?array +end note + +note right of ReplaceInterface::item + Search over an item fields + + since: 3.2.0 + return: void + + arguments: + object $item + ?int $id = null + ?string $table = null +end note + +note right of ReplaceInterface::items + Search over an array of items + + since: 3.2.0 + return: void +end note + +note right of ReplaceInterface::reset + Reset all updated values of a table + + since: 3.2.0 + return: void +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/code.php b/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/code.php new file mode 100644 index 0000000..6bc17f5 --- /dev/null +++ b/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/code.php @@ -0,0 +1,66 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Interfaces; + + +/** + * Search Replace Interface + * + * @since 3.2.0 + */ +interface ReplaceInterface +{ + /** + * Get updated values + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(?string $table = null): ?array; + + /** + * Search over an item fields + * + * @param object $item The item object of fields to search through + * @param int|null $id The item id + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function item(object $item, ?int $id =null, ?string $table = null); + + /** + * Search over an array of items + * + * @param array|null $items The array of items to search through + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null); + + /** + * Reset all updated values of a table + * + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(?string $table = null); + +} + diff --git a/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/code.power b/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/code.power new file mode 100644 index 0000000..3227675 --- /dev/null +++ b/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/code.power @@ -0,0 +1,42 @@ + /** + * Get updated values + * + * @param string|null $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(?string $table = null): ?array; + + /** + * Search over an item fields + * + * @param object $item The item object of fields to search through + * @param int|null $id The item id + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function item(object $item, ?int $id =null, ?string $table = null); + + /** + * Search over an array of items + * + * @param array|null $items The array of items to search through + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function items(?array $items = null, ?string $table = null); + + /** + * Reset all updated values of a table + * + * @param string|null $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(?string $table = null); diff --git a/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/settings.json b/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/settings.json new file mode 100644 index 0000000..72d0592 --- /dev/null +++ b/src/afdae35d-fe7f-4055-99ea-afd8ff8349b6/settings.json @@ -0,0 +1,18 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "afdae35d-fe7f-4055-99ea-afd8ff8349b6", + "implements": null, + "load_selection": null, + "name": "ReplaceInterface", + "power_version": "1.0.0", + "system_name": "JCB.Search.Interfaces.ReplaceInterface", + "type": "interface", + "use_selection": null, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Interfaces.ReplaceInterface", + "description": "Search Replace Interface\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/README.md b/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/README.md new file mode 100644 index 0000000..b23925c --- /dev/null +++ b/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/README.md @@ -0,0 +1,77 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Agent (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Service** +```uml +@startuml +class Agent #Gold { + + register(Container $container) : void + + getAgent(Container $container) : SearchAgent + + getFind(Container $container) : Find + + getReplace(Container $container) : Replace + + getSearch(Container $container) : Search + + getUpdate(Container $container) : Update +} + +note right of Agent::register + Registers the service provider with a DI container. + + since: 3.2.0 + return: void +end note + +note right of Agent::getAgent + Get the Search Agent + + since: 3.2.0 + return: SearchAgent +end note + +note right of Agent::getFind + Get the Search Agent Find + + since: 3.2.0 + return: Find +end note + +note right of Agent::getReplace + Get the Search Agent Replace + + since: 3.2.0 + return: Replace +end note + +note right of Agent::getSearch + Get the Search Agent Search + + since: 3.2.0 + return: Search +end note + +note right of Agent::getUpdate + Get the Search Agent Update + + since: 3.2.0 + return: Update +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/code.php b/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/code.php new file mode 100644 index 0000000..17ad513 --- /dev/null +++ b/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/code.php @@ -0,0 +1,143 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Service; + + +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use VDM\Joomla\Componentbuilder\Search\Agent as SearchAgent; +use VDM\Joomla\Componentbuilder\Search\Agent\Find; +use VDM\Joomla\Componentbuilder\Search\Agent\Replace; +use VDM\Joomla\Componentbuilder\Search\Agent\Search; +use VDM\Joomla\Componentbuilder\Search\Agent\Update; + + +/** + * Agent Service Provider + * + * @since 3.2.0 + */ +class Agent implements ServiceProviderInterface +{ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(SearchAgent::class, 'Agent') + ->share('Agent', [$this, 'getAgent'], true); + + $container->alias(Find::class, 'Agent.Find') + ->share('Agent.Find', [$this, 'getFind'], true); + + $container->alias(Replace::class, 'Agent.Replace') + ->share('Agent.Replace', [$this, 'getReplace'], true); + + $container->alias(Search::class, 'Agent.Search') + ->share('Agent.Search', [$this, 'getSearch'], true); + + $container->alias(Update::class, 'Agent.Update') + ->share('Agent.Update', [$this, 'getUpdate'], true); + } + + /** + * Get the Search Agent + * + * @param Container $container The DI container. + * + * @return SearchAgent + * @since 3.2.0 + */ + public function getAgent(Container $container): SearchAgent + { + return new SearchAgent( + $container->get('Config'), + $container->get('Load.Database'), + $container->get('Insert.Database'), + $container->get('Agent.Find'), + $container->get('Agent.Replace'), + $container->get('Agent.Search'), + $container->get('Agent.Update'), + $container->get('Table') + ); + } + + /** + * Get the Search Agent Find + * + * @param Container $container The DI container. + * + * @return Find + * @since 3.2.0 + */ + public function getFind(Container $container): Find + { + return new Find( + $container->get('Config'), + $container->get('Agent.Search') + ); + } + + /** + * Get the Search Agent Replace + * + * @param Container $container The DI container. + * + * @return Replace + * @since 3.2.0 + */ + public function getReplace(Container $container): Replace + { + return new Replace( + $container->get('Config'), + $container->get('Agent.Update') + ); + } + + /** + * Get the Search Agent Search + * + * @param Container $container The DI container. + * + * @return Search + * @since 3.2.0 + */ + public function getSearch(Container $container): Search + { + return new Search( + $container->get('Config'), + $container->get('Search') + ); + } + + /** + * Get the Search Agent Update + * + * @param Container $container The DI container. + * + * @return Update + * @since 3.2.0 + */ + public function getUpdate(Container $container): Update + { + return new Update( + $container->get('Search') + ); + } + +} + diff --git a/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/code.power b/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/code.power new file mode 100644 index 0000000..f2db15a --- /dev/null +++ b/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/code.power @@ -0,0 +1,110 @@ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(SearchAgent::class, 'Agent') + ->share('Agent', [$this, 'getAgent'], true); + + $container->alias(Find::class, 'Agent.Find') + ->share('Agent.Find', [$this, 'getFind'], true); + + $container->alias(Replace::class, 'Agent.Replace') + ->share('Agent.Replace', [$this, 'getReplace'], true); + + $container->alias(Search::class, 'Agent.Search') + ->share('Agent.Search', [$this, 'getSearch'], true); + + $container->alias(Update::class, 'Agent.Update') + ->share('Agent.Update', [$this, 'getUpdate'], true); + } + + /** + * Get the Search Agent + * + * @param Container $container The DI container. + * + * @return SearchAgent + * @since 3.2.0 + */ + public function getAgent(Container $container): SearchAgent + { + return new SearchAgent( + $container->get('Config'), + $container->get('Load.Database'), + $container->get('Insert.Database'), + $container->get('Agent.Find'), + $container->get('Agent.Replace'), + $container->get('Agent.Search'), + $container->get('Agent.Update'), + $container->get('Table') + ); + } + + /** + * Get the Search Agent Find + * + * @param Container $container The DI container. + * + * @return Find + * @since 3.2.0 + */ + public function getFind(Container $container): Find + { + return new Find( + $container->get('Config'), + $container->get('Agent.Search') + ); + } + + /** + * Get the Search Agent Replace + * + * @param Container $container The DI container. + * + * @return Replace + * @since 3.2.0 + */ + public function getReplace(Container $container): Replace + { + return new Replace( + $container->get('Config'), + $container->get('Agent.Update') + ); + } + + /** + * Get the Search Agent Search + * + * @param Container $container The DI container. + * + * @return Search + * @since 3.2.0 + */ + public function getSearch(Container $container): Search + { + return new Search( + $container->get('Config'), + $container->get('Search') + ); + } + + /** + * Get the Search Agent Update + * + * @param Container $container The DI container. + * + * @return Update + * @since 3.2.0 + */ + public function getUpdate(Container $container): Update + { + return new Update( + $container->get('Search') + ); + } diff --git a/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/settings.json b/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/settings.json new file mode 100644 index 0000000..d0f7964 --- /dev/null +++ b/src/cc6972a7-1574-4ae0-92a8-7f1012aac6f7/settings.json @@ -0,0 +1,42 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "cc6972a7-1574-4ae0-92a8-7f1012aac6f7", + "implements": [ + "-1" + ], + "load_selection": null, + "name": "Agent", + "power_version": "1.0.0", + "system_name": "JCB.Search.Service.Agent", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "0b658434-3767-401e-addc-eabfd1d0e94a", + "as": "SearchAgent" + }, + "use_selection1": { + "use": "15d9e1a9-3364-4d69-9d9f-9b87db820e5c", + "as": "default" + }, + "use_selection2": { + "use": "abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7", + "as": "default" + }, + "use_selection3": { + "use": "e544a248-4b6a-46cb-9926-a3ac9937807c", + "as": "default" + }, + "use_selection4": { + "use": "3ac29912-0681-4ca9-8197-d5a8f6a49ac7", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Service.Agent", + "description": "Agent Service Provider\r\n\r\n@since 3.2.0", + "implements_custom": "ServiceProviderInterface", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\DI\\Container;\r\nuse Joomla\\DI\\ServiceProviderInterface;", + "composer": "" +} \ No newline at end of file diff --git a/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/README.md b/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/README.md new file mode 100644 index 0000000..a7c5482 --- /dev/null +++ b/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/README.md @@ -0,0 +1,61 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Database (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Service** +```uml +@startuml +class Database #Gold { + + register(Container $container) : void + + getLoad(Container $container) : Load + + getDatabaseLoad(Container $container) : LoadDatabase + + getDatabaseInsert(Container $container) : InsertDatabase +} + +note right of Database::register + Registers the service provider with a DI container. + + since: 3.2.0 + return: void +end note + +note right of Database::getLoad + Get the Core Load Database + + since: 3.2.0 + return: Load +end note + +note right of Database::getDatabaseLoad + Get the Load Database + + since: 3.2.0 + return: LoadDatabase +end note + +note right of Database::getDatabaseInsert + Get the Insert Database + + since: 3.2.0 + return: InsertDatabase +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/code.php b/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/code.php new file mode 100644 index 0000000..cd0aece --- /dev/null +++ b/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/code.php @@ -0,0 +1,98 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Service; + + +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use VDM\Joomla\Componentbuilder\Database\Load; +use VDM\Joomla\Componentbuilder\Search\Database\Load as LoadDatabase; +use VDM\Joomla\Componentbuilder\Search\Database\Insert as InsertDatabase; + + +/** + * Database Service Provider + * + * @since 3.2.0 + */ +class Database implements ServiceProviderInterface +{ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Load::class, 'Load') + ->share('Load', [$this, 'getLoad'], true); + + $container->alias(LoadDatabase::class, 'Load.Database') + ->share('Load.Database', [$this, 'getDatabaseLoad'], true); + + $container->alias(InsertDatabase::class, 'Insert.Database') + ->share('Insert.Database', [$this, 'getDatabaseInsert'], true); + } + + /** + * Get the Core Load Database + * + * @param Container $container The DI container. + * + * @return Load + * @since 3.2.0 + */ + public function getLoad(Container $container): Load + { + return new Load(); + } + + /** + * Get the Load Database + * + * @param Container $container The DI container. + * + * @return LoadDatabase + * @since 3.2.0 + */ + public function getDatabaseLoad(Container $container): LoadDatabase + { + return new LoadDatabase( + $container->get('Config'), + $container->get('Table'), + $container->get('Load.Model'), + $container->get('Load') + ); + } + + /** + * Get the Insert Database + * + * @param Container $container The DI container. + * + * @return InsertDatabase + * @since 3.2.0 + */ + public function getDatabaseInsert(Container $container): InsertDatabase + { + return new InsertDatabase( + $container->get('Config'), + $container->get('Table'), + $container->get('Insert.Model') + ); + } + +} + diff --git a/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/code.power b/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/code.power new file mode 100644 index 0000000..3559dea --- /dev/null +++ b/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/code.power @@ -0,0 +1,67 @@ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Load::class, 'Load') + ->share('Load', [$this, 'getLoad'], true); + + $container->alias(LoadDatabase::class, 'Load.Database') + ->share('Load.Database', [$this, 'getDatabaseLoad'], true); + + $container->alias(InsertDatabase::class, 'Insert.Database') + ->share('Insert.Database', [$this, 'getDatabaseInsert'], true); + } + + /** + * Get the Core Load Database + * + * @param Container $container The DI container. + * + * @return Load + * @since 3.2.0 + */ + public function getLoad(Container $container): Load + { + return new Load(); + } + + /** + * Get the Load Database + * + * @param Container $container The DI container. + * + * @return LoadDatabase + * @since 3.2.0 + */ + public function getDatabaseLoad(Container $container): LoadDatabase + { + return new LoadDatabase( + $container->get('Config'), + $container->get('Table'), + $container->get('Load.Model'), + $container->get('Load') + ); + } + + /** + * Get the Insert Database + * + * @param Container $container The DI container. + * + * @return InsertDatabase + * @since 3.2.0 + */ + public function getDatabaseInsert(Container $container): InsertDatabase + { + return new InsertDatabase( + $container->get('Config'), + $container->get('Table'), + $container->get('Insert.Model') + ); + } diff --git a/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/settings.json b/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/settings.json new file mode 100644 index 0000000..12e5299 --- /dev/null +++ b/src/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3/settings.json @@ -0,0 +1,34 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "d5de47ce-9a9e-4e76-a5c6-61ed74842ea3", + "implements": [ + "-1" + ], + "load_selection": null, + "name": "Database", + "power_version": "1.0.0", + "system_name": "JCB.Search.Service.Database", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "06f8eada-d59b-441c-b287-0aea1793da5a", + "as": "default" + }, + "use_selection1": { + "use": "2dabfb4a-64cd-4c04-9772-4a75f9f3b710", + "as": "LoadDatabase" + }, + "use_selection2": { + "use": "6caf9473-133c-49a9-afa0-9f84151b5155", + "as": "InsertDatabase" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Service.Database", + "description": "Database Service Provider\r\n\r\n@since 3.2.0", + "implements_custom": "ServiceProviderInterface", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\DI\\Container;\r\nuse Joomla\\DI\\ServiceProviderInterface;", + "composer": "" +} \ No newline at end of file diff --git a/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/README.md b/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/README.md new file mode 100644 index 0000000..0705881 --- /dev/null +++ b/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/README.md @@ -0,0 +1,78 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Search (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Service** +```uml +@startuml +class Search #Gold { + # $searchEngine + + register(Container $container) : void + + getConfig(Container $container) : Config + + getTable(Container $container) : Table + + getRegex(Container $container) : Regex + + getBasic(Container $container) : Basic + + getSearch(Container $container) : SearchEngine +} + +note right of Search::register + Registers the service provider with a DI container. + + since: 3.2.0 + return: void +end note + +note right of Search::getConfig + Get the Config + + since: 3.2.0 + return: Config +end note + +note right of Search::getTable + Get the Table + + since: 3.2.0 + return: Table +end note + +note right of Search::getRegex + Get the Regex Type Search Engine + + since: 3.2.0 + return: Regex +end note + +note right of Search::getBasic + Get the Basic Type Search Engine + + since: 3.2.0 + return: Basic +end note + +note right of Search::getSearch + Get the Search Engine + + since: 3.2.0 + return: SearchEngine +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/code.php b/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/code.php new file mode 100644 index 0000000..945be98 --- /dev/null +++ b/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/code.php @@ -0,0 +1,149 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Service; + + +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Componentbuilder\Table; +use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface as SearchEngine; +use VDM\Joomla\Componentbuilder\Search\Engine\Regex; +use VDM\Joomla\Componentbuilder\Search\Engine\Basic; + + +/** + * Search Service Provider + * + * @since 3.2.0 + */ +class Search implements ServiceProviderInterface +{ + /** + * Selected search engine + * + * @var int + * @since 3.2.0 + **/ + protected $searchEngine = 101; + + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Config::class, 'Config') + ->share('Config', [$this, 'getConfig'], true); + + $container->alias(Table::class, 'Table') + ->share('Table', [$this, 'getTable'], true); + + $container->alias(Regex::class, 'Search.Regex') + ->share('Search.Regex', [$this, 'getRegex'], true); + + $container->alias(Basic::class, 'Search.Basic') + ->share('Search.Basic', [$this, 'getBasic'], true); + + $container->alias(SearchEngine::class, 'Search') + ->share('Search', [$this, 'getSearch'], true); + } + + /** + * Get the Config + * + * @param Container $container The DI container. + * + * @return Config + * @since 3.2.0 + */ + public function getConfig(Container $container): Config + { + return new Config(); + } + + /** + * Get the Table + * + * @param Container $container The DI container. + * + * @return Table + * @since 3.2.0 + */ + public function getTable(Container $container): Table + { + return new Table(); + } + + /** + * Get the Regex Type Search Engine + * + * @param Container $container The DI container. + * + * @return Regex + * @since 3.2.0 + */ + public function getRegex(Container $container): Regex + { + return new Regex( + $container->get('Config') + ); + } + + /** + * Get the Basic Type Search Engine + * + * @param Container $container The DI container. + * + * @return Basic + * @since 3.2.0 + */ + public function getBasic(Container $container): Basic + { + return new Basic( + $container->get('Config') + ); + } + + /** + * Get the Search Engine + * + * @param Container $container The DI container. + * + * @return SearchEngine + * @since 3.2.0 + */ + public function getSearch(Container $container): SearchEngine + { + // set the search engine to use for this container + if ($this->searchEngine == 101) + { + $this->searchEngine = (int) $container->get('Config')->regex_search; + } + + // get the correct type of search engine + if ($this->searchEngine == 1) + { + return $container->get('Search.Regex'); + } + + // the default is the basic + return $container->get('Search.Basic'); + } + + +} + diff --git a/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/code.power b/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/code.power new file mode 100644 index 0000000..522d210 --- /dev/null +++ b/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/code.power @@ -0,0 +1,116 @@ + /** + * Selected search engine + * + * @var int + * @since 3.2.0 + **/ + protected $searchEngine = 101; + + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Config::class, 'Config') + ->share('Config', [$this, 'getConfig'], true); + + $container->alias(Table::class, 'Table') + ->share('Table', [$this, 'getTable'], true); + + $container->alias(Regex::class, 'Search.Regex') + ->share('Search.Regex', [$this, 'getRegex'], true); + + $container->alias(Basic::class, 'Search.Basic') + ->share('Search.Basic', [$this, 'getBasic'], true); + + $container->alias(SearchEngine::class, 'Search') + ->share('Search', [$this, 'getSearch'], true); + } + + /** + * Get the Config + * + * @param Container $container The DI container. + * + * @return Config + * @since 3.2.0 + */ + public function getConfig(Container $container): Config + { + return new Config(); + } + + /** + * Get the Table + * + * @param Container $container The DI container. + * + * @return Table + * @since 3.2.0 + */ + public function getTable(Container $container): Table + { + return new Table(); + } + + /** + * Get the Regex Type Search Engine + * + * @param Container $container The DI container. + * + * @return Regex + * @since 3.2.0 + */ + public function getRegex(Container $container): Regex + { + return new Regex( + $container->get('Config') + ); + } + + /** + * Get the Basic Type Search Engine + * + * @param Container $container The DI container. + * + * @return Basic + * @since 3.2.0 + */ + public function getBasic(Container $container): Basic + { + return new Basic( + $container->get('Config') + ); + } + + /** + * Get the Search Engine + * + * @param Container $container The DI container. + * + * @return SearchEngine + * @since 3.2.0 + */ + public function getSearch(Container $container): SearchEngine + { + // set the search engine to use for this container + if ($this->searchEngine == 101) + { + $this->searchEngine = (int) $container->get('Config')->regex_search; + } + + // get the correct type of search engine + if ($this->searchEngine == 1) + { + return $container->get('Search.Regex'); + } + + // the default is the basic + return $container->get('Search.Basic'); + } + diff --git a/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/settings.json b/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/settings.json new file mode 100644 index 0000000..42cefed --- /dev/null +++ b/src/da714ea5-96bb-4eb1-959b-39b457be9cd1/settings.json @@ -0,0 +1,42 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "da714ea5-96bb-4eb1-959b-39b457be9cd1", + "implements": [ + "-1" + ], + "load_selection": null, + "name": "Search", + "power_version": "1.0.0", + "system_name": "JCB.Search.Service.Search", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + }, + "use_selection1": { + "use": "bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8", + "as": "default" + }, + "use_selection2": { + "use": "117d8c9e-3f8d-40ae-b375-1efa2fe5538a", + "as": "SearchEngine" + }, + "use_selection3": { + "use": "83efa9a0-4aec-41f8-9c05-b1ac9617746e", + "as": "default" + }, + "use_selection4": { + "use": "db093eca-63b3-4d6c-9232-3ceb058121c0", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Service.Search", + "description": "Search Service Provider\r\n\r\n@since 3.2.0", + "implements_custom": "ServiceProviderInterface", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\DI\\Container;\r\nuse Joomla\\DI\\ServiceProviderInterface;", + "composer": "" +} \ No newline at end of file diff --git a/src/db093eca-63b3-4d6c-9232-3ceb058121c0/README.md b/src/db093eca-63b3-4d6c-9232-3ceb058121c0/README.md new file mode 100644 index 0000000..59b2ab4 --- /dev/null +++ b/src/db093eca-63b3-4d6c-9232-3ceb058121c0/README.md @@ -0,0 +1,93 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Basic (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Engine** +```uml +@startuml +class Basic #Gold { + # string $regexValue + + __construct(?Config $config = null) + + string(string $value) : ?string + + replace(string $value) : string + # replaceWhole(string $value) : string + # searchWhole(string $value) : ?string + + match(string $value) : bool + # searchAll(string $value) : ?string + # replaceAll(string $value) : string +} + +note right of Basic::__construct + Constructor + + since: 3.2.0 +end note + +note left of Basic::string + Search inside a string + + since: 3.2.0 + return: ?string +end note + +note right of Basic::replace + Replace found instances inside string value + + since: 3.2.0 + return: string +end note + +note left of Basic::replaceWhole + Replace whole words + + since: 3.2.0 + return: string +end note + +note right of Basic::searchWhole + Search for whole words + + since: 3.2.0 + return: ?string +end note + +note left of Basic::match + Math the Regular Expression + + since: 3.0.9 + return: bool +end note + +note right of Basic::searchAll + Search for all instances + + since: 3.2.0 + return: ?string +end note + +note left of Basic::replaceAll + Replace for all instances + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/db093eca-63b3-4d6c-9232-3ceb058121c0/code.php b/src/db093eca-63b3-4d6c-9232-3ceb058121c0/code.php new file mode 100644 index 0000000..2be7282 --- /dev/null +++ b/src/db093eca-63b3-4d6c-9232-3ceb058121c0/code.php @@ -0,0 +1,271 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Engine; + + +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface; +use VDM\Joomla\Componentbuilder\Search\Abstraction\Engine; + + +/** + * Search Type String + * + * @since 3.2.0 + */ +class Basic extends Engine implements SearchTypeInterface +{ + /** + * Regex Search Value + * + * @var string + * @since 3.2.0 + */ + protected string $regexValue = ''; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null) + { + parent::__construct($config); + + // quote all regular expression characters + $searchValue = preg_quote((string) $this->searchValue, '/'); + + $start = ''; $end = ''; + + // if this is a whole word search we need to do some prep + if ($this->wholeWord == 1) + { + // get first character of search string + $first = mb_substr((string) $this->searchValue, 0, 1); + // get last character of search string + $last = mb_substr((string) $this->searchValue, -1); + + // set the start boundary behavior + $start = '(\b)'; + if (\preg_match("/\W/", $first)) + { + $start = '(\b|\B)'; + } + + // set the boundary behavior + $end = '(\b)'; + if (\preg_match("/\W/", $last)) + { + $end = '(\b|\B)'; + } + } + + // set search based on match case + $case = ''; + if ($this->matchCase == 0) + { + $case = 'i'; + } + + $this->regexValue = "/" . $start . '(' . $searchValue . ')' . $end . "/" . $case; + } + + /** + * Search inside a string + * + * @param string $value The string value + * + * @return string|null The marked string if found, else null + * @since 3.2.0 + */ + public function string(string $value): ?string + { + // we count every line + $this->lineCounter(); + + if (StringHelper::check($this->searchValue)) + { + if ($this->wholeWord == 1) + { + return $this->searchWhole($value); + } + else + { + return $this->searchAll($value); + } + } + + return null; + } + + /** + * Replace found instances inside string value + * + * @param string $value The string value to update + * + * @return string The updated string + * @since 3.2.0 + */ + public function replace(string $value): string + { + if (StringHelper::check($this->searchValue)) + { + if ($this->wholeWord == 1) + { + return $this->replaceWhole($value); + } + else + { + return $this->replaceAll($value); + } + } + return $value; + } + + /** + * Replace whole words + * + * @param string $value The string value + * + * @return string The marked string if found, else null + * @since 3.2.0 + */ + protected function replaceWhole(string $value): string + { + if ($this->match($value)) + { + return preg_replace( + $this->regexValue . 'm', + "$1" . $this->replaceValue . "$3", + $value + ); + } + + return $value; + } + + /** + * Search for whole words + * + * @param string $value The string value + * + * @return string|null The marked string if found, else null + * @since 3.2.0 + */ + protected function searchWhole(string $value): ?string + { + if ($this->match($value)) + { + return trim(preg_replace( + $this->regexValue . 'm', + "$1" . $this->start . "$2" . $this->end . "$3", + $value + )); + } + + return null; + } + + /** + * Math the Regular Expression + * + * @param string $value The string value + * + * @return bool true if match is found + * @since 3.0.9 + */ + public function match(string $value): bool + { + $match = []; + + preg_match($this->regexValue, $value, $match); + + $match = array_filter( + $match, + fn($found) => !empty($found) + ); + + return (bool) ArrayHelper::check($match); + } + + /** + * Search for all instances + * + * @param string $value The string value + * + * @return string|null The marked string if found, else null + * @since 3.2.0 + */ + protected function searchAll(string $value): ?string + { + if ($this->matchCase == 1) + { + if (strpos($value, (string) $this->searchValue) !== false) + { + return trim(preg_replace( + $this->regexValue . 'm', + $this->start . "$1" . $this->end, + $value + )); + } + } + elseif (stripos($value, (string) $this->searchValue) !== false) + { + return trim(preg_replace( + $this->regexValue . 'm', + $this->start . "$1" . $this->end, + $value + )); + } + + return null; + } + + /** + * Replace for all instances + * + * @param string $value The string value + * + * @return string The marked string if found, else null + * @since 3.2.0 + */ + protected function replaceAll(string $value): string + { + if ($this->matchCase == 1) + { + if (strpos($value, (string) $this->searchValue) !== false) + { + return preg_replace( + $this->regexValue . 'm', + (string) $this->replaceValue, + $value + ); + } + } + elseif (stripos($value, (string) $this->searchValue) !== false) + { + return preg_replace( + $this->regexValue . 'm', + (string) $this->replaceValue, + $value + ); + } + + return $value; + } + +} + diff --git a/src/db093eca-63b3-4d6c-9232-3ceb058121c0/code.power b/src/db093eca-63b3-4d6c-9232-3ceb058121c0/code.power new file mode 100644 index 0000000..3adf33e --- /dev/null +++ b/src/db093eca-63b3-4d6c-9232-3ceb058121c0/code.power @@ -0,0 +1,240 @@ + /** + * Regex Search Value + * + * @var string + * @since 3.2.0 + */ + protected string $regexValue = ''; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null) + { + parent::__construct($config); + + // quote all regular expression characters + $searchValue = preg_quote((string) $this->searchValue, '/'); + + $start = ''; $end = ''; + + // if this is a whole word search we need to do some prep + if ($this->wholeWord == 1) + { + // get first character of search string + $first = mb_substr((string) $this->searchValue, 0, 1); + // get last character of search string + $last = mb_substr((string) $this->searchValue, -1); + + // set the start boundary behavior + $start = '(\b)'; + if (\preg_match("/\W/", $first)) + { + $start = '(\b|\B)'; + } + + // set the boundary behavior + $end = '(\b)'; + if (\preg_match("/\W/", $last)) + { + $end = '(\b|\B)'; + } + } + + // set search based on match case + $case = ''; + if ($this->matchCase == 0) + { + $case = 'i'; + } + + $this->regexValue = "/" . $start . '(' . $searchValue . ')' . $end . "/" . $case; + } + + /** + * Search inside a string + * + * @param string $value The string value + * + * @return string|null The marked string if found, else null + * @since 3.2.0 + */ + public function string(string $value): ?string + { + // we count every line + $this->lineCounter(); + + if (StringHelper::check($this->searchValue)) + { + if ($this->wholeWord == 1) + { + return $this->searchWhole($value); + } + else + { + return $this->searchAll($value); + } + } + + return null; + } + + /** + * Replace found instances inside string value + * + * @param string $value The string value to update + * + * @return string The updated string + * @since 3.2.0 + */ + public function replace(string $value): string + { + if (StringHelper::check($this->searchValue)) + { + if ($this->wholeWord == 1) + { + return $this->replaceWhole($value); + } + else + { + return $this->replaceAll($value); + } + } + return $value; + } + + /** + * Replace whole words + * + * @param string $value The string value + * + * @return string The marked string if found, else null + * @since 3.2.0 + */ + protected function replaceWhole(string $value): string + { + if ($this->match($value)) + { + return preg_replace( + $this->regexValue . 'm', + "$1" . $this->replaceValue . "$3", + $value + ); + } + + return $value; + } + + /** + * Search for whole words + * + * @param string $value The string value + * + * @return string|null The marked string if found, else null + * @since 3.2.0 + */ + protected function searchWhole(string $value): ?string + { + if ($this->match($value)) + { + return trim(preg_replace( + $this->regexValue . 'm', + "$1" . $this->start . "$2" . $this->end . "$3", + $value + )); + } + + return null; + } + + /** + * Math the Regular Expression + * + * @param string $value The string value + * + * @return bool true if match is found + * @since 3.0.9 + */ + public function match(string $value): bool + { + $match = []; + + preg_match($this->regexValue, $value, $match); + + $match = array_filter( + $match, + fn($found) => !empty($found) + ); + + return (bool) ArrayHelper::check($match); + } + + /** + * Search for all instances + * + * @param string $value The string value + * + * @return string|null The marked string if found, else null + * @since 3.2.0 + */ + protected function searchAll(string $value): ?string + { + if ($this->matchCase == 1) + { + if (strpos($value, (string) $this->searchValue) !== false) + { + return trim(preg_replace( + $this->regexValue . 'm', + $this->start . "$1" . $this->end, + $value + )); + } + } + elseif (stripos($value, (string) $this->searchValue) !== false) + { + return trim(preg_replace( + $this->regexValue . 'm', + $this->start . "$1" . $this->end, + $value + )); + } + + return null; + } + + /** + * Replace for all instances + * + * @param string $value The string value + * + * @return string The marked string if found, else null + * @since 3.2.0 + */ + protected function replaceAll(string $value): string + { + if ($this->matchCase == 1) + { + if (strpos($value, (string) $this->searchValue) !== false) + { + return preg_replace( + $this->regexValue . 'm', + (string) $this->replaceValue, + $value + ); + } + } + elseif (stripos($value, (string) $this->searchValue) !== false) + { + return preg_replace( + $this->regexValue . 'm', + (string) $this->replaceValue, + $value + ); + } + + return $value; + } diff --git a/src/db093eca-63b3-4d6c-9232-3ceb058121c0/settings.json b/src/db093eca-63b3-4d6c-9232-3ceb058121c0/settings.json new file mode 100644 index 0000000..6f27c9c --- /dev/null +++ b/src/db093eca-63b3-4d6c-9232-3ceb058121c0/settings.json @@ -0,0 +1,33 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "8f9449fc-bfbc-49a5-b146-d58c8c17dfdf", + "guid": "db093eca-63b3-4d6c-9232-3ceb058121c0", + "implements": [ + "117d8c9e-3f8d-40ae-b375-1efa2fe5538a" + ], + "load_selection": null, + "name": "Basic", + "power_version": "1.0.0", + "system_name": "JCB.Search.Engine.Basic", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + }, + "use_selection1": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + }, + "use_selection2": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Engine.Basic", + "description": "Search Type String\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/e544a248-4b6a-46cb-9926-a3ac9937807c/README.md b/src/e544a248-4b6a-46cb-9926-a3ac9937807c/README.md new file mode 100644 index 0000000..106e8ea --- /dev/null +++ b/src/e544a248-4b6a-46cb-9926-a3ac9937807c/README.md @@ -0,0 +1,105 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Search (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Agent** +```uml +@startuml +class Search #Gold { + # array $found + # Config $config + # SearchEngine $search + + __construct(?Config $config = null, ?SearchEngine $search = null) + + get(string $table) : ?array + + value(mixed $value, int $id, ...) : bool + + reset(string $table) : void + # searchValue(mixed $value) : ?array + # string(string $value) : ?array + # prep(int $id, string $field, ...) : void + # fieldCounter() +} + +note right of Search::__construct + Constructor + + since: 3.2.0 +end note + +note left of Search::get + Get found values + + since: 3.2.0 + return: ?array +end note + +note right of Search::value + Search inside a value + + since: 3.2.0 + return: bool + + arguments: + mixed $value + int $id + string $field + string $table +end note + +note left of Search::reset + Empty the found values + + since: 3.2.0 + return: void +end note + +note right of Search::searchValue + Search inside a string + + since: 3.2.0 + return: ?array +end note + +note left of Search::string + Search inside a string + + since: 3.2.0 + return: ?array +end note + +note right of Search::prep + Prep the bucket + + since: 3.2.0 + return: void + + arguments: + int $id + string $field + string $table +end note + +note left of Search::fieldCounter + we count every field being searched + + since: 3.2.0 +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/e544a248-4b6a-46cb-9926-a3ac9937807c/code.php b/src/e544a248-4b6a-46cb-9926-a3ac9937807c/code.php new file mode 100644 index 0000000..9ccd89a --- /dev/null +++ b/src/e544a248-4b6a-46cb-9926-a3ac9937807c/code.php @@ -0,0 +1,302 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Agent; + + +use VDM\Joomla\Utilities\ArrayHelper; +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Componentbuilder\Search\Factory; +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface as SearchEngine; +use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchInterface; + + +/** + * Search Agent Search + * + * @since 3.2.0 + */ +class Search implements SearchInterface +{ + /** + * Search results found + * + * @var array + * @since 3.2.0 + */ + protected array $found = []; + + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search Engine + * + * @var SearchEngine + * @since 3.2.0 + */ + protected SearchEngine $search; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param SearchEngine|null $search The search engine object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?SearchEngine $search = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->search = $search ?: Factory::_('Search'); + } + + /** + * Get found values + * + * @param string $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(string $table): ?array + { + if (isset($this->found[$table])) + { + return $this->found[$table]; + } + + return null; + } + + /** + * Search inside a value + * + * @param mixed $value The field value + * @param int $id The item ID + * @param string $field The field key + * @param string $table The table + * + * @return bool + * @since 3.2.0 + */ + public function value($value, int $id, string $field, string $table): bool + { + // search the mixed value + $found = $this->searchValue($value); + + // check if we found any match + if (ArrayHelper::check($found)) + { + foreach ($found as $line => $line_value) + { + // may not be needed... but being old school + $this->prep($id, $field, $table); + + // load the detail into our multidimensional array... lol + // Table->Item_id->Field_name->Line_number = marked_full_line + // Search Example: soon... + // Marked Line Example: Soon.... + $this->found[$table][$id][$field][$line] = $line_value; + } + return true; + } + + return false; + } + + /** + * Empty the found values + * + * @param string $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(string $table) + { + unset($this->found[$table]); + } + + /** + * Search inside a string + * + * @param mixed $value The field value + * + * @return array|null + * @since 3.2.0 + */ + protected function searchValue($value): ?array + { + // check if this is an array + $found = null; + + // I know this is a little crazy... TODO refactor into recursion functions + // the possibility of searching sub-forms in sub-forms + if (ArrayHelper::check($value)) + { + // first layer + foreach ($value as $keys => $rows) + { + if (ArrayHelper::check($rows)) + { + // second layer + foreach ($rows as $key => $row) + { + if (ArrayHelper::check($row)) + { + // third layer + foreach ($row as $ke => $ro) + { + if (ArrayHelper::check($ro)) + { + // forth layer + foreach ($ro as $k => $r) + { + if (StringHelper::check($r) && ($_found = $this->string($r)) !== null) + { + foreach ($_found as $_n => $_f) + { + $found[$keys . '.' . $key . '.' . $ke . '.' . $k . '.' . $_n] = $_f; + } + } + } + } + elseif (StringHelper::check($ro) && ($_found = $this->string($ro)) !== null) + { + foreach ($_found as $_n => $_f) + { + $found[$keys. '.' . $key . '.' . $ke . '.' . $_n] = $_f; + } + } + + } + } + elseif (StringHelper::check($row) && ($_found = $this->string($row)) !== null) + { + foreach ($_found as $_n => $_f) + { + $found[$keys. '.' . $key . '.' . $_n] = $_f; + } + } + } + } + elseif (StringHelper::check($rows) && ($_found = $this->string($rows)) !== null) + { + foreach ($_found as $_n => $_f) + { + $found[$keys. '.' . $_n] = $_f; + } + } + } + } + elseif (StringHelper::check($value)) + { + $found = $this->string($value); + } + + return $found; + } + + /** + * Search inside a string + * + * @param string $value The field value + * + * @return array|null + * @since 3.2.0 + */ + protected function string(string $value): ?array + { + // line counter + $line = 1; + + // we count every field we search + $this->fieldCounter(); + + // check if string has a new line + if (\preg_match('/\R/', $value)) + { + $search_array = \preg_split('/\R/', $value); + + // start search bucket + $found = []; + + // loop over the lines + foreach ($search_array as $line_value) + { + if (($_found = $this->search->string($line_value)) !== null) + { + $found[$line] = $_found; + } + + // next line + $line++; + } + + if (ArrayHelper::check($found)) + { + return $found; + } + } + elseif (($found = $this->search->string($value)) !== null) + { + return [$line => $found]; + } + + return null; + } + + /** + * Prep the bucket + * + * @param int $id The item ID + * @param string $field The field key + * @param string $table The table + * + * @return void + * @since 3.2.0 + */ + protected function prep(int $id, string $field, string $table) + { + if (empty($this->found[$table])) + { + $this->found[$table] = []; + } + if (empty($this->found[$table][$id])) + { + $this->found[$table][$id] = []; + } + if (empty($this->found[$table][$id][$field])) + { + $this->found[$table][$id][$field] = []; + } + // we should add a call to get the item name if the table has a name field TODO + } + + /** + * we count every field being searched + * + * @since 3.2.0 + */ + protected function fieldCounter() + { + // we count every field we search + $this->config->field_counter += 1; + } +} + diff --git a/src/e544a248-4b6a-46cb-9926-a3ac9937807c/code.power b/src/e544a248-4b6a-46cb-9926-a3ac9937807c/code.power new file mode 100644 index 0000000..ea03a4f --- /dev/null +++ b/src/e544a248-4b6a-46cb-9926-a3ac9937807c/code.power @@ -0,0 +1,271 @@ + /** + * Search results found + * + * @var array + * @since 3.2.0 + */ + protected array $found = []; + + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Search Engine + * + * @var SearchEngine + * @since 3.2.0 + */ + protected SearchEngine $search; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param SearchEngine|null $search The search engine object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?SearchEngine $search = null) + { + $this->config = $config ?: Factory::_('Config'); + $this->search = $search ?: Factory::_('Search'); + } + + /** + * Get found values + * + * @param string $table The table being searched + * + * @return array|null + * @since 3.2.0 + */ + public function get(string $table): ?array + { + if (isset($this->found[$table])) + { + return $this->found[$table]; + } + + return null; + } + + /** + * Search inside a value + * + * @param mixed $value The field value + * @param int $id The item ID + * @param string $field The field key + * @param string $table The table + * + * @return bool + * @since 3.2.0 + */ + public function value($value, int $id, string $field, string $table): bool + { + // search the mixed value + $found = $this->searchValue($value); + + // check if we found any match + if (ArrayHelper::check($found)) + { + foreach ($found as $line => $line_value) + { + // may not be needed... but being old school + $this->prep($id, $field, $table); + + // load the detail into our multidimensional array... lol + // Table->Item_id->Field_name->Line_number = marked_full_line + // Search Example: soon... + // Marked Line Example: Soon.... + $this->found[$table][$id][$field][$line] = $line_value; + } + return true; + } + + return false; + } + + /** + * Empty the found values + * + * @param string $table The table being searched + * + * @return void + * @since 3.2.0 + */ + public function reset(string $table) + { + unset($this->found[$table]); + } + + /** + * Search inside a string + * + * @param mixed $value The field value + * + * @return array|null + * @since 3.2.0 + */ + protected function searchValue($value): ?array + { + // check if this is an array + $found = null; + + // I know this is a little crazy... TODO refactor into recursion functions + // the possibility of searching sub-forms in sub-forms + if (ArrayHelper::check($value)) + { + // first layer + foreach ($value as $keys => $rows) + { + if (ArrayHelper::check($rows)) + { + // second layer + foreach ($rows as $key => $row) + { + if (ArrayHelper::check($row)) + { + // third layer + foreach ($row as $ke => $ro) + { + if (ArrayHelper::check($ro)) + { + // forth layer + foreach ($ro as $k => $r) + { + if (StringHelper::check($r) && ($_found = $this->string($r)) !== null) + { + foreach ($_found as $_n => $_f) + { + $found[$keys . '.' . $key . '.' . $ke . '.' . $k . '.' . $_n] = $_f; + } + } + } + } + elseif (StringHelper::check($ro) && ($_found = $this->string($ro)) !== null) + { + foreach ($_found as $_n => $_f) + { + $found[$keys. '.' . $key . '.' . $ke . '.' . $_n] = $_f; + } + } + + } + } + elseif (StringHelper::check($row) && ($_found = $this->string($row)) !== null) + { + foreach ($_found as $_n => $_f) + { + $found[$keys. '.' . $key . '.' . $_n] = $_f; + } + } + } + } + elseif (StringHelper::check($rows) && ($_found = $this->string($rows)) !== null) + { + foreach ($_found as $_n => $_f) + { + $found[$keys. '.' . $_n] = $_f; + } + } + } + } + elseif (StringHelper::check($value)) + { + $found = $this->string($value); + } + + return $found; + } + + /** + * Search inside a string + * + * @param string $value The field value + * + * @return array|null + * @since 3.2.0 + */ + protected function string(string $value): ?array + { + // line counter + $line = 1; + + // we count every field we search + $this->fieldCounter(); + + // check if string has a new line + if (\preg_match('/\R/', $value)) + { + $search_array = \preg_split('/\R/', $value); + + // start search bucket + $found = []; + + // loop over the lines + foreach ($search_array as $line_value) + { + if (($_found = $this->search->string($line_value)) !== null) + { + $found[$line] = $_found; + } + + // next line + $line++; + } + + if (ArrayHelper::check($found)) + { + return $found; + } + } + elseif (($found = $this->search->string($value)) !== null) + { + return [$line => $found]; + } + + return null; + } + + /** + * Prep the bucket + * + * @param int $id The item ID + * @param string $field The field key + * @param string $table The table + * + * @return void + * @since 3.2.0 + */ + protected function prep(int $id, string $field, string $table) + { + if (empty($this->found[$table])) + { + $this->found[$table] = []; + } + if (empty($this->found[$table][$id])) + { + $this->found[$table][$id] = []; + } + if (empty($this->found[$table][$id][$field])) + { + $this->found[$table][$id][$field] = []; + } + // we should add a call to get the item name if the table has a name field TODO + } + + /** + * we count every field being searched + * + * @since 3.2.0 + */ + protected function fieldCounter() + { + // we count every field we search + $this->config->field_counter += 1; + } \ No newline at end of file diff --git a/src/e544a248-4b6a-46cb-9926-a3ac9937807c/settings.json b/src/e544a248-4b6a-46cb-9926-a3ac9937807c/settings.json new file mode 100644 index 0000000..3dc3cdc --- /dev/null +++ b/src/e544a248-4b6a-46cb-9926-a3ac9937807c/settings.json @@ -0,0 +1,41 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "e544a248-4b6a-46cb-9926-a3ac9937807c", + "implements": [ + "0d9442ab-54d9-4947-a219-244cfaea3084" + ], + "load_selection": null, + "name": "Search", + "power_version": "1.0.0", + "system_name": "JCB.Search.Agent.Search", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a", + "as": "default" + }, + "use_selection1": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + }, + "use_selection2": { + "use": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "as": "default" + }, + "use_selection3": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + }, + "use_selection4": { + "use": "117d8c9e-3f8d-40ae-b375-1efa2fe5538a", + "as": "SearchEngine" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Agent.Search", + "description": "Search Agent Search\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/f523ab49-907a-4356-b064-51c85a187fbd/README.md b/src/f523ab49-907a-4356-b064-51c85a187fbd/README.md new file mode 100644 index 0000000..036c9f7 --- /dev/null +++ b/src/f523ab49-907a-4356-b064-51c85a187fbd/README.md @@ -0,0 +1,85 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Load (Details) +> namespace: **VDM\Joomla\Componentbuilder\Search\Model** +```uml +@startuml +class Load #Gold { + # Config $config + + __construct(?Config $config = null, ?Table $table = null) + + value(mixed $value, string $field, ...) : mixed + # validateBefore(mixed $value, ?string $field = null, ...) : bool + # validateAfter(mixed $value, ?string $field = null, ...) : bool + # getTable() : string +} + +note right of Load::__construct + Constructor + + since: 3.2.0 +end note + +note right of Load::value + Model the value +Example: $this->value(value, 'value_key', 'table_name'); + + since: 3.2.0 + return: mixed + + arguments: + mixed $value + string $field + ?string $table = null +end note + +note right of Load::validateBefore + Validate before the value is modelled (basic, override in child class) + + since: 3.2.0 + return: bool + + arguments: + mixed $value + ?string $field = null + ?string $table = null +end note + +note right of Load::validateAfter + Validate after the value is modelled (basic, override in child class) + + since: 3.2.0 + return: bool + + arguments: + mixed $value + ?string $field = null + ?string $table = null +end note + +note right of Load::getTable + Get the current active table + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/f523ab49-907a-4356-b064-51c85a187fbd/code.php b/src/f523ab49-907a-4356-b064-51c85a187fbd/code.php new file mode 100644 index 0000000..1f0f363 --- /dev/null +++ b/src/f523ab49-907a-4356-b064-51c85a187fbd/code.php @@ -0,0 +1,142 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Search\Model; + + +use VDM\Joomla\Componentbuilder\Search\Factory; +use VDM\Joomla\Componentbuilder\Table; +use VDM\Joomla\Componentbuilder\Search\Config; +use VDM\Joomla\Utilities\JsonHelper; +use VDM\Joomla\Utilities\StringHelper; +use VDM\Joomla\Componentbuilder\Interfaces\ModelInterface; +use VDM\Joomla\Componentbuilder\Abstraction\Model; + + +/** + * Search Load Model + * + * @since 3.2.0 + */ +class Load extends Model implements ModelInterface +{ + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Table|null $table The search table object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Table $table = null) + { + parent::__construct($table ?? Factory::_('Table')); + + $this->config = $config ?: Factory::_('Config'); + } + + /** + * Model the value + * Example: $this->value(value, 'value_key', 'table_name'); + * + * @param mixed $value The value to model + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value($value, string $field, ?string $table = null) + { + // load the table + if (empty($table)) + { + $table = $this->getTable(); + } + + // check if this is a valid table + if (StringHelper::check($value) && ($store = $this->table->get($table, $field, 'store')) !== null) + { + // open the value based on the store method + switch($store) + { + case 'base64': + $value = base64_decode((string) $value); + break; + case 'json': + // check if there is a json string + if (JsonHelper::check($value)) + { + $value = json_decode((string) $value, true); + } + break; + } + } + return $value; + } + + /** + * Validate before the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool + { + return true; + } + + /** + * Validate after the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool + { + // check values + if (StringHelper::check($value) || ArrayHelper::check($value, true)) + { + return true; + } + // remove empty values + return false; + } + + /** + * Get the current active table + * + * @return string + * @since 3.2.0 + */ + protected function getTable(): string + { + return $this->config->table_name; + } + +} + diff --git a/src/f523ab49-907a-4356-b064-51c85a187fbd/code.power b/src/f523ab49-907a-4356-b064-51c85a187fbd/code.power new file mode 100644 index 0000000..11adbdb --- /dev/null +++ b/src/f523ab49-907a-4356-b064-51c85a187fbd/code.power @@ -0,0 +1,109 @@ + /** + * Search Config + * + * @var Config + * @since 3.2.0 + */ + protected Config $config; + + /** + * Constructor + * + * @param Config|null $config The search config object. + * @param Table|null $table The search table object. + * + * @since 3.2.0 + */ + public function __construct(?Config $config = null, ?Table $table = null) + { + parent::__construct($table ?? Factory::_('Table')); + + $this->config = $config ?: Factory::_('Config'); + } + + /** + * Model the value + * Example: $this->value(value, 'value_key', 'table_name'); + * + * @param mixed $value The value to model + * @param string $field The field key + * @param string|null $table The table + * + * @return mixed + * @since 3.2.0 + */ + public function value($value, string $field, ?string $table = null) + { + // load the table + if (empty($table)) + { + $table = $this->getTable(); + } + + // check if this is a valid table + if (StringHelper::check($value) && ($store = $this->table->get($table, $field, 'store')) !== null) + { + // open the value based on the store method + switch($store) + { + case 'base64': + $value = base64_decode((string) $value); + break; + case 'json': + // check if there is a json string + if (JsonHelper::check($value)) + { + $value = json_decode((string) $value, true); + } + break; + } + } + return $value; + } + + /** + * Validate before the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool + { + return true; + } + + /** + * Validate after the value is modelled (basic, override in child class) + * + * @param mixed $value The field value + * @param string|null $field The field key + * @param string|null $table The table + * + * @return bool + * @since 3.2.0 + */ + protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool + { + // check values + if (StringHelper::check($value) || ArrayHelper::check($value, true)) + { + return true; + } + // remove empty values + return false; + } + + /** + * Get the current active table + * + * @return string + * @since 3.2.0 + */ + protected function getTable(): string + { + return $this->config->table_name; + } diff --git a/src/f523ab49-907a-4356-b064-51c85a187fbd/settings.json b/src/f523ab49-907a-4356-b064-51c85a187fbd/settings.json new file mode 100644 index 0000000..ebbbf46 --- /dev/null +++ b/src/f523ab49-907a-4356-b064-51c85a187fbd/settings.json @@ -0,0 +1,41 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "584747d1-3a86-453d-b7a3-a2219de8d777", + "guid": "f523ab49-907a-4356-b064-51c85a187fbd", + "implements": [ + "8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff" + ], + "load_selection": null, + "name": "Load", + "power_version": "1.0.0", + "system_name": "JCB.Search.Model.Load", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "as": "default" + }, + "use_selection1": { + "use": "bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8", + "as": "default" + }, + "use_selection2": { + "use": "6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "as": "default" + }, + "use_selection3": { + "use": "4b225c51-d293-48e4-b3f6-5136cf5c3f18", + "as": "default" + }, + "use_selection4": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Componentbuilder.Search.Model.Load", + "description": "Search Load Model\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/super-powers.json b/super-powers.json new file mode 100644 index 0000000..33ec46a --- /dev/null +++ b/super-powers.json @@ -0,0 +1,242 @@ +{ + "6e2ca779-f70e-4871-a138-0ee5eaec6a97": { + "name": "Config", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search", + "code": "src\/6e2ca779-f70e-4871-a138-0ee5eaec6a97\/code.php", + "power": "src\/6e2ca779-f70e-4871-a138-0ee5eaec6a97\/code.power", + "settings": "src\/6e2ca779-f70e-4871-a138-0ee5eaec6a97\/settings.json", + "path": "src\/6e2ca779-f70e-4871-a138-0ee5eaec6a97", + "guid": "6e2ca779-f70e-4871-a138-0ee5eaec6a97" + }, + "117d8c9e-3f8d-40ae-b375-1efa2fe5538a": { + "name": "SearchTypeInterface", + "type": "interface", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Interfaces", + "code": "src\/117d8c9e-3f8d-40ae-b375-1efa2fe5538a\/code.php", + "power": "src\/117d8c9e-3f8d-40ae-b375-1efa2fe5538a\/code.power", + "settings": "src\/117d8c9e-3f8d-40ae-b375-1efa2fe5538a\/settings.json", + "path": "src\/117d8c9e-3f8d-40ae-b375-1efa2fe5538a", + "guid": "117d8c9e-3f8d-40ae-b375-1efa2fe5538a" + }, + "8f9449fc-bfbc-49a5-b146-d58c8c17dfdf": { + "name": "Engine", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Abstraction", + "code": "src\/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf\/code.php", + "power": "src\/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf\/code.power", + "settings": "src\/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf\/settings.json", + "path": "src\/8f9449fc-bfbc-49a5-b146-d58c8c17dfdf", + "guid": "8f9449fc-bfbc-49a5-b146-d58c8c17dfdf" + }, + "83efa9a0-4aec-41f8-9c05-b1ac9617746e": { + "name": "Regex", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Engine", + "code": "src\/83efa9a0-4aec-41f8-9c05-b1ac9617746e\/code.php", + "power": "src\/83efa9a0-4aec-41f8-9c05-b1ac9617746e\/code.power", + "settings": "src\/83efa9a0-4aec-41f8-9c05-b1ac9617746e\/settings.json", + "path": "src\/83efa9a0-4aec-41f8-9c05-b1ac9617746e", + "guid": "83efa9a0-4aec-41f8-9c05-b1ac9617746e" + }, + "db093eca-63b3-4d6c-9232-3ceb058121c0": { + "name": "Basic", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Engine", + "code": "src\/db093eca-63b3-4d6c-9232-3ceb058121c0\/code.php", + "power": "src\/db093eca-63b3-4d6c-9232-3ceb058121c0\/code.power", + "settings": "src\/db093eca-63b3-4d6c-9232-3ceb058121c0\/settings.json", + "path": "src\/db093eca-63b3-4d6c-9232-3ceb058121c0", + "guid": "db093eca-63b3-4d6c-9232-3ceb058121c0" + }, + "da714ea5-96bb-4eb1-959b-39b457be9cd1": { + "name": "Search", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Service", + "code": "src\/da714ea5-96bb-4eb1-959b-39b457be9cd1\/code.php", + "power": "src\/da714ea5-96bb-4eb1-959b-39b457be9cd1\/code.power", + "settings": "src\/da714ea5-96bb-4eb1-959b-39b457be9cd1\/settings.json", + "path": "src\/da714ea5-96bb-4eb1-959b-39b457be9cd1", + "guid": "da714ea5-96bb-4eb1-959b-39b457be9cd1" + }, + "f523ab49-907a-4356-b064-51c85a187fbd": { + "name": "Load", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Model", + "code": "src\/f523ab49-907a-4356-b064-51c85a187fbd\/code.php", + "power": "src\/f523ab49-907a-4356-b064-51c85a187fbd\/code.power", + "settings": "src\/f523ab49-907a-4356-b064-51c85a187fbd\/settings.json", + "path": "src\/f523ab49-907a-4356-b064-51c85a187fbd", + "guid": "f523ab49-907a-4356-b064-51c85a187fbd" + }, + "02efe40a-7792-4c82-9444-7d0377243483": { + "name": "Insert", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Model", + "code": "src\/02efe40a-7792-4c82-9444-7d0377243483\/code.php", + "power": "src\/02efe40a-7792-4c82-9444-7d0377243483\/code.power", + "settings": "src\/02efe40a-7792-4c82-9444-7d0377243483\/settings.json", + "path": "src\/02efe40a-7792-4c82-9444-7d0377243483", + "guid": "02efe40a-7792-4c82-9444-7d0377243483" + }, + "7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a": { + "name": "Model", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Service", + "code": "src\/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a\/code.php", + "power": "src\/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a\/code.power", + "settings": "src\/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a\/settings.json", + "path": "src\/7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a", + "guid": "7f40cc7d-9ab8-4601-8a2b-4eb3d712a40a" + }, + "2bd1a32c-3d90-4646-9314-28d44d164f76": { + "name": "LoadInterface", + "type": "interface", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Interfaces", + "code": "src\/2bd1a32c-3d90-4646-9314-28d44d164f76\/code.php", + "power": "src\/2bd1a32c-3d90-4646-9314-28d44d164f76\/code.power", + "settings": "src\/2bd1a32c-3d90-4646-9314-28d44d164f76\/settings.json", + "path": "src\/2bd1a32c-3d90-4646-9314-28d44d164f76", + "guid": "2bd1a32c-3d90-4646-9314-28d44d164f76" + }, + "2dabfb4a-64cd-4c04-9772-4a75f9f3b710": { + "name": "Load", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Database", + "code": "src\/2dabfb4a-64cd-4c04-9772-4a75f9f3b710\/code.php", + "power": "src\/2dabfb4a-64cd-4c04-9772-4a75f9f3b710\/code.power", + "settings": "src\/2dabfb4a-64cd-4c04-9772-4a75f9f3b710\/settings.json", + "path": "src\/2dabfb4a-64cd-4c04-9772-4a75f9f3b710", + "guid": "2dabfb4a-64cd-4c04-9772-4a75f9f3b710" + }, + "4c44e5d3-750c-4609-88c8-aa441838b8fe": { + "name": "InsertInterface", + "type": "interface", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Interfaces", + "code": "src\/4c44e5d3-750c-4609-88c8-aa441838b8fe\/code.php", + "power": "src\/4c44e5d3-750c-4609-88c8-aa441838b8fe\/code.power", + "settings": "src\/4c44e5d3-750c-4609-88c8-aa441838b8fe\/settings.json", + "path": "src\/4c44e5d3-750c-4609-88c8-aa441838b8fe", + "guid": "4c44e5d3-750c-4609-88c8-aa441838b8fe" + }, + "6caf9473-133c-49a9-afa0-9f84151b5155": { + "name": "Insert", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Database", + "code": "src\/6caf9473-133c-49a9-afa0-9f84151b5155\/code.php", + "power": "src\/6caf9473-133c-49a9-afa0-9f84151b5155\/code.power", + "settings": "src\/6caf9473-133c-49a9-afa0-9f84151b5155\/settings.json", + "path": "src\/6caf9473-133c-49a9-afa0-9f84151b5155", + "guid": "6caf9473-133c-49a9-afa0-9f84151b5155" + }, + "d5de47ce-9a9e-4e76-a5c6-61ed74842ea3": { + "name": "Database", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Service", + "code": "src\/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3\/code.php", + "power": "src\/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3\/code.power", + "settings": "src\/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3\/settings.json", + "path": "src\/d5de47ce-9a9e-4e76-a5c6-61ed74842ea3", + "guid": "d5de47ce-9a9e-4e76-a5c6-61ed74842ea3" + }, + "55280ec7-e48d-431b-af25-10308dd30636": { + "name": "FindInterface", + "type": "interface", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Interfaces", + "code": "src\/55280ec7-e48d-431b-af25-10308dd30636\/code.php", + "power": "src\/55280ec7-e48d-431b-af25-10308dd30636\/code.power", + "settings": "src\/55280ec7-e48d-431b-af25-10308dd30636\/settings.json", + "path": "src\/55280ec7-e48d-431b-af25-10308dd30636", + "guid": "55280ec7-e48d-431b-af25-10308dd30636" + }, + "0d9442ab-54d9-4947-a219-244cfaea3084": { + "name": "SearchInterface", + "type": "interface", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Interfaces", + "code": "src\/0d9442ab-54d9-4947-a219-244cfaea3084\/code.php", + "power": "src\/0d9442ab-54d9-4947-a219-244cfaea3084\/code.power", + "settings": "src\/0d9442ab-54d9-4947-a219-244cfaea3084\/settings.json", + "path": "src\/0d9442ab-54d9-4947-a219-244cfaea3084", + "guid": "0d9442ab-54d9-4947-a219-244cfaea3084" + }, + "e544a248-4b6a-46cb-9926-a3ac9937807c": { + "name": "Search", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Agent", + "code": "src\/e544a248-4b6a-46cb-9926-a3ac9937807c\/code.php", + "power": "src\/e544a248-4b6a-46cb-9926-a3ac9937807c\/code.power", + "settings": "src\/e544a248-4b6a-46cb-9926-a3ac9937807c\/settings.json", + "path": "src\/e544a248-4b6a-46cb-9926-a3ac9937807c", + "guid": "e544a248-4b6a-46cb-9926-a3ac9937807c" + }, + "15d9e1a9-3364-4d69-9d9f-9b87db820e5c": { + "name": "Find", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Agent", + "code": "src\/15d9e1a9-3364-4d69-9d9f-9b87db820e5c\/code.php", + "power": "src\/15d9e1a9-3364-4d69-9d9f-9b87db820e5c\/code.power", + "settings": "src\/15d9e1a9-3364-4d69-9d9f-9b87db820e5c\/settings.json", + "path": "src\/15d9e1a9-3364-4d69-9d9f-9b87db820e5c", + "guid": "15d9e1a9-3364-4d69-9d9f-9b87db820e5c" + }, + "afdae35d-fe7f-4055-99ea-afd8ff8349b6": { + "name": "ReplaceInterface", + "type": "interface", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Interfaces", + "code": "src\/afdae35d-fe7f-4055-99ea-afd8ff8349b6\/code.php", + "power": "src\/afdae35d-fe7f-4055-99ea-afd8ff8349b6\/code.power", + "settings": "src\/afdae35d-fe7f-4055-99ea-afd8ff8349b6\/settings.json", + "path": "src\/afdae35d-fe7f-4055-99ea-afd8ff8349b6", + "guid": "afdae35d-fe7f-4055-99ea-afd8ff8349b6" + }, + "3ac29912-0681-4ca9-8197-d5a8f6a49ac7": { + "name": "Update", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Agent", + "code": "src\/3ac29912-0681-4ca9-8197-d5a8f6a49ac7\/code.php", + "power": "src\/3ac29912-0681-4ca9-8197-d5a8f6a49ac7\/code.power", + "settings": "src\/3ac29912-0681-4ca9-8197-d5a8f6a49ac7\/settings.json", + "path": "src\/3ac29912-0681-4ca9-8197-d5a8f6a49ac7", + "guid": "3ac29912-0681-4ca9-8197-d5a8f6a49ac7" + }, + "abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7": { + "name": "Replace", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Agent", + "code": "src\/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7\/code.php", + "power": "src\/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7\/code.power", + "settings": "src\/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7\/settings.json", + "path": "src\/abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7", + "guid": "abc37ddd-1ff5-4204-9e5b-015ab4f3d4c7" + }, + "0b658434-3767-401e-addc-eabfd1d0e94a": { + "name": "Agent", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search", + "code": "src\/0b658434-3767-401e-addc-eabfd1d0e94a\/code.php", + "power": "src\/0b658434-3767-401e-addc-eabfd1d0e94a\/code.power", + "settings": "src\/0b658434-3767-401e-addc-eabfd1d0e94a\/settings.json", + "path": "src\/0b658434-3767-401e-addc-eabfd1d0e94a", + "guid": "0b658434-3767-401e-addc-eabfd1d0e94a" + }, + "cc6972a7-1574-4ae0-92a8-7f1012aac6f7": { + "name": "Agent", + "type": "class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search\\Service", + "code": "src\/cc6972a7-1574-4ae0-92a8-7f1012aac6f7\/code.php", + "power": "src\/cc6972a7-1574-4ae0-92a8-7f1012aac6f7\/code.power", + "settings": "src\/cc6972a7-1574-4ae0-92a8-7f1012aac6f7\/settings.json", + "path": "src\/cc6972a7-1574-4ae0-92a8-7f1012aac6f7", + "guid": "cc6972a7-1574-4ae0-92a8-7f1012aac6f7" + }, + "01a89ba8-f8bb-435c-93de-0a8f3fa9432a": { + "name": "Factory", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Search", + "code": "src\/01a89ba8-f8bb-435c-93de-0a8f3fa9432a\/code.php", + "power": "src\/01a89ba8-f8bb-435c-93de-0a8f3fa9432a\/code.power", + "settings": "src\/01a89ba8-f8bb-435c-93de-0a8f3fa9432a\/settings.json", + "path": "src\/01a89ba8-f8bb-435c-93de-0a8f3fa9432a", + "guid": "01a89ba8-f8bb-435c-93de-0a8f3fa9432a" + } +} \ No newline at end of file