Created
December 14, 2010 14:46
-
-
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
This file contains 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 | |
$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