Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Gallery module with subdirectories


Reply


719 Views

Avatar
m-phil

Community Member, 37 Posts

6 May 2010 at 2:59am

Edited: 06/05/2010 3:01am

Hello everybody, here is an idea to display all files (for example images) existing in the selected directory and also in subdirectories for the gallery module (v0.2.2).

I've found a topic about that problem in the archive (http://silverstripe.org/archive/show/225684#post225684) and an enhancement ticket (http://open.silverstripe.org/ticket/3170).
Perhaps someone can add a comment there...

OK, here it is:
There is a // TODO comment in the Items() function on line 207 in code/GalleryPage.php
You need to replace it with this lines of code, where it searchs for subdirectories and builds a new extended where query with all FolderIDs

/** Searching through sub-directories if required to find appropriate files **/
      $subdirs = DataObject::get("File", "`ClassName` = 'Folder' AND `ParentID` = '{$this->FolderID}'", "`File`.`Sort` ASC");
      $subdirQuery = '';
      if ($subdirs) {
         $subdirIDStr = '';
         foreach($subdirs as $subdir) {
            $subdirIDStr .= " OR `ParentID` = '{$subdir->ID}'";
         }
         $subdirQuery = "(`ParentID` = '{$this->FolderID}'".$subdirIDStr.")";
      } else {
         $subdirQuery = "`ParentID` = '{$this->FolderID}'";
      }

Now we need to add the query to the file select statement...
Replace Line 223

return DataObject::get("File", "`Filename` REGEXP '[.]({$extensions})\$' AND `ParentID` = '{$this->FolderID}'", $sort, "", $limit);

With this

return DataObject::get("File", "`Filename` REGEXP '[.]({$extensions})\$' AND ".$subdirQuery, $sort, "", $limit);

@all admins: It would be nice to have a message service in this forum to get in contact with other members