Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-48822

Find last visual post in a discussion

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.7.2, 2.8
    • 2.9
    • Forum
    • MOODLE_27_STABLE, MOODLE_28_STABLE
    • MOODLE_29_STABLE
    • MDL-48822-master
    • Hide
      The tests you need to run:
      1. Inspect the post at the bottom of the page and check that the post has the 'lastpost' class
      2. Run the following JS and check that it returns 1

        Y.all('.lastpost').size();
        

      Testing instructions
      1. Create a new forum and post a new discussion in it (post1)
        • Run checks
      2. Reply to post1 with post2
        • Run checks
      3. Reply to post2 with post3
        • Run checks
      4. Reply to post3 with post4
        • Run checks
      5. Reply to post1 with post5
        • Run checks
      6. Reply to post2 with post6
        • Run checks
      7. Reply to post3 with post7
        • Run checks
      8. Reply to post6 with post8
        • Run checks

      Do some other tests as you see fit.

      Show
      The tests you need to run: Inspect the post at the bottom of the page and check that the post has the 'lastpost' class Run the following JS and check that it returns 1 Y.all('.lastpost').size(); Testing instructions Create a new forum and post a new discussion in it (post1) Run checks Reply to post1 with post2 Run checks Reply to post2 with post3 Run checks Reply to post3 with post4 Run checks Reply to post1 with post5 Run checks Reply to post2 with post6 Run checks Reply to post3 with post7 Run checks Reply to post6 with post8 Run checks Do some other tests as you see fit.

    Description

      During setting custom styling to the forum, I found out that I could really use an indicator for the last post in a discussion. Not the chronologically last post but the last one to be displayed.

      I came up with this code that I added at the end of forum_get_all_discussion_posts() after the $posts array has been rearranged.

      $lastpost = false;
      // start with the last child of the first post
      $post = &$posts[reset($posts)->id];
      while (!$lastpost) {
          if (!isset($post->children)) {
              $post->lastpost = true;
              $lastpost = true;
          }
          else // go to the last child of this post
              $post = &$posts[end($post->children)->id];
      }
      

      Later on, when building the HTML, if isset($post->lastpost) is true I add the "lastpost" class (same syntax as "firstpost" that's already in the code).

      This improvement is purely for the benefit of the front-end output and I believe it will come in handy when working with styling and script writing.

      Attachments

        Issue Links

          Activity

            People

              dobedobedoh Andrew Lyons
              l.gil Lior Gil
              Andrew Lyons Andrew Lyons
              David Monllaó David Monllaó
              Adrian Greeve Adrian Greeve
              Adrian Greeve, Ilya Tregubov, Kevin Percy, Mathew May, Mihail Geshoski, Shamim Rezaie
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                11/May/15