2023-04-15 14:53:53 +00:00
|
|
|
/**
|
|
|
|
* Search Table
|
|
|
|
*
|
|
|
|
* @var Table
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
protected Table $table;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Database Load
|
|
|
|
*
|
|
|
|
* @var Database
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
protected Database $load;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param Table|null $table The core table object.
|
|
|
|
* @param Database|null $load The database object.
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public function __construct(?Table $table = null, ?Database $load = null)
|
|
|
|
{
|
|
|
|
$this->table = $table ?: Factory::_('Table');
|
|
|
|
$this->load = $load ?: Factory::_('Load');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a value from a given table
|
|
|
|
* Example: $this->value(23, 'value_key', 'table_name');
|
|
|
|
*
|
|
|
|
* @param int $id The item ID
|
|
|
|
* @param string $field The field key
|
|
|
|
* @param string $table The table
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public function value(int $id, string $field, string $table)
|
|
|
|
{
|
|
|
|
// check if this is a valid table
|
|
|
|
if ($id > 0 && $this->table->exist($table, $field))
|
|
|
|
{
|
|
|
|
return $this->load->value(
|
|
|
|
["a.${field}" => $field], ['a' => $table], ['a.id' => $id]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get values from a given table
|
|
|
|
* Example: $this->item(23, 'table_name');
|
|
|
|
*
|
|
|
|
* @param int $id The item ID
|
|
|
|
* @param string $table The table
|
|
|
|
*
|
|
|
|
* @return object|null
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public function item(int $id, ?string $table): ?object
|
|
|
|
{
|
|
|
|
// check if this is a valid table
|
|
|
|
if ($id > 0 && $this->table->exist($table))
|
|
|
|
{
|
|
|
|
return $this->load->item(
|
|
|
|
['all' => 'a.*'], ['a' => $table], ['a.id' => $id]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get values from a given table
|
|
|
|
* Example: $this->items($ids, 'table_name');
|
|
|
|
*
|
|
|
|
* @param array $ids The item ids
|
|
|
|
* @param string $table The table
|
|
|
|
*
|
|
|
|
* @return array|null
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public function items(array $ids, string $table): ?array
|
|
|
|
{
|
|
|
|
// check if this is a valid table
|
|
|
|
if ($this->table->exist($table))
|
|
|
|
{
|
|
|
|
return $this->load->items(
|
|
|
|
['all' => 'a.*'], ['a' => $table], ['a.id' => $ids]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2023-10-10 09:39:38 +00:00
|
|
|
}
|