We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40045
    • 534 Posts
    Quote from: fourroses666 at May 20, 2014, 02:47 AM
    Thanks Exside, that would be a very good idea.
    I might contact you (if the client says go) to help me out (payed).

    Sure =), let me know if I can help!
      • 3749
      • 24,544 Posts
      Extended fields are fine for extra user data, but they can be a real pain (and very slow) if you need to search for users on the basis of the extended field's content. If that's the case, you might want to consider extending the modUser object either manually or by using the ClassExtender extra.

      Extending modUser basically gives each user an extra User Profile containing your extra fields. For updating the profile (including your extra fields), you can add the fields to the Create/Edit User form and let users edit it in the Manager or you can create a front-end form using the Login package's UpdateProfile snippet plus a snippet in the ClassExtender package to handle the extra fields.
        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
        • 40045
        • 534 Posts
        Quote from: BobRay at May 20, 2014, 11:33 AM
        Extended fields are fine for extra user data, but they can be a real pain (and very slow) if you need to search for users on the basis of the extended field's content. If that's the case, you might want to consider extending the modUser object either manually or by using the ClassExtender extra.

        Extending modUser basically gives each user an extra User Profile containing your extra fields. For updating the profile (including your extra fields), you can add the fields to the Create/Edit User form and let users edit it in the Manager or you can create a front-end form using the Login package's UpdateProfile snippet plus a snippet in the ClassExtender package to handle the extra fields.

        Definitely have to try this out, more interested in extending modResource though =)...what do you think, would it performance wise be better to have an extended modResource object or TVs? I guess an extended object would be faster?? Is it possible to add an image/file TV (or other input types) for example as an additional field with ClassExtender?
          • 3749
          • 24,544 Posts
          ClassExtender will also extend modResource and as you suspect, using the extended object is *way* faster than TVs when it comes to searching and sorting.

          http://bobsguides.com/classextender-class.html

          The problem with using TVs is that the data you need is in three different tables -- The site_content table has the resource data, but the TV information is split between the TV table with the default values and the intersect table with the modTemplateVarResource data.

          The worst issue is that for any TV that has an inherited or default value, the actual value is not in the modTemplateVarResource, but you have to check it to know that. Then you have to pull the TV object itself, usually in a separate query, and parse its value. Plus there's the question of whether you want the raw value or the rendered value (another step, done once for each TV that needs it).

          Another big issue is sorting. There's no fast way to sort by TV values because they're split between two different tables and you have to check each one to see if you need to go to the second table. The sort has to be done after you have them all.

          All of that goes away when you extend modResource. Using getObjectGraph() or getCollectionGraph(), you can get everything you need in a single query with a built-in sort. On one site I converted with ClassExtender, the time differences were pretty striking. I didn't measure them, but displays that took about 4 or 5 seconds were coming in at less than a second. That was from extending modUser. Extending modResource should yield a much more dramatic improvement because of the TV issues. YMMV.

          I have couple of blog posts coming up on the advantages of extending modUser and modResource, but it may be a few weeks before they appear.

          [ed. note: BobRay last edited this post 12 years, 4 months ago.]
            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
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I'm getting myself psyched up to use classExtender to create a static resource that works with media sources. Much better than hacking the modStaticResource core files. I expect it to be an interesting exercise.
              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
              • 3749
              • 24,544 Posts
              ClassExtender will get you part of the way there, but by default it really just creates a regular resource with a bunch of extra fields in a custom table (much like the User Profile, but for Resources).

              Of course you can put whatever you like in the schema and make it do anything you want, but you might want to use it to extend modStaticResource rather than modResource and you'll probably want to override some methods. The default class only overrides the constructor to set the class_key.
                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
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Actually the modStaticResource processor does a lot more if the static resource is also binary. See modresponse.class.php (search for "binary") and modstaticresource.class.php (again, search for "binary"). I need it to be able to get a base URI from a media source, and fetch that file from the remote source for streaming.
                  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
                  • 40045
                  • 534 Posts
                  Love to read these blog posts =) keep 'em coming! Sounds very interesting, will check out with my next project which is just appearing these days! What about the "TV-type-fields" question? Is it possible to have an additional field added by class extender that resembles an image or file TV for example?