We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27708 MODX Staff
    • 2,502 Posts
    I want to create a plugin or snippet that will set the unpubdate timestamp to the timestamp set in a tv called "eventDate" + 3600 86400 seconds (one day after the event happens.

    I am thinking I would need to use the OnTemplateFormSave event to do this but I am not sure. I am currently struggling with Soda’s Front End Document Manager not saving dates and times and it would be easier anyway if I could just have the document unpublish automatically the day after the event.

    I certainly know I could make the events show up or hide using PHx but I want them to be invisible to bots and searches.

    If someone could point me in the right direction that would be good.

    All the best,

    Jay
      Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
      • 21560
      • 145 Posts
      Interesting concept. Though why not set the unpublish date yourself?

      Anyway, if you want a push in the right direction: http://modxcms.com/forums/index.php/topic,19891.0.html

      It’s a nice example of how to edit values in a content directly.
        [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
        • 27708 MODX Staff
        • 2,502 Posts
        Nimja,

        Thanks for the response,

        The reason for the automatic unpublish is that the client is using Ditto for a Upcoming Events System and I implemented Soda’s Front End Document Manager and it is not storing the unpublish dates and also since the dates will always be the same (1 day after the event) it makes sense for MODx to handle this instead of the client having to do it every single time.

        I find the calendar widget annoying as it is so reducing the number of times someone has to use it is great.

        Cheers,

        Jay
          Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
          • 21560
          • 145 Posts
          Well if you want to learn something yourself, find out how to read template variables in a document (which should be easy)

          And then simply update the end-date with a nice PHPDATE + 1 day.

          If only I could remember by heart how to read TV’s
            [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
            • 7231
            • 4,205 Posts
            You can use the getTemplateVarOutput api function.
            http://modxcms.com/gettemplatevaroutput.html
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 27708 MODX Staff
              • 2,502 Posts
              Okay...Hmmm.

              I think what I would like to do is do something like

              Here is where I am lost.

              If I use FDM (Front End Document Manager) it has fields that (using eForm) post input data to the db based on the field names.

              I don’t want to apply this snippet/plugin to all documents but only those for a certain template.

              I want the function to run on the FDM form save/post.

              I don’t think this will work because the field info won’t yet be in the db to get. It will still be in the form.

              I think that the only way to do this is to actually create a hidden field in the form and use PHx to do the calc in the value and hope that the value actually gets saved.

              Thoughs?

                Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                • 27376
                • 576 Posts
                The correct event you’re looking for is OnDocFormSave. You can’t use OnBeforeDocFormSave because not all the document- and template-variables are available to you.

                The code in the plugin would use getTemplateVarOutput() to retrieve the date (convert it to a unix timestamp if necessary), and then modify the pub_date field accordingly.

                Also, 3600 seconds is 1 hour, not 1 day.
                  • 27708 MODX Staff
                  • 2,502 Posts
                  sirlancalot,

                  Thanks for the tips. I was writing the post with the 3600 seconds it is obviously 86400--brain freeze.

                  Cheers,

                  Jay
                    Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                    • 27708 MODX Staff
                    • 2,502 Posts
                    I admit that I am not the most adept php guy and without asking people to write the plugin for me any suggestions of previously written plugins that might use the OnDocFormSave? Otherwise options as to how to achieve this.
                      Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                      • 27708 MODX Staff
                      • 2,502 Posts
                      Okay I have tried to start by outputting the values from the event_date TV and I keep getting the following error:

                      Fatal error: Call to undefined function getTemplateVar() in C:\xampp\htdocs\nqnh\manager\includes\document.parser.class.inc.php(766) : eval()'d code on line 2


                      I just did this with a snippet to start just to see if I could return the value before I went on to write the plugin. I may have written it wrong but here it was:

                      <?php
                      $idname = 'event_date';
                      echo getTemplateVarOutput($idname);
                      ?>
                      


                      You may need to make fun of me for my messy or wrong code but I want to be able to figure this out. smiley
                        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub