Skip to content

Commit

Permalink
add advanced where clause param
Browse files Browse the repository at this point in the history
  • Loading branch information
Septdir committed Apr 25, 2018
1 parent 1686ab3 commit d99dca5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libraries/src/Language/Associations.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ class Associations
* @param string $pk The name of the primary key in the given $table.
* @param string $aliasField If the table has an alias field set it here. Null to not use it
* @param string $catField If the table has a catid field set it here. Null to not use it
* @param array $advClause Array with advanced where clause use c as parent column key, c2 as associations column key
*
* @return array The associated items
*
* @since 3.1
*
* @throws \Exception
*/
public static function getAssociations($extension, $tablename, $context, $id, $pk = 'id', $aliasField = 'alias', $catField = 'catid')
public static function getAssociations($extension, $tablename, $context, $id, $pk = 'id', $aliasField = 'alias', $catField = 'catid', $advClause = array())
{
// To avoid doing duplicate database queries.
static $multilanguageAssociations = array();

// Multilanguage association array key. If the key is already in the array we don't need to run the query again, just return it.
$queryKey = implode('|', func_get_args());
$queryKey = implode('|', array($extension, $tablename, $context, $id));

if (!isset($multilanguageAssociations[$queryKey]))
{
Expand Down Expand Up @@ -97,6 +98,15 @@ public static function getAssociations($extension, $tablename, $context, $id, $p
$query->where('c.extension = ' . $db->quote($extension));
}

// Advanced where clause
if (!empty($advClause))
{
foreach ($advClause as $clause)
{
$query->where($clause);
}
}

$db->setQuery($query);

try
Expand Down

0 comments on commit d99dca5

Please sign in to comment.