scanSubDir and check empty folder

This commit is contained in:
Prof Langues 2021-02-10 16:59:17 +01:00
parent c648d328d6
commit 3f68897639
2 changed files with 41 additions and 40 deletions

View File

@ -137,6 +137,8 @@ class helper {
public static function getModules() { public static function getModules() {
$dirs = array_diff(scandir('module'), array('..', '.')); $dirs = array_diff(scandir('module'), array('..', '.'));
foreach ($dirs as $key => $value) { foreach ($dirs as $key => $value) {
// Dossier non vide
if (file_exists('module/' . $value . '/' . $value . '.php')) {
// Lire les constantes // Lire les constantes
$class_reflex = new \ReflectionClass($value); $class_reflex = new \ReflectionClass($value);
$class_constants = $class_reflex->getConstants(); $class_constants = $class_reflex->getConstants();
@ -158,10 +160,29 @@ class helper {
'version' => $version 'version' => $version
]; ];
} }
}
return($modules); return($modules);
} }
/**
* Scanne le contenu d'un dossier et de ses sous-dossiers
* @param string $dir Dossier à scanner
* @return array
*/
public static function scanSubDir($dir) {
$dirContent = [];
$iterator = new DirectoryIterator($dir);
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isDir()) {
$dirContent[] = $dir . '/' . $fileInfos->getBasename();
$dirContent = array_merge($dirContent, self::scanSubDir($dir . '/' . $fileInfos->getBasename()));
}
}
return $dirContent;
}
/** /**
* Retourne true si le protocole est en TLS * Retourne true si le protocole est en TLS
* @return bool * @return bool

View File

@ -324,7 +324,7 @@ class gallery extends common {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'display' => self::DISPLAY_JSON, 'display' => self::DISPLAY_JSON,
'content' => galleriesHelper::scanDir(self::FILE_DIR.'source') 'content' => helper::scanSubDir(self::FILE_DIR.'source')
]); ]);
} }
@ -674,23 +674,3 @@ class gallery extends common {
} }
} }
class galleriesHelper extends helper {
/**
* Scan le contenu d'un dossier et de ses sous-dossiers
* @param string $dir Dossier à scanner
* @return array
*/
public static function scanDir($dir) {
$dirContent = [];
$iterator = new DirectoryIterator($dir);
foreach($iterator as $fileInfos) {
if($fileInfos->isDot() === false AND $fileInfos->isDir()) {
$dirContent[] = $dir . '/' . $fileInfos->getBasename();
$dirContent = array_merge($dirContent, self::scanDir($dir . '/' . $fileInfos->getBasename()));
}
}
return $dirContent;
}
}