For a small, utility snippet with no functions, I wouldn’t worry about OOP.
My only comments would be that: 1) You should probably handle the case where $project is undefined in the snippet call (see below); 2) It will fail if there are any extraneous files in the image directory (e.g. .svn or FTP log files). If you’re sure that can’t happen, it’s not really a problem; 2) The fact that you are depending on the relationship between document ID number and directory names seems iffy, although it should work if you’re careful. I’m just thinking of a case where you deleted a document by mistake and had to recreate it. It would get a new document ID and things would get kind of complicated.
$project = isset($project) ? $project : 1;
Otherwise, it looks very well done to me.
Cases 1 and 2 are both unlikely in this situation but I’ve added the suggested error checking anyway. Can’t be too careful, right? As for the thing with the document IDs, I agree, it is iffy but I’ve yet to come up with a better way of doing it. I started a thread elsewhere about how to get Wayfinder to output an iterator so that no matter what the document IDs are, the links will still have rel values that proceed consecutively from 0 to 11 but I still haven’t found a solid way to do that. Thanks for the input!
Another option for naming the dir is to use the alias. The advantage to using the doc id is that it is permanent whereas the alias and other settings can change. Maxi uses the doc id for gallery folder names.
In this situation it’s better for me to use a number. I’m using the rel attribute in a calculation. I would prefer it start with 0 but I haven’t found a way to do that yet and using the document ID will work if I adjust for the offset because the documents are in consecutive order. If that were to ever change it would break all to hell but it’s not something that I’m anticipating changing.
I just had a thought. The documents have a menu index. Is this a value I can access via a placeholder in Wayfinder? Like, [+wf.menuIndex+] or something? That would be perfect.