Back to InstallerScript class

Method getItemArray

public array
getItemArray
(mixed $element, mixed $table, mixed $column, mixed $identifier)
Builds a standard select query to produce better DRY code in this script.
Parameters
  • string $element The element to get from the query
  • string $table The table to search for the data in
  • string $column The column of the database to search from
  • mixed $identifier The integer id or the string
Returns
  • array Associated array containing data from the cell
Since
  • 3.6

Method getItemArray - Source code

/**
 * Builds a standard select query to produce better DRY code in this script.
 * This should produce a single unique cell which is json encoded - it will then
 * return an associated array with this data in.
 *
 * @param   string  $element     The element to get from the query
 * @param   string  $table       The table to search for the data in
 * @param   string  $column      The column of the database to search from
 * @param   mixed   $identifier  The integer id or the string
 *
 * @return  array  Associated array containing data from the cell
 *
 * @since   3.6
 */
public function getItemArray($element, $table, $column, $identifier)
{
    // Get the DB and query objects
    $db = Factory::getDbo();
    $paramType = is_numeric($identifier) ? ParameterType::INTEGER : ParameterType::STRING;
    // Build the query
    $query = $db->getQuery(true)->select($db->quoteName($element))->from($db->quoteName($table))->where($db->quoteName($column) . ' = :id')->bind(':id', $identifier, $paramType);
    $db->setQuery($query);
    // Load the single cell and json_decode data
    return json_decode($db->loadResult(), true);
}