diff --git a/README.md b/README.md index 3cade74..d42c106 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ This repository contains an index (see below) of all the approved powers within - **class Spreadsheet** | [Details](src/c4a188de-ad78-4a6d-9d5b-01866846d701) | [Code](src/c4a188de-ad78-4a6d-9d5b-01866846d701/code.php) | [Settings](src/c4a188de-ad78-4a6d-9d5b-01866846d701/settings.json) | SPK: `Super---c4a188de_ad78_4a6d_9d5b_01866846d701---Power` - **Namespace**: [VDM\Joomla\Componentbuilder\Spreadsheet](#vdm-joomla-componentbuilder-spreadsheet) + - **final class ChunkReadFilter** | [Details](src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5) | [Code](src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.php) | [Settings](src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/settings.json) | SPK: `Super---9ae018a5_9064_40ed_ad69_9c1ed2a459f5---Power` - **final class Exporter** | [Details](src/e250638e-4a50-41f9-9172-db3e7f174d26) | [Code](src/e250638e-4a50-41f9-9172-db3e7f174d26/code.php) | [Settings](src/e250638e-4a50-41f9-9172-db3e7f174d26/settings.json) | SPK: `Super---e250638e_4a50_41f9_9172_db3e7f174d26---Power` - **final class Header** | [Details](src/fd3f322a-082d-4579-93ad-3352c5adfc71) | [Code](src/fd3f322a-082d-4579-93ad-3352c5adfc71/code.php) | [Settings](src/fd3f322a-082d-4579-93ad-3352c5adfc71/settings.json) | SPK: `Super---fd3f322a_082d_4579_93ad_3352c5adfc71---Power` - **final class Importer** | [Details](src/c4169332-3914-400e-b861-972b2d465963) | [Code](src/c4169332-3914-400e-b861-972b2d465963/code.php) | [Settings](src/c4169332-3914-400e-b861-972b2d465963/settings.json) | SPK: `Super---c4169332_3914_400e_b861_972b2d465963---Power` diff --git a/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/README.md b/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/README.md new file mode 100644 index 0000000..f5e6a2f --- /dev/null +++ b/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/README.md @@ -0,0 +1,65 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# final class ChunkReadFilter (Details) +> namespace: **VDM\Joomla\Componentbuilder\Spreadsheet** +> extends: **IReadFilter** + +```uml +@startuml +class ChunkReadFilter << (F,LightGreen) >> #RoyalBlue { + - $startRow + - $endRow + + __construct(int $startRow, int $chunkSize) + + readCell(string $column, int $row, ...) : bool +} + +note right of ChunkReadFilter::__construct + Constructor to initialize the chunk filter. + +end note + +note right of ChunkReadFilter::readCell + Determines whether a cell should be read based on its row and column. + + return: bool + + arguments: + string $column + int $row + string|null $worksheetName = null +end note + +@enduml +``` + +The Power feature in JCB allows you to write PHP classes and their implementations, making it easy to include them in your Joomla project. JCB handles linking, autoloading, namespacing, and folder structure creation for you. + +By using the SPK (Super Power Key) in your custom code (replacing the class name in your code with the SPK), JCB will automatically pull the power from the repository into your project. This makes it available in your JCB instance, allowing you to edit it and include the class in your generated Joomla component. + +JCB uses placeholders like [[[`NamespacePrefix`]]] and [[[`ComponentNamespace`]]] in namespacing to prevent collisions and improve reusability across different JCB systems. You can also set the **JCB powers path** globally or per component under the **Dynamic Integration** tab, providing flexibility and easy maintainability. + +To add this specific Power to your project in JCB: + +> simply use this SPK +``` +Super---9ae018a5_9064_40ed_ad69_9c1ed2a459f5---Power +``` +> remember to replace the `---` with `___` to activate this Power in your code + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.php b/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.php new file mode 100644 index 0000000..c725ab1 --- /dev/null +++ b/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.php @@ -0,0 +1,72 @@ + + * @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\Spreadsheet; + + +use PhpOffice\PhpSpreadsheet\Reader\IReadFilter; + + +/** + * Chunk Read Filter Class + * + * @since 3.2.0 + */ +final class ChunkReadFilter extends IReadFilter +{ + /** + * The first row to read in the current chunk. + * + * @var int + */ + private $startRow; + + /** + * The last row to read in the current chunk. + * This is calculated as $startRow + $chunkSize - 1. + * + * @var int + */ + private $endRow; + + /** + * Constructor to initialize the chunk filter. + * + * @param int $startRow The starting row to read. + * @param int $chunkSize The number of rows to read in each chunk. + */ + public function __construct(int $startRow, int $chunkSize) + { + $this->startRow = $startRow; + $this->endRow = $startRow + $chunkSize - 1; + } + + /** + * Determines whether a cell should be read based on its row and column. + * + * @param string $column The column index (e.g., 'A', 'B', 'C'). + * @param int $row The row index. + * @param string|null $worksheetName The worksheet name (not used in this case). + * + * @return bool Whether the cell should be read. + */ + public function readCell($column, $row, $worksheetName = null) + { + // Only read rows that fall within the chunk range + if ($row >= $this->startRow && $row <= $this->endRow) + { + return true; + } + + return false; + } +} + diff --git a/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.power b/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.power new file mode 100644 index 0000000..053c8c8 --- /dev/null +++ b/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.power @@ -0,0 +1,46 @@ + /** + * The first row to read in the current chunk. + * + * @var int + */ + private $startRow; + + /** + * The last row to read in the current chunk. + * This is calculated as $startRow + $chunkSize - 1. + * + * @var int + */ + private $endRow; + + /** + * Constructor to initialize the chunk filter. + * + * @param int $startRow The starting row to read. + * @param int $chunkSize The number of rows to read in each chunk. + */ + public function __construct(int $startRow, int $chunkSize) + { + $this->startRow = $startRow; + $this->endRow = $startRow + $chunkSize - 1; + } + + /** + * Determines whether a cell should be read based on its row and column. + * + * @param string $column The column index (e.g., 'A', 'B', 'C'). + * @param int $row The row index. + * @param string|null $worksheetName The worksheet name (not used in this case). + * + * @return bool Whether the cell should be read. + */ + public function readCell($column, $row, $worksheetName = null) + { + // Only read rows that fall within the chunk range + if ($row >= $this->startRow && $row <= $this->endRow) + { + return true; + } + + return false; + } \ No newline at end of file diff --git a/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/settings.json b/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/settings.json new file mode 100644 index 0000000..fd6396e --- /dev/null +++ b/src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/settings.json @@ -0,0 +1,29 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "-1", + "guid": "9ae018a5-9064-40ed-ad69-9c1ed2a459f5", + "implements": null, + "load_selection": null, + "name": "ChunkReadFilter", + "power_version": "1.0.0", + "system_name": "JCB.Spreadsheet.ChunkReadFilter", + "type": "final class", + "use_selection": null, + "extendsinterfaces": null, + "namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Spreadsheet.ChunkReadFilter", + "description": "Chunk Read Filter Class\r\n\r\n@since 3.2.0", + "extends_custom": "IReadFilter", + "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": { + "composer0": { + "access_point": "phpspreadsheet\/vendor\/autoload.php", + "namespace": { + "namespace0": { + "use": "PhpOffice\\PhpSpreadsheet\\Reader\\IReadFilter" + } + } + } + } +} \ No newline at end of file diff --git a/src/c4169332-3914-400e-b861-972b2d465963/code.php b/src/c4169332-3914-400e-b861-972b2d465963/code.php index d146091..b68f0a8 100644 --- a/src/c4169332-3914-400e-b861-972b2d465963/code.php +++ b/src/c4169332-3914-400e-b861-972b2d465963/code.php @@ -13,9 +13,9 @@ namespace VDM\Joomla\Componentbuilder\Spreadsheet; use PhpOffice\PhpSpreadsheet\IOFactory; -use PhpOffice\PhpSpreadsheet\Reader\IReadFilter; use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException; +use VDM\Joomla\Componentbuilder\Spreadsheet\ChunkReadFilter; /** diff --git a/src/c4169332-3914-400e-b861-972b2d465963/settings.json b/src/c4169332-3914-400e-b861-972b2d465963/settings.json index 7e72b06..157695a 100644 --- a/src/c4169332-3914-400e-b861-972b2d465963/settings.json +++ b/src/c4169332-3914-400e-b861-972b2d465963/settings.json @@ -9,7 +9,12 @@ "power_version": "1.0.0", "system_name": "JCB.Spreadsheet.Importer", "type": "final class", - "use_selection": null, + "use_selection": { + "use_selection0": { + "use": "9ae018a5-9064-40ed-ad69-9c1ed2a459f5", + "as": "default" + } + }, "extendsinterfaces": null, "namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Spreadsheet.Importer", "description": "Spreadsheet Importer Class\r\n\r\n@since 3.2.0", @@ -22,9 +27,6 @@ "namespace0": { "use": "PhpOffice\\PhpSpreadsheet\\IOFactory" }, - "namespace1": { - "use": "PhpOffice\\PhpSpreadsheet\\Reader\\IReadFilter" - }, "namespace2": { "use": "PhpOffice\\PhpSpreadsheet\\Reader\\Exception as ReaderException" }, diff --git a/src/fd3f322a-082d-4579-93ad-3352c5adfc71/code.php b/src/fd3f322a-082d-4579-93ad-3352c5adfc71/code.php index 2944f61..e683029 100644 --- a/src/fd3f322a-082d-4579-93ad-3352c5adfc71/code.php +++ b/src/fd3f322a-082d-4579-93ad-3352c5adfc71/code.php @@ -13,7 +13,7 @@ namespace VDM\Joomla\Componentbuilder\Spreadsheet; use PhpOffice\PhpSpreadsheet\IOFactory; -use PhpOffice\PhpSpreadsheet\Reader\IReadFilter; +use VDM\Joomla\Componentbuilder\Spreadsheet\ChunkReadFilter; /** @@ -40,7 +40,7 @@ final class Header } try { - $chunkFilter = new ChunkReadFilter(2, 1); + $chunkFilter = new ChunkReadFilter(20, 1); $inputFileType = IOFactory::identify($filePath); $reader = IOFactory::createReader($inputFileType); $reader->setReadFilter($chunkFilter); diff --git a/src/fd3f322a-082d-4579-93ad-3352c5adfc71/code.power b/src/fd3f322a-082d-4579-93ad-3352c5adfc71/code.power index 2b6220e..1719377 100644 --- a/src/fd3f322a-082d-4579-93ad-3352c5adfc71/code.power +++ b/src/fd3f322a-082d-4579-93ad-3352c5adfc71/code.power @@ -15,7 +15,7 @@ } try { - $chunkFilter = new ChunkReadFilter(2, 1); + $chunkFilter = new ChunkReadFilter(20, 1); $inputFileType = IOFactory::identify($filePath); $reader = IOFactory::createReader($inputFileType); $reader->setReadFilter($chunkFilter); diff --git a/src/fd3f322a-082d-4579-93ad-3352c5adfc71/settings.json b/src/fd3f322a-082d-4579-93ad-3352c5adfc71/settings.json index 6f2ef9a..acd13b3 100644 --- a/src/fd3f322a-082d-4579-93ad-3352c5adfc71/settings.json +++ b/src/fd3f322a-082d-4579-93ad-3352c5adfc71/settings.json @@ -9,7 +9,12 @@ "power_version": "1.0.0", "system_name": "JCB.Spreadsheet.Header", "type": "final class", - "use_selection": null, + "use_selection": { + "use_selection0": { + "use": "9ae018a5-9064-40ed-ad69-9c1ed2a459f5", + "as": "default" + } + }, "extendsinterfaces": null, "namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Spreadsheet.Header", "description": "Spreadsheet Header Class\r\n\r\n@since 3.2.0", @@ -21,9 +26,6 @@ "namespace": { "namespace0": { "use": "PhpOffice\\PhpSpreadsheet\\IOFactory" - }, - "namespace1": { - "use": "PhpOffice\\PhpSpreadsheet\\Reader\\IReadFilter" } } } diff --git a/super-powers.json b/super-powers.json index e0c039c..abd7d42 100644 --- a/super-powers.json +++ b/super-powers.json @@ -736,6 +736,17 @@ "spk": "Super---95c02df3_fe0a_405b_b506_b7a5b8605b66---Power", "guid": "95c02df3-fe0a-405b-b506-b7a5b8605b66" }, + "9ae018a5-9064-40ed-ad69-9c1ed2a459f5": { + "name": "ChunkReadFilter", + "type": "final class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Spreadsheet", + "code": "src\/9ae018a5-9064-40ed-ad69-9c1ed2a459f5\/code.php", + "power": "src\/9ae018a5-9064-40ed-ad69-9c1ed2a459f5\/code.power", + "settings": "src\/9ae018a5-9064-40ed-ad69-9c1ed2a459f5\/settings.json", + "path": "src\/9ae018a5-9064-40ed-ad69-9c1ed2a459f5", + "spk": "Super---9ae018a5_9064_40ed_ad69_9c1ed2a459f5---Power", + "guid": "9ae018a5-9064-40ed-ad69-9c1ed2a459f5" + }, "9c3aa650-e536-4eea-a2d4-73cc3e184aa9": { "name": "DeleteInterface", "type": "interface",