Jump to:

10929 Posts in 2613 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » Gallery module with subdirectories

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 668 Views
  • m-phil
    Avatar
    Community Member
    37 Posts

    Gallery module with subdirectories Link to this post

    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

    668 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.