We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36426
    • 197 Posts
    Quote from: BobRay at Jul 16, 2018, 08:50 PM
    Bob has no idea. wink

    There's this: https://bobsguides.com/blog.html/2013/09/18/displaying-modx-date-fields/. But I'm not sure how that all affects date fields in ClassExtender when they're shown in the Manager.

    In the DB are you seeing human-readable dates or just a large number?

    It occurs to me that ClassExtender may be using str_replace() to replace the placeholders. If that's true, using output modifiers would lead to no output.

    Do you get any output if you leave off the output modifier?

    FWIW, the snippets and plugins in CE are sort of "suggestions" to get you started with the class. They were never meant to do everything you might want, and I suspect that date fields might require some extra code in the snippet.

    Hi thanks Bob.

    In the database the entries don't go in if I enter a date such as 15/03/1979 - it just saves 0000-00-00 in the database. So if I instead enter it in that matching format like 15-03-1979 then it does save correctly in the database. So I suppose I just have to change to make sure users and webmasters enter dates in the xx-xx-xxxx format for a start.

    But even with that, say I edit a user's dates (which save in the database but don't show in the backend or frontend when trying view them). Then I click out of the user, go back in and enter a new date - in phpmyadmin I can see it just adds an additional table row with the new data such as:

    userdata_id      checkin        checkout
    13               2016-11-11     2016-11-11
    11               0000-00-00     0000-00-00
    11               2018-03-10     2018-04-10
    11               2017-05-20     2017-05-21
    


    So it isn't overwriting that table row with the new information. sad

    If I leave the modifiers off it still makes no difference and it doesn't show in the backend or frontend, but does still save in the database.

    Thanks for any support and to everyone trying to help smiley
      Yorkshire UK based hosting provider: https://www.simulant.uk
      • 46886
      • 1,154 Posts
      >One thing i think about this issue, forgive me if I am out of line or plain wrong, but it seems to me you are trying to use a value within Modx along with values outside of Modx (CE), and this is a source of great trouble and also somehow not aligned well.

      Your CE system presumably has a bunch of values for users in it, let's call them values 1-5, but let's recognize that your User system (user values) is/are the real focus. From that angle your user data system looks weird:

      UserValue 1 - In CE DB
      UserValue 2 - In CE DB
      UserValue 3 - In CE DB
      UserValue 4 - In Modx>Users>Profile>Path DB
      UserValue N - In CE DB

      This is the true source of the problem IMHO and can be remedied extremely easily by using a CE value for this data.

      I have a tool from my forum days which gets the user creation date and can output, so this task isn't hard (happy to post that if you need), the problem is the intricacies of how Modx parses and manages that string.
        • 3749
        • 24,544 Posts
        I just checked, and you're right. PHP's strtoTime() function will not handle 15/03/1979 (though it will handle an incredibly wide variety of date and time formats). It will handle 03/15/1978, or 1978/03/15. It will also handle 'March 15, 1979' -- The day always has to come before the month. It makes sense since with dates below 13, it has no way of knowing which is the date and which is the month.

        On the duplicates, I'm not sure why that's happening.

        You might try adding index="unique" to the userdata_id field:

        <field key="userdata_id" dbtype="int" precision="11" phptype="integer" null="false" index="unique" attributes="unsigned"/>


        You'll have to regenerate the class and map files after making the change. Let me know if it works. [ed. note: BobRay last edited this post 5 years, 8 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
          • 36426
          • 197 Posts
          Quote from: BobRay at Jul 23, 2018, 05:49 AM
          I just checked, and you're right. PHP's strtoTime() function will not handle 15/03/1979 (though it will handle an incredibly wide variety of date and time formats). It will handle 03/15/1978, or 1978/03/15. It will also handle 'March 15, 1979' -- The day always has to come before the month. It makes sense since with dates below 13, it has no way of knowing which is the date and which is the month.

          On the duplicates, I'm not sure why that's happening.

          You might try adding index="unique" to the userdata_id field:

          <field key="userdata_id" dbtype="int" precision="11" phptype="integer" null="false" index="unique" attributes="unsigned">


          You'll have to regenerate the class and map files after making the change. Let me know if it works.</field>

          Hi thanks Bob, This is really driving me bonkers.

          I've added the index="unique" in there and regenerated the class and map files...

          It still gave duplicates so I dropped the and deleted the table and created it again. This time I set the userdata_id as a primary key to see if that would help (before my table had no primary key).

          This now still saves the dates and works (if I enter them like you say as mm/dd/yy - hard for me to get used to as in Britain we always use dd/mm/yy haha) but it will only save it once!

          If I then go out of the user and back in the date has disappeared, as it was doing before - I can then enter another new different date and save it. Check the phpmyadmin database view and the old date is still there. Like the screenshot attached...

          So could all my problems just be down to the fact that my database table isn't set up right. I'm not sure what should be a primary key (if any), whether to set the rows indexes to unique, full text, spatial etc.

          and if they should be type int, date etc. Should anything else be set? I've attached a second screenshot of how I currently have them but is this correct?

            Yorkshire UK based hosting provider: https://www.simulant.uk
            • 3749
            • 24,544 Posts
            I wish I could tell you what's wrong. It could be a bug in ClassExtender, but no one else has reported this problem, and I think it would have showed up by now.

            I based the schema and object on the modUserProfile object (modx_user_attributes table) because it's doing the same thing.

            For that table, 'id' is the primary key.

            The 'id' and 'internalKey' fields are both indexes and both are set to be unique.

            I see your table has no id field. I can't look back at your schema right now, but is it possible that your object extends xPDOObject instead of xPDOSimpleObject? The second gets an automatic, autoincrement id field. The first assumes that you will be creating that field yourself if you need it (which you do).

            You need an id field that's unique, set to autoincrement, and is the primary key. Extending xPDOSimpleObject and leaving the id field out of the schema will give you all that automatically.

            You also need an 'internalKey' field that is unique, not autoincrement, and is an index (but not the primary index).
              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
              • 36426
              • 197 Posts
              Hi Bob,

              Ok thanks I changed my table to match your described one (screenshot attached) but now no data will save in it at all when I update a user.

              The schema looks ok to me but I'm not really sure if you can take a look for me if you get chance:

              <?xml version="1.0" encoding="UTF-8"?>
              <model package="extendeduser" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" tablePrefix="ext_" version="1.0.0">
                  <!-- extend the modUser class -->
                  <object class="extUser" extends="modUser">
                      <composite alias="Data" local="id" class="userData" foreign="userdata_id" cardinality="one" owner="local"/>
                  </object>
                  <object class="userData" table="user_data" extends="xPDOSimpleObject">
                      <field key="userdata_id" dbtype="int" precision="11" phptype="integer" null="false" index="unique" attributes="unsigned"/>
                      <field key="checkin" dbtype="date" precision="100" phptype="date" null="true"/>
                      <field key="checkout" dbtype="date" precision="100" phptype="date" null="true"/>
              
                      <index alias="userdata_id" name="userdata_id" primary="false" unique="true" type="BTREE">
                          <column key="userdata_id" length="" collation="A" null="false"/>
                      </index>
                      <aggregate alias="User" class= "modUser" local="userdata_id" foreign="id" cardinality="one" owner="foreign"/>
                      <aggregate alias="Profile" class="modUserProfile" local="userdata_id" foreign="internalKey" cardinality="one" owner="foreign"/>
                  </object>
              </model>


              Thanks again for any help
                Yorkshire UK based hosting provider: https://www.simulant.uk
                • 36426
                • 197 Posts
                Quote from: nuan88 at Jul 22, 2018, 04:56 PM
                >One thing i think about this issue, forgive me if I am out of line or plain wrong, but it seems to me you are trying to use a value within Modx along with values outside of Modx (CE), and this is a source of great trouble and also somehow not aligned well.

                Your CE system presumably has a bunch of values for users in it, let's call them values 1-5, but let's recognize that your User system (user values) is/are the real focus. From that angle your user data system looks weird:

                UserValue 1 - In CE DB
                UserValue 2 - In CE DB
                UserValue 3 - In CE DB
                UserValue 4 - In Modx>Users>Profile>Path DB
                UserValue N - In CE DB

                This is the true source of the problem IMHO and can be remedied extremely easily by using a CE value for this data.

                I have a tool from my forum days which gets the user creation date and can output, so this task isn't hard (happy to post that if you need), the problem is the intricacies of how Modx parses and manages that string.

                Hi thanks also for your reply, but I'm not really sure what you mean. Bob's extension is supposed to extend the user data, that's the whole point of it I believe. So it should work fine??
                  Yorkshire UK based hosting provider: https://www.simulant.uk
                  • 3749
                  • 24,544 Posts
                  I think the problem with your schema is the dbtype and phptype specification of the date fields. Otherwise, I don't see anything wrong with it.

                  These are the examples I found in the MODX schema:

                  <field key="dob" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
                  <field key="createdon" dbtype="int" precision="20" phptype="timestamp" null="false" default="0" />
                  <field key="editedon" dbtype="timestamp" phptype="timestamp" null="true" default="NULL" />
                  <field key="createdon" dbtype="datetime" phptype="datetime" />


                  I don't know which would work best for your use case. I'd try the first one first since it's for the modUserProfile object.
                    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
                    • 36426
                    • 197 Posts
                    Quote from: BobRay at Jul 28, 2018, 08:06 PM
                    I think the problem with your schema is the dbtype and phptype specification of the date fields. Otherwise, I don't see anything wrong with it.

                    These are the examples I found in the MODX schema:

                    <field key="dob" dbtype="int" precision="10" phptype="integer" null="false" default="0">
                    <field key="createdon" dbtype="int" precision="20" phptype="timestamp" null="false" default="0">
                    <field key="editedon" dbtype="timestamp" phptype="timestamp" null="true" default="NULL">
                    <field key="createdon" dbtype="datetime" phptype="datetime">


                    I don't know which would work best for your use case. I'd try the first one first since it's for the modUserProfile object.</field></field></field></field>

                    Hi Bob, I finally got it working. Thanks it was something going wrong with that schema. So in the end I just set them both to be type="text" phptype="text" and now it works well. Any trying with date or other types and I can't get it working. Also if I add the precision="10" or such it won't work either, so I removed that and "text" seems to do the job so that will be fine!

                    Thanks again for your help smiley
                      Yorkshire UK based hosting provider: https://www.simulant.uk
                      • 3749
                      • 24,544 Posts
                      Thanks for reporting back.

                      Are you saving timestamps or human-readable dates there? If it's the latter, it will be difficult (but not impossible) to do date arithmetic on them (e.g., "you've been a member for 2 years and 3 months").

                      I should have remembered that the modUser object already has a createdon field (added somewhat recently), but not an editedon field. Since you're extending modUser, that could have caused your troubles. Using a different name for that field might have made it work as a date field.
                        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