We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36924 ☆ A M B ☆
    • 298 Posts
    Hi. I want to implement this I needed some help:

    Users become members by signing up. When they do they have access and download classified project documents. I want to log the User who downloaed, Time of Download and Title of file downloaded and have it displayed either within the manager or at the front end.

    Thanks.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      If you are using Revo, you can use Static Resources for the file downloads - create custom Content Types (such as .pdf or .zip) for them. Then you can use plugins to record who is doing what with these static resources, just like any other resource.

      To the user, the only difference would be the URL would be for the actual static resource; the URL to the file itself wouldn't be displayed. For example, if you have a static resource with the alias "myfile" and a content type of .pdf (binary, attachment), whose path points to /assets/files/docs/pdfs/myfile.pdf, the user would see "domain.com/myfile.pdf" and still get the .pdf file to display or download, however his browser is configured to handle .pdf files.

      You could use a plugin, check for a class_key of modStaticResource, and log whatever you want. Or, you could use a special template for these files, and have a snippet in the template to log whatever you want. That would save the system from having to check every resource for modStaticResource types. The rest of the template really doesn't matter, since it'll never get displayed anyway - a static resource only serves the file it points to (when it's set to be an attachment, anyway). But since it's a resource, it can have TVs and all the rest of the resource fields (except content). [ed. note: sottwell last edited this post 13 years, 2 months ago.]
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 8274 ☆ A M B ☆
        • 222 Posts
        THe template idea with snippet is a really good idea, and you can even use the existing template and put a conditional in there to load the snippet if it is a static resource type.
        <code>
        [[*class_key:eq=`modStaticResource`:then=`[[$trackingSnippet]]`]]
        </code>

        If the page loads and the class_key setting passes the test, it will run the snippet.

        Although, honestly I am not sure if string modifiers or plugins are more efficient. For this it may be nominal, but probably easier to use the placholder than add another template or write a plugin.
          • 36924 ☆ A M B ☆
          • 298 Posts
          You could use a plugin, check for a class_key of modStaticResource, and log whatever you want. Or, you could use a special template for these files, and have a snippet in the template to log whatever you want.

          <code>
          [[*class_key:eq=`modStaticResource`:then=`[[$trackingSnippet]]`]]
          </code>


          My, I appreciate the suggestions. They come very clear. I have the static resource functional now. It maybe asking for too much but can you help with the code for the snippet or plugin?
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            First, there's a clever trick to using those output modifiers. Instead of making MODx process the chunk every time, which it will do before it even looks at the eq= part, you only want it processed if it's necessary. So instead of putting the whole chunk tag inside the modifier's tags, put the chunk's outer tags outside the modifier and just put the chunk name inside, like this:
            [[[[*class_key:eq=`modStaticResource`:then=`$trackingSnippet`]]]]

            Now if the result of the eq= is false, just the empty outer [[]] will be generated, which MODx will remove next time through the content, while if it is true then [[$trackingSnippet]] will be output, and MODx will later process the chunk.

            Now. On to the point. Using an output modifier in this case isn't such a good idea; it's much slower than running a snippet, and since you want to run a snippet anyway, why make MODx process an output modifier, then process a chunk, in order to find a snippet to run? Just use the snippet, and have your conditional in a snippet.
            if($modx->resource->get('class_key') == 'modStaticResource') {
                //do stuff here
            }
            

            See Bob's Guides for how to deal with resources in the MODx way. I can also recommend Bob's book, as well as W. Shawn Wilkerson's book.

            Actually, I would use MIGXdb to create and manage the custom tables for storing the data, as well as for managing it with a MIGx-based CMP. This tutorial will help you get started in creating and managing your custom tables. (as of this writing, the new documentation site is a little buggy; it's best viewed with the latest version of Google Chrome for now. Otherwise, if the pages won't scroll down, you have to use the links at the beginning of the page, and the back button on your browser to navigate through the tutorial page)
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 36924 ☆ A M B ☆
              • 298 Posts
              I appreciate your taking your time to provide these directions. But for project time schedule, I should just be fine with these tutorials and books. Still http://bobsguides.com/revolution-objects.html looks promising to expedite on my requirement. Will see how it goes.
                • 8274 ☆ A M B ☆
                • 222 Posts
                Bob's guides are a great resource for quite tuts about Revo. Cut many of snippets using those things (until I bought his book... the cover is almost gone from that thing now)