Created
August 2, 2017 16:29
-
-
Save andronex/e136c4772d753e09ff2140a21d4c977e to your computer and use it in GitHub Desktop.
Сниппет для вывода всех фото из ресурса, сгруппированных по тегам (категориям)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
вызов на странице [[snippet?res=`[[*id]]`]] | |
*/ | |
$tplHead = '<h2>[[+title]]</h2>'; | |
$out = ''; | |
$title_arr = $modx->runSnippet('pdoResources', array( | |
'loadModels' => 'ms2gallery' | |
,'class' => 'msResourceFileTag' | |
,'leftJoin' => '{ "File":{ "class":"msResourceFile", "on":"File.id = msResourceFileTag.file_id" } }' | |
,'select' => '{ "msResourceFileTag": "*", "File": "*" }' | |
,'where' => '{ "File.resource_id": \' ~ '.$res.' ~ \' }' | |
,'groupby' => 'tag' | |
,'sortby' => '{ "tag":"ASC" }' | |
,'limit' => '0' | |
,'tpl' => '@INLINE [[+tag]]' | |
,'outputSeparator' => ',' | |
)); | |
$title_arr = explode(',',$title_arr); | |
foreach ($title_arr as $title){ | |
$out .= str_replace('[[+title]]', $title, $tplHead); | |
$out .= '<div class="row">'; | |
$gallery = $modx->runSnippet('ms2Gallery', array( | |
'tags' => $title, | |
'tplRow' => '@INLINE <div class="col-xs-12 col-sm-6 col-md-3" style="height: 220px;"><a href="[[+url]]" rel="photo" class="fancybox" tabindex="[[+id]]"><img src="[[+170x170]]" alt="[[+name]]"></a></div>', | |
'tplOuter' => '@INLINE [[+rows]]' | |
)); | |
$out .= $gallery; | |
$out .= '</div>'; | |
} | |
return $out; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
вызов [[snippet]] | |
выводит все фото из всех ресурсов, сгруппированных по названиям ресурсов (по категориям) | |
*/ | |
$tpl = '<div class="col-xs-12 col-sm-3"><a href="[[+url]]" rel="photo" class="fancybox"><img src="[[+img]]" alt="[[+alt]]"></a></div>'; | |
$tplHead = '<h2>[[+title]]</h2>'; | |
$out = $gallery = ''; | |
$modx->addPackage('ms2gallery', MODX_CORE_PATH . 'components/ms2gallery/model/'); | |
$q = $modx->newQuery('msResourceFile'); | |
$q->leftJoin('modDocument', 'modDocument', 'modDocument.id = msResourceFile.resource_id'); | |
$q->where( | |
array( | |
'`msResourceFile`.`path`:LIKE' => '%170x170%', | |
'`msResourceFile`.`active`' => 1, | |
'`modDocument`.`template`:!=' => 25 | |
) | |
); | |
$q->sortby('`msResourceFile`.`resource_id`', 'asc'); | |
$q->select(array( | |
"{$q->getAlias()}.*" | |
,"modDocument.*" | |
)); | |
$q->limit(0); | |
$q->groupby('resource_id'); | |
if ($q->prepare() && $q->stmt->execute()) { | |
foreach ($q->stmt->fetchAll(PDO::FETCH_ASSOC) as $item) { | |
//print_r($item);continue; | |
$out .= str_replace('[[+title]]', $item['pagetitle'], $tplHead); | |
$out .= '<div class="row">'; | |
$gallery = $modx->runSnippet('ms2Gallery', array( | |
'resources' => $item['resource_id'], | |
'parents' => 0, | |
'tplRow' => '@INLINE <div class="col-xs-12 col-sm-6 col-md-3" style="height: 220px;"><a href="[[+url]]" rel="photo" class="fancybox" tabindex="[[+id]]"><img src="[[+170x170]]" alt="[[+name]]"></a></div>', | |
'tplOuter' => '@INLINE [[+rows]]' | |
)); | |
$out .= $gallery; | |
$out .= '</div>'; | |
} | |
} | |
return $out; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment