1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public function recupererDerniersFichiers($nombreFichiers) {
// On créé un Array collection de l'ensemble des fichiers de l'utilisateur
$fichiers = array();
foreach ($this->getOperations() as $operation){
foreach($operation->getCategories() as $categorie){
$collectionFichiers = new ArrayCollection(
$fichiers = array_merge($fichiers, $categorie->getFichiers()->toArray())
);
}
}
// On sélectionne les x ($nombreFichiers) derniers fichiers en comparant leurs ids
$tableauIndice = array();
$tableauId = array();
for($i=0; $i<$nombreFichiers; $i++) {
$tableauId[$i] = null;
foreach ($collectionFichiers as $key => $fichier){
if(($fichier->getId() > $tableauId[$i]) && !in_array($fichier->getId(), $tableauId)) {
$tableauIndice[$i] = $key;
$tableauId[$i] = $fichier->getId();
}
}
$collectionDerniersFichiers[$i] = $collectionFichiers[$tableauIndice[$i]];
}
return $collectionDerniersFichiers;
} |