We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9496
    • 113 Posts
    I’m basically trying to gallery overview on my index page (lets say the most recent uploads) I have a chunk with this Maxigallery call:

    [!MaxiGallery?  &view_gallery=`2`  &css=`assets/css/maxigallery_QSL.css` &galleryOuterTpl=`@FILE:/assets/snippets/maxigallery/templates/qsl_galleryoutertpl.html` &galleryPictureTpl=`@FILE:assets/snippets/maxigallery/templates/qsl_gallerypicturetpl_index.html` &pictureTpl=`@FILE:assets/snippets/maxigallery/templates/qsl_picturetpl.html` &order_by=`date` &picture_target=`2` &limit=`3`!]


    which returns nothing.

    Now I wa sjjust playinga round a bit with the &limit parameter and by changing the parameter to 20 (totally arbitrary btw)

    [!MaxiGallery?  &view_gallery=`2`  &css=`assets/css/maxigallery_QSL.css` &galleryOuterTpl=`@FILE:/assets/snippets/maxigallery/templates/qsl_galleryoutertpl.html` &galleryPictureTpl=`@FILE:assets/snippets/maxigallery/templates/qsl_gallerypicturetpl_index.html` &pictureTpl=`@FILE:assets/snippets/maxigallery/templates/qsl_picturetpl.html` &order_by=`date` &picture_target=`2` &limit=`20`!]


    which worked. I figure I must be missing something with this parameter. Can someone please explain to me the purpose (and use) of the &limit?

    Thanks again-
    P
      • 7923
      • 4,213 Posts
      Take a look at the maxigallery database table if you have some unnecessary rows there.


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 9496
        • 113 Posts
        doze-
        thanks. I see what the issue is. I am trying to pull out only those with a winner custom field marked yes. and then show three of those. The problem is that they arent all in a row so whats happing is that the &limit will only cycle through X amount of rows so if there arent any winners in those first three queries (or whatever the limit is) it wont show anything (and obviously shouldnt) because I have on the gallery template set to show only the ones marked winner .

        Since I have a winner in row 3,12, 19 setting & limit parameter to show 20 will hit those fine. Ill have take a look into it a bit further, but I think I would need to some custom mod. Unless I could tell MG to only look for those with the winner custom field. Then take the first three from there.

        Not sure but I understand the logic now.
        -P
          • 7923
          • 4,213 Posts
          Hmm.. yeah.. You’d need to do an additional parameter to MaxiGallery where you could set custom sql where conditions. Then add the parameter to the SELECT queries that MaxiGallery executes and use it in your snippet call. Would be quite easy to add that functionality.


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 9496
            • 113 Posts
            Yeah I was just thinking that. Something like

            SELECT * FROM `modx_maxigallery` WHERE `winner`= "yes"


            Where would I add the parameter to run it, in the class.inc, config or both, as well as not effect other gallery calls? Im not too sure how all of the pieces fit together. Hey at least I got the SELECT statement correct, eh?


            I suppose Ideally it would function directly in the call maybe like
            [!MaxiGallery $custom_query=`1 (1=on 0=off)` $custom_query_code=`custom query 1||custom query 2||etc..}
            Which I think is what you are proposing...
              • 7923
              • 4,213 Posts
              Yeah.. what I was thinking is that in the top of maxigallery.php you would do something like:

              <?php
              $mgconfig['custom_where'] = (isset($custom_where)) ? $custom_where : "";
              ?>
              


              Then go through the queries in maxigallery.php and modify for example this:

              <?php
              $rs=$modx->db->select(
                      "*", 
                      $modx->db->config['table_prefix'].$mg->mgconfig['gtable'],
                      "(gal_id='" . $mg->pageinfo['id'] . "' AND NOT hide='1')",
                      $orderby.' '.$mg->mgconfig['order_direction'], 
                      $mg->mgconfig['offset'].','.$mg->mgconfig['limit']);
              ?>
              


              to this:


              <?php
              $rs=$modx->db->select(
                      "*", 
                      $modx->db->config['table_prefix'].$mg->mgconfig['gtable'],
                      "(gal_id='" . $mg->pageinfo['id'] . "' AND NOT hide='1') ".$mg->mgconfig['custom_where']."",
                      $orderby.' '.$mg->mgconfig['order_direction'], 
                      $mg->mgconfig['offset'].','.$mg->mgconfig['limit']);
              ?>
              


              And then you could do something like this in your snippet call

              [!MaxiGallery? &custom_where=`AND winner="yes"`!]

              Of course you would need to validate the contents of &custom_where if you don’t trust your users.

              The thumbnails are queried at the bottom of maxigallery.php, so you could try the above there..


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 9496
                • 113 Posts
                Thanks again. I’ll walk through it. One question By validation you ’re talkin to prevent a bad query statement coming from the snippet call right (effectively breaking the gallery call altogether)

                P
                  • 7923
                  • 4,213 Posts
                  Yes.


                    "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                    • 9496
                    • 113 Posts
                    So maybe I should be policing myself. I have everything in properly but the
                    snippet call causes a parse error:

                    « Execution of a query to the database failed - Unknown column 'winne' in 'where clause' »
                          SQL: SELECT * FROM modx_maxigallery WHERE (gal_id='2' AND NOT hide='1') AND winne ORDER BY date DESC LIMIT 0,1  


                    and heres the snippet call:
                    [[MaxiGallery? &custom_where=`AND winner="yes"` &limit=`1`]]


                    Just by looking at it has something to do with the equal sign getting lost or treated differently. BTW I set it up as you outlined. Is there more than one query that needs addressing?

                    thanks again and again and again
                      • 7923
                      • 4,213 Posts
                      Hmm.. it might be that the snippet parameter values cannot contain equal sings.. not sure though.

                      Anyways, try going around it by doing something like this:

                      <?php
                      $mgconfig['custom_where_fields'] = (isset($custom_where_fields)) ? explode(',',$custom_where_fields) : array();
                      $mgconfig['custom_where_values'] = (isset($custom_where_values)) ? explode(',',$custom_where_values) : array();
                      ?>
                      


                      Then try the query like this:

                      <?php
                      $conditions = "";
                      $fieldcount = count($mg->mgconfig['custom_where_fields']);
                      for ($i=0; $i < $fieldcount; $i++) {
                         $conditions .= " AND ".$mg->mgconfig['custom_where_fields'][$i]."='".$mg->mgconfig['custom_where_values'][$i]."'";
                         if ($i < $fieldcount-1) {
                            $conditions .= ",";
                         }
                      }
                      $rs=$modx->db->select(
                              "*", 
                              $modx->db->config['table_prefix'].$mg->mgconfig['gtable'],
                              "(gal_id='" . $mg->pageinfo['id'] . "' AND NOT hide='1') ".$conditions.",
                              $orderby.' '.$mg->mgconfig['order_direction'], 
                              $mg->mgconfig['offset'].','.$mg->mgconfig['limit']);
                      ?>
                      


                      And then do something like this in your snippet call

                      [!MaxiGallery? &custom_where_fields=`winner` &custom_where_values=`yes`!]

                      If that works, you should be able to do multiple columns like this:

                      [!MaxiGallery? &custom_where_fields=`winner,someothercolumn` &custom_where_values=`yes,some other value`!]

                      Didn’t test the code though, so there can be typos and bugs.


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