Skip to content

Commit

Permalink
#25: enable grouping for title sort
Browse files Browse the repository at this point in the history
  • Loading branch information
ctgraham committed May 29, 2020
1 parent ad37f55 commit fc7ffa2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
25 changes: 24 additions & 1 deletion pages/BrowseBySectionHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ public function view($args, $request) {
}
}
}
$articleGroups = array();
if ($orderBy === 'title') {
// segment into groups alphabetically
$key = '';
$group = array();
foreach ($publishedArticles as $article) {
$newkey = mb_substr($article->getLocalizedTitle(), 0, 1);
if ($newkey !== $key) {
if (count($group)) {
$articleGroups[] = array('key' => $key, 'articles' => $group);
}
$group = array();
$key = $newkey;
}
$group[] = $article;
}
if (count($group)) {
$articleGroups[] = array('key' => $key, 'articles' => $group);
}
} else if (count($publishedArticles)) {
// one continuous group
$articleGroups[] = array('key' => null, 'articles' => $publishedArticles);
}

$issues = array();
if (!empty($publishedArticles)) {
Expand All @@ -152,7 +175,7 @@ public function view($args, $request) {
'section' => $section,
'sectionPath' => $sectionPath,
'sectionDescription' => $section->getLocalizedData('browseByDescription'),
'articles' => $publishedArticles,
'articleGroups' => $articleGroups,
'issues' => $issues,
'showingStart' => $showingStart,
'showingEnd' => $showingEnd,
Expand Down
11 changes: 9 additions & 2 deletions templates/frontend/pages/section.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,22 @@
{$sectionDescription|strip_unsafe_html}
</div>

{if $articles|@count}
{if $articleGroups|@count}
{foreach from=$articleGroups item=group}
{if $group.key}
<div class="cmp_article_header" id="browse_by_section_group_{$group.key|escape}">
{$group.key|escape}
</div>
{/if}
<ul class="cmp_article_list">
{foreach from=$articles item=article}
{foreach from=$group.articles item=article}
<li>
{* TODO remove section=null workaround. article_summary.tpl expects a specific section array. See issue_toc.tpl. *}
{include file="frontend/objects/article_summary.tpl" section=null showDatePublished=true hideGalleys=true}
</li>
{/foreach}
</ul>
{/foreach}

{* Pagination *}
{if $prevPage > 1}
Expand Down

0 comments on commit fc7ffa2

Please sign in to comment.