Skip to content

Instantly share code, notes, and snippets.

@ideesimple
Created December 14, 2010 14:46
Show Gist options
  • Save ideesimple/740511 to your computer and use it in GitHub Desktop.
Save ideesimple/740511 to your computer and use it in GitHub Desktop.
récupère la position d'une ressource ainsi que le nombre de ressource de son parent
<?php
$count = 0;
$IdAvant='';
$IdApres='';
$position='';
$criteria = array(
'parent' => $parent,
'deleted' => false,
'published' => true,
);
$count = $modx->getCount('modResource', $criteria);
$fieldmenuindex='menuindex';
$criteria = $modx->newQuery('modResource');
$criteria->select($modx->getSelectColumns('modResource','modResource','',array('id',$fieldmenuindex)));
$criteria->where(array('id'=>$id));
$resource = $modx->getObject('modResource',$criteria);
$fieldValue = $resource->get($fieldmenuindex);
$menuindex = $fieldValue;
if ($menuindex == ($count-1)) {
$position='dernier';
}
else if ($menuindex == 0) {
$position='permier';
}
else {
$position='milieu';
$positionAvant=$menuindex-1;
$positionApres=$menuindex+1;
$criteria = $modx->newQuery('modResource');
$criteria->select($modx->getSelectColumns('modResource','modResource','',array('id')));
$criteria->andCondition(array('parent' => $parent));
$criteria->andCondition(array('menuindex'=>$positionAvant));
$resource = $modx->getObject('modResource',$criteria);
$fieldValue = $resource->get('id');
$IdAvant = $fieldValue;
$criteria = $modx->newQuery('modResource');
$criteria->select($modx->getSelectColumns('modResource','modResource','',array('id')));
$criteria->andCondition(array('parent' => $parent));
$criteria->andCondition(array('menuindex'=>$positionApres));
$resource = $modx->getObject('modResource',$criteria);
$fieldValue = $resource->get('id');
$IdApres = $fieldValue;
}
return $count.'_'.$menuindex.'_'.$IdAvant.'_'.$IdApres.'_'.$position;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment