Release of v5.1.0

Add [AllowDynamicProperties] in the base view class for J5. Move the _prepareDocument  above the display call in the base view class. Remove all backward compatibility issues, so JCB will not need the [Backward Compatibility] plugin to run. Added new import powers for custom import of spreadsheets. Move the setDocument and _prepareDocument above the display in the site view and custom admin view. Update the trashhelper layout to work in Joomla 5. Add AllowDynamicProperties (Joomla 4+5) to view class to allow Custom Dynamic Get methods to work without issues. Fix Save failed issue in dynamicGet. #1148. Move all [TEXT, EDITOR, TEXTAREA] fields from [NOT NULL] to [NULL]. Add the DateHelper class and improve the date methods. Add simple SessionHelper class. Add first classes for the new import engine. Improve the [VDM Registry] to be Joomla Registry Compatible. Move all registries to the [VDM Registry] class. Fix Checked Out to be null and not 0. (#1194). Fix created_by, modified_by, checked_out fields in the compiler of the SQL. (#1194). Update all core date fields in table class. (#1188). Update created_by, modified_by, checked_out fields in table class. Implementation of the decentralized Super-Power CORE repository network. (#1190). Fix the noticeboard to display Llewellyn's Joomla Social feed. Started compiling JCB5 on Joomla 5 with PHP 8.2. Add init_defaults option for dynamic form selection setup (to int new items with default values dynamically). Update all JCB 5 tables to utf8mb4_unicode_ci collation if misaligned. Move all internal ID linking to GUID inside of JCB 5. Updated the admin-tab-fields in add-fields view. #1205. Remove Custom Import Tab from admin view. Improved the customcode and placeholder search features.
This commit is contained in:
2025-02-14 22:55:55 +02:00
parent 82922eca5a
commit 442263e387
645 changed files with 42297 additions and 18475 deletions

View File

@@ -0,0 +1,130 @@
<?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 Joomla\CMS\Language\Text;
use VDM\Joomla\Componentbuilder\Import\Data;
use VDM\Joomla\Componentbuilder\Interfaces\ImportStatusInterface as Status;
use VDM\Joomla\Componentbuilder\Interfaces\ImportMessageInterface as Message;
use VDM\Joomla\Componentbuilder\Interfaces\ImportAssessorInterface;
/**
* Import Assessor Class
*
* @since 4.0.3
*/
final class Assessor implements ImportAssessorInterface
{
/**
* The Data Class.
*
* @var Data
* @since 4.0.3
*/
protected Data $data;
/**
* The Import Status Class.
*
* @var Status
* @since 4.0.3
*/
protected Status $status;
/**
* The Import Message Class.
*
* @var Message
* @since 4.0.3
*/
protected Message $message;
/**
* Constants for defining the success threshold
* Minimum success rate to consider the import successful
*
* @since 4.0.3
*/
private const SUCCESS_THRESHOLD = 0.80;
/**
* Constructor.
*
* @param Data $data The Data Class.
* @param Status $status The Import Status Class.
* @param Message $message The Import Message Class.
*
* @since 4.0.3
*/
public function __construct(Data $data, Status $status, Message $message)
{
$this->data = $data;
$this->status = $status;
$this->message = $message;
}
/**
* Evaluates the import process and sets the success/error message based on the success rate.
*
* @param int $rowCounter Total number of rows processed.
* @param int $successCounter Number of successfully processed rows.
* @param int $errorCounter Number of rows that failed to process.
*
* @return void
* @since 4.0.3
*/
public function evaluate(int $rowCounter, int $successCounter, int $errorCounter): void
{
// No rows processed case
if ($rowCounter === 0)
{
$this->message->addError(Text::_('COM_COMPONENTBUILDER_NO_ROWS_WERE_PROCESSED'));
if (($guid = $this->data->get('import.guid')) !== null)
{
$this->status->set(4, $guid); // Status 4 => completed with errors
}
return;
}
$successRate = $successCounter / $rowCounter;
$errorRate = (1 - $successRate) * 100;
$successPercentage = $successRate * 100;
// Determine appropriate message based on success rate
if ($successRate >= self::SUCCESS_THRESHOLD)
{
$this->message->addSuccess(Text::sprintf('COM_COMPONENTBUILDER_D_ROWS_PROCESSED_SUCCESS_RATE_TWOF_IMPORT_SUCCESSFUL',
$rowCounter,
$successPercentage
));
}
else
{
$this->message->addError(Text::sprintf('COM_COMPONENTBUILDER_IMPORT_FAILED_D_ROWS_PROCESSED_WITH_ONLY_D_SUCCESSES_ERROR_RATE_TWOF',
$rowCounter,
$successCounter,
$errorRate
));
}
if (($guid = $this->data->get('import.guid')) !== null)
{
// Update import status based on success rate
$importStatus = ($successPercentage == 100) ? 3 : 4; // 3 => completed, 4 => completed with errors
$this->status->set($importStatus, $guid);
}
}
}

View File

@@ -0,0 +1,26 @@
<?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\Abstraction\Registry;
/**
* Import Data Registry
*
* @since 3.2.0
*/
class Data extends Registry
{
}

View File

@@ -0,0 +1,60 @@
<?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 Joomla\DI\Container;
use VDM\Joomla\Service\Table;
use VDM\Joomla\Service\Database;
use VDM\Joomla\Service\Model;
use VDM\Joomla\Service\Data;
use VDM\Joomla\Componentbuilder\Import\Service\Import;
use VDM\Joomla\Componentbuilder\File\Service\File;
use VDM\Joomla\Componentbuilder\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 Import())
->registerServiceProvider(new File())
->registerServiceProvider(new Spreadsheet());
}
}

View File

@@ -0,0 +1,270 @@
<?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\Interfaces\TableValidatorInterface as Validator;
use VDM\Joomla\Interfaces\Data\ItemInterface as DataItem;
use VDM\Joomla\Componentbuilder\Interfaces\ImportRowInterface as Row;
use VDM\Joomla\Utilities\GuidHelper;
use VDM\Joomla\Componentbuilder\Interfaces\ImportItemInterface;
/**
* Import Item Class
*
* @since 4.0.3
*/
final class Item implements ImportItemInterface
{
/**
* The Table Validator Class.
*
* @var Validator
* @since 4.0.3
*/
protected Validator $validator;
/**
* The Item Class.
*
* @var Item
* @since 4.0.3
*/
protected DataItem $item;
/**
* The Import Row Class.
*
* @var Row
* @since 4.0.3
*/
protected Row $row;
/**
* Constructor.
*
* @param Validator $validator The Table ValidatorI Class.
* @param DataItem $item The Item Class.
* @param Row $row The Import Row Class.
*
* @since 4.0.3
*/
public function __construct(Validator $validator, DataItem $item, Row $row)
{
$this->validator = $validator;
$this->item = $item;
$this->row = $row;
}
/**
* Get the item from the import row values and ensure it is valid
*
* @param string $table The table these columns belongs to.
* @param array $columns The columns to extract.
*
* @return array|null
* @since 4.0.3
*/
public function get(string $table, array $columns): ?array
{
$item = [];
foreach ($columns as $column => $map)
{
if (($value = $this->row->getValue($column)) !== null && !isset($item[$map['name']]))
{
// get the valid importable value
$item[$map['name']] = $this->getImportValue($value, $map['name'], $table, $map['link'] ?? null);
// remove value from global row values set
$this->row->unsetValue($column);
}
}
return $item ?? null;
}
/**
* Get the correct value needed for the import of the related row (item).
*
* @param mixed $value The value from the row.
* @param string $field The field name where the value is being stored.
* @param string $table The table this field belongs to.
* @param array $link The field link values.
*
* @return mixed
* @since 4.0.3
*/
private function getImportValue($value, string $field, string $table, ?array $link)
{
// Validate the link array and return the original value if invalid
if (empty($link) || $link['type'] !== 1 || empty($link['table']) || empty($link['key']) || empty($link['value']))
{
return $this->validImportValue($value, $field, $table);
}
// Handle GUID key with validation via GuidHelper
if ($link['key'] === 'guid' && GuidHelper::item($value, $link['table']))
{
return $value;
}
// Handle numeric ID with validation
if ($link['key'] === 'id' && is_numeric($value) && $this->isValueExists($value, $link))
{
return (int) $value;
}
// Attempt to retrieve the local value
$local_value = $this->getLocalValue($value, $link);
// If no local value exists, create it if necessary
if ($local_value === null)
{
$local_value = $this->setLocalValue($value, $link);
}
return $this->validImportValue($local_value, $field, $table);
}
/**
* Make sure we have a valid import value
*
* @param mixed $value The value.
* @param string $field The field name where the value is being stored.
* @param string $table The table this field belongs to.
*
* @return mixed
* @since 4.0.3
*/
private function validImportValue($value, string $field, string $table)
{
// make sure our value will fit in the database table datatype
return $this->validator->getValid($value, $field, $table);
}
/**
* Helper function to get the local value from the database table.
*
* @param mixed $value The value to search for.
* @param array $link The field link details.
*
* @return mixed|null The local value or null if not found.
* @since 4.0.3
*/
private function getLocalValue($value, array $link)
{
// Attempt to retrieve the value based on the link['value'] and link['key']
$local_value = $this->item->table($link['table'])->value($value, $link['value'], $link['key']);
// If not found, try retrieving by link['key'] and link['key']
if ($local_value === null && $this->isValueExists($value, $link))
{
return $value;
}
return $local_value;
}
/**
* Check if the value exists in the table for the given link.
*
* @param mixed $value The value to check.
* @param array $link The field link details.
*
* @return bool True if the value exists, false otherwise.
* @since 4.0.3
*/
private function isValueExists($value, array $link): bool
{
return $this->item->table($link['table'])->value($value, $link['key'], $link['key']) !== null;
}
/**
* Create a new value in the database table if it doesn't already exist.
*
* @param mixed $value The value to create.
* @param array $link The field link details.
*
* @return mixed|null The newly created value or null if creation failed.
* @since 4.0.3
*/
private function setLocalValue($value, array $link)
{
// Handle GUID creation if the provided value is not valid
if ($link['key'] === 'guid')
{
if (!GuidHelper::valid($value))
{
return $this->insertItemWithGuid($value, $link);
}
return null;
}
// Handle ID creation
if ($link['key'] === 'id')
{
if (!is_numeric($value))
{
return $this->insertItemWithId($value, $link);
}
return null;
}
// could not create local item (we don't have enough details)
return null;
}
/**
* Insert a new item with a GUID.
*
* @param mixed $value The value to insert.
* @param array $link The field link details.
*
* @return string|null The new GUID or null if insertion failed.
* @since 4.0.3
*/
private function insertItemWithGuid($value, array $link): ?string
{
$guid = GuidHelper::get();
$item = (object) [$link['value'] => $value, $link['key'] => $guid];
if ($this->item->table($link['table'])->set($item, $link['key'], 'insert'))
{
return $guid;
}
return null;
}
/**
* Insert a new item with a non-numeric ID.
*
* @param mixed $value The value to insert.
* @param array $link The field link details.
*
* @return mixed|null The new ID or null if insertion failed.
* @since 4.0.3
*/
private function insertItemWithId($value, array $link)
{
$item = (object) [$link['key'] => 0, $link['value'] => $value];
if ($this->item->table($link['table'])->set($item, $link['key'], 'insert'))
{
return $this->item->table($link['table'])->value($value, $link['value'], $link['key']);
}
return null;
}
}

View File

@@ -0,0 +1,154 @@
<?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\Interfaces\TableInterface as Table;
use VDM\Joomla\Componentbuilder\Interfaces\ImportMapperInterface;
/**
* Import Mapper Class
*
* @since 4.0.3
*/
final class Mapper implements ImportMapperInterface
{
/**
* The Table Class.
*
* @var Table
* @since 4.0.3
*/
protected Table $table;
/**
* The current parent table map.
*
* @var array
* @since 4.0.3
*/
private array $parent = [];
/**
* The current join tables map.
*
* @var array
* @since 4.0.3
*/
private array $join = [];
/**
* Constructor.
*
* @param Table $table The Table Class.
*
* @since 4.0.3
*/
public function __construct(Table $table)
{
$this->table = $table;
}
/**
* Set the tables mapper
*
* @param object $map The import file map.
* @param string $parentTable The parent table name.
*
* @return void
* @since 4.0.3
*/
public function set(object $map, string $parentTable): void
{
// always reset these
$this->parent = [];
$this->join = [];
foreach ($map as $row)
{
$target = $row->target ?? null;
if (empty($target))
{
continue;
}
if (($tm = $this->getTableField($target)) !== null)
{
$field = $this->table->get($tm->table, $tm->field);
if ($tm->table === $parentTable)
{
$this->parent[$row->column] = $field;
}
else
{
$this->join[$tm->table][$row->column] = $field;
}
}
}
}
/**
* Get the parent table keys
*
* @return array
* @since 4.0.3
*/
public function getParent(): array
{
return $this->parent;
}
/**
* Get the join tables keys
*
* @return array
* @since 4.0.3
*/
public function getJoin(): array
{
return $this->join;
}
/**
* Get the table and field name
*
* @param string $key The import file key.
*
* @return object|null
* @since 4.0.3
*/
private function getTableField(string $key): ?object
{
// Find the position of the first dot
$dotPosition = strpos($key, '.');
// If no dot is found, return the whole string
if ($dotPosition === false)
{
return null;
}
// Extract the table (before the dot) and the field (after the dot)
$table = substr($key, 0, $dotPosition);
$field = substr($key, $dotPosition + 1);
if ($this->table->exist($table ?? '_error', $field))
{
return (object) ['table' => $table, 'field' => $field];
}
return null;
}
}

View File

@@ -0,0 +1,307 @@
<?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\Interfaces\Data\UpdateInterface as Update;
use VDM\Joomla\Interfaces\Data\InsertInterface as Insert;
use VDM\Joomla\Utilities\GuidHelper;
use VDM\Joomla\Componentbuilder\Interfaces\ImportMessageInterface;
/**
* Import Messages Class
*
* @since 5.0.2
*/
final class Message implements ImportMessageInterface
{
/**
* The Update Class.
*
* @var Update
* @since 5.0.2
*/
protected Update $update;
/**
* The Insert Class.
*
* @var Insert
* @since 5.0.2
*/
protected Insert $insert;
/**
* The success message bus.
*
* @var array
* @since 5.0.2
*/
private array $success = [];
/**
* The info message bus.
*
* @var array
* @since 5.0.2
*/
private array $info = [];
/**
* The error message bus.
*
* @var array
* @since 5.0.2
*/
private array $error = [];
/**
* The entity GUID value.
*
* @var string
* @since 5.0.2
*/
private ?string $guid = null;
/**
* The entity type value.
*
* @var string|null
* @since 5.0.2
*/
private ?string $entity = null;
/**
* The entity table value.
*
* @var string|null
* @since 5.0.2
*/
private ?string $table = null;
/**
* Constructor.
*
* @param Update $update The Update Class.
* @param Insert $insert The Insert Class.
*
* @since 5.0.2
*/
public function __construct(Update $update, Insert $insert)
{
$this->update = $update;
$this->insert = $insert;
}
/**
* Load an entity that these message belong to
*
* @param string $guid The entity guid these messages must be linked to.
* @param string $entity The entity type these messages must be linked to.
* @param string $table The messages table where these message must be stored.
*
* @return self
* @throws \InvalidArgumentException if any of the parameters are null or empty.
* @since 5.0.2
*/
public function load(string $guid, string $entity, string $table): self
{
if (empty($guid) || empty($entity) || empty($table))
{
throw new \InvalidArgumentException('GUID, entity, and table must not be null or empty.');
}
// set entity details
$this->guid = $guid;
$this->entity = $entity;
$this->table = $table;
return $this;
}
/**
* Get the messages of the last import event
*
* @return object
* @since 5.0.2
*/
public function get(): object
{
return (object) [
'message_success' => $this->success ?? null,
'message_info' => $this->info ?? null,
'message_error' => $this->error ?? null
];
}
/**
* Reset the messages of the last import event
*
* @return void
* @since 5.0.2
*/
public function reset(): void
{
// clear the message bus
$this->success = [];
$this->info = [];
$this->error = [];
$this->guid = null;
$this->entity = null;
$this->table = null;
}
/**
* Archive the messages in the DB of the last import event
*
* @return self
* @throws \InvalidArgumentException if GUID, entity, or table is null.
* @since 5.0.2
*/
public function archive(): self
{
if (empty($this->guid) || empty($this->entity) || empty($this->table))
{
throw new \InvalidArgumentException('GUID, entity, and table must not be null or empty.');
}
// trash all messages from the past
$this->update->table($this->table)->rows([['entity' => $this->guid, 'published' => -2]], 'entity');
return $this;
}
/**
* Set the messages in the DB of the last import event
*
* @return self
* @throws \InvalidArgumentException if GUID, entity, or table is null.
* @since 5.0.2
*/
public function set(): self
{
if (empty($this->guid) || empty($this->entity) || empty($this->table))
{
throw new \InvalidArgumentException('GUID, entity, and table must not be null or empty.');
}
// start message bucket
$messages = [];
// set the success messages
if (!empty($this->success))
{
foreach ($this->success as $message)
{
$messages[] = [
'guid' => GuidHelper::get(),
'entity' => $this->guid,
'entity_type' => $this->entity,
'message' => $message,
'message_status' => 1
];
}
}
// set the info messages
if (!empty($this->info))
{
foreach ($this->info as $message)
{
$messages[] = [
'guid' => GuidHelper::get(),
'entity' => $this->guid,
'entity_type' => $this->entity,
'message' => $message,
'message_status' => 2
];
}
}
// set the error messages
if (!empty($this->error))
{
foreach ($this->error as $message)
{
$messages[] = [
'guid' => GuidHelper::get(),
'entity' => $this->guid,
'entity_type' => $this->entity,
'message' => $message,
'message_status' => 3
];
}
}
$this->insert->table($this->table)->rows($messages);
return $this;
}
/**
* Adds a success message to the log.
*
* This method records a success message for the import process. The message provides
* relevant information, such as the number of rows processed and the success rate.
*
* @param string $message The success message to log.
*
* @return self
* @since 5.0.2
*/
public function addSuccess(string $message): self
{
$this->success[] = $message;
return $this;
}
/**
* Adds a info message to the log.
*
* This method records a info message for the import process. The message provides
* relevant information, such as the number of rows processed and the info rate.
*
* @param string $message The info message to log.
*
* @return self
* @since 5.0.2
*/
public function addInfo(string $message): self
{
$this->info[] = $message;
return $this;
}
/**
* Adds an error message to the log.
*
* This method records an error message when the import process encounters issues.
* The message includes details about the failures, such as the number of failed rows
* and the corresponding error rate.
*
* @param string $message The error message to log.
*
* @return self
* @since 5.0.2
*/
public function addError(string $message): self
{
$this->error[] = $message;
return $this;
}
}

View File

@@ -0,0 +1,131 @@
<?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\Componentbuilder\Interfaces\ImportRowInterface;
/**
* Import Row Class
*
* @since 4.0.3
*/
final class Row implements ImportRowInterface
{
/**
* The row array of values.
*
* @var array
* @since 5.0.2
*/
private array $values;
/**
* The row index.
*
* @var int
* @since 5.0.2
*/
private int $index;
/**
* A flag to track if values and index are set.
*
* @var bool
* @since 5.0.2
*/
private bool $isSet = false;
/**
* Set the row details
*
* @param int $index The row index
* @param array $values The values
*
* @return void
* @since 5.0.2
*/
public function set(int $index, array $values): void
{
$this->index = $index;
$this->values = $values;
$this->isSet = true;
}
/**
* Clear the row details
*
* @return self
* @since 5.0.2
*/
public function clear(): self
{
$this->index = 0;
$this->values = [];
$this->isSet = false;
return $this;
}
/**
* Get Index
*
* @return int
* @throws \InvalidArgumentException if any of the parameters are null or empty.
* @since 5.0.2
*/
public function getIndex(): int
{
if (!$this->isSet)
{
throw new \InvalidArgumentException('Index must not be null or empty. Use the set method to first set the index.');
}
return $this->index;
}
/**
* Get Value
*
* @return mixed
* @throws \InvalidArgumentException if any of the parameters are null or empty.
* @since 5.0.2
*/
public function getValue(string $key)
{
if (!$this->isSet)
{
throw new \InvalidArgumentException('Values must be set before accessing. Use the set method to first set the values.');
}
return $this->values[$key] ?? null;
}
/**
* Unset Value
*
* @return void
* @throws \InvalidArgumentException if any of the parameters are null or empty.
* @since 5.0.2
*/
public function unsetValue(string $key): void
{
if (!$this->isSet)
{
throw new \InvalidArgumentException('Values must be set before accessing. Use the set method to first set the values.');
}
unset($this->values[$key]);
}
}

View File

@@ -0,0 +1,171 @@
<?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\Service;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Import\Data;
use VDM\Joomla\Componentbuilder\Import\Mapper;
use VDM\Joomla\Componentbuilder\Import\Row;
use VDM\Joomla\Componentbuilder\Import\Item;
use VDM\Joomla\Componentbuilder\Import\Message;
use VDM\Joomla\Componentbuilder\Import\Status;
use VDM\Joomla\Componentbuilder\Import\Assessor;
/**
* Import Service Provider
*
* @since 5.0.3
*/
class Import 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(Data::class, 'Import.Data')
->share('Import.Data', [$this, 'getData'], true);
$container->alias(Mapper::class, 'Import.Mapper')
->share('Import.Mapper', [$this, 'getMapper'], true);
$container->alias(Row::class, 'Import.Row')
->share('Import.Row', [$this, 'getRow'], true);
$container->alias(Item::class, 'Import.Item')
->share('Import.Item', [$this, 'getItem'], true);
$container->alias(Message::class, 'Import.Message')
->share('Import.Message', [$this, 'getMessage'], true);
$container->alias(Status::class, 'Import.Status')
->share('Import.Status', [$this, 'getStatus'], true);
$container->alias(Assessor::class, 'Import.Assessor')
->share('Import.Assessor', [$this, 'getAssessor'], true);
}
/**
* Get The Data Class.
*
* @param Container $container The DI container.
*
* @return Data
* @since 5.0.3
*/
public function getData(Container $container): Data
{
return new Data();
}
/**
* Get The Mapper Class.
*
* @param Container $container The DI container.
*
* @return Mapper
* @since 5.0.3
*/
public function getMapper(Container $container): Mapper
{
return new Mapper(
$container->get('Table')
);
}
/**
* Get The Row Class.
*
* @param Container $container The DI container.
*
* @return Row
* @since 5.0.3
*/
public function getRow(Container $container): Row
{
return new Row();
}
/**
* Get The Item Class.
*
* @param Container $container The DI container.
*
* @return Item
* @since 5.0.3
*/
public function getItem(Container $container): Item
{
return new Item(
$container->get('Table.Validator'),
$container->get('Data.Item'),
$container->get('Import.Row')
);
}
/**
* Get The Message Class.
*
* @param Container $container The DI container.
*
* @return Message
* @since 5.0.3
*/
public function getMessage(Container $container): Message
{
return new Message(
$container->get('Data.Update'),
$container->get('Data.Insert')
);
}
/**
* Get The Status Class.
*
* @param Container $container The DI container.
*
* @return Status
* @since 5.0.3
*/
public function getStatus(Container $container): Status
{
return new Status(
$container->get('Data.Item')
);
}
/**
* Get The Assessor Class.
*
* @param Container $container The DI container.
*
* @return Assessor
* @since 5.0.3
*/
public function getAssessor(Container $container): Assessor
{
return new Assessor(
$container->get('Import.Data'),
$container->get('Import.Status'),
$container->get('Import.Message')
);
}
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -0,0 +1,149 @@
<?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\Interfaces\Data\ItemInterface as Item;
use VDM\Joomla\Componentbuilder\Interfaces\ImportStatusInterface;
/**
* Import Status Class
*
* @since 5.0.2
*/
final class Status implements ImportStatusInterface
{
/**
* The Item Class.
*
* @var Item
* @since 5.0.2
*/
protected Item $item;
/**
* Table Name
*
* @var string
* @since 5.0.2
*/
protected string $table;
/**
* Status Field Name
*
* @var string
* @since 5.0.2
*/
protected string $fieldName;
/**
* Constructor.
*
* @param Item $item The Item Class.
* @param string|null $table The table name
* @param string|null $field The field name.
*
* @since 5.0.2
*/
public function __construct(Item $item, ?string $table = null, ?string $field = null)
{
$this->item = $item;
if ($table !== null)
{
$this->table = $table;
}
if ($field !== null)
{
$this->field = $field;
}
}
/**
* Updates the status in the database.
*
* This method updates the import status in the database based on the result of the import process.
* Status codes:
* - 2: Being Processed.
* - 3: Import completed successfully.
* - 4: Import completed with errors.
*
* @param int $status The status code to set for the import (2 => processing, 3 => success, 4 => errors).
* @param string $guid The target import GUID
*
* @return void
* @since 5.0.2
*/
public function set(int $status, string $guid): void
{
$this->item->table($this->getTable())->set((object) [
'guid' => $guid,
$this->getField() => $status
]);
}
/**
* Set the current active table
*
* @param string $table The table that should be active
*
* @return self
* @since 3.2.2
*/
public function table(string $table): self
{
$this->table = $table;
return $this;
}
/**
* Set the current target status field name
*
* @param string $fieldName The field name where the status is set
*
* @return self
* @since 3.2.2
*/
public function field(string $fieldName): self
{
$this->fieldName = $fieldName;
return $this;
}
/**
* Get the current active table
*
* @return string
* @since 3.2.2
*/
public function getTable(): string
{
return $this->table;
}
/**
* Get the current target status field name
*
* @return string
* @since 3.2.2
*/
public function getField(): string
{
return $this->fieldName;
}
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>