Update 2024-10-02 04:42:31

This commit is contained in:
Robot 2024-10-02 04:42:50 +02:00
parent a980aa9f81
commit 25b4ae4215
Signed by untrusted user: Robot
GPG Key ID: 14DECD44E7E1BB95
22 changed files with 1769 additions and 0 deletions

View File

@ -110,6 +110,14 @@ This repository contains an index (see below) of all the approved powers within
- **final class Handler** | [Details](src/4144ad3b-2ad5-401f-af0c-a3d856c1e688) | [Code](src/4144ad3b-2ad5-401f-af0c-a3d856c1e688/code.php) | [Settings](src/4144ad3b-2ad5-401f-af0c-a3d856c1e688/settings.json) | SPK: `Super---4144ad3b_2ad5_401f_af0c_a3d856c1e688---Power` - **final class Handler** | [Details](src/4144ad3b-2ad5-401f-af0c-a3d856c1e688) | [Code](src/4144ad3b-2ad5-401f-af0c-a3d856c1e688/code.php) | [Settings](src/4144ad3b-2ad5-401f-af0c-a3d856c1e688/settings.json) | SPK: `Super---4144ad3b_2ad5_401f_af0c_a3d856c1e688---Power`
- **final class Manager** | [Details](src/67a5e0ca-0ff0-4979-9b41-da0b09988016) | [Code](src/67a5e0ca-0ff0-4979-9b41-da0b09988016/code.php) | [Settings](src/67a5e0ca-0ff0-4979-9b41-da0b09988016/settings.json) | SPK: `Super---67a5e0ca_0ff0_4979_9b41_da0b09988016---Power` - **final class Manager** | [Details](src/67a5e0ca-0ff0-4979-9b41-da0b09988016) | [Code](src/67a5e0ca-0ff0-4979-9b41-da0b09988016/code.php) | [Settings](src/67a5e0ca-0ff0-4979-9b41-da0b09988016/settings.json) | SPK: `Super---67a5e0ca_0ff0_4979_9b41_da0b09988016---Power`
- **final class Type** | [Details](src/12a2a8de-a893-4dbb-a53d-b52de4f6cb0e) | [Code](src/12a2a8de-a893-4dbb-a53d-b52de4f6cb0e/code.php) | [Settings](src/12a2a8de-a893-4dbb-a53d-b52de4f6cb0e/settings.json) | SPK: `Super---12a2a8de_a893_4dbb_a53d_b52de4f6cb0e---Power` - **final class Type** | [Details](src/12a2a8de-a893-4dbb-a53d-b52de4f6cb0e) | [Code](src/12a2a8de-a893-4dbb-a53d-b52de4f6cb0e/code.php) | [Settings](src/12a2a8de-a893-4dbb-a53d-b52de4f6cb0e/settings.json) | SPK: `Super---12a2a8de_a893_4dbb_a53d_b52de4f6cb0e---Power`
- **Namespace**: [VDM\Joomla\Componentbuilder\Import](#vdm-joomla-componentbuilder-import)
- **abstract class Factory** | [Details](src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068) | [Code](src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/code.php) | [Settings](src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/settings.json) | SPK: `Super---ff8d5fdb_2d1f_4178_bd18_a43b8efd1068---Power`
- **Namespace**: [VDM\Joomla\Componentbuilder\Spreadsheet](#vdm-joomla-componentbuilder-spreadsheet)
- **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`
- **Namespace**: [VDM\Joomla\Componentbuilder\Table](#vdm-joomla-componentbuilder-table) - **Namespace**: [VDM\Joomla\Componentbuilder\Table](#vdm-joomla-componentbuilder-table)
- **final class Schema** | [Details](src/b3d2ec33-76d4-4c3b-bb2c-86ac14a221ce) | [Code](src/b3d2ec33-76d4-4c3b-bb2c-86ac14a221ce/code.php) | [Settings](src/b3d2ec33-76d4-4c3b-bb2c-86ac14a221ce/settings.json) | SPK: `Super---b3d2ec33_76d4_4c3b_bb2c_86ac14a221ce---Power` - **final class Schema** | [Details](src/b3d2ec33-76d4-4c3b-bb2c-86ac14a221ce) | [Code](src/b3d2ec33-76d4-4c3b-bb2c-86ac14a221ce/code.php) | [Settings](src/b3d2ec33-76d4-4c3b-bb2c-86ac14a221ce/settings.json) | SPK: `Super---b3d2ec33_76d4_4c3b_bb2c_86ac14a221ce---Power`
@ -168,6 +176,9 @@ This repository contains an index (see below) of all the approved powers within
- **Namespace**: [VDM\Joomla\Componentbuilder\File\Service](#vdm-joomla-componentbuilder-file-service) - **Namespace**: [VDM\Joomla\Componentbuilder\File\Service](#vdm-joomla-componentbuilder-file-service)
- **class File** | [Details](src/202ccd9e-dfcf-4cde-a0ce-bde1fd27f088) | [Code](src/202ccd9e-dfcf-4cde-a0ce-bde1fd27f088/code.php) | [Settings](src/202ccd9e-dfcf-4cde-a0ce-bde1fd27f088/settings.json) | SPK: `Super---202ccd9e_dfcf_4cde_a0ce_bde1fd27f088---Power` - **class File** | [Details](src/202ccd9e-dfcf-4cde-a0ce-bde1fd27f088) | [Code](src/202ccd9e-dfcf-4cde-a0ce-bde1fd27f088/code.php) | [Settings](src/202ccd9e-dfcf-4cde-a0ce-bde1fd27f088/settings.json) | SPK: `Super---202ccd9e_dfcf_4cde_a0ce_bde1fd27f088---Power`
- **Namespace**: [VDM\Joomla\Componentbuilder\Spreadsheet\Service](#vdm-joomla-componentbuilder-spreadsheet-service)
- **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\Utilities\Exception](#vdm-joomla-componentbuilder-utilities-exception) - **Namespace**: [VDM\Joomla\Componentbuilder\Utilities\Exception](#vdm-joomla-componentbuilder-utilities-exception)
- **class NoUserIdFoundException** | [Details](src/1c10a5f1-204d-4f17-ad9f-0e0684f2030d) | [Code](src/1c10a5f1-204d-4f17-ad9f-0e0684f2030d/code.php) | [Settings](src/1c10a5f1-204d-4f17-ad9f-0e0684f2030d/settings.json) | SPK: `Super---1c10a5f1_204d_4f17_ad9f_0e0684f2030d---Power` - **class NoUserIdFoundException** | [Details](src/1c10a5f1-204d-4f17-ad9f-0e0684f2030d) | [Code](src/1c10a5f1-204d-4f17-ad9f-0e0684f2030d/code.php) | [Settings](src/1c10a5f1-204d-4f17-ad9f-0e0684f2030d/settings.json) | SPK: `Super---1c10a5f1_204d_4f17_ad9f_0e0684f2030d---Power`

View File

@ -0,0 +1,57 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Importer (Details)
> namespace: **VDM\Joomla\Componentbuilder\Spreadsheet**
```uml
@startuml
class Importer << (F,LightGreen) >> #RoyalBlue {
+ get(string $filePath, int $startRow = 1, ...) : \Generator
}
note right of Importer::get
Stream rows from a CSV or Excel file one by one using yield.
since: 3.2.0
return: \Generator
arguments:
string $filePath
int $startRow = 1
int $chunkSize = 100
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---c4169332_3914_400e_b861_972b2d465963---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)

View File

@ -0,0 +1,99 @@
<?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\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
/**
* Spreadsheet Importer Class
*
* @since 3.2.0
*/
final class Importer
{
/**
* Stream rows from a CSV or Excel file one by one using yield.
*
* @param string $filePath The path to the file.
* @param int $startRow The starting row index (default is 1).
* @param int $chunkSize The number of rows to read per chunk (default is 100).
*
* @return \Generator A generator that yields each row as an array.
* @throws \InvalidArgumentException If the file does not exist.
* @throws ReaderException If there is an error identifying or reading the file.
* @throws SpreadsheetException If there is an error working with the spreadsheet.
* @since 3.2.0
*/
public function get(string $filePath, int $startRow = 1, int $chunkSize = 100): \Generator
{
// Check if the file exists
if (!is_file($filePath))
{
throw new \InvalidArgumentException("File not found: $filePath");
}
try {
// Initialize variables for row processing
$totalRows = $startRow;
do {
// Set up a new chunk filter for the current chunk
$chunkFilter = new ChunkReadFilter($totalRows, $chunkSize);
$inputFileType = IOFactory::identify($filePath);
$reader = IOFactory::createReader($inputFileType);
$reader->setReadFilter($chunkFilter);
$reader->setReadDataOnly(true);
// Load the chunk into the spreadsheet
$spreadsheet = $reader->load($filePath);
$worksheet = $spreadsheet->getActiveSheet();
// Iterate through the rows in the current chunk
foreach ($worksheet->getRowIterator($totalRows) as $row)
{
$rowIndex = $row->getRowIndex();
$rowData = [];
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false); // Include empty cells
// Collect all cell data in the row
foreach ($cellIterator as $cell)
{
$rowData[$cell->getColumn()] = $cell->getValue();
}
yield $rowData;
// Update the row index for the next chunk
$totalRows = $rowIndex + 1;
}
// Disconnect the spreadsheet to free memory
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
} while (!empty($rowData)); // Continue reading until no more rows are available
} catch (ReaderException $e) {
throw new ReaderException("Error reading the file: " . $e->getMessage(), $e->getCode(), $e);
} catch (SpreadsheetException $e) {
throw new SpreadsheetException("Error with the spreadsheet: " . $e->getMessage(), $e->getCode(), $e);
}
}
}

View File

@ -0,0 +1,70 @@
/**
* Stream rows from a CSV or Excel file one by one using yield.
*
* @param string $filePath The path to the file.
* @param int $startRow The starting row index (default is 1).
* @param int $chunkSize The number of rows to read per chunk (default is 100).
*
* @return \Generator A generator that yields each row as an array.
* @throws \InvalidArgumentException If the file does not exist.
* @throws ReaderException If there is an error identifying or reading the file.
* @throws SpreadsheetException If there is an error working with the spreadsheet.
* @since 3.2.0
*/
public function get(string $filePath, int $startRow = 1, int $chunkSize = 100): \Generator
{
// Check if the file exists
if (!is_file($filePath))
{
throw new \InvalidArgumentException("File not found: $filePath");
}
try {
// Initialize variables for row processing
$totalRows = $startRow;
do {
// Set up a new chunk filter for the current chunk
$chunkFilter = new ChunkReadFilter($totalRows, $chunkSize);
$inputFileType = IOFactory::identify($filePath);
$reader = IOFactory::createReader($inputFileType);
$reader->setReadFilter($chunkFilter);
$reader->setReadDataOnly(true);
// Load the chunk into the spreadsheet
$spreadsheet = $reader->load($filePath);
$worksheet = $spreadsheet->getActiveSheet();
// Iterate through the rows in the current chunk
foreach ($worksheet->getRowIterator($totalRows) as $row)
{
$rowIndex = $row->getRowIndex();
$rowData = [];
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false); // Include empty cells
// Collect all cell data in the row
foreach ($cellIterator as $cell)
{
$rowData[$cell->getColumn()] = $cell->getValue();
}
yield $rowData;
// Update the row index for the next chunk
$totalRows = $rowIndex + 1;
}
// Disconnect the spreadsheet to free memory
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
} while (!empty($rowData)); // Continue reading until no more rows are available
} catch (ReaderException $e) {
throw new ReaderException("Error reading the file: " . $e->getMessage(), $e->getCode(), $e);
} catch (SpreadsheetException $e) {
throw new SpreadsheetException("Error with the spreadsheet: " . $e->getMessage(), $e->getCode(), $e);
}
}

View File

@ -0,0 +1,37 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "",
"guid": "c4169332-3914-400e-b861-972b2d465963",
"implements": null,
"load_selection": null,
"name": "Importer",
"power_version": "1.0.0",
"system_name": "JCB.Spreadsheet.Importer",
"type": "final class",
"use_selection": null,
"extendsinterfaces": null,
"namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Spreadsheet.Importer",
"description": "Spreadsheet Importer Class\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 <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\\IOFactory"
},
"namespace1": {
"use": "PhpOffice\\PhpSpreadsheet\\Reader\\IReadFilter"
},
"namespace2": {
"use": "PhpOffice\\PhpSpreadsheet\\Reader\\Exception as ReaderException"
},
"namespace3": {
"use": "PhpOffice\\PhpSpreadsheet\\Exception as SpreadsheetException"
}
}
}
}
}

View File

@ -0,0 +1,76 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# class Spreadsheet (Details)
> namespace: **VDM\Joomla\Componentbuilder\Spreadsheet\Service**
```uml
@startuml
class Spreadsheet #Gold {
+ register(Container $container) : void
+ getHeader(Container $container) : Header
+ getExporter(Container $container) : Exporter
+ getImporter(Container $container) : Importer
}
note right of Spreadsheet::register
Registers the service provider with a DI container.
since: 5.0.3
return: void
end note
note right of Spreadsheet::getHeader
Get The Header Class.
since: 5.0.3
return: Header
end note
note right of Spreadsheet::getExporter
Get The Exporter Class.
since: 5.0.3
return: Exporter
end note
note right of Spreadsheet::getImporter
Get The Importer Class.
since: 5.0.3
return: Importer
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---c4a188de_ad78_4a6d_9d5b_01866846d701---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)

View File

@ -0,0 +1,88 @@
<?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\Service;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Spreadsheet\Header;
use VDM\Joomla\Componentbuilder\Spreadsheet\Exporter;
use VDM\Joomla\Componentbuilder\Spreadsheet\Importer;
/**
* Spreadsheet Service Provider
*
* @since 5.0.3
*/
class Spreadsheet implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
* @since 5.0.3
*/
public function register(Container $container)
{
$container->alias(Header::class, 'Spreadsheet.Header')
->share('Spreadsheet.Header', [$this, 'getHeader'], true);
$container->alias(Exporter::class, 'Spreadsheet.Exporter')
->share('Spreadsheet.Exporter', [$this, 'getExporter'], true);
$container->alias(Importer::class, 'Spreadsheet.Importer')
->share('Spreadsheet.Importer', [$this, 'getImporter'], true);
}
/**
* Get The Header Class.
*
* @param Container $container The DI container.
*
* @return Header
* @since 5.0.3
*/
public function getHeader(Container $container): Header
{
return new Header();
}
/**
* Get The Exporter Class.
*
* @param Container $container The DI container.
*
* @return Exporter
* @since 5.0.3
*/
public function getExporter(Container $container): Exporter
{
return new Exporter();
}
/**
* Get The Importer Class.
*
* @param Container $container The DI container.
*
* @return Importer
* @since 5.0.3
*/
public function getImporter(Container $container): Importer
{
return new Importer();
}
}

View File

@ -0,0 +1,58 @@
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
* @since 5.0.3
*/
public function register(Container $container)
{
$container->alias(Header::class, 'Spreadsheet.Header')
->share('Spreadsheet.Header', [$this, 'getHeader'], true);
$container->alias(Exporter::class, 'Spreadsheet.Exporter')
->share('Spreadsheet.Exporter', [$this, 'getExporter'], true);
$container->alias(Importer::class, 'Spreadsheet.Importer')
->share('Spreadsheet.Importer', [$this, 'getImporter'], true);
}
/**
* Get The Header Class.
*
* @param Container $container The DI container.
*
* @return Header
* @since 5.0.3
*/
public function getHeader(Container $container): Header
{
return new Header();
}
/**
* Get The Exporter Class.
*
* @param Container $container The DI container.
*
* @return Exporter
* @since 5.0.3
*/
public function getExporter(Container $container): Exporter
{
return new Exporter();
}
/**
* Get The Importer Class.
*
* @param Container $container The DI container.
*
* @return Importer
* @since 5.0.3
*/
public function getImporter(Container $container): Importer
{
return new Importer();
}

View File

@ -0,0 +1,35 @@
{
"add_head": "1",
"add_licensing_template": "2",
"extends": "",
"guid": "c4a188de-ad78-4a6d-9d5b-01866846d701",
"implements": [
"-1"
],
"load_selection": null,
"name": "Spreadsheet",
"power_version": "1.0.0",
"system_name": "JCB.Spreadsheet.Service.Spreadsheet",
"type": "class",
"use_selection": {
"use_selection0": {
"use": "fd3f322a-082d-4579-93ad-3352c5adfc71",
"as": "default"
},
"use_selection1": {
"use": "e250638e-4a50-41f9-9172-db3e7f174d26",
"as": "default"
},
"use_selection2": {
"use": "c4169332-3914-400e-b861-972b2d465963",
"as": "default"
}
},
"extendsinterfaces": null,
"namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Spreadsheet.Service.Spreadsheet",
"description": "Spreadsheet Service Provider\r\n\r\n@since 5.0.3",
"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 <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": "use Joomla\\DI\\Container;\r\nuse Joomla\\DI\\ServiceProviderInterface;",
"composer": ""
}

View File

@ -0,0 +1,133 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Exporter (Details)
> namespace: **VDM\Joomla\Componentbuilder\Spreadsheet**
```uml
@startuml
class Exporter << (F,LightGreen) >> #RoyalBlue {
- User $user
- Spreadsheet $spreadsheet
- string $fileName
- string $fileType
- string $subjectTab
- array $headerStyles
- array $sideStyles
- array $normalStyles
+ __construct()
+ export(array $rows, ?string $fileName = null, ...) : void
- setDocumentProperties(string $creator, ?string $title = null, ...) : void
- populateSpreadsheet(array $rows) : void
- determineXlsMode(int $size) : int
- applyStyles(Worksheet $sheet, int $rowIndex, ...) : void
- outputSpreadsheet() : void
}
note right of Exporter::__construct
SpreadsheetExporter constructor.
Initializes styles and the Spreadsheet object.
since: 3.2.0
end note
note right of Exporter::export
Prepares the spreadsheet with data.
since: 3.2.0
return: void
arguments:
array $rows
?string $fileName = null
?string $title = null
?string $subjectTab = null
string $creator = 'Vast Development Method'
?string $description = null
?string $category = null
?string $keywords = null
?string $modified = null
end note
note right of Exporter::setDocumentProperties
Set the document properties for the spreadsheet.
since: 3.2.0
return: void
arguments:
string $creator
?string $title = null
?string $description = null
?string $category = null
?string $keywords = null
?string $modified = null
end note
note right of Exporter::populateSpreadsheet
Populate the spreadsheet with the provided rows.
since: 3.2.0
return: void
end note
note right of Exporter::determineXlsMode
Determine the XLS mode based on the number of rows.
since: 3.2.0
return: int
end note
note right of Exporter::applyStyles
Apply styles to the cells based on the row and column index.
since: 3.2.0
return: void
arguments:
Worksheet $sheet
int $rowIndex
string $columnIndex
int $xlsMode
end note
note right of Exporter::outputSpreadsheet
Output the spreadsheet as an Excel or CSV file.
since: 3.2.0
return: void
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---e250638e_4a50_41f9_9172_db3e7f174d26---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)

View File

@ -0,0 +1,325 @@
<?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\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Writer\Exception;
use VDM\Joomla\Utilities\ArrayHelper;
/**
* Spreadsheet Exporter Class
*
* @since 3.2.0
*/
final class Exporter
{
/**
* The current active user.
*
* @var User $user
* @since 3.2.0
*/
private User $user;
/**
* The PhpSpreadsheet object used to create and manage the spreadsheet.
*
* @var Spreadsheet $spreadsheet
* @since 3.2.0
*/
private Spreadsheet $spreadsheet;
/**
* The name of the file to be exported, including the date if not provided.
*
* @var string $fileName
* @since 3.2.0
*/
private string $fileName;
/**
* The format of the exported file, typically 'Xls' or 'Csv'.
*
* @var string $fileType
* @since 3.2.0
*/
private string $fileType;
/**
* The name of the worksheet tab in the exported spreadsheet.
*
* @var string $subjectTab
* @since 3.2.0
*/
private string $subjectTab;
/**
* The styles applied to the header row, including font size, color, and bold formatting.
*
* @var array $headerStyles
* @since 3.2.0
*/
private array $headerStyles;
/**
* The styles applied to the first column (side) of the spreadsheet, usually for labeling rows.
*
* @var array $sideStyles
* @since 3.2.0
*/
private array $sideStyles;
/**
* The styles applied to normal cells in the spreadsheet, such as font color and size.
*
* @var array $normalStyles
* @since 3.2.0
*/
private array $normalStyles;
/**
* SpreadsheetExporter constructor.
* Initializes styles and the Spreadsheet object.
*
* @since 3.2.0
*/
public function __construct()
{
$this->user = Factory::getUser();
$this->spreadsheet = new Spreadsheet();
$this->headerStyles = [
'font' => [
'bold' => true,
'color' => ['rgb' => '1171A3'],
'size' => 12,
'name' => 'Verdana'
]
];
$this->sideStyles = [
'font' => [
'bold' => true,
'color' => ['rgb' => '444444'],
'size' => 11,
'name' => 'Verdana'
]
];
$this->normalStyles = [
'font' => [
'color' => ['rgb' => '444444'],
'size' => 11,
'name' => 'Verdana'
]
];
}
/**
* Prepares the spreadsheet with data.
*
* @param array $rows
* @param string|null $fileName
* @param string|null $title
* @param string|null $subjectTab
* @param string $creator
* @param string|null $description
* @param string|null $category
* @param string|null $keywords
* @param string|null $modified
*
* @return void
* @throws Exception
* @since 3.2.0
*/
public function export(
array $rows,
?string $fileName = null,
?string $title = null,
?string $subjectTab = null,
string $creator = 'Vast Development Method',
?string $description = null,
?string $category = null,
?string $keywords = null,
?string $modified = null
): void {
$this->fileName = $fileName ?? 'exported_' . Factory::getDate()->format('jS_F_Y');
$this->fileType = 'Xls';
$this->subjectTab = $subjectTab ?? 'Sheet1';
$this->setDocumentProperties($creator, $title, $description, $category, $keywords, $modified);
$this->populateSpreadsheet($rows);
// Output the spreadsheet
$this->outputSpreadsheet();
}
/**
* Set the document properties for the spreadsheet.
*
* @param string $creator
* @param string|null $title
* @param string|null $description
* @param string|null $category
* @param string|null $keywords
* @param string|null $modified
* @since 3.2.0
*/
private function setDocumentProperties(
string $creator,
?string $title = null,
?string $description = null,
?string $category = null,
?string $keywords = null,
?string $modified = null
): void
{
$modifiedBy = $modified ?? $this->user->name;
$this->spreadsheet->getProperties()
->setCreator($creator)
->setCompany('Vast Development Method')
->setLastModifiedBy($modifiedBy)
->setTitle($title ?? 'Book1')
->setSubject($this->subjectTab);
if ($description)
{
$this->spreadsheet->getProperties()->setDescription($description);
}
if ($category)
{
$this->spreadsheet->getProperties()->setCategory($category);
}
if ($keywords)
{
$this->spreadsheet->getProperties()->setKeywords($keywords);
}
}
/**
* Populate the spreadsheet with the provided rows.
*
* @param array $rows
*
* @since 3.2.0
*/
private function populateSpreadsheet(array $rows): void
{
if (($size = ArrayHelper::check($rows)) === false)
{
return;
}
$xlsMode = $this->determineXlsMode($size);
$activeSheet = $this->spreadsheet->setActiveSheetIndex(0);
$rowIndex = 1;
foreach ($rows as $array)
{
$columnIndex = 'A';
foreach ($array as $value)
{
$activeSheet->setCellValue($columnIndex . $rowIndex, $value);
$this->applyStyles($activeSheet, $rowIndex, $columnIndex, $xlsMode);
$columnIndex++;
}
$rowIndex++;
}
$activeSheet->setTitle($this->subjectTab);
}
/**
* Determine the XLS mode based on the number of rows.
*
* @param int $size
* @return int
*
* @since 3.2.0
*/
private function determineXlsMode(int $size): int
{
if ($size > 3000)
{
$this->fileType = 'Csv';
return 3;
}
if ($size > 2000)
{
return 2;
}
return 1;
}
/**
* Apply styles to the cells based on the row and column index.
*
* @param Worksheet $sheet
* @param int $rowIndex
* @param string $columnIndex
* @param int $xlsMode
*
* @since 3.2.0
*/
private function applyStyles(Worksheet $sheet, int $rowIndex, string $columnIndex, int $xlsMode): void
{
if ($xlsMode === 3)
{
return;
}
if ($rowIndex === 1)
{
$sheet->getColumnDimension($columnIndex)->setAutoSize(true);
$sheet->getStyle($columnIndex . $rowIndex)->applyFromArray($this->headerStyles);
$sheet->getStyle($columnIndex . $rowIndex)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
}
elseif ($columnIndex === 'A')
{
$sheet->getStyle($columnIndex . $rowIndex)->applyFromArray($this->sideStyles);
}
else
{
$sheet->getStyle($columnIndex . $rowIndex)->applyFromArray($this->normalStyles);
}
}
/**
* Output the spreadsheet as an Excel or CSV file.
*
* @return void
* @throws Exception
* @since 3.2.0
*/
private function outputSpreadsheet(): void
{
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $this->fileName . '.' . strtolower($this->fileType) . '"');
header('Cache-Control: max-age=0');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: cache, must-revalidate');
header('Pragma: public');
$writer = IOFactory::createWriter($this->spreadsheet, $this->fileType);
$writer->save('php://output');
exit;
}
}

View File

@ -0,0 +1,294 @@
/**
* The current active user.
*
* @var User $user
* @since 3.2.0
*/
private User $user;
/**
* The PhpSpreadsheet object used to create and manage the spreadsheet.
*
* @var Spreadsheet $spreadsheet
* @since 3.2.0
*/
private Spreadsheet $spreadsheet;
/**
* The name of the file to be exported, including the date if not provided.
*
* @var string $fileName
* @since 3.2.0
*/
private string $fileName;
/**
* The format of the exported file, typically 'Xls' or 'Csv'.
*
* @var string $fileType
* @since 3.2.0
*/
private string $fileType;
/**
* The name of the worksheet tab in the exported spreadsheet.
*
* @var string $subjectTab
* @since 3.2.0
*/
private string $subjectTab;
/**
* The styles applied to the header row, including font size, color, and bold formatting.
*
* @var array $headerStyles
* @since 3.2.0
*/
private array $headerStyles;
/**
* The styles applied to the first column (side) of the spreadsheet, usually for labeling rows.
*
* @var array $sideStyles
* @since 3.2.0
*/
private array $sideStyles;
/**
* The styles applied to normal cells in the spreadsheet, such as font color and size.
*
* @var array $normalStyles
* @since 3.2.0
*/
private array $normalStyles;
/**
* SpreadsheetExporter constructor.
* Initializes styles and the Spreadsheet object.
*
* @since 3.2.0
*/
public function __construct()
{
$this->user = Factory::getUser();
$this->spreadsheet = new Spreadsheet();
$this->headerStyles = [
'font' => [
'bold' => true,
'color' => ['rgb' => '1171A3'],
'size' => 12,
'name' => 'Verdana'
]
];
$this->sideStyles = [
'font' => [
'bold' => true,
'color' => ['rgb' => '444444'],
'size' => 11,
'name' => 'Verdana'
]
];
$this->normalStyles = [
'font' => [
'color' => ['rgb' => '444444'],
'size' => 11,
'name' => 'Verdana'
]
];
}
/**
* Prepares the spreadsheet with data.
*
* @param array $rows
* @param string|null $fileName
* @param string|null $title
* @param string|null $subjectTab
* @param string $creator
* @param string|null $description
* @param string|null $category
* @param string|null $keywords
* @param string|null $modified
*
* @return void
* @throws Exception
* @since 3.2.0
*/
public function export(
array $rows,
?string $fileName = null,
?string $title = null,
?string $subjectTab = null,
string $creator = 'Vast Development Method',
?string $description = null,
?string $category = null,
?string $keywords = null,
?string $modified = null
): void {
$this->fileName = $fileName ?? 'exported_' . Factory::getDate()->format('jS_F_Y');
$this->fileType = 'Xls';
$this->subjectTab = $subjectTab ?? 'Sheet1';
$this->setDocumentProperties($creator, $title, $description, $category, $keywords, $modified);
$this->populateSpreadsheet($rows);
// Output the spreadsheet
$this->outputSpreadsheet();
}
/**
* Set the document properties for the spreadsheet.
*
* @param string $creator
* @param string|null $title
* @param string|null $description
* @param string|null $category
* @param string|null $keywords
* @param string|null $modified
* @since 3.2.0
*/
private function setDocumentProperties(
string $creator,
?string $title = null,
?string $description = null,
?string $category = null,
?string $keywords = null,
?string $modified = null
): void
{
$modifiedBy = $modified ?? $this->user->name;
$this->spreadsheet->getProperties()
->setCreator($creator)
->setCompany('Vast Development Method')
->setLastModifiedBy($modifiedBy)
->setTitle($title ?? 'Book1')
->setSubject($this->subjectTab);
if ($description)
{
$this->spreadsheet->getProperties()->setDescription($description);
}
if ($category)
{
$this->spreadsheet->getProperties()->setCategory($category);
}
if ($keywords)
{
$this->spreadsheet->getProperties()->setKeywords($keywords);
}
}
/**
* Populate the spreadsheet with the provided rows.
*
* @param array $rows
*
* @since 3.2.0
*/
private function populateSpreadsheet(array $rows): void
{
if (($size = ArrayHelper::check($rows)) === false)
{
return;
}
$xlsMode = $this->determineXlsMode($size);
$activeSheet = $this->spreadsheet->setActiveSheetIndex(0);
$rowIndex = 1;
foreach ($rows as $array)
{
$columnIndex = 'A';
foreach ($array as $value)
{
$activeSheet->setCellValue($columnIndex . $rowIndex, $value);
$this->applyStyles($activeSheet, $rowIndex, $columnIndex, $xlsMode);
$columnIndex++;
}
$rowIndex++;
}
$activeSheet->setTitle($this->subjectTab);
}
/**
* Determine the XLS mode based on the number of rows.
*
* @param int $size
* @return int
*
* @since 3.2.0
*/
private function determineXlsMode(int $size): int
{
if ($size > 3000)
{
$this->fileType = 'Csv';
return 3;
}
if ($size > 2000)
{
return 2;
}
return 1;
}
/**
* Apply styles to the cells based on the row and column index.
*
* @param Worksheet $sheet
* @param int $rowIndex
* @param string $columnIndex
* @param int $xlsMode
*
* @since 3.2.0
*/
private function applyStyles(Worksheet $sheet, int $rowIndex, string $columnIndex, int $xlsMode): void
{
if ($xlsMode === 3)
{
return;
}
if ($rowIndex === 1)
{
$sheet->getColumnDimension($columnIndex)->setAutoSize(true);
$sheet->getStyle($columnIndex . $rowIndex)->applyFromArray($this->headerStyles);
$sheet->getStyle($columnIndex . $rowIndex)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
}
elseif ($columnIndex === 'A')
{
$sheet->getStyle($columnIndex . $rowIndex)->applyFromArray($this->sideStyles);
}
else
{
$sheet->getStyle($columnIndex . $rowIndex)->applyFromArray($this->normalStyles);
}
}
/**
* Output the spreadsheet as an Excel or CSV file.
*
* @return void
* @throws Exception
* @since 3.2.0
*/
private function outputSpreadsheet(): void
{
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $this->fileName . '.' . strtolower($this->fileType) . '"');
header('Cache-Control: max-age=0');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: cache, must-revalidate');
header('Pragma: public');
$writer = IOFactory::createWriter($this->spreadsheet, $this->fileType);
$writer->save('php://output');
exit;
}

View File

@ -0,0 +1,45 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "",
"guid": "e250638e-4a50-41f9-9172-db3e7f174d26",
"implements": null,
"load_selection": null,
"name": "Exporter",
"power_version": "1.0.0",
"system_name": "JCB.Spreadsheet.Exporter",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a",
"as": "default"
}
},
"extendsinterfaces": null,
"namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Spreadsheet.Exporter",
"description": "Spreadsheet Exporter Class\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 <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\\IOFactory"
},
"namespace1": {
"use": "PhpOffice\\PhpSpreadsheet\\Spreadsheet"
},
"namespace2": {
"use": "PhpOffice\\PhpSpreadsheet\\Worksheet\\Worksheet"
},
"namespace3": {
"use": "PhpOffice\\PhpSpreadsheet\\Style\\Alignment"
},
"namespace4": {
"use": "PhpOffice\\PhpSpreadsheet\\Writer\\Exception"
}
}
}
}
}

View File

@ -0,0 +1,52 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Header (Details)
> namespace: **VDM\Joomla\Componentbuilder\Spreadsheet**
```uml
@startuml
class Header << (F,LightGreen) >> #RoyalBlue {
+ get(string $filePath, int $targetRow = 1) : ?array
}
note right of Header::get
Get CSV or Excel headers from the provided file path.
since: 3.2.0
return: ?array
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---fd3f322a_082d_4579_93ad_3352c5adfc71---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)

View File

@ -0,0 +1,75 @@
<?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\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
/**
* Spreadsheet Header Class
*
* @since 3.2.0
*/
final class Header
{
/**
* Get CSV or Excel headers from the provided file path.
*
* @param string $filePath
* @param int $targetRow
*
* @return array|null
* @since 3.2.0
*/
public function get(string $filePath, int $targetRow = 1): ?array
{
if (!is_file($filePath))
{
return null;
}
try {
$chunkFilter = new ChunkReadFilter(2, 1);
$inputFileType = IOFactory::identify($filePath);
$reader = IOFactory::createReader($inputFileType);
$reader->setReadFilter($chunkFilter);
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($filePath);
$headers = [];
foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row)
{
if ($row->getRowIndex() === $targetRow)
{
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell)
{
$headers[$cell->getColumn()] = $cell->getValue();
}
break;
}
}
$spreadsheet->disconnectWorksheets();
return $headers;
} catch (\Exception $e) {
// Log or handle exceptions as necessary
return null;
}
}
}

View File

@ -0,0 +1,48 @@
/**
* Get CSV or Excel headers from the provided file path.
*
* @param string $filePath
* @param int $targetRow
*
* @return array|null
* @since 3.2.0
*/
public function get(string $filePath, int $targetRow = 1): ?array
{
if (!is_file($filePath))
{
return null;
}
try {
$chunkFilter = new ChunkReadFilter(2, 1);
$inputFileType = IOFactory::identify($filePath);
$reader = IOFactory::createReader($inputFileType);
$reader->setReadFilter($chunkFilter);
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($filePath);
$headers = [];
foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row)
{
if ($row->getRowIndex() === $targetRow)
{
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell)
{
$headers[$cell->getColumn()] = $cell->getValue();
}
break;
}
}
$spreadsheet->disconnectWorksheets();
return $headers;
} catch (\Exception $e) {
// Log or handle exceptions as necessary
return null;
}
}

View File

@ -0,0 +1,31 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "",
"guid": "fd3f322a-082d-4579-93ad-3352c5adfc71",
"implements": null,
"load_selection": null,
"name": "Header",
"power_version": "1.0.0",
"system_name": "JCB.Spreadsheet.Header",
"type": "final class",
"use_selection": null,
"extendsinterfaces": null,
"namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Spreadsheet.Header",
"description": "Spreadsheet Header Class\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 <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\\IOFactory"
},
"namespace1": {
"use": "PhpOffice\\PhpSpreadsheet\\Reader\\IReadFilter"
}
}
}
}
}

View File

@ -0,0 +1,53 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class Factory (Details)
> namespace: **VDM\Joomla\Componentbuilder\Import**
> extends: **ExtendingFactory**
```uml
@startuml
abstract Factory #Orange {
# {static} createContainer() : Container
}
note right of Factory::createContainer
Create a container object
since: 3.2.2
return: Container
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---ff8d5fdb_2d1f_4178_bd18_a43b8efd1068---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)

View File

@ -0,0 +1,57 @@
<?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\Import;
use VDM\Joomla\Service\Table;
use VDM\Joomla\Service\Database;
use VDM\Joomla\Service\Model;
use VDM\Joomla\Service\Data;
use VDM\Joomla\Componentbuilder\File\Service\File;
use VDM\Joomla\Componentbuilder\Spreadsheet\Service\Spreadsheet;
use VDM\Joomla\Interfaces\FactoryInterface;
use VDM\Joomla\Abstraction\Factory as ExtendingFactory;
/**
* Import Factory
*
* @since 3.2.2
*/
abstract class Factory extends ExtendingFactory implements FactoryInterface
{
/**
* Global Package Container
*
* @var Container|null
* @since 0.0.0
**/
protected static ?Container $container = null;
/**
* Create a container object
*
* @return Container
* @since 3.2.2
*/
protected static function createContainer(): Container
{
return (new Container())
->registerServiceProvider(new Table())
->registerServiceProvider(new Database())
->registerServiceProvider(new Model())
->registerServiceProvider(new Data())
->registerServiceProvider(new File())
->registerServiceProvider(new Spreadsheet());
}
}

View File

@ -0,0 +1,24 @@
/**
* Global Package Container
*
* @var Container|null
* @since 0.0.0
**/
protected static ?Container $container = null;
/**
* Create a container object
*
* @return Container
* @since 3.2.2
*/
protected static function createContainer(): Container
{
return (new Container())
->registerServiceProvider(new Table())
->registerServiceProvider(new Database())
->registerServiceProvider(new Model())
->registerServiceProvider(new Data())
->registerServiceProvider(new File())
->registerServiceProvider(new Spreadsheet());
}

View File

@ -0,0 +1,46 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "2e5bf608-de5c-4b00-a20d-47c26aa350d9",
"guid": "ff8d5fdb-2d1f-4178-bd18-a43b8efd1068",
"implements": [
"caf33c5d-858c-4f9a-894f-ab302ec5445a"
],
"load_selection": null,
"name": "Factory",
"power_version": "1.0.0",
"system_name": "JCB.Import.Factory",
"type": "abstract class",
"use_selection": {
"use_selection0": {
"use": "19b2ba92-1655-4384-acfb-979c80de8b6d",
"as": "default"
},
"use_selection1": {
"use": "4815e1c7-a433-443d-a112-d1e03d7df84b",
"as": "default"
},
"use_selection2": {
"use": "2dcedd6c-c95b-4a37-9cac-95d28faedca3",
"as": "default"
},
"use_selection3": {
"use": "a5daf189-3345-4b13-8716-c51f686f545b",
"as": "default"
},
"use_selection4": {
"use": "202ccd9e-dfcf-4cde-a0ce-bde1fd27f088",
"as": "default"
},
"use_selection5": {
"use": "c4a188de-ad78-4a6d-9d5b-01866846d701",
"as": "default"
}
},
"extendsinterfaces": null,
"namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Import.Factory",
"description": "Import Factory\r\n\r\n@since 3.2.2",
"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": ""
}

View File

@ -934,6 +934,28 @@
"spk": "Super---c182506a_ab84_439c_b962_1e606b58d545---Power", "spk": "Super---c182506a_ab84_439c_b962_1e606b58d545---Power",
"guid": "c182506a-ab84-439c-b962-1e606b58d545" "guid": "c182506a-ab84-439c-b962-1e606b58d545"
}, },
"c4169332-3914-400e-b861-972b2d465963": {
"name": "Importer",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Spreadsheet",
"code": "src\/c4169332-3914-400e-b861-972b2d465963\/code.php",
"power": "src\/c4169332-3914-400e-b861-972b2d465963\/code.power",
"settings": "src\/c4169332-3914-400e-b861-972b2d465963\/settings.json",
"path": "src\/c4169332-3914-400e-b861-972b2d465963",
"spk": "Super---c4169332_3914_400e_b861_972b2d465963---Power",
"guid": "c4169332-3914-400e-b861-972b2d465963"
},
"c4a188de-ad78-4a6d-9d5b-01866846d701": {
"name": "Spreadsheet",
"type": "class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Spreadsheet\\Service",
"code": "src\/c4a188de-ad78-4a6d-9d5b-01866846d701\/code.php",
"power": "src\/c4a188de-ad78-4a6d-9d5b-01866846d701\/code.power",
"settings": "src\/c4a188de-ad78-4a6d-9d5b-01866846d701\/settings.json",
"path": "src\/c4a188de-ad78-4a6d-9d5b-01866846d701",
"spk": "Super---c4a188de_ad78_4a6d_9d5b_01866846d701---Power",
"guid": "c4a188de-ad78-4a6d-9d5b-01866846d701"
},
"c548640c-a461-4424-9ac5-8dfb5ed06d8d": { "c548640c-a461-4424-9ac5-8dfb5ed06d8d": {
"name": "LoadInterface", "name": "LoadInterface",
"type": "interface", "type": "interface",
@ -1066,6 +1088,17 @@
"spk": "Super---e0f6ddbe_2a35_4537_942c_faff2ebd04f6---Power", "spk": "Super---e0f6ddbe_2a35_4537_942c_faff2ebd04f6---Power",
"guid": "e0f6ddbe-2a35-4537-942c-faff2ebd04f6" "guid": "e0f6ddbe-2a35-4537-942c-faff2ebd04f6"
}, },
"e250638e-4a50-41f9-9172-db3e7f174d26": {
"name": "Exporter",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Spreadsheet",
"code": "src\/e250638e-4a50-41f9-9172-db3e7f174d26\/code.php",
"power": "src\/e250638e-4a50-41f9-9172-db3e7f174d26\/code.power",
"settings": "src\/e250638e-4a50-41f9-9172-db3e7f174d26\/settings.json",
"path": "src\/e250638e-4a50-41f9-9172-db3e7f174d26",
"spk": "Super---e250638e_4a50_41f9_9172_db3e7f174d26---Power",
"guid": "e250638e-4a50-41f9-9172-db3e7f174d26"
},
"e335dd61-c2f9-4536-8ed9-aec5edee0b26": { "e335dd61-c2f9-4536-8ed9-aec5edee0b26": {
"name": "SetInterface", "name": "SetInterface",
"type": "interface", "type": "interface",
@ -1110,6 +1143,17 @@
"spk": "Super---f3c04c28_bce4_422e_be93_7d163e4e342b---Power", "spk": "Super---f3c04c28_bce4_422e_be93_7d163e4e342b---Power",
"guid": "f3c04c28-bce4-422e-be93-7d163e4e342b" "guid": "f3c04c28-bce4-422e-be93-7d163e4e342b"
}, },
"fd3f322a-082d-4579-93ad-3352c5adfc71": {
"name": "Header",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Spreadsheet",
"code": "src\/fd3f322a-082d-4579-93ad-3352c5adfc71\/code.php",
"power": "src\/fd3f322a-082d-4579-93ad-3352c5adfc71\/code.power",
"settings": "src\/fd3f322a-082d-4579-93ad-3352c5adfc71\/settings.json",
"path": "src\/fd3f322a-082d-4579-93ad-3352c5adfc71",
"spk": "Super---fd3f322a_082d_4579_93ad_3352c5adfc71---Power",
"guid": "fd3f322a-082d-4579-93ad-3352c5adfc71"
},
"ff7d0111-8f79-42aa-ac14-b53ba2c49369": { "ff7d0111-8f79-42aa-ac14-b53ba2c49369": {
"name": "IsString", "name": "IsString",
"type": "trait", "type": "trait",
@ -1121,6 +1165,17 @@
"spk": "Super---ff7d0111_8f79_42aa_ac14_b53ba2c49369---Power", "spk": "Super---ff7d0111_8f79_42aa_ac14_b53ba2c49369---Power",
"guid": "ff7d0111-8f79-42aa-ac14-b53ba2c49369" "guid": "ff7d0111-8f79-42aa-ac14-b53ba2c49369"
}, },
"ff8d5fdb-2d1f-4178-bd18-a43b8efd1068": {
"name": "Factory",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Import",
"code": "src\/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068\/code.php",
"power": "src\/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068\/code.power",
"settings": "src\/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068\/settings.json",
"path": "src\/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068",
"spk": "Super---ff8d5fdb_2d1f_4178_bd18_a43b8efd1068---Power",
"guid": "ff8d5fdb-2d1f-4178-bd18-a43b8efd1068"
},
"ffbd4e1f-a342-4080-ab7d-1de3741bf319": { "ffbd4e1f-a342-4080-ab7d-1de3741bf319": {
"name": "BaseConfig", "name": "BaseConfig",
"type": "abstract class", "type": "abstract class",