Skip to content

Commit

Permalink
add advanced where clause for com_content article associations
Browse files Browse the repository at this point in the history
  • Loading branch information
Septdir committed Apr 25, 2018
1 parent d99dca5 commit 79ed099
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion components/com_content/helpers/association.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,36 @@ public static function getAssociations($id = 0, $view = null, $layout = null)
{
if ($id)
{
$associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id);
$user = JFactory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$db = JFactory::getDbo();
$advClause = array();

// Filter by user groups
$advClause[] = 'c2.access IN (' . $groups . ')';

// Filter by current language
$advClause[] = 'c2.language != '.$db->quote(JFactory::getLanguage()->getTag());


if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content')))
{
// Filter by start and end dates.
$nullDate = $db->quote($db->getNullDate());
$date = JFactory::getDate();

$nowDate = $db->quote($date->toSql());

$advClause[] = '(c2.publish_up = ' . $nullDate . ' OR c2.publish_up <= ' . $nowDate . ')';
$advClause[] = '(c2.publish_down = ' . $nullDate . ' OR c2.publish_down >= ' . $nowDate . ')';

// Filter by published
$advClause[] = 'c2.state = 1';
}


$associations = JLanguageAssociations::getAssociations('com_content', '#__content',
'com_content.item', $id, 'id', 'alias', 'catid', $advClause);

$return = array();

Expand Down

0 comments on commit 79ed099

Please sign in to comment.