On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hi

    I'm looking to create some 'favourite' functionality for a website I'm working on. If someone is logged in (using the Login extra), I'd like for them to be able to 'favourite' certain pages with the relevant resource id added to a custom field. Is it possible for me to store an array within the custom fields that I can use with GetResources to output a list of their favourites?

    Phillip

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      There are several approaches to do something like that. One is to list the Resource IDs of favorites in the extended field of the user's profile. You'd need a custom snippet to store them and another one to display the pages, but they would be fairly simple. This would be the most efficient approach (a custom DB table would be better, but I think it's overkill for your use case). It's also the most logical, since it's really user data you're saving.

      Another way to go would be to 'tag' each resource with the user's username in a TV (or a MIGX TV). Then search for them with MIGX or with something like getResourcesTag (part of the TagLister package). I think you'd still need a custom snippet to save the user's "likes." The problem with this method is speed. The algorithm has to search through all the resources to find the user's favorites. With the method above, you just grab that one field of the Profile and you've got them all.

      Either way, you've got a separate issue of creating a method to let users select a page as a favorite. The best method would probably be a button that triggered an Ajax call to a processor that would save the preference.
        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
      • Hi bobray

        Thanks for the reply. I'll go with the first option you have suggested and create a comma separated list of Resource ID's as an extended field of the users profile.