Change: SUB COLLECTION
I make possible to see the nested sub collections and other
Change: see sub collection inside collection
I create a new sistem setting mostra_sub_collections to decide whether to see them or not inside other collection
On file core\components\collections\src\Processors\Resource\ GetList.php
in function prepareQueryBeforeCount (about line 293)
I change last “where” (with sistem setting)
if (!$this->modx->getOption('mostra_sub_collections', null, false))
{
$c->where([
'class_key:!=' => CollectionContainer::class,
// "NOT EXISTS (SELECT 1 FROM {$this->modx->getTableName('modResource')} r WHERE r.parent = modResource.id)"
]);
}
Change: see sub collection in resourc’s tree
I create a new sistem setting mostra_sub_collections_tree to decide whether to see them or not on resource’s (only for nested collection)
For make this
On file core\components\collections\src\Processors\Events\ OnBeforeDocFormSave.php
For function run i change if (line 24) in this (
if ($resource->class_key == CollectionContainer::class) {
//MABOL, aggiunta possibilità di nascondere le collectioni nel Tree (else valore originario)
if ($this->modx->getOption('mostra_sub_collections_tree', null, true)==false && $parent && ($parent->class_key == CollectionContainer::class))
{
$resource->set('show_in_tree', 0);
}else{
$resource->set('show_in_tree', 1);
}
}
For function switchToCollections i change if (line 141) in this (
if ($child->class_key == CollectionContainer::class) {
//MABOL, aggiunta possibilità di nascondere le collectioni nel Tree (else valore originario)
if ($this->modx->getOption('mostra_sub_collections_tree', null, true)==false)
{
$resource->set('show_in_tree', 0);
}else{
$resource->set('show_in_tree', 1);
}
}
On file core\components\collections\src\Processors\Events\ OnResourceBeforeSort.php
For function run i change if (line 38) in this (
if ($resource->class_key == CollectionContainer::class) {
//MABOL, aggiunta possibilità di nascondere le collectioni nel Tree (else valore originario)
if ($this->modx->getOption('mostra_sub_collections_tree', null, true)==false && $parent && ($parent->class_key == CollectionContainer::class))
{
$resource->set('show_in_tree', 0);
}else{
$resource->set('show_in_tree', 1);
}
}
Issue (Change) for RefreshTree, selection
In collection in resource tre when i change status of these, the resource’s tree don’t refresh and the status don’t syncronize
This, obviously, only if mostra_sub_collections_tree is set to true
For make this
On file assets\components\collections\js\mgr\widgets\category\ collections.grid.resources.js add
if(MODx.config.mostra_sub_collections_tree == true){
Ext.getCmp('modx-layout').refreshTrees();
}
for listeners success function in
deleteChild, remoChild, deleteSelected, undeleteSelected, publishSelected, unpublishSelected, publishChild, unpublishChild
Customization: COLLECTION’s “HEADER”
In some of my projects user groups can only see a collection and nothing else.
To make it more understandable I have introduced a header for each collection or selection with a small breadcrumb
i’m not an expert of extjs but this is my implementation
I create a new sistem setting mostra_cs_testata to decide whether to see them or not the collection’header
and then
Create a new processor file testata.php inside Extra
core\components\collections\src\Processors\Extra\ Testata.php
namespace Collections\Processors\Extra;
use MODX\Revolution\modResource;
use MODX\Revolution\Processors\Processor;
class Testata extends Processor
{
public function process()
{
$collection = (int)$this->getProperty('collection', 0);
$selection = (int)$this->getProperty('selection', 0);
if ($collection <= 0) {
return $this->failure();
}
$resource = $this->modx->getObject(modResource::class, $collection);
if (!$resource) {
return $this->failure();
}
//Discrimino a seconda che sia selezione oppure no per icona
$resource->published?$classPub ='pubblicata':$classPub ='ritirata';
if($selection)
{
$icona ='<i class="icon selectioncontainer"></i>';
}else{
$icona ='<i class="icon collectioncontainer"></i>';
}
//Contesto
$contextKey = $resource->context_key;
$context = $this->modx->getContext( $contextKey );
$contextName = $context->name;
//Prima creo menu
//Prima parte del menu il contesto con la sua icona
$menu = '<span class="eleMenu contesto"><i class="icon tree-context"></i>'.$contextName.'</span>';
$pids = $this->modx->getParentIds($collection, 10, array('context' => $contextKey));
$gids = array_reverse($pids);
foreach($gids as $gid)
{
if($gid == 0){continue;}
$genit = $this->modx->getObject(modResource::class, $gid);
if (!$genit){continue;}
$genit->published?$classPubGen ='pubblicata':$classPubGen ='ritirata';
$genit->hidemenu?$classMenuGen ='nomenu':$classMenuGen ='simenu';
$menu .= '<span class="eleMenu '.$classPubGen.' '.$classMenuGen.'">'.$genit->pagetitle.'</span>';
}
//Ultimo elemento del menu la sua icona
$menu .= '<span class="ultimo '.$classPub.'">'.$icona.'</span>';
$RisAjax [] = $menu;
//Adesso nome a cui aggiungo icona
$nome = $icona;
$nome .= $resource->pagetitle;
$RisAjax [] = $nome;
return $this->outputArray($RisAjax);
}
}
On file assets\components\collections\js\mgr\widgets\category\ collections.grid.resources.js
i add, after window.history.replaceState({}, '', window.location.href);
(line 52) , this
if(MODx.config.mostra_cs_testata == true)
{
this.getTestataCollection(config);
}
Then i introduce 2 new function (getTestataCollection printTestataCollection) near the end
,getTestataCollection: function(config) {
var collection = parseInt(MODx.request.id);
MODx.Ajax.request({
url: MODx.config.connector_url
,params: {
action: 'Collections\\Processors\\Extra\\Testata'
,collection: collection
,selection: 0
}
,listeners: {
success: {
fn: function(r) {
this.printTestataCollection(r);
},scope: this
},
failure: {
fn: function(){
this.store.removeAll();
this.currentFolder = collections.template.parent;
this.getStore().baseParams.parent = collections.template.parent;
this.getBottomToolbar().changePage(1);
},
scope: this
}
}
});
}
,printTestataCollection: function(r) {
this.testata = ({
items : [{
html: '<div class="titoloTestataCS">'+r.results[1]+'</div>'+
'<div class="menuTestataCS">'+r.results[0]+'</div>'
,bodyCssClass: 'contentTestataCS'
,anchor: '100%'
}]
});
this.getTopToolbar().insert(1,this.testata);
}
On file assets\components\collections\js\mgr\widgets\category\ collections.grid.selection.js
add only function getTestataCollection with parameter selection to 1
,getTestataCollection: function(config) {
var collection = parseInt(MODx.request.id);
MODx.Ajax.request({
url: MODx.config.connector_url
,params: {
action: 'Collections\\Processors\\Extra\\Testata'
,collection: collection
,selection: 1
}
,listeners: {
success: {
fn: function(r) {
this.printTestataCollection(r);
},scope: this
},
failure: {
fn: function(){
this.store.removeAll();
this.currentFolder = collections.template.parent;
this.getStore().baseParams.parent = collections.template.parent;
this.getBottomToolbar().changePage(1);
},
scope: this
}
}
});
}
That’s All
While waiting for your opinions, improvements and error report, I leave you with some images that make everything clearer
Second level collection, no in tree, with header with little crumbs
First Level collection
Collection with 2 resource opened
Slection 1 lev
Selection 3 lev