We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20765
    • 90 Posts
    myfriendscallmebill Reply #1, 19 years, 6 months ago
    I’m running Ditto 2.0.1 on MODx 0.9.6RC2. I created ten documents as children of doc ID 48, and gave them pagetitles of "1" to "10".

    When I make the following Ditto call, all 10 docs are listed in reverse chronological order, as expected:
    [!Ditto? &parents=`48` &display=`all`!]

    And when I add pagination I get the same list plus the appropriate pagination placeholders are filled in:
    [!Ditto? &parents=`48` &display=`all` &paginate=`1`!]

    But when I add &start, things get odd. For example, if I make the following call:
    [!Ditto? &parents=`48` &display=`all` &paginate=`1` &start=`3`!]

    Then the displayed list only includes documents 4 through 7. In other words, the number of items I specify in &start are chopped off both the top and the bottom of the list. On the other hand, as I try various values for &start, the pagination placeholders such as [+start+], [+stop+], and [+total+] have the values I expect (given that I expect items only to be chopped off the top of the list).

    Is this the expected behavoir, or should I file this as a bug?


      • 25663 MODX Staff
      • 12,272 Posts
      Quote from: myfriendscallmebill at Mar 27, 2007, 02:51 PM

      But when I add &start, things get odd. For example, if I make the following call:
      [!Ditto? &parents=`48` &display=`all` &paginate=`1` &start=`3`!]

      Then the displayed list only includes documents 4 through 7. In other words, the number of items I specify in &start are chopped off both the top and the bottom of the list. On the other hand, as I try various values for &start, the pagination placeholders such as [+start+], [+stop+], and [+total+] have the values I expect (given that I expect items only to be chopped off the top of the list).

      Is this the expected behavoir, or should I file this as a bug?
      I think I’d file that one as a bug. I would expect to see 4-10 displayed... :/
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 20765
        • 90 Posts
        myfriendscallmebill Reply #3, 19 years, 6 months ago
        bug filed.
          • 18397
          • 3,250 Posts
          1. Pagination with &display=`all` doesn’t make sense. The two are opposites.
          2. Pagination with &start=`3` and &display=`3` does cause issues exactly as you describe. I believe I’ve fixed them in the development version. Please download a copy from my signerature and try it.
            • 20765
            • 90 Posts
            myfriendscallmebill Reply #5, 19 years, 6 months ago
            Quote from: Mark at Mar 27, 2007, 06:53 PM

            Please download a copy from my signature and try it.
            Mark:

            (1) SETUP
            I installed Ditto r1403 under MODx 0.9.6-RC2.
            I created a parent document at ID=62.
            I created ten child documents, titled "1" to "10".

            (2) TEST-1
            This Ditto call produces the expected results:
            [!Ditto_r1403? &ditto_base=`assets/snippets/ditto_r1403/` &parents=`62` &display=`5` &paginate=`1` &debug=`1` !]

            (3) TEST-2
            Adding an acsending sort to test 1 produces the expected result on page 1, but on page 2 the list is empty, even though the paging placeholders say that items 6 through 10 are being displayed. Here’s the call:
            [!Ditto_r1403? &ditto_base=`assets/snippets/ditto_r1403/` &parents=`62` &display=`5` &paginate=`1` &sortDir=`ASC` &debug=`1` !]

            (4) TEST-3
            Adding @start to test 1 causes items to be cut from the BOTTOM of the list. E.g. @start=`2` will cause documents "10" to "6" to be displayed on page 1, and documents "5" to "3" to be displayed on page 2. Isn’t @start supposed to cut from the TOP of the list? Here’s the call:
            [!Ditto_r1403? &ditto_base=`assets/snippets/ditto_r1403/` &parents=`62` &display=`5` &paginate=`1` &start=`2` &debug=`1` !]

            Debug files attached.

            What do you think?
              • 18397
              • 3,250 Posts
              Ok, made another commit that should fix this.

              Here is the diff since its only a few lines:
              Index: trunk/snippet.ditto.php
              ===================================================================
              --- trunk/snippet.ditto.php (revision 1403)
              +++ trunk/snippet.ditto.php (revision 1404)
              @@ -894,12 +894,12 @@
               	switch($sortDir) {
               		case "DESC":
              -			$start = $start;
              -			$stop = $stop + $start; 
              +			$stop += $start; 
               		break;
               		case "ASC":
              -			$start = $start - $offset;
              -			$stop = $stop;
              +			$start += $offset;
              +			$stop += $start;
               		break;
               	}
              +
               	if ($ditto->prefetch !== false) {
               		$documentIDs = array_slice($documentIDs,$start,$stop);
              
                • 20765
                • 90 Posts
                myfriendscallmebill Reply #7, 19 years, 6 months ago
                Quote from: Mark at Mar 28, 2007, 12:54 AM

                Ok, made another commit that should fix this.

                Mark:

                (1) SETUP
                o I installed Ditto r1404 under MODx 0.9.6-RC2.
                o I duplicated my previous test parent (to ID=74) with it’s 10 children titled "1" to "10".
                o I manually edited the unpub_date of each child to make them sequentially 1 second apart.

                (2) TEST-1
                With this Ditto call the documents sort correctly, and the pagination placeholders update correctly, but 5 items are displayed on each page, rather than 5 on the first and 3 on the second:
                [!Ditto_r1403? &ditto_base=`assets/snippets/ditto_r1404/` &parents=`74` &display=`5` &paginate=`1` &start=`2` &sortDir=`DESC` &debug=`1` &sortBy=`unpub_date` !]

                (3) TEST-2
                If I simply change the above call to have an ascending sort then: The first page shows items 9 then 10 (while the paging placholders say Ditto’s showing items 1 to 5 of eight), and the second page shows items 4, 5, and 6 (while the paging placholders say Ditto’s showing items 6 to 8 of eight). Here’s the call:
                [!Ditto_r1403? &ditto_base=`assets/snippets/ditto_r1404/` &parents=`74` &display=`5` &paginate=`1` &start=`2` &sortDir=`ASC` &debug=`1` &sortBy=`unpub_date` !]

                Debug files attached.
                  • 18397
                  • 3,250 Posts
                  Ok, this should fix that. Its been commited as rev 1405.

                  Index: trunk/snippet.ditto.php
                  ===================================================================
                  --- trunk/snippet.ditto.php (revision 1404)
                  +++ trunk/snippet.ditto.php (revision 1405)
                  @@ -894,5 +894,5 @@
                   	switch($sortDir) {
                   		case "DESC":
                  -			$stop += $start; 
                  +			$stop = ($ditto->prefetch === false) ? $stop + $start : $stop; 
                   		break;
                   		case "ASC":
                  
                  


                  Just wanted to say thanks for the detailed test cases! They make finding the problematic code so much quicker!
                    • 20765
                    • 90 Posts
                    myfriendscallmebill Reply #9, 19 years, 6 months ago
                    Quote from: Mark at Mar 28, 2007, 12:41 PM

                    Ok, this should fix that. Its been commited as rev 1405.

                    Ok, everything works correctly now except possibly this one thing: &start always trims the OLDEST items from the list. I had thought it was supposed to trim the FIRST items from the list, which would change depending upon how the list was sorted. I also wonder what would happen if I was sorting by an alphanumeric field: would &start still trim the oldest items, and would that make random items disappear from the middle of the list...?

                    Anyway, thanks for all your great work!

                    Quote from: Mark at Mar 28, 2007, 12:41 PM

                    IJust wanted to say thanks for the detailed test cases! They make finding the problematic code so much quicker!

                    Your welcome, my pleasure smiley
                      • 18397
                      • 3,250 Posts
                      Drat, your right that is backwards... Fixed in 1406.

                      Index: trunk/snippet.ditto.php
                      ===================================================================
                      --- trunk/snippet.ditto.php (revision 1405)
                      +++ trunk/snippet.ditto.php (revision 1406)
                      @@ -894,5 +894,6 @@
                       	switch($sortDir) {
                       		case "DESC":
                      -			$stop = ($ditto->prefetch === false) ? $stop + $start : $stop; 
                      +			$stop = ($ditto->prefetch === false) ? $stop + $start + $offset : $stop + $offset; 
                      +			$start += $offset;
                       		break;
                       		case "ASC":