Андрей Сухомозгий

Андрей Сухомозгий

С нами с 06 декабря 2013; Место в рейтинге пользователей: #119
Юрий
26 июля 2017, 13:35
1
0
нет не опечатка. Сложно сверстать под него что ли?
Василий Наумкин
19 ноября 2015, 10:23
10
+7
My quick example:
<?php
$tplWrapper = '@INLINE <ul>{{+output}}</ul>';
$tplYear = '@INLINE <li>{{+year}}<sup>({{+count}})</sup><ul>{{+resources}}</ul></li>';
$tplMonth = '@INLINE <li>{{+month}}<sup>({{+count}})</sup><ul>{{+resources}}</ul></li>';
$tpl = '@INLINE <li><a href="{{+uri}}">{{+pagetitle}}</a></li>';

$pdo = $modx->getService('pdoFetch');

$resources = $pdo->getCollection(
	'modResource',
	array('published' => true, 'deleted' => false),
	array('parents' => 0, 'sortby' => 'createdon', 'sortdir' => 'DESC')
);
$tree = array();
foreach ($resources as $resource) {
	$year = date('Y', $resource['createdon']);
	$month = date('m', $resource['createdon']);
	$tree[$year][$month][] = $resource;
}

$output = '';
foreach ($tree as $year => $months) {
	$tmp1 = '';
	$count = 0;
	foreach ($months as $month => $resources) {
		$tmp2 = '';
		foreach ($resources as $resource) {
			$tmp2 .= $pdo->getChunk($tpl, $resource);
			$count++;
		}
		$tmp1 .=  $pdo->getChunk($tplMonth, array(
			'month' => $month,
			'count' => count($resources),
			'resources' => $tmp2,
		));
	}
	$output .=  $pdo->getChunk($tplYear, array(
		'year' => $year,
		'count' => $count,
		'resources' => $tmp1,
	));
}

return $pdo->getChunk($tplWrapper, array('output' => $output));

Result:
Максим Кузнецов
03 июня 2015, 20:43
2
+2
Конечно. У меня, в свое время, тоже она возникла..) Сортировка — при помощи mfilter2:

<a data-sort="rating" data-dir="[[+mse2_sort:is=`rating:asc`:then=`asc`]]" data-default="desc" class="rating sort">рейтингу <span></span></a>
А у самого вызова я leftJoin'ю сниппет VoteForms:

[[!mFilter2? &suggestions=`1` &limit=`25` &loadModels=`voteforms` &paginator=`pdoPage@Pagination` &class=`msProduct` &element=`msProducts` &depth=`0` &toPlaceholders=`mse2_` &includeThumbs=`70x70` &showEmptyFilters=`0`
&sort=`price:asc, rating:desc`
&where=`{"class_key":"msProduct"}`
&leftJoin=`{
	"VoteFormThread": {
		"class": "VoteFormThread",
		"on": "msProduct.id = VoteFormThread.resource AND VoteFormThread.form = 1"
	}
}`
&select=`{"Data": "[[!getProductDataFields]]",  "VoteFormThread": "VoteFormThread.rating AS rating, VoteFormThread.users_count AS totalVoted"
}`
&tpls=`item.list.table`
]]
Руслан Хуснутдинов
06 октября 2013, 17:21
1
0
Нашел в документации, проглядел в 1 раз
[[!getPage?
    &element=`msProducts`
    &limit=`5`
    &parents=`2`   
    &sortdir=`DESC`   
    &where=`{"Data.new":"1"}`
]]