Skip to content

Commit

Permalink
Add &groupByYear and &groupByYearTpl to allow for grouping results by…
Browse files Browse the repository at this point in the history
… year in Archivist, into nested lists
  • Loading branch information
Shaun McCormick committed Dec 7, 2011
1 parent 426f937 commit 45d2cfe
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 14 deletions.
2 changes: 1 addition & 1 deletion _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/* define package */
define('PKG_NAME','Archivist');
define('PKG_NAME_LOWER','archivist');
define('PKG_VERSION','1.1.2');
define('PKG_VERSION','1.2.0');
define('PKG_RELEASE','pl');

/* define sources */
Expand Down
16 changes: 16 additions & 0 deletions _build/data/properties/properties.archivist.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@
'value' => false,
'lexicon' => 'archivist:properties',
),
array(
'name' => 'groupByYear',
'desc' => 'prop_archivist.groupbyyear_desc',
'type' => 'combo-boolean',
'options' => '',
'value' => false,
'lexicon' => 'archivist:properties',
),
array(
'name' => 'groupByYearTpl',
'desc' => 'prop_archivist.groupbyyeartpl_desc',
'type' => 'textfield',
'options' => '',
'value' => 'yeargroup',
'lexicon' => 'archivist:properties',
),
array(
'name' => 'dateFormat',
'desc' => 'prop_archivist.dateformat_desc',
Expand Down
4 changes: 4 additions & 0 deletions core/components/archivist/docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog for Archivist.

Archivist 1.2.0
===============
- Add &groupByYear and &groupByYearTpl to allow for grouping results by year in Archivist, into nested lists

Archivist 1.1.2
===============
- Fix issues with &where in getArchives
Expand Down
8 changes: 0 additions & 8 deletions core/components/archivist/elements/chunks/wrapper.chunk.tpl

This file was deleted.

7 changes: 7 additions & 0 deletions core/components/archivist/elements/chunks/yeargroup.chunk.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ul>
<li><a href="[[+url]]">[[+year]]</a>
<ul>
[[+row]]
</ul>
</li>
</ul>
32 changes: 27 additions & 5 deletions core/components/archivist/elements/snippets/snippet.archivist.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,26 @@
*
* @package archivist
*/
/*
/**
* Display an archived result filter list
*
* @var modX $modx
* @var array $scriptProperties
* @var Archivist $archivist
*
* @package archivist
*/
$archivist = $modx->getService('archivist','Archivist',$modx->getOption('archivist.core_path',null,$modx->getOption('core_path').'components/archivist/').'model/archivist/',$scriptProperties);
if (!($archivist instanceof Archivist)) return '';

/* setup default properties */
$tpl = $modx->getOption('tpl',$scriptProperties,'row');
$wrapperTpl = $modx->getOption('wrapperTpl',$scriptProperties,'wrapper');
$parents = !empty($scriptProperties['parents']) ? $scriptProperties['parents'] : $modx->resource->get('id');
$parents = explode(',',$parents);
$target = !empty($scriptProperties['target']) ? $scriptProperties['target'] : $modx->resource->get('id');
$sortBy = $modx->getOption('sortBy',$scriptProperties,'publishedon');
$sortDir = $modx->getOption('sortDir',$scriptProperties,'DESC');
$groupByYear = $modx->getOption('groupByYear',$scriptProperties,true);
$groupByYear = $modx->getOption('groupByYear',$scriptProperties,false);
$sortYear = $modx->getOption('sortYear',$scriptProperties,'DESC');
$depth = $modx->getOption('depth',$scriptProperties,10);
$where = $modx->getOption('where',$scriptProperties,'');
Expand Down Expand Up @@ -81,6 +84,7 @@
if (!empty($children)) $parents = array_merge($parents, $children);

/* get filter format */
$sqlDateFormat = '%Y';
if (empty($dateFormat)) {
$dateFormat = $sqlDateFormat = '%Y';
if ($useMonth) {
Expand Down Expand Up @@ -131,6 +135,7 @@
$groupByYearOutput = array();
$idx = 0;
$count = count($resources);
/** @var modResource $resource */
foreach ($resources as $resource) {
$resourceArray = $resource->toArray();

Expand Down Expand Up @@ -190,17 +195,34 @@
}

if ($groupByYear) {
$wrapperTpl = $modx->getOption('yearGroupTpl',$scriptProperties,'yeargroup');
$wrapperRowSeparator = $modx->getOption('yearGroupRowSeparator',$scriptProperties,"\n");
if (strtolower($sortYear) === 'asc') {
ksort($groupByYearOutput);
} else {
krsort($groupByYearOutput);
}
foreach ($groupByYearOutput as $year => $row) {
$wrapper['year'] = $year;
$wrapper['row'] = '';

$params = array();
$params[$filterPrefix.'year'] = $year;

if ($useFurls) {
$params = implode('/',$params);
if (!empty($extraParams)) $params .= '?'.$extraParams;
$wrapper['url'] = $modx->makeUrl($target).$params;
} else {
$params = http_build_query($params);
if (!empty($extraParams)) $params .= '&'.$extraParams;
$wrapper['url'] = $modx->makeUrl($target,'',$params);
}

$wrapper['row'] = array();
foreach ($row as $month) {
$wrapper['row'] .= $archivist->getChunk($tpl,$month);
$wrapper['row'][] = $archivist->getChunk($tpl,$month);
}
$wrapper['row'] = implode($wrapperRowSeparator,$wrapper['row']);
$output[] = $archivist->getChunk($wrapperTpl,$wrapper);
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/components/archivist/lexicon/en/properties.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
$_lang['prop_archivist.setlocale_desc'] = 'If 1, Archivist will run the setlocale function with your cultureKey setting if your cultureKey is not "en".';
$_lang['prop_archivist.locale_desc'] = 'If this is set and setLocale is 1, will use this value instead of the cultureKey setting to set the locale by.';
$_lang['prop_archivist.hidecontainers_desc'] = 'If 1, will not show Containers in the results.';
$_lang['prop_archivist.groupbyyear_desc'] = 'If 1, Archivist will attempt to group the results by year and display results in a nested list.';
$_lang['prop_archivist.groupbyyeartpl_desc'] = 'The Chunk to use for the wrapper when grouping by year.';

/* getArchives snippet */
$_lang['prop_getarchives.tpl_desc'] = 'Name of a chunk serving as a resource template.';
Expand Down

0 comments on commit 45d2cfe

Please sign in to comment.