Just to confirm @comments: this is NOT literal folders, they are represented using objects, and all exist in the same folder, known by MySQL. Working with someone else's code -- I would have used a true document tree.
Edit 2: Guys, basically, the documents are stored somewhere but their location doesn't matter. To make the admin nicer and have things associated with the documents, there's a few classes, DocumentCategory which is the folder as it were. I need to count a folders total files, including subfolders, so that I'm not displaying an empty tree.
I'm trying to write a recursive function which counts the files inside a folder, which can have subfolders. Here's what I have so far, but I'm not sure how I can keep the count:
function recursiveCount($id, $access_permission, $count) {
global $db;
$count = 0;
$count += Document::GetAll($id, $access_permission);
$docCats = DocumentCategory::GetAll($id);
if(!empty($docCats)) {
foreach($docCats as $docCat) {
// what to do recursively
// i need to call this function again
}
}
}