We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1540
    • 4 Posts
    I’m starting the development of a new site in Revo and I would like to take the chance of improve my modx understandings.

    In short, beside others, I have this requirement:

    "There are ’Hotels’ and ’Special Services’. ’Special Services’ are shared between ’Hotels’, but each Hotel has an unique description for the special service selected".
    E.g. the hotel "Modx Inn" has the special service "Experienced php developer". The "experienced developer" has his description "He can sit in front of a monitor for more than 12 hours", but has also a specific description to be shown in the "Modx Inn" hotel page (e.g. "He can develop and play Wow at the same time"). There are other attributes involved but I keep it simple just to focus on the question.

    So this is an Many-to-Many relation with some attributes in the realtionship. The schema would look like this:

    Hotel <--> Hotel_SpecialService <--> Special Service

    [table]
    [tr][td]Model[/td][td]Attributes[/td][/tr]
    [tr][td]Hotel[/td][td]name,description...[/td][/tr]
    [tr][td]Special Service[/td][td]name,description...[/td][/tr]
    [tr][td]Hotel_SpecialService[/td][td]hotel_id,specialservice_id,description...[/td][/tr]
    [/table]

    In the manager an Editor User should be able to edit an Hotel page and to select between a list of Special Services and to edit the custom description.

    So, my idea is to:

    - Create some DocumentResources "Hotel A", "Hotel B" etc.
    - Create some DocumentResources "Special Service A", "Special Service B" etc.
    - Create with xpdo a custom table and model "Hotel_SpecialService"
    - Create a custom TV wich present in every hotel’s resource edit the list of services with the description input field


    The problems are:
    - The TV, of course, implies that there is a template called "Hotels" and a template called "Special Services" to force the custom widget to appear only on some pages and to select only some resources.
    In my opinion this would be not correct because I would put a Model attribute in the View, breaking the MVC pattern. So is there a way to define models?
    - Even if I feel brave enough to break the MVC pattern how can I make aware the custom table that there is an One to One relationship (the many to many splits in two one to one relationship).

    Looks like I’m looking for Drupal’s "Content Types" ...

    So the question is: which is this the best way to achieve my goal?

    (Please... don’t answer "Use drupal"!)
      • 4172
      • 5,888 Posts
      perhaps you can create a custom-tv-input type which shows all options in a grid with checkboxes and a contextmenue to edit the description in a form-window and store all selections and descriptions as Json in that TV.

      see http://modxcms.com/forums/index.php/topic,57045.0.html
      and multiItemsGridTV in my signature.

      This could be a combination of both.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 1540
        • 4 Posts
        Interesting suggestion.
        I have to think about the implication of not having the possibility to easily perform queries.

        Let’s suppose that I’m asked to provide a list of all hotels with a filter box, to filter all hotels having some special services.

        If I have a table I can just create a query like "SELECT .... JOIN ... WHERE service_id = 1 OR service_id=2", otherwise I should get all TV and filter result with php code.

        I feel that this second approach is more prone to produce bugs, but I’ll give it a try.
          • 4172
          • 5,888 Posts
          you can also store the result per onDocFormSave-plugin into your custom-table if you need todo sql-queries.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 1540
            • 4 Posts
            Yes I’ve found also this interesting plugin http://modxcms.com/forums/index.php/topic,56636.0.html that should be useful to edit custom tables...
              • 3749
              • 24,544 Posts
              I think you’ll be happier in the long run if you put *all* the data in custom tables and just use a resource (or resources) to display it.
              Just my $.02. smiley

              There’s some info here that might be useful to you: http://bobsguides.com/custom-db-tables.html
                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