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

    I want to display, the gallery of my webusers in a specific php page (actually i’m using webloginPE to have a page per webuser...)
    example: For user X, i ’ve :
    -profile of X (with ditto)
    [[Ditto? &tpl=`culture_connexe_tpl` &language=`francais-utf8` &id=`cult` &startID=`671` &depth=`1` &display=`4` &tagData=`tvmotcle` &tagDelimiter=`,` &tagMode=`onlyTags` &tags=`[+view.username+]`]]
    -articles written by X,(with ditto) ....
    -and i want "pictures posted by X" whith a set of 4 or 5 pictures ordered by dates for example... with maxigallery
    [[MaxiGallery? &pic_query_ids=`??????` &display=`embedded` &embedtype=`slimbox` &pics_per_row=`2` &clearerTpl=`` &galleryPictureTpl=`GalInnerTplSearch` &galleryOuterTpl=`galleryOuterTplVille` &css=`/css/galeriecss.css`]]

    Is it possible to select pictures by they owner ids (own_id in maxigallery sql base).
    I dont find anyresponse for this , do i have to create a snippet to fill the &pic_query_ids field? If the answer is yes, could you help me to write it?

    Thanks for help

      • 7923
      • 4,213 Posts
      Quote from: labourlingue at Aug 05, 2008, 11:40 AM

      Is it possible to select pictures by they owner ids (own_id in maxigallery sql base).
      I dont find anyresponse for this , do i have to create a snippet to fill the &pic_query_ids field? If the answer is yes, could you help me to write it?
      Yes. Try this and let me know how it goes:
      <?php
      //Snippet: GetWebUserPicIds
      //Usage: [!GetWebUserPicIds? &username=`somewebuser`!] or to save db queries [!GetWebUserPicIds? &userid=`99`!] where 99 is the web users id.
      
      $mgTblName  = (isset($mgTblName)) ? $mgTblName : "maxigallery"; // MaxiGallery database table name
      $username = (isset($username)) ? $username : '';
      $userid = (isset($userid)) ? $userid : '';
      if ($userid = '' && $username == ''){
      	$modx->logEvent(1, 3, "GetWebUserPicIds: Error - Neither username or user id was supplied");
      	return;
      }
      $own_id = 0;
      $picsTbl = $modx->db->config['dbase'].".".$modx->db->config['table_prefix'].$mgTblName;
      if ($userid == '') {
      	$sql = "SELECT id FROM ".$modx->getFullTableName("web_users")." WHERE username='$username'";
      	if(!$rs = $modx->db->query($sql)){
      		$modx->logEvent(1, 3, "GetWebUserPicIds: Error - Could not execute the query to select id for username ($sql)");
      		return; 
      	} 
      	$limit = $modx->db->getRecordCount($rs);
      	if($limit>0) {
      		$row = $modx->fetchRow($rs);
      		$own_id = $row['id'];
      	} else {
      		$modx->logEvent(1, 1, "GetWebUserPicIds: Username ($username) was not found from MODx web users");
      		return;
      	}
      } else {
      	$own_id = $userid;
      }
      $sql = "SELECT id FROM ".$picsTbl." WHERE own_id=".$own_id;
      $picIdArr = array();
      if(!$rs = $modx->db->query($sql)){
      	$modx->logEvent(1, 3, "GetWebUserPicIds: Error - Could not execute the query to find pictures for set web user ($sql)");
      	return;
      } 
      $limit = $modx->db->getRecordCount($rs);
      if($limit>0) {
      	while ($row = $modx->db->getRow($rs)) {
      		array_push($picIdArr, $row['id']);
      	}
      	return implode(",", $picIdArr);
      } else {
      	$modx->logEvent(1, 1, "GetWebUserPicIds: No pictures for supplied username/id ($username/$own_id) found.");
      	return;
      }
      ?>


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 16550
        • 23 Posts
        It’s good but...

        the snippet itself looks good it displays reliable result but when inserted inside maxigallery by this way:

        [!MaxiGallery? &pic_query_ids=`[[GetWebUserPicIds? &username=`aurel`]]` &display=`embedded` &embedtype=`slimbox` &pics_per_row=`3` &clearerTpl=`
        ` &galleryPictureTpl=`GalInnerTplSearch` &galleryOuterTpl=`galleryOuterTplVille` &css=`/css/galeriecss.css`!]

        The text appears on the frontend website after processing and not the result of the call (pictures).
        By the way i want to insert the whole code in a third snippet (weblogin PE), so il think i must cache maxigallery snippet too:

        [[MaxiGallery? &pic_query_ids=`[[GetWebUserPicIds? &username=`aurel`]]` &display=`embedded` &embedtype=`slimbox` &pics_per_row=`3` &clearerTpl=`
        ` &galleryPictureTpl=`GalInnerTplSearch` &galleryOuterTpl=`galleryOuterTplVille` &css=`/css/galeriecss.css`]]

        And i’m afraid it should not work???
        ps: i’ve red this somwhere:
        snippets can even be run inside of other snippets with the $modx->runSnippet() function??? it should help maybe??
          • 7923
          • 4,213 Posts
          Try setting the document not cacheable and set every snippet call cached


            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 16550
            • 23 Posts
            First: thanks for all that you have done, that quite a great step

            secondly:

            I cannot put 2 cached snippet because the ]] of the snippet inside close the first snippet:

            [[MaxiGallery? &pic_query_ids=`[[GetWebUserPicIds? &username=`xxxx`]]` &display=`embedded` &embedtype=`slimbox` &pics_per_row=`3` &clearerTpl=`
            ` &galleryPictureTpl=`tpl2` &galleryOuterTpl=`tpl1` &css=`xxx.css`]]

            the final call should have more or less this shape:
            I wonder if it’s possible >:(

            [[MaxiGallery? &pic_query_ids=`[[GetWebUserPicIds? &username=`[+view.webuser+]`]]` &display=`embedded` &embedtype=`slimbox` &pics_per_row=`3` &clearerTpl=`
            ` &galleryPictureTpl=`tplb` &galleryOuterTpl=`tpla` &css=`xxx.css`]]



              • 7923
              • 4,213 Posts
              Should be possible.. did you try it?

              The reason why the snippet calls render on the page instead of getting parsed is because of the old issue with PHx and nested snippet calls (and/or inside chunks)..

              There is some combination that works, but can’t remember what.. I think it was that document has to be set to not cacheable and have the snippet calls cached.. you can try to alter the inner snippet calls to be not cacheable..

              You can though create another snippet that use the $modx->runSnippet api to run all the different snippets.. eg, something like:
              <?php
              $username = (isset($username)) ? $username : '';
              $params = array();
              $params['username'] = $username;
              $picIds = $modx->runSnippet('GetWebUserPicIds', $params);
              $params = array();
              $params['pic_query_ids'] = "$picIds";
              $params['display'] = "embedded";
              $params['embedtype'] = "slimbox";
              $params['pics_per_row'] = "3";
              $params['clearerTpl'] = "";
              $params['galleryPictureTpl'] = "tpl2";
              $params['galleryOuterTpl'] = "tpl1";
              $params['css'] = "xxx.css";
              $galleryOutput = $modx->runSnippet('MaxiGallery', $params);
              return $galleryOutput;
              ?>


              And use it like [[Snippet? &username=`[+view.webuser+]`]]


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 16550
                • 23 Posts
                the last solution is working, maybe a little bit slow to parse but the result is perfect

                thanks doze!!
                grin grin
                  • 19980 ☆ A M B ☆
                  • 275 Posts
                  Quote from: doze at Aug 06, 2008, 07:31 AM

                  Try setting the document not cacheable and set every snippet call cached

                  Hi

                  i did make the doc not cachable

                  and called
                  [[MaxiGallery? &amp;pic_query_ids=`[!GetWebUserPicIds? &amp;username=`[+view.webuser+]`!]` &amp;display=`embedded` &amp;embedtype=`slimbox` &amp;pics_per_row=`3` &amp;galleryPictureTpl=`tplb` &amp;galleryOuterTpl=`tpla`]]
                  and then
                  [[MaxiGallery? &amp;pic_query_ids=`[[GetWebUserPicIds? &amp;username=`[+view.webuser+]`]]` &amp;display=`embedded` &amp;embedtype=`slimbox` &amp;pics_per_row=`3` &amp;galleryPictureTpl=`tplb` &amp;galleryOuterTpl=`tpla`]]

                  but GOT NO OUTPUT (
                  it means that snipped hasnot worked, has it?
                    modx and ecommerce pro
                    • 7923
                    • 4,213 Posts
                    Yea.. it seems that the snippet isn’t even run, if there’s no output. It should atleast put the slimbox resources to document <head>.

                    So if it isn’t run, there’s probably some php error in your scripts or the snippet call is malformed (odd characters in it or in multiple lines or something). First check the snippet call with editor set to none and then look at modx / apache log for errors.


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