We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36626
    • 51 Posts
    Is it possible to extend Login to allow users to re-enter a site after logging out and return to the last page they were viewing? In this context I'm thinking of something like a sequential e-learning course where the progress of the user is being tracked. Has anyone done anything like this with Revo?

    Any input is appreciated
      • 3749
      • 24,544 Posts
      One way would be to create an extended user field and use a plugin to save the ID of the page there when they view it and forward the user to it on login.

      The plugin (attached to OnWebPageComplete and OnWebLogin) would look something like this (untested):

      <?php
      
      switch ($modx->event->name) {
          case 'OnWebPageComplete':
              if (! $modx->user->hasSessionContext('web')) {
             /* ignore users who are not logged in */
            return;
           }
          $profile = $modx->user->getOne('Profile');
          $extendedFields = $profile->get('extended');
          $extendedFields['last_page'] = $modx->resource->get('id');
          $profile->set('extended', $extendedFields);
          $profile->save();
          break;
      
      case 'OnWebLogin':
          $profile = $user->getOne('Profile');
          $extended = $profile->get('extended');
          if (isset($extended['last_page']) && $extended['last_page']) {
             $url = $modx->makeUrl($extended['last_page'],'','','full');
             $modx->sendRedirect($url);
          }
          break;
      }
      


      You might want to add a test in the first case statement so the page is only saved if it's one of the e-learning pages.
      [ed. note: BobRay last edited this post 12 years, 7 months ago.]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 36626
        • 51 Posts
        Thank you very much. I will give this a go and see how it works.
          • 3749
          • 24,544 Posts
          bodhic,

          There was a line missing from the code above that would keep it from working.
           $profile->set('extended', $extendedFields);


          I corrected the code above. Sorry about the confusion.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 36626
            • 51 Posts
            Thank you BobRay. This did the trick! This was a huge help.

            If I wanted to grab a specific div or anchor on a page would I do so by adding something like .'#' to $modx->resource->get('id')? The reason I ask is that I'm considering using one of the html "slide shows" like s5 or similar. It seems as though it should be possible using getResources to load content into the "slides" which are actually divs with id's.

            Thank you again. [ed. note: bodhic last edited this post 12 years, 7 months ago.]
              • 3749
              • 24,544 Posts
              If I'm understanding you (and I'm not sure I am), I think you'd want to do something like this in the second case section:


              $url = $modx->makeUrl($extended['last_page'],'','','full');
              $url .= '#anchorName';

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 36626
                • 51 Posts
                Basically, the html slideshow would turn this into a one page site. I would use getResources to load document content into divs instead of loading a new page. Instead of redirecting people to a whole new page I'd be redirecting them to a specific div. Does that make sense?
                [ed. note: bodhic last edited this post 12 years, 7 months ago.]
                  • 3749
                  • 24,544 Posts
                  I'm not at all familiar with html slideshow, but it sounds like it might work.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 36626
                    • 51 Posts
                    What I'm struggling with his how to actually grab the anchor name. The javascript that controls the slideshow appends a hashtag to the url. I have one actual document index.php?id=1, then the subsequent screens are index.php?id=1#2, index.php?id=1#3, etc... Would you have any insight as to how I can store the last document along with the #divId?

                    I've read through the namedAnchor documentation and scoured the forum, but I haven't been able to come up with anything.

                    thank you
                      • 3749
                      • 24,544 Posts
                      I don't really understand the process you're using so I'm pretty much talking out of my butt here, but If you could have the JS insert something like this, it might work:

                      a href="[[~[[*id]]]]#hashtag" 


                      If you need to store things, you can save them in a $_SESSION variable with a snippet and read them with another snippet, but I'm not sure the parsing order would work out.

                      You might need to resort to a plugin connected to OnHandleRequest or OnParseDocument. Hopefully, someone who has a better grip on the process will chime in.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting