We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17446
    • 23 Posts
    Hi,

    I would like to do something with MaxiGallery but I can’t find how to do it.
    I would like to organize my galleries into subgalleries which will contain some childgalleries, and I would like to have an index with only one pic per subgallery, picture which should be picked randomly from any of the childgalleries in the subgallery.

    As I know I’m not at ease to describe well my problem, a little example will be easier to understand...

    Let say my gallery structure is composed as follows :


    Index
    ----> Gallery 1
    ----> Index subgallery 2
    ---------> Gallery 2a
    ---------> Gallery 2b
    -----> Gallery 3
    ----> Index subgallery 4
    ---------> Gallery 4a
    ---------> Gallery 4b

    So I have pictures managed by MaxiGallery in Gallery 1, Gallery 2a, Gallery 2b, Gallery 3, Gallery 4a and Gallery 4b.

    What I would like to have is the following : In the Index, I would like to have 4 pics with links respectively to Gallery 1, Index subgallery 2, Gallery 3 and Index subgallery 4.
    Thumb-picture for Gallery 1 link would be picked randomly in Gallery 1 pictures. Same for Gallery 3.
    Thumb-picture for Index subgallery 2 link would be picked randomly in Gallery 2a or Gallery 2b pictures. Same for Gallery 4.


    Index subgallery 2 should contain 2 thumb pictures to Gallery 2a and 2b, with a picture randomly taken respectively from each Gallery. Same for Gallery 4.

    For the moment I’m able to have the Index subgallery 2 and 4 correct, but my problem is for the Index : In the Index, all galleries appear (so I have links to 6 galleries instead of 4), and links are directly to Galleries 2a or 2b and 4a or 4b, so I don’t access the Index subgallery 2 or 4.


    Is there any possibility to do what I want with Maxigallery ?

    Thanks,

    Louis
      • 7923
      • 4,213 Posts
      Quote from: looloo06 at Jun 07, 2007, 07:53 AM

      For the moment I’m able to have the Index subgallery 2 and 4 correct, but my problem is for the Index : In the Index, all galleries appear (so I have links to 6 galleries instead of 4), and links are directly to Galleries 2a or 2b and 4a or 4b, so I don’t access the Index subgallery 2 or 4.


      Is there any possibility to do what I want with Maxigallery ?
      Not possible with maxigallery by itself because maxigallery can only list it’s galleries and "Index subgallery 2" + "Index subgallery 4" documents don’t actually have any gallery, just a view of childgalleries..

      But what you can do is list those main documents with Ditto (by using level limit parameter) and in Ditto’s template, get the picture from right gallery. For example do a Snippet what checks that is there a maxigallery one the page (by doing distinct gal_id query to maxigallery database and compare Ditto’s [+id+] placeholder to the results) and if there is, return one random picture from it using maxigallery (with $modx->runSnippet(’MaxiGallery’, array(’parameter1’ => ’value1’, ’parameter2’ => ’value2’); call in the snippet). If there is no pictures in the document, its a subgallery index, so get random picture from the childgalleries (again using maxigallery by $modx->runSnippet(...))

      That should do it..


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 17446
        • 23 Posts
        Ok thanks Doze,

        I will try that as soon as possible (never used ditto for the moment, but I have to for a news module with RSS feed).

        I will let you know if I managed to obtain what I want.

        Louis
          • 7923
          • 4,213 Posts
          It would go something like this:

          1. In the "Index" document, you would make Ditto to list each document that is direct child if index:

          [[Ditto? &parents=`[*id*]` &depth=`1` &tpl=`dittoTpl`]]

          2. Create "dittoTpl" chunk to template Ditto’s output (to call your snippet):

          [[YourSnippet? &docId=`[+id+]`]]
          


          3. Create "YourSnippet" snippet to call MaxiGallery:

          <?php
          if($docId == null || $docId == '') {
             return 'Empty docId';
          }
          //get gallery ids
          $rs = $modx->db->select("DISTINCT gal_id", $modx->db->config['table_prefix'].'maxigallery');
          $galIds= array();
          while ($row = $modx->db->getRow($rs)) {
             array_push($galIds, $row['gal_id']);
          }
          //if document has gallery, show a random pic from it
          if (in_array($docId, $galIds)) {
             $mgOutput = $modx->runSnippet('MaxiGallery', array('gal_query_ids' => $docId, 'limit' => '1', 'order_by' => 'random', 'galleryOuterTpl' => '@CODE:[+maxigallery.pictures+]', 'galleryPictureTpl' => 'mgGalleryPictureTpl'));
          } else { //else show a random pic from it's childgalleries
             $mgOutput = $modx->runSnippet('MaxiGallery', array('childgalleries_ids' => $docId, 'limit' => '1', 'order_by' => 'random', 'galleryOuterTpl' => '@CODE:[+maxigallery.childgalleries+]', 'childgalleryTpl' => 'mgChildgalleryTpl'));
          }
          return '<div class="thumbscontainer"><ul class="thumbs">'.$mgOutput.'</ul></div>';
          ?>


          4. Then do a "mgGalleryPictureTpl" to link to the gallery index instead of straight to the picture:

          <li>
             <a href="[~[+maxigallery.picture.gal_id+]~]">
                <img src="[(base_url)][+maxigallery.path_to_gal+]tn_[+maxigallery.picture.filename+]" class="thumbnail" title="[+maxigallery.strings.go_to_gallery+]" alt="[+maxigallery.strings.go_to_gallery+]" />
             </a>
             <p style="width:[+maxigallery.picture_width_thumb+]px;">[+maxigallery.pageinfo.pagetitle:htmlent+]</p>
          </li>
          


          5. Do a "mgChildgalleryTpl" to link to the gallery parent (Index subgallery), instead of the gallery itself

          <li>
             <a href="[~[+maxigallery.pageinfo.parent+]~]">
                <img src="[(base_url)][+maxigallery.path_to_gal+]tn_[+maxigallery.picture.filename+]" class="thumbnail" title="[+maxigallery.strings.go_to_gallery+]" alt="[+maxigallery.strings.go_to_gallery+]" />
             </a>
             <p style="width:[+maxigallery.picture_width_thumb+]px;">[+maxigallery.pageinfo.pagetitle:htmlent+]</p>
          </li>
          


          This might not work straight out of the box, but should get you pretty close..


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 17446
            • 23 Posts
            Ok thanks a lot Doze,

            I tried implementing it, and just have a problem with this line :

            else { //else show a random pic from it's childgalleries
               $mgOutput = $modx->runSnippet('MaxiGallery', array('childgalleries_ids' => $docId, 'limit' => '1', 'order_by' => 'random', 'galleryOuterTpl' => '@CODE:[+maxigallery.childgalleries+]', 'childgalleryTpl' => 'mgChildgalleryTpl'));
            }
            


            This does not return anything, and if I add
            'display' => 'childgalleries'
            I obtain all the childgalleries, and not only one.

            So I don’t know how to ask MaxiGallery just to return 1 picture from a randomly taken childgallery.

            I’m wondering wether it would be better to add one function to MaxiGallery, which returns only one pic randomly taken from all the pics in childgalleries of a document, or add some tricky code to the snippet to select randomly one of the children documents and perform the MaxiGallery request on it.
              • 7923
              • 4,213 Posts
              Quote from: looloo06 at Jun 08, 2007, 07:10 AM

              This does not return anything, and if I add
              'display' => 'childgalleries'
              I obtain all the childgalleries, and not only one.
              yes, add the &display parameter and replace &limit with &childgalleries_limit, see http://wiki.modxcms.com/index.php/MaxiGallery for parameter documentation. Like I said, I just wrote that up quickly and it may not work straight on..

              Quote from: looloo06 at Jun 08, 2007, 07:10 AM

              I’m wondering wether it would be better to add one function to MaxiGallery, which returns only one pic randomly taken from all the pics in childgalleries of a document, or add some tricky code to the snippet to select randomly one of the children documents and perform the MaxiGallery request on it.
              Those are already implemented in the form of &childgalleries_order_by (give RAND() for random chilgallery), &order_by (to order the picture returned from the childgallery), &childgalleries_limit (to limit how many chilgalleries to return), &limit (to limit number of pictures to return in gallery view modes and in query mode).. see also the parameters from wiki that have "query" in them..


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 17446
                • 23 Posts
                Ok Thanks a lot Doze !

                I couldn’t use the RAND function for the childgalleries_limit parameter, as it doesn’t take a number as argument but a modx field.
                So as I never have more than 2 childgalleries, I decided to randomize the childgalleries_order_direction parameter, so I have exactly the wanted effect !

                Thanks again a lot for your help, it permit me to economize a lot of time, and hairs !!!

                Louis
                  • 7923
                  • 4,213 Posts
                  Yea.. My hair is already gone so I don’t mind doing it.. grin

                  I’ll make a "random" option possible for &childgalleries_order_by for next version if the RAND() doesn’t work yet straight as the parameter value..


                    "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                    • 17446
                    • 23 Posts
                    Well,

                    I think it could be easily implemented by affecting numeric values to the parameters.

                    So I now have something which is almost working well. I just have a problem with the placeholder [+maxigallery.pageinfo.pagetitle:htmlent+], which should report the page title of the gallery page (as [+maxigallery.path_to_gal:htmlent+] returns the good path to the gallery), but instead it is reporting the page title of the current page ! (i.e. : the index page, not the gallery one).

                    It’s too late now to search where’s the problem/bug. I will have a look tomorrow and let you know !
                      • 7923
                      • 4,213 Posts
                      Do you use the childgalleries display mode? it should give the childgallery page title.. but if you use normal display mode, it gives the title from the page that the snippet is called in. You can get the page title in that case by using GetField snippet in maxigallery template and get the id of the document from [+maxigallery.picture.gal_id+]


                        "He can have a lollipop any time he wants to. That's what it means to be a programmer."