forked from joomla/Component-Builder
Rename some database classes, adds the core database classes.
This commit is contained in:
parent
1c7515d0f5
commit
6c42b5af61
@ -140,14 +140,14 @@ TODO
|
||||
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
|
||||
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
+ *First Build*: 30th April, 2015
|
||||
+ *Last Build*: 20th November, 2022
|
||||
+ *Last Build*: 27th November, 2022
|
||||
+ *Version*: 3.1.12
|
||||
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
|
||||
+ *Line count*: **334395**
|
||||
+ *Line count*: **335381**
|
||||
+ *Field count*: **2004**
|
||||
+ *File count*: **2186**
|
||||
+ *Folder count*: **382**
|
||||
+ *File count*: **2192**
|
||||
+ *Folder count*: **383**
|
||||
|
||||
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
|
||||
> Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
|
||||
|
@ -140,14 +140,14 @@ TODO
|
||||
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
|
||||
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
+ *First Build*: 30th April, 2015
|
||||
+ *Last Build*: 20th November, 2022
|
||||
+ *Last Build*: 27th November, 2022
|
||||
+ *Version*: 3.1.12
|
||||
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
|
||||
+ *Line count*: **334395**
|
||||
+ *Line count*: **335381**
|
||||
+ *Field count*: **2004**
|
||||
+ *File count*: **2186**
|
||||
+ *Folder count*: **382**
|
||||
+ *File count*: **2192**
|
||||
+ *Folder count*: **383**
|
||||
|
||||
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
|
||||
> Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension type="component" version="4" method="upgrade">
|
||||
<name>COM_COMPONENTBUILDER</name>
|
||||
<creationDate>20th November, 2022</creationDate>
|
||||
<creationDate>27th November, 2022</creationDate>
|
||||
<author>Llewellyn van der Merwe</author>
|
||||
<authorEmail>joomla@vdm.io</authorEmail>
|
||||
<authorUrl>https://dev.vdm.io</authorUrl>
|
||||
|
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd 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\Abstraction;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory as JoomlaFactory;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Database
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Database
|
||||
{
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @var \JDatabaseDriver
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected \JDatabaseDriver $db;
|
||||
|
||||
/**
|
||||
* Core Component Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \JDatabaseDriver|null $db The database driver
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?\JDatabaseDriver $db = null)
|
||||
{
|
||||
$this->db = $db ?: JoomlaFactory::getDbo();
|
||||
|
||||
// set the component table
|
||||
$this->table = '#__' . Helper::getCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value based on data type
|
||||
*
|
||||
* @param mixed $value The value to set
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function quote($value)
|
||||
{
|
||||
if (is_numeric($value))
|
||||
{
|
||||
if (filter_var($value, FILTER_VALIDATE_INT))
|
||||
{
|
||||
return (int) $value;
|
||||
}
|
||||
elseif (filter_var($value, FILTER_VALIDATE_FLOAT))
|
||||
{
|
||||
return (float) $value;
|
||||
}
|
||||
}
|
||||
elseif (is_bool($value))
|
||||
{
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
// default just escape it
|
||||
return $this->db->quote($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a table name, adding the
|
||||
* core component as needed
|
||||
*
|
||||
* @param string $table The table string
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function getTable(string $table): string
|
||||
{
|
||||
if (strpos($table, '#__') === false)
|
||||
{
|
||||
return $this->table . '_' . $table;
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ use VDM\Joomla\Componentbuilder\Compiler\Service\Power;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Component;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Extension;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Field;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Factoryinterface;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\FactoryInterface;
|
||||
|
||||
|
||||
/**
|
||||
@ -31,7 +31,7 @@ use VDM\Joomla\Componentbuilder\Interfaces\Factoryinterface;
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Factory implements Factoryinterface
|
||||
abstract class Factory implements FactoryInterface
|
||||
{
|
||||
/**
|
||||
* Global Compiler Container
|
||||
@ -81,7 +81,7 @@ abstract class Factory implements Factoryinterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a the global compiler container
|
||||
* Get the global compiler container
|
||||
*
|
||||
* @return Container
|
||||
* @since 3.2.0
|
||||
|
@ -272,7 +272,7 @@ class Data
|
||||
)
|
||||
);
|
||||
}
|
||||
// set the field modeling
|
||||
// set the field modelling
|
||||
$field->model_field['save'] = explode(
|
||||
PHP_EOL, $this->placeholder->update(
|
||||
$this->customcode->update(
|
||||
|
@ -0,0 +1,306 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd 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\Database;
|
||||
|
||||
|
||||
use Joomla\CMS\Date\Date;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\InsertInterface;
|
||||
use VDM\Joomla\Componentbuilder\Abstraction\Database;
|
||||
|
||||
|
||||
/**
|
||||
* Database Insert Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Insert extends Database implements InsertInterface
|
||||
{
|
||||
/**
|
||||
* Switch to set the defaults
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.2.0
|
||||
**/
|
||||
public bool $defaults = true;
|
||||
|
||||
/**
|
||||
* Set rows to the database
|
||||
*
|
||||
* @param array $data Dataset to store in database [array of arrays (key => value)]
|
||||
* @param string $table The table where the data is being added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $data, string $table): bool
|
||||
{
|
||||
// get a query object
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// get the first row
|
||||
$row = array_values($data)[0];
|
||||
|
||||
// set the insert columns
|
||||
if (!ArrayHelper::check($row))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$columns = array_keys($row);
|
||||
|
||||
// set joomla default columns
|
||||
$add_created = false;
|
||||
$add_version = false;
|
||||
$add_published = false;
|
||||
|
||||
// check if we should load the defaults
|
||||
if ($this->defaults)
|
||||
{
|
||||
// get the date
|
||||
$date = (new Date())->toSql();
|
||||
|
||||
if (!in_array('created', $columns))
|
||||
{
|
||||
$columns[] = 'created';
|
||||
$add_created = true;
|
||||
}
|
||||
if (!in_array('version', $columns))
|
||||
{
|
||||
$columns[] = 'version';
|
||||
$add_version = true;
|
||||
}
|
||||
if (!in_array('published', $columns))
|
||||
{
|
||||
$columns[] = 'published';
|
||||
$add_published = true;
|
||||
}
|
||||
}
|
||||
|
||||
// set the query targets
|
||||
$query->insert($this->db->quoteName($table))->columns($this->db->quoteName($columns));
|
||||
|
||||
// limiting factor on the amount of rows to insert before we reset the query
|
||||
$limit = 300;
|
||||
|
||||
// set the insert values
|
||||
foreach ($data as $set)
|
||||
{
|
||||
// check the limit
|
||||
if ($limit <= 1)
|
||||
{
|
||||
// execute and reset the query
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// reset limit
|
||||
$limit = 300;
|
||||
|
||||
// get a query object
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// set the query targets
|
||||
$query->insert($this->db->quoteName($table))->columns($this->db->quoteName($columns));
|
||||
}
|
||||
|
||||
$row = [];
|
||||
foreach ($set as $value)
|
||||
{
|
||||
$row[] = $this->quote($value);
|
||||
}
|
||||
|
||||
// set joomla default columns
|
||||
if ($add_created)
|
||||
{
|
||||
$row[] = $this->db->quote($date);
|
||||
}
|
||||
if ($add_version)
|
||||
{
|
||||
$row[] = 1;
|
||||
}
|
||||
if ($add_published)
|
||||
{
|
||||
$row[] = 1;
|
||||
}
|
||||
|
||||
// add to query
|
||||
$query->values(implode(',', $row));
|
||||
|
||||
// decrement the limiter
|
||||
$limit--;
|
||||
}
|
||||
|
||||
// execute the final query
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// always reset the default switch
|
||||
$this->defaults = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set items to the database
|
||||
*
|
||||
* @param array $data Data to store in database (array of objects)
|
||||
* @param array $columns Data columns
|
||||
* @param string $table The table where the data is being added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $data, array $columns, string $table): bool
|
||||
{
|
||||
// get a query object
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// set the query targets
|
||||
$query->insert($this->db->quoteName($table))->columns($this->db->quoteName(array_keys($columns)));
|
||||
|
||||
// limiting factor on the amount of rows to insert before we reset the query
|
||||
$limit = 400;
|
||||
|
||||
// set the insert values
|
||||
foreach ($data as $nr => $value)
|
||||
{
|
||||
// check the limit
|
||||
if ($limit <= 1)
|
||||
{
|
||||
// execute and reset the query
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// reset limit
|
||||
$limit = 400;
|
||||
|
||||
// get a query object
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// set the query targets
|
||||
$query->insert($this->db->quoteName($table))->columns($this->db->quoteName(array_keys($columns)));
|
||||
}
|
||||
|
||||
$row = [];
|
||||
// load only what is part of the columns set
|
||||
foreach ($columns as $key)
|
||||
{
|
||||
if (isset($value->{$key}))
|
||||
{
|
||||
$row[] = $this->quote($value->{$key});
|
||||
}
|
||||
else
|
||||
{
|
||||
$row[] = '';
|
||||
}
|
||||
}
|
||||
|
||||
// add to query
|
||||
$query->values(implode(',', $row));
|
||||
|
||||
// decrement the limiter
|
||||
$limit--;
|
||||
|
||||
// clear the data from memory
|
||||
unset($data[$nr]);
|
||||
}
|
||||
|
||||
// execute the final query
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set row to the database
|
||||
*
|
||||
* @param array $data Dataset to store in database (key => value)
|
||||
* @param string $table The table where the data is being added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $data, string $table): bool
|
||||
{
|
||||
// get a query object
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
$columns = array_keys($data);
|
||||
|
||||
// set joomla default columns
|
||||
$add_created = false;
|
||||
$add_version = false;
|
||||
$add_published = false;
|
||||
|
||||
// check if we should load the defaults
|
||||
if ($this->defaults)
|
||||
{
|
||||
// get the date
|
||||
$date = (new Date())->toSql();
|
||||
|
||||
if (!in_array('created', $columns))
|
||||
{
|
||||
$columns[] = 'created';
|
||||
$add_created = true;
|
||||
}
|
||||
if (!in_array('version', $columns))
|
||||
{
|
||||
$columns[] = 'version';
|
||||
$add_version = true;
|
||||
}
|
||||
if (!in_array('published', $columns))
|
||||
{
|
||||
$columns[] = 'published';
|
||||
$add_published = true;
|
||||
}
|
||||
}
|
||||
|
||||
// set the query targets
|
||||
$query->insert($this->db->quoteName($table))->columns($this->db->quoteName($columns));
|
||||
|
||||
// set the insert values
|
||||
$row = [];
|
||||
foreach ($data as $value)
|
||||
{
|
||||
$row[] = $this->quote($value);
|
||||
}
|
||||
|
||||
// set joomla default columns
|
||||
if ($add_created)
|
||||
{
|
||||
$row[] = $this->db->quote($date);
|
||||
}
|
||||
if ($add_version)
|
||||
{
|
||||
$row[] = 1;
|
||||
}
|
||||
if ($add_published)
|
||||
{
|
||||
$row[] = 1;
|
||||
}
|
||||
|
||||
// add to query
|
||||
$query->values(implode(',', $row));
|
||||
|
||||
// execute the final query
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// always reset the default switch
|
||||
$this->defaults = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,380 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd 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\Database;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\LoadInterface;
|
||||
use VDM\Joomla\Componentbuilder\Abstraction\Database;
|
||||
|
||||
|
||||
/**
|
||||
* Database Load
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Load extends Database implements LoadInterface
|
||||
{
|
||||
/**
|
||||
* Load data rows as an array of associated arrays
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $select, array $tables, ?array $where = null,
|
||||
?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']);
|
||||
}
|
||||
|
||||
// check if we can get many rows
|
||||
if ($this->many($select, $tables, $where, $order, $limit))
|
||||
{
|
||||
// return associated arrays from the table records
|
||||
return $this->db->loadAssocList($key);
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data rows as an array of objects
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $select, array $tables, ?array $where = null,
|
||||
?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']);
|
||||
}
|
||||
|
||||
// check if we can get many rows
|
||||
if ($this->many($select, $tables, $where, $order, $limit))
|
||||
{
|
||||
// return associated arrays from the table records
|
||||
return $this->db->loadObjectList($key);
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data row as an associated array
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $select, array $tables, ?array $where = null, ?array $order = null): ?array
|
||||
{
|
||||
// check if we can get one row
|
||||
if ($this->one($select, $tables, $where, $order))
|
||||
{
|
||||
return $this->db->loadAssoc();
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data row as an object
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object
|
||||
{
|
||||
// check if we can get one row
|
||||
if ($this->one($select, $tables, $where, $order))
|
||||
{
|
||||
return $this->db->loadObject();
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load one value from a row
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function value(array $select, array $tables, ?array $where = null, ?array $order = null)
|
||||
{
|
||||
// check if we can get one value
|
||||
if ($this->one($select, $tables, $where, $order))
|
||||
{
|
||||
return $this->db->loadResult();
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load many
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function many(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): bool
|
||||
{
|
||||
// only do check if we have the table set
|
||||
if (isset($tables['a']))
|
||||
{
|
||||
// get the query
|
||||
$query = $this->query($select, $tables, $where, $order);
|
||||
|
||||
// Load the items
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load one
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function one(array $select, array $tables, ?array $where = null, ?array $order = null): bool
|
||||
{
|
||||
// only do check if we have the table set
|
||||
if (isset($tables['a']))
|
||||
{
|
||||
// get the query
|
||||
$query = $this->query($select, $tables, $where, $order);
|
||||
|
||||
// Load the item
|
||||
$this->db->setQuery($query, 0, 1);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query object
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return object|null The query object (DatabaseQuery)
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function query(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?object
|
||||
{
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// check if we have an all selection set
|
||||
if (isset($select['all']))
|
||||
{
|
||||
// all selection example array: ['all' => ['a.*', 'b.*']]
|
||||
if (ArrayHelper::check($select['all']))
|
||||
{
|
||||
foreach ($select['all'] as $select_all)
|
||||
{
|
||||
// set target selection
|
||||
$query->select(
|
||||
$select_all
|
||||
);
|
||||
}
|
||||
}
|
||||
// all selection example string: ['all' =>'a.*']
|
||||
elseif (is_string($select['all']))
|
||||
{
|
||||
// set target selection
|
||||
$query->select(
|
||||
$select['all']
|
||||
);
|
||||
}
|
||||
unset($select['all']);
|
||||
}
|
||||
|
||||
// load the table where join
|
||||
if (ArrayHelper::check($select))
|
||||
{
|
||||
// set target selection
|
||||
$query->select(
|
||||
$this->db->quoteName(
|
||||
array_keys($select),
|
||||
array_values($select)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// set main table
|
||||
$query->from($this->db->quoteName($this->getTable($tables['a']), 'a'));
|
||||
|
||||
// remove main table
|
||||
unset($tables['a']);
|
||||
|
||||
// load the table where join
|
||||
if (ArrayHelper::check($tables))
|
||||
{
|
||||
foreach ($tables as $as => $table)
|
||||
{
|
||||
$query->join(
|
||||
'LEFT', $this->db->quoteName(
|
||||
$this->getTable($table['name']), $as
|
||||
) . ' ON (' . $this->db->quoteName($table['join_on'])
|
||||
. ' = ' . $this->db->quoteName($table['as_on']) . ')'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// load the table where getters
|
||||
if (ArrayHelper::check($where))
|
||||
{
|
||||
foreach ($where as $key => $value)
|
||||
{
|
||||
if (ArrayHelper::check($value))
|
||||
{
|
||||
if (isset($value['value']) && isset($value['operator']))
|
||||
{
|
||||
if (ArrayHelper::check($value['value']))
|
||||
{
|
||||
// add the where by array
|
||||
$query->where($this->db->quoteName($key) . ' ' .
|
||||
$value['operator'] . ' (' .
|
||||
implode(',',
|
||||
array_map(function ($val) {
|
||||
return $this->quote($val);
|
||||
}, $value['value'])
|
||||
)
|
||||
. ')'
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the where
|
||||
$query->where($this->db->quoteName($key) . ' ' .
|
||||
$value['operator'] . ' ' . $this->quote($value['value']));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we should through an exception
|
||||
// for security we just return nothing for now
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the where
|
||||
$query->where($this->db->quoteName($key) .
|
||||
' = ' . $this->quote($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// load the row ordering
|
||||
if (ArrayHelper::check($order))
|
||||
{
|
||||
foreach ($order as $key => $direction)
|
||||
{
|
||||
// add the ordering
|
||||
$query->order($this->db->quoteName($key) .
|
||||
' ' . $direction);
|
||||
}
|
||||
}
|
||||
|
||||
// only return a limited number
|
||||
if (is_numeric($limit))
|
||||
{
|
||||
$query->setLimit($limit);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@ -16,12 +16,12 @@ use Joomla\DI\Container;
|
||||
|
||||
|
||||
/**
|
||||
* The Basic Factory Interface
|
||||
* The Container Factory Interface
|
||||
*/
|
||||
interface Factoryinterface
|
||||
interface FactoryInterface
|
||||
{
|
||||
/**
|
||||
* Get any class from the compiler container
|
||||
* Get any class from the container
|
||||
*
|
||||
* @param string $key The container class key
|
||||
*
|
||||
@ -31,7 +31,7 @@ interface Factoryinterface
|
||||
public static function _(string $key);
|
||||
|
||||
/**
|
||||
* Get a the global compiler container
|
||||
* Get the global container
|
||||
*
|
||||
* @return Container
|
||||
* @since 3.2.0
|
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd 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\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Database Insert Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface InsertInterface
|
||||
{
|
||||
/**
|
||||
* Set rows to the database
|
||||
*
|
||||
* @param array $data Dataset to store in database [array of arrays (key => value)]
|
||||
* @param string $table The table where the data is being added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $data, string $table): bool;
|
||||
|
||||
/**
|
||||
* Set items to the database
|
||||
*
|
||||
* @param array $data Data to store in database (array of objects)
|
||||
* @param array $columns Data columns
|
||||
* @param string $table The table where the data is being added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $data, array $columns, string $table): bool;
|
||||
|
||||
/**
|
||||
* Set row to the database
|
||||
*
|
||||
* @param array $data Dataset to store in database (key => value)
|
||||
* @param string $table The table where the data is being added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $data, string $table): bool;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Component.Builder
|
||||
*
|
||||
* @created 3rd 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\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Database Load Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface LoadInterface
|
||||
{
|
||||
/**
|
||||
* Load data rows as an array of associated arrays
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?array;
|
||||
|
||||
/**
|
||||
* Load data rows as an array of objects
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?array;
|
||||
|
||||
/**
|
||||
* Load data row as an associated array
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $select, array $tables, ?array $where = null, ?array $order = null): ?array;
|
||||
|
||||
/**
|
||||
* Load data row as an object
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object;
|
||||
|
||||
/**
|
||||
* Load one value from a row
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function value(array $select, array $tables, ?array $where = null, ?array $order = null);
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace VDM\Joomla\Componentbuilder\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* The Table Interface
|
||||
* The Core JCB Table Interface
|
||||
*/
|
||||
interface Tableinterface
|
||||
{
|
||||
|
@ -15,8 +15,8 @@ namespace VDM\Joomla\Componentbuilder\Search;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Get;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Set;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Load;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Insert;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Find;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Replace;
|
||||
use VDM\Joomla\Componentbuilder\Search\Agent\Search;
|
||||
@ -40,20 +40,20 @@ class Agent
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Search Get Database
|
||||
* Search Load Database
|
||||
*
|
||||
* @var Get
|
||||
* @var Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Get $get;
|
||||
protected Load $load;
|
||||
|
||||
/**
|
||||
* Search Set Database
|
||||
* Search Insert Database
|
||||
*
|
||||
* @var Set
|
||||
* @var Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Set $set;
|
||||
protected Insert $insert;
|
||||
|
||||
/**
|
||||
* Search Find
|
||||
@ -123,8 +123,8 @@ class Agent
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Get|null $get The search get database object.
|
||||
* @param Set|null $set The search get database object.
|
||||
* @param Load|null $load The search load database object.
|
||||
* @param Insert|null $insert The search insert database object.
|
||||
* @param Find|null $find The search find object.
|
||||
* @param Replace|null $replace The search replace object.
|
||||
* @param Search|null $search The search object.
|
||||
@ -133,13 +133,13 @@ class Agent
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Get $get = null,
|
||||
?Set$set = null, ?Find $find = null, ?Replace $replace = null,
|
||||
public function __construct(?Config $config = null, ?Load $load = null,
|
||||
?Insert $insert = null, ?Find $find = null, ?Replace $replace = null,
|
||||
?Search $search = null, ?Update $update = null, ?Table $table = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->get = $get ?: Factory::_('Get.Database');
|
||||
$this->set = $set ?: Factory::_('Set.Database');
|
||||
$this->load = $load ?: Factory::_('Load.Database');
|
||||
$this->insert = $insert ?: Factory::_('Insert.Database');
|
||||
$this->find = $find ?: Factory::_('Agent.Find');
|
||||
$this->replace = $replace ?: Factory::_('Agent.Replace');
|
||||
$this->search = $search ?: Factory::_('Agent.Search');
|
||||
@ -156,11 +156,11 @@ class Agent
|
||||
* @param string|null $table The table
|
||||
* @param bool $update The switch to triger an update (default is false)
|
||||
*
|
||||
* @return string
|
||||
* @return string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getValue(int $id, string $field, $line = null,
|
||||
?string $table = null, bool $update = false): string
|
||||
?string $table = null, bool $update = false): ?string
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
@ -168,7 +168,7 @@ class Agent
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
if (($value = $this->get->value($id, $field, $table)) !== null)
|
||||
if (($value = $this->load->value($id, $field, $table)) !== null)
|
||||
{
|
||||
// we only return strings that can load in an editor
|
||||
if (is_string($value))
|
||||
@ -207,7 +207,7 @@ class Agent
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
return $this->set->value($value, $id, $field, $table);
|
||||
return $this->insert->value($value, $id, $field, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,7 +271,7 @@ class Agent
|
||||
$set = 1;
|
||||
|
||||
// continue loading items until all are searched
|
||||
while(($items = $this->get->items($table, $set)) !== null)
|
||||
while(($items = $this->load->items($table, $set)) !== null)
|
||||
{
|
||||
$this->find->items($items, $table);
|
||||
$set++;
|
||||
@ -300,7 +300,7 @@ class Agent
|
||||
$replaced = 0;
|
||||
|
||||
// continue loading items until all was loaded
|
||||
while(($items = $this->get->items($table, $set)) !== null)
|
||||
while(($items = $this->load->items($table, $set)) !== null)
|
||||
{
|
||||
// search for items
|
||||
$this->find->items($items, $table);
|
||||
@ -309,7 +309,7 @@ class Agent
|
||||
$this->replace->items($this->find->get($table), $table);
|
||||
|
||||
// update the database
|
||||
if ($this->set->items($this->replace->get($table), $table))
|
||||
if ($this->insert->items($this->replace->get($table), $table))
|
||||
{
|
||||
$replaced++;
|
||||
}
|
||||
|
@ -16,9 +16,9 @@ use Joomla\CMS\Factory as JoomlaFactory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Set as Model;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Insert as Model;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\SetInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\InsertInterface;
|
||||
|
||||
|
||||
/**
|
||||
@ -26,7 +26,7 @@ use VDM\Joomla\Componentbuilder\Search\Interfaces\SetInterface;
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Set implements SetInterface
|
||||
class Insert implements InsertInterface
|
||||
{
|
||||
/**
|
||||
* Search Config
|
||||
@ -75,7 +75,7 @@ class Set implements SetInterface
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->table = $table ?: Factory::_('Table');
|
||||
$this->model = $model ?: Factory::_('Set.Model');
|
||||
$this->model = $model ?: Factory::_('Insert.Model');
|
||||
$this->db = $db ?: JoomlaFactory::getDbo();
|
||||
}
|
||||
|
@ -16,16 +16,17 @@ use Joomla\CMS\Factory as JoomlaFactory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Get as Model;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\GetInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Load as Model;
|
||||
use VDM\Joomla\Componentbuilder\Database\Load as Database;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\LoadInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Search Database Get
|
||||
* Search Database Load
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Get implements GetInterface
|
||||
class Load implements LoadInterface
|
||||
{
|
||||
/**
|
||||
* Bundle Size
|
||||
@ -60,12 +61,12 @@ class Get implements GetInterface
|
||||
protected Model $model;
|
||||
|
||||
/**
|
||||
* Database object to query local DB
|
||||
* Database load class
|
||||
*
|
||||
* @var \JDatabaseDriver
|
||||
* @var Database
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected \JDatabaseDriver $db;
|
||||
protected Database $load;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -73,17 +74,17 @@ class Get implements GetInterface
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Table|null $table The search table object.
|
||||
* @param Model|null $model The search get model object.
|
||||
* @param \JDatabaseDriver|null $db The database object.
|
||||
* @param Database|null $load The database object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Table $table = null,
|
||||
?Model $model = null, ?\JDatabaseDriver $db = null)
|
||||
?Model $model = null, ?Database $load = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->table = $table ?: Factory::_('Table');
|
||||
$this->model = $model ?: Factory::_('Get.Model');
|
||||
$this->db = $db ?: JoomlaFactory::getDbo();
|
||||
$this->model = $model ?: Factory::_('Load.Model');
|
||||
$this->load = $load ?: Factory::_('Load');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,30 +106,19 @@ class Get implements GetInterface
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// check if this is a valid field and table
|
||||
if ($id > 0 && ($name = $this->table->get($table, $field, 'name')) !== null)
|
||||
// check if this is a valid table
|
||||
if ($id > 0 && $this->table->exist($table, $field) &&
|
||||
($value = $this->load->value(
|
||||
["a.${field}" => $field], // select
|
||||
['a' => $table], // tables
|
||||
['a.id' => $id] // where
|
||||
)) !== null)
|
||||
{
|
||||
// Create a new query object.
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// Order it by the ordering field.
|
||||
$query->select($this->db->quoteName($name));
|
||||
$query->from($this->db->quoteName('#__componentbuilder_' . $table));
|
||||
|
||||
// get by id
|
||||
$query->where($this->db->quoteName('id') . " = " . (int) $id);
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have any values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
// return found values
|
||||
return $this->model->value($this->db->loadResult(), $name, $table);
|
||||
}
|
||||
return $this->model->value(
|
||||
$value, $field, $table
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -151,32 +141,17 @@ class Get implements GetInterface
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if ($id > 0 && ($fields = $this->table->fields($table)) !== null)
|
||||
{
|
||||
// add the ID
|
||||
array_unshift($fields , 'id');
|
||||
|
||||
// Create a new query object.
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// Order it by the ordering field.
|
||||
$query->select($this->db->quoteName($fields));
|
||||
$query->from($this->db->quoteName('#__componentbuilder_' . $table));
|
||||
|
||||
// get by id
|
||||
$query->where($this->db->quoteName('id') . " = " . $id);
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have any values
|
||||
if ($this->db->getNumRows())
|
||||
if ($id > 0 && ($fields = $this->getFields($table)) !== null &&
|
||||
($item = $this->load->item(
|
||||
$fields, // select
|
||||
['a' => $table], // tables
|
||||
['a.id' => $id] // where
|
||||
)) !== null)
|
||||
{
|
||||
// return found values
|
||||
return $this->model->item($this->db->loadObject(), $table);
|
||||
}
|
||||
return $this->model->item($item, $table);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -199,43 +174,46 @@ class Get implements GetInterface
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if (($fields = $this->table->fields($table)) !== null)
|
||||
if ( ($fields = $this->getFields($table)) !== null)
|
||||
{
|
||||
// add the ID
|
||||
array_unshift($fields , 'id');
|
||||
|
||||
// add a key to the selection return set
|
||||
$fields['key'] = 'id';
|
||||
// get the title value
|
||||
$title = $this->table->titleName($table);
|
||||
|
||||
// Create a new query object.
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// Order it by the ordering field.
|
||||
$query->select($this->db->quoteName($fields));
|
||||
$query->from($this->db->quoteName('#__componentbuilder_' . $table));
|
||||
$query->order($title .' ASC');
|
||||
// set order
|
||||
$order = [$title => 'ASC'];
|
||||
// select all
|
||||
$where = null;
|
||||
// no limit
|
||||
$limit = null;
|
||||
|
||||
// add limitation and pagination
|
||||
if ($bundle > 0)
|
||||
{
|
||||
// get the incremental number
|
||||
$query->where($this->db->quoteName('id') . " >= " . $this->next($table, $bundle));
|
||||
$where = ['a.id' => [
|
||||
'operator' => '>=',
|
||||
'value' => $this->next($table, $bundle)
|
||||
]
|
||||
];
|
||||
|
||||
// only return a limited number
|
||||
$query->setLimit($this->bundle);
|
||||
$limit = $this->bundle;
|
||||
}
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have any values
|
||||
if ($this->db->getNumRows())
|
||||
if (($items = $this->load->items(
|
||||
$fields, // select
|
||||
['a' => $table], // tables
|
||||
$where,
|
||||
$order,
|
||||
$limit
|
||||
)) !== null)
|
||||
{
|
||||
// return found values
|
||||
return $this->model->items($this->db->loadObjectList('id'), $table);
|
||||
return $this->model->items($items, $table);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -291,5 +269,35 @@ class Get implements GetInterface
|
||||
return (($bundle * $this->bundle) - $this->bundle) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Fields ready to use in database call
|
||||
*
|
||||
* @param string $table The table which fields we want to get
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getFields(string $table, string $key = 'a', bool $addId = true): ?array
|
||||
{
|
||||
if (($fields = $this->table->fields($table)) !== null)
|
||||
{
|
||||
// add the ID
|
||||
if ($addId)
|
||||
{
|
||||
array_unshift($fields , 'id');
|
||||
}
|
||||
|
||||
$bucket = [];
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
$bucket[$key . '.' . $field] = $field;
|
||||
}
|
||||
|
||||
return $bucket;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ use VDM\Joomla\Componentbuilder\Search\Service\Search;
|
||||
use VDM\Joomla\Componentbuilder\Search\Service\Model;
|
||||
use VDM\Joomla\Componentbuilder\Search\Service\Database;
|
||||
use VDM\Joomla\Componentbuilder\Search\Service\Agent;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\Factoryinterface;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\FactoryInterface;
|
||||
|
||||
|
||||
/**
|
||||
@ -25,10 +25,10 @@ use VDM\Joomla\Componentbuilder\Interfaces\Factoryinterface;
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Factory implements Factoryinterface
|
||||
abstract class Factory implements FactoryInterface
|
||||
{
|
||||
/**
|
||||
* Global Compiler Container
|
||||
* Global Search Container
|
||||
*
|
||||
* @var Container
|
||||
* @since 3.2.0
|
||||
@ -36,7 +36,7 @@ abstract class Factory implements Factoryinterface
|
||||
protected static $container = null;
|
||||
|
||||
/**
|
||||
* Get any class from the compiler container
|
||||
* Get any class from the search container
|
||||
*
|
||||
* @param string $key The container class key
|
||||
*
|
||||
@ -49,7 +49,7 @@ abstract class Factory implements Factoryinterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a the global compiler container
|
||||
* Get the global search container
|
||||
*
|
||||
* @return Container
|
||||
* @since 3.2.0
|
||||
|
@ -13,11 +13,11 @@ namespace VDM\Joomla\Componentbuilder\Search\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Search Database Set Interface
|
||||
* Search Database Insert Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface SetInterface
|
||||
interface InsertInterface
|
||||
{
|
||||
/**
|
||||
* Set values to a given table
|
@ -13,11 +13,11 @@ namespace VDM\Joomla\Componentbuilder\Search\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Search Database Get Interface
|
||||
* Search Database Load Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface GetInterface
|
||||
interface LoadInterface
|
||||
{
|
||||
/**
|
||||
* Get a value from a given table
|
@ -17,11 +17,11 @@ use VDM\Joomla\Componentbuilder\Search\Abstraction\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Search Set Model
|
||||
* Search Insert Model
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Set extends Model implements ModelInterface
|
||||
class Insert extends Model implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Model the value
|
@ -19,11 +19,11 @@ use VDM\Joomla\Componentbuilder\Search\Abstraction\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Search Get Model
|
||||
* Search Load Model
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Get extends Model implements ModelInterface
|
||||
class Load extends Model implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Model the value
|
@ -66,8 +66,8 @@ class Agent implements ServiceProviderInterface
|
||||
{
|
||||
return new SearchAgent(
|
||||
$container->get('Config'),
|
||||
$container->get('Get.Database'),
|
||||
$container->get('Set.Database'),
|
||||
$container->get('Load.Database'),
|
||||
$container->get('Insert.Database'),
|
||||
$container->get('Agent.Find'),
|
||||
$container->get('Agent.Replace'),
|
||||
$container->get('Agent.Search'),
|
||||
|
@ -14,8 +14,10 @@ namespace VDM\Joomla\Componentbuilder\Search\Service;
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Get as GetDatabase;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Set as SetDatabase;
|
||||
use VDM\Joomla\Componentbuilder\Database\Load;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Load as LoadDatabase;
|
||||
use VDM\Joomla\Componentbuilder\Database\Insert;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Insert as InsertDatabase;
|
||||
|
||||
|
||||
/**
|
||||
@ -35,44 +37,77 @@ class Database implements ServiceProviderInterface
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(GetDatabase::class, 'Get.Database')
|
||||
->share('Get.Database', [$this, 'getDatabaseGet'], true);
|
||||
$container->alias(Load::class, 'Load')
|
||||
->share('Load', [$this, 'getLoad'], true);
|
||||
|
||||
$container->alias(SetDatabase::class, 'Set.Database')
|
||||
->share('Set.Database', [$this, 'getDatabaseSet'], true);
|
||||
$container->alias(LoadDatabase::class, 'Load.Database')
|
||||
->share('Load.Database', [$this, 'getDatabaseLoad'], true);
|
||||
|
||||
$container->alias(Insert::class, 'Insert')
|
||||
->share('Insert', [$this, 'getInsert'], true);
|
||||
|
||||
$container->alias(InsertDatabase::class, 'Insert.Database')
|
||||
->share('Insert.Database', [$this, 'getDatabaseInsert'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Get Database
|
||||
* Get the Core Load Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return GetDatabase
|
||||
* @return Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getDatabaseGet(Container $container): GetDatabase
|
||||
public function getLoad(Container $container): Load
|
||||
{
|
||||
return new GetDatabase(
|
||||
return new Load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Load Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return LoadDatabase
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getDatabaseLoad(Container $container): LoadDatabase
|
||||
{
|
||||
return new LoadDatabase(
|
||||
$container->get('Config'),
|
||||
$container->get('Table'),
|
||||
$container->get('Get.Model')
|
||||
$container->get('Load.Model'),
|
||||
$container->get('Load')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Set Database
|
||||
* Get the Core Insert Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return SetDatabase
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getDatabaseSet(Container $container): SetDatabase
|
||||
public function getInsert(Container $container): Insert
|
||||
{
|
||||
return new SetDatabase(
|
||||
return new Insert();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Insert Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return InsertDatabase
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getDatabaseInsert(Container $container): InsertDatabase
|
||||
{
|
||||
return new InsertDatabase(
|
||||
$container->get('Config'),
|
||||
$container->get('Table'),
|
||||
$container->get('Set.Model')
|
||||
$container->get('Insert.Model')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,8 @@ namespace VDM\Joomla\Componentbuilder\Search\Service;
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Get;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Set;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Load;
|
||||
use VDM\Joomla\Componentbuilder\Search\Model\Insert;
|
||||
|
||||
|
||||
/**
|
||||
@ -35,40 +35,40 @@ class Model implements ServiceProviderInterface
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Get::class, 'Get.Model')
|
||||
->share('Get.Model', [$this, 'getModelGet'], true);
|
||||
$container->alias(Load::class, 'Load.Model')
|
||||
->share('Load.Model', [$this, 'getModelLoad'], true);
|
||||
|
||||
$container->alias(Set::class, 'Set.Model')
|
||||
->share('Set.Model', [$this, 'getModelSet'], true);
|
||||
$container->alias(Insert::class, 'Insert.Model')
|
||||
->share('Insert.Model', [$this, 'getModelInsert'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Get Model
|
||||
* Get the Load Model
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Get
|
||||
* @return Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelGet(Container $container): Get
|
||||
public function getModelLoad(Container $container): Load
|
||||
{
|
||||
return new Get(
|
||||
return new Load(
|
||||
$container->get('Config'),
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Set Model
|
||||
* Get the Insert Model
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Set
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelSet(Container $container): Set
|
||||
public function getModelInsert(Container $container): Insert
|
||||
{
|
||||
return new Set(
|
||||
return new Insert(
|
||||
$container->get('Config'),
|
||||
$container->get('Table')
|
||||
);
|
||||
|
@ -27,7 +27,7 @@ abstract class Helper
|
||||
/**
|
||||
* The current option
|
||||
*
|
||||
* @var String
|
||||
* @var string
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static $option;
|
||||
@ -43,14 +43,14 @@ abstract class Helper
|
||||
/**
|
||||
* Gets the parameter object for the component
|
||||
*
|
||||
* @param String $option The option for the component.
|
||||
* @param string $option The option for the component.
|
||||
*
|
||||
* @return Registry A Registry object.
|
||||
*
|
||||
* @see Registry
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getParams($option = null)
|
||||
public static function getParams($option = null): Registry
|
||||
{
|
||||
// check that we have an option
|
||||
if (empty($option))
|
||||
@ -70,13 +70,13 @@ abstract class Helper
|
||||
/**
|
||||
* Gets the component option
|
||||
*
|
||||
* @param String|Bool $default The default return value if none is found
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return String|Bool A component option
|
||||
* @return string|null A component option
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getOption($default = 'empty')
|
||||
public static function getOption($default = 'empty'): ?string
|
||||
{
|
||||
if (empty(self::$option))
|
||||
{
|
||||
@ -95,14 +95,14 @@ abstract class Helper
|
||||
/**
|
||||
* Gets the component code name
|
||||
*
|
||||
* @param String $option The option for the component.
|
||||
* @param String|Bool $default The default return value if none is found
|
||||
* @param string $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return String|Mixed A component code name
|
||||
* @return string|null A component code name
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getCode($option = null, $default = null)
|
||||
public static function getCode($option = null, $default = null): ?string
|
||||
{
|
||||
// check that we have an option
|
||||
if (empty($option))
|
||||
@ -121,14 +121,14 @@ abstract class Helper
|
||||
/**
|
||||
* Gets the component abstract helper class
|
||||
*
|
||||
* @param String $option The option for the component.
|
||||
* @param String|Bool $default The default return value if none is found
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return String|Mixed A component helper name
|
||||
* @return string|null A component helper name
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function get($option = null, $default = null)
|
||||
public static function get($option = null, $default = null): ?string
|
||||
{
|
||||
// check that we have an option
|
||||
// and get the code name from it
|
||||
|
Loading…
Reference in New Issue
Block a user