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

    I think the code pasted above has some string syntax problems in this part:

    AND ($access) ".
            GROUP BY sc.id
            ($sort ? " ORDER BY $sort $dir ":"")." $limit ";


    Check the use of quotes, etc. Compare it to the original file. I actually don’t recall editing any DITTO files myself, but for whatever reason I haven’t noticed any glitches with it.

    Sorry, I can’t be of more assistance right now as I am busy finishing a thesis for uni (+ I’m no PHP expert, coming from an ASP/VBS background).

    Anton

      • 15826
      • 160 Posts
      Solved!

      Should be:
        function getDocumentChildren($parentid=0, $published=1, $deleted=0, $fields="*", $where='', $sort="menuindex", $dir="ASC", $limit="") {
          $limit = ($limit != "") ? "LIMIT $limit" : "";
          $tblsc = $this->getFullTableName("site_content");
          $tbldg = $this->getFullTableName("document_groups");
          // modify field names to use sc. table reference
          $fields = 'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$fields)));
          $sort = ($sort=="") ? "":'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$sort)));
          if ($where!='') $where = 'AND '.$where;
          // get document groups for current user
          if($docgrp = $this->getUserDocGroups()) $docgrp = implode(",",$docgrp);
          // build query
          $access = ($this->isFrontend() ? "sc.privateweb=0":"1='".$_SESSION['mgrRole']."' OR sc.privatemgr=0").
            (!$docgrp ? "":" OR dg.document_group IN ($docgrp)");
          $sql = "SELECT DISTINCT $fields
            FROM $tblsc sc
            LEFT JOIN $tbldg dg on dg.document = sc.id
            WHERE sc.parent = '$parentid' AND sc.published=$published AND sc.deleted=$deleted $where
            AND ($access)
      	  GROUP BY sc.id ".
            ($sort ? " ORDER BY $sort $dir ":"")." $limit ";
          $result = $this->dbQuery($sql);
          $resourceArray = array();
          for($i=0;$i<@$this->recordCount($result);$i++)  {
            array_push($resourceArray,@$this->fetchRow($result));
          }
          return $resourceArray;
        }
      
        function getDocuments($ids=array(), $published=1, $deleted=0, $fields="*", $where='', $sort="menuindex", $dir="ASC", $limit="") {
          if(count($ids)==0) {
            return false;
          } else {
            $limit = ($limit != "") ? "LIMIT $limit" : ""; // LIMIT capabilities - rad14701
            $tblsc = $this->getFullTableName("site_content");
            $tbldg = $this->getFullTableName("document_groups");
            // modify field names to use sc. table reference
            $fields = 'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$fields)));
            $sort = ($sort=="") ? "":'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$sort)));
            if ($where!='') $where = 'AND '.$where;
            // get document groups for current user
            if($docgrp = $this->getUserDocGroups()) $docgrp = implode(",",$docgrp);
            $access = ($this->isFrontend() ? "sc.privateweb=0":"1='".$_SESSION['mgrRole']."' OR sc.privatemgr=0").
              (!$docgrp ? "":" OR dg.document_group IN ($docgrp)");
            $sql = "SELECT DISTINCT $fields FROM $tblsc sc
              LEFT JOIN $tbldg dg on dg.document = sc.id
              WHERE (sc.id IN (".join($ids, ",").") AND sc.published=$published AND sc.deleted=$deleted $where)
              AND ($access)
      		GROUP BY sc.id ".
              ($sort ? " ORDER BY $sort $dir":"")." $limit ";
            $result = $this->dbQuery($sql);
            $resourceArray = array();
            for($i=0;$i<@$this->recordCount($result);$i++)  {
              array_push($resourceArray,@$this->fetchRow($result));
            }
            return $resourceArray;
          }
        }
        "I’d love to change the world but I can’t find the source code . . ."

        Custom ModX Templates
        • 33337
        • 3,975 Posts
        Zaigham (aka zi) Reply #33, 20 years ago
        Thank you kickass rolleyes
          Zaigham R - MODX Professional | Skype | Email | Twitter

          Digging the interwebs for #MODX gems and bringing it to you. modx.link
          • 15826
          • 160 Posts
          Yeah, and I was half asleep already when I wrote that wrapup last night and didn’t credit you with the fix. Zi fixed it, folks. Thank you, Zi!
            "I’d love to change the world but I can’t find the source code . . ."

            Custom ModX Templates
            • 18646
            • 106 Posts
            I’m having the same issue, the doc tree in the manager will not sort, but my PHP version is 4.4.8 and MySQL is 5.0.32.

            I found this on the MODx About page under "for optimal results":

            - MySQL 4.1.x or above. The 5.0.x and above branches are even better, as long as you’re not using 5.0.51 which contains known bugs with sorting/grouping.

            Could this be the issue? I’m not using that exact version, but it seems I’m having sorting/grouping issues sad

            Regards,
            Matt