Skip to content

Commit

Permalink
[mod_articles_category] Option to group by tags (#21083)
Browse files Browse the repository at this point in the history
* [mod_articles_category] Grouping by tags

* CS, argument default value
  • Loading branch information
SharkyKZ authored and Michael Babker committed Jul 16, 2018
1 parent bb48cb6 commit 922e46d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions language/en-GB/en-GB.mod_articles_category.ini
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ MOD_ARTICLES_CATEGORY_OPTION_YEAR_VALUE="Year"
MOD_ARTICLES_CATEGORY_READ_MORE="Read more: "
MOD_ARTICLES_CATEGORY_READ_MORE_TITLE="Read More ..."
MOD_ARTICLES_CATEGORY_REGISTER_TO_READ_MORE="Register to read more"
MOD_ARTICLES_CATEGORY_UNTAGGED="Untagged"
MOD_ARTICLES_CATEGORY_XML_DESCRIPTION="This module displays a list of articles from one or more categories."
42 changes: 41 additions & 1 deletion modules/mod_articles_category/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function getList(&$params)
$articles->setState('list.start', 0);
$articles->setState('list.limit', (int) $params->get('count', 0));
$articles->setState('filter.published', 1);
$articles->setState('load_tags', $params->get('show_tags', 0));
$articles->setState('load_tags', $params->get('show_tags', 0) || $params->get('article_grouping', 'none') === 'tags');

// Access filter
$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
Expand Down Expand Up @@ -502,4 +502,44 @@ public static function groupByDate($list, $type = 'year', $article_grouping_dire

return $grouped;
}

/**
* Groups items by tags
*
* @param array $list list of items
* @param string $direction ordering direction
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function groupByTags($list, $direction = 'ksort')
{
$grouped = array();
$untagged = JText::_('MOD_ARTICLES_CATEGORY_UNTAGGED');

if (!$list)
{
return $grouped;
}

foreach ($list as $item)
{
if ($item->tags->itemTags)
{
foreach ($item->tags->itemTags as $tag)
{
$grouped[$tag->title][] = $item;
}
}
else
{
$grouped[$untagged][] = $item;
}
}

$direction($grouped);

return $grouped;
}
}
3 changes: 3 additions & 0 deletions modules/mod_articles_category/mod_articles_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
case 'category_title' :
$list = ModArticlesCategoryHelper::groupBy($list, $article_grouping, $article_grouping_direction);
break;
case 'tags' :
$list = ModArticlesCategoryHelper::groupByTags($list, $article_grouping_direction);
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions modules/mod_articles_category/mod_articles_category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
<option value="month_year">MOD_ARTICLES_CATEGORY_OPTION_MONTHYEAR_VALUE</option>
<option value="author">JAUTHOR</option>
<option value="category_title">JCATEGORY</option>
<option value="tags">JTAG</option>
</field>

<field
Expand Down

0 comments on commit 922e46d

Please sign in to comment.