Release of v5.0.1-alpha5

Add repositories for better integration with gitea. Refactored the Data classes. Add new Data classes.
This commit is contained in:
2024-06-21 03:25:28 +02:00
parent fc6b04cb5c
commit c51ef999a9
120 changed files with 8945 additions and 3699 deletions

View File

@@ -0,0 +1,132 @@
<?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\Database;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Interfaces\DeleteInterface;
use VDM\Joomla\Abstraction\Database;
/**
* Database Delete Class
*
* @since 3.2.0
*/
final class Delete extends Database implements DeleteInterface
{
/**
* Delete all items in the database that match these conditions
*
* @param array $conditions Conditions by which to delete the data in database [array of arrays (key => value)]
* @param string $table The table where the data is being deleted
*
* @return bool
* @since 3.2.2
**/
public function items(array $conditions, string $table): bool
{
// set the update columns
if ($conditions === [])
{
return false;
}
// get a query object
$query = $this->db->getQuery(true);
// start the conditions bucket
$_conditions = [];
foreach ($conditions as $key => $value)
{
if (ArrayHelper::check($value))
{
if (isset($value['value']) && isset($value['operator']))
{
// check if value needs to be quoted
$quote = $value['quote'] ?? true;
if (!$quote)
{
if (ArrayHelper::check($value['value']))
{
// add the where by array
$_conditions[] = $this->db->quoteName($key)
. ' ' . $value['operator']
. ' ' . ' (' .
implode(',', $value['value'])
. ')';
}
else
{
// add the conditions
$_conditions[] = $this->db->quoteName($key)
. ' ' . $value['operator']
. ' ' . $value['value'];
}
}
else
{
if (ArrayHelper::check($value['value']))
{
// add the where by array
$_conditions[] = $this->db->quoteName($key)
. ' ' . $value['operator']
. ' ' . ' (' .
implode(',', array_map(fn($val) => $this->quote($val), $value['value']))
. ')';
}
else
{
// add the conditions
$_conditions[] = $this->db->quoteName($key)
. ' ' . $value['operator']
. ' ' . $this->quote($value['value']);
}
}
}
else
{
// we should through an exception
// for security we just return false for now
return false;
}
}
else
{
// add default condition
$_conditions[] = $this->db->quoteName($key) . ' = ' . $this->quote($value);
}
}
// set the query targets
$query->delete($this->db->quoteName($this->getTable($table)));
$query->where($_conditions);
$this->db->setQuery($query);
return $this->db->execute();
}
/**
* Truncate a table
*
* @param string $table The table that should be truncated
*
* @return void
* @since 3.2.2
**/
public function truncate(string $table): void
{
$this->db->truncateTable($this->getTable($table));
}
}

View File

@@ -40,15 +40,7 @@ final class Load extends Database implements LoadInterface
?array $order = null, ?int $limit = null): ?array
{
// set key if found
$key = '';
if (isset($select['key']))
{
if (is_string($select['key']))
{
$key = $select['key'];
}
unset($select['key']);
}
$key = $this->getKey($select);
// check if we can get many rows
if ($this->many($select, $tables, $where, $order, $limit))
@@ -77,15 +69,7 @@ final class Load extends Database implements LoadInterface
?array $order = null, ?int $limit = null): ?array
{
// set key if found
$key = '';
if (isset($select['key']))
{
if (is_string($select['key']))
{
$key = $select['key'];
}
unset($select['key']);
}
$key = $this->getKey($select);
// check if we can get many rows
if ($this->many($select, $tables, $where, $order, $limit))
@@ -464,6 +448,30 @@ final class Load extends Database implements LoadInterface
return $query;
}
/**
* Get the key from the selection array.
*
* This function retrieves a key from the provided selection array.
* The key is removed from the array after being retrieved.
*
* @param array $select Array of selection keys.
*
* @return string|null The key, or null if no key is found.
* @since 3.2.2
**/
protected function getKey(array &$select): ?string
{
$key = null;
// Check for 'key' first and ensure it's a string.
if (isset($select['key']) && is_string($select['key']))
{
$key = $select['key'];
unset($select['key']); // Remove 'key' from the array.
}
return $key;
}
}