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

    To show the date and hour of the last modification of a page on my site I put this code :
    [[*editedon:strtotime:date=`%d/%m/%Y à %Hh%M`]]


    But I’m looking for a code that shows the last modification of the site. It would show the day and hour of the latest modified page on any page of the site.

    An alternative would be a code that shows the last Manager log in of a specific user...

    Does anyone knows that code?

    Thanks

    ;-)
    Sub
      • 22427
      • 793 Posts
      In Evo I use a snippet [tt]SiteLastUpdated[/tt] with the following code:
      <?php
      $dateFormat = isset($dateFormat)? $dateFormat:'Y-m-d';
      return date($dateFormat, $modx->db->getValue($modx->db->select('editedon', 
          $modx->getFullTableName('site_content'), 'published=1', 'editedon DESC', 1)));
      ?>
      
      Of the [tt]editedon[/tt] values of all the published pages from the table [tt]site_content[/tt] the selection takes the first one in descending order.
      Change the [tt]$dateFormat[/tt] to match your needs.

      I don’t know the modifications necessary for Revo.
        • 3749
        • 24,544 Posts
        I couldn’t help adding a little more functionality to it, but it will do what you want. I called it getDocuments() because it will get the most recent or the least recent (oldest) documents. You can sort by any date field (editedon, publishedon, createdon, pub_date, unpub_date) and in either direction using the &sort and &dir properties. It sets placeholders for all document fields (which is kind of overkill), so you could edit it to just set the one(s) you need.

        In your case, you would call it like this (more or less):

        [[getDocuments]]
        
        <p>Site Last Updated: [[+get_documents.editedon]]
        


        The snippet returns no output, so put it at the top of the page (or the top of the <body> section of the template if you want it on lots of pages) and put the placeholder tag wherever you want the date. You can format the date with output modifiers, if necessary.

        If you set the &limit property to something greater than 1, the placeholders get indexes so you you can do this:

        <p>Recent Documents
            <br />Pagetitle: [[+get_documents1.pagetitle]]
            <br />ID: [[+get_documents1.id]]
            <br />Published: [[+get_documents1.published]]
            <br />Last Edited on: [[+get_documents1.editedon]]
        </p>
        
        <p>
            <br />Pagetitle: [[+get_documents2.pagetitle]]
            <br />ID: [[+get_doduments2.id]]
            <br />Published: [[+get_documents2.published]]
            <br />Last Edited on: [[+get_documents2.editedon]]
        </p>
        


        I resisted the impulse to have it use a Tpl chunk, but you might want that for a more complex display.

        /* getDocuments Snippet */
        $sort = $modx->getOption('sort',$scriptProperties,'editedon');
        $dir = $modx->getOption('dir',$scriptProperties,'DESC');
        $limit = $modx->getOption('limit',$scriptProperties, 1);
        
        $c = $modx->newQuery('modResource');
        
        /* ignore deleted resources */
        $c->where(array(
            'deleted' => 0,
        ));
        
        $c->sortby($sort,$dir);
        $c->limit($limit, 0);
        
        $resources = $modx->getCollection('modResource',$c);
        
        if (empty($resources)) {
            return 'No resources found';
        }
        
        $index = $limit > 1? 1 : '';
        foreach($resources as $resource) {
        
             /* set placeholders for all resource fields */
             $modx->toPlaceholders($resource->toArray(),'get_documents' . $index , '.');
             if ($limit == 1) break;
             $index++;
        }
        return '';      
        


        I should say that you could also use getResources for this, but this might be easier to use for some people.
          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
          • 36098
          • 46 Posts
          Thanks that is perfect!


          But I have another time linked problem : my server time is not right so I tried to change "sever_offset_time" from 0 to 7 in the system settings but it doesn’t change my time... is that normal?


          Thanks for your help !
            • 3749
            • 24,544 Posts
            Did you clear the site cache?

            Changing it will only affect newly created or edited docs, not ones already in the DB.

            You may have to call the snippet uncached [[!getDocuments]] -- I’m not sure if the site cache is cleared when a new document is created. It will be slower, so don’t do it unless you have to.
              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
              • 36098
              • 46 Posts
              Well your snippet works perfectly but my problem is linked to the time of my server that is 7 hours less than my home time. I tried to change "sever_offset_time" from 0 to 7 in the system settings but it doesn’t change my time.

              (but your snippets is up to date after every site modification... just the time is 7 hours in delay)

                • 22840
                • 1,572 Posts
                Works great, thanks Bobby

                Is there any way to edit the date format, I want it to show like July 17th 2011

                Thanks

                EDIT:

                worked it out

                [[+get_documents.editedon:strtotime:date=`%A, %B %e, %Y`]]
                  • 48842
                  • 37 Posts
                  Old thread, but seems to be authoritative!

                  I've gotten it to work with returning a correct value for the edit date of a specific page. However, I can not get it to work to return "recent documents" as described below.


                  Quote from: BobRay at Jul 23, 2011, 01:32 AM
                  If you set the &limit property to something greater than 1, the placeholders get indexes so you you can do this:

                  <p>Recent Documents
                  Pagetitle: [[+get_documents1.pagetitle]]
                  ID: [[+get_documents1.id]]
                  Published: [[+get_documents1.published]]
                  Last Edited on: [[+get_documents1.editedon]]</p>
                  
                  <p>Pagetitle: [[+get_documents2.pagetitle]]
                  ID: [[+get_doduments2.id]]
                  Published: [[+get_documents2.published]]
                  Last Edited on: [[+get_documents2.editedon]]</p>
                  



                  So, to make the above work, which of the following 2 lines are we supposed to edit? $limit line ("1" before ")" at end) or $index line (1 before and/or after "?") ?

                  Quote from: BobRay

                  $limit = $modx->getOption('limit',$scriptProperties, 1);
                  
                  $index = $limit > 1? 1 : '';
                  



                  It seems one should edit the $limit line and change 1 to 2 or 3 or however many documents one wants returned, but that didn't work for me. Or am I looking in the wrong place?

                  [ed. note: fbachofner last edited this post 12 years ago.]
                    • 3749
                    • 24,544 Posts
                    If you are sending a specific limit in the tag (e.g., &limit=`10`), just remove this line:

                    $index = $limit > 1? 1 : '';
                      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