forked from joomla/super-powers
Update 2024-10-08 03:57:31
This commit is contained in:
parent
8c8f4a0b58
commit
492bab1f36
@ -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`
|
||||
|
65
src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/README.md
Normal file
65
src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/README.md
Normal file
@ -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)
|
||||
|
72
src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.php
Normal file
72
src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 4th September, 2022
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git Joomla Component Builder <https://git.vdm.dev/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;
|
||||
}
|
||||
}
|
||||
|
46
src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.power
Normal file
46
src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/code.power
Normal file
@ -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;
|
||||
}
|
29
src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/settings.json
Normal file
29
src/9ae018a5-9064-40ed-ad69-9c1ed2a459f5/settings.json
Normal file
@ -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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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"
|
||||
},
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user