We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25586
    • 105 Posts
    Over the past weeks I have been working on a projectManagement snippet. To finalize the snippet I realy need some help. So I’m hoping you guys can think with me. And I’m sorry if my English is sometimes hard to read because it’s not my native language smiley

    So far I can:


    • Register new users
    • Create a project with user registration
    • Create clients for projects
    • Create fellow company members
    • List projects
    • Edit projects

    In have 3 objectclasses (tables) called: pmUsers, pmProjects and pmCompany.

    pmUsers contains extended profile fields like firstname and surname
    pmProjects contains projects
    pmCompany contains company information

    When a user submits a project for the first time he has to register himself in the orderprocess and the following steps are executed:


    • The User gets registerd
    • Firstname and surname are placed in the pmUsers table
    • Filled in project information is added as a new project in the pmProjects table
    • Company info is added to the pmCompany table

    My question is: How do I link this info (tables) together? I’m thinking of a company identifier (company_id for example) which is added to all the tables as the user submits registration. But how do I get a unique number renerated which I can use?

    The easiest way is to get the increment ID of the modx_users table copied to the company_id key as the data is written to the tables. Is it possible to get the new increment ID in modx_users and use it?

    Or is it better to use composite and aggregate db relations? I have tried working with it but I can’t seem te figure out how to use it.

    It has been a long post and hopefully someone can help me out so I can distribute my first snippet!

    Thanks for al the effort so far smiley

    Rogier
      • 22295
      • 153 Posts
      General notes:
      - extend modUser class
      - use xpdo relations (aggr/comp) - undoubtedly!

      I’ve gone the same path, with a more complex structure then the one you present, you can find in this forum some questions/answers in this regards that’ll help you.

      Post your schema.xml, it’ll be much simpler to assist you directly on that.
        • 25586
        • 105 Posts
        Quote from: oori at May 20, 2010, 06:47 AM

        General notes:
        - extend modUser class
        - use xpdo relations (aggr/comp) - undoubtedly!

        I’ve gone the same path, with a more complex structure then the one you present, you can find in this forum some questions/answers in this regards that’ll help you.

        Post your schema.xml, it’ll be much simpler to assist you directly on that.

        Haha oori I found your post about 3 hours ago with google and you helped me so much with that post!

        I think I have figured it out thanks to your topic. I’ll get back when I stumble on a problem.

        Thanks!

        Rogier
          • 25586
          • 105 Posts
          I have created my schema:

            <object class="pmRegistredUser" extends="modUser">
              <composite alias="UserAttributes" class="pmUserAttributes" local="id" foreign="internalKey" cardinality="one" owner="local" />
            </object>
          
            <object class="pmUserAttributes" table="projectmanager_user_attributes" extends="modUser">
              <field key="internalKey" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
              <field key="company_id" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
              <field key="project_id" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
              <field key="firstname" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
              <field key="surname" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
          
              <composite alias="RegistredUser" class="RegistredUser" local="internalKey" foreign="id" cardinality="one" owner="foreign" />
            </object>


          But how do I register a new user?

          Normaly I would typ this:
          $object = $modx->newObject('modUser');
          $object->fromArray(array(
                  'username' => 'myusername',
          	'password' => 'password',
          	'class_key' => 'modUser',
          	'active' => '1',
          ));
          $object->save();


          But how do I get the "pmUserAttributes" filled in aswel?

          Thanks
            • 22303 MODX Staff
            • 10,725 Posts
            First, pmUserAttributes should not extend modUser, only pmRegistredUser. BTW, you do know you misspelled registered throughout this schema?

            Second your composite is wrong in pmRegistredUser; there is no class in your schema called RegistredUser. That should be class="pmRegistredUser".

            Here is how you’d create your objects (NOTE that you’ll want to create the MODx Profile object as well):
            $user = $modx->newObject('pmRegistredUser');
            $user->fromArray(array(
                'username' => 'myusername',
                'password' => 'password',
                'active' => '1',
            ));
            
            $profile = $modx->newObject('modUserProfile');
            $profile->fromArray(array(
                'email' => '[email protected]',
                'fullname' => 'My Full Name'
            ));
            $user->addOne($profile);
            
            $pmProfile = $modx->newObject('pmUserAttributes');
            $pmProfile->fromArray(array(
                'firstname' => 'My Full',
                'surname' => 'Name'
            ));
            $user->addOne($pmProfile);
            
            $user->save();
              • 25586
              • 105 Posts
              Quote from: OpenGeek at May 20, 2010, 12:47 PM

              First, pmUserAttributes should not extend modUser, only pmRegistredUser. BTW, you do know you misspelled registered throughout this schema?

              Yeah I figured that part out myself. And no I dinn’t know I misspelled registered.. shocked multiple times even! Good note smiley

              Thank you for your effort, it is working. Now I can expand the table and work further for a while!

              Rogier
                • 22295
                • 153 Posts
                I highly recommend reading this post (and everything around it, incl. the bugs in rc1...):
                http://modxcms.com/forums/index.php/topic,47758.msg280528.html#msg280528

                extension_packages is not documented anywhere - but is very needed for extenders like us. in addition, for whatever unknown reason - using that i got a massive performance gain.. but even if not - it’s simply comfortable.
                  • 25586
                  • 105 Posts
                  Quote from: oori at May 20, 2010, 06:27 PM

                  I highly recommend reading this post (and everything around it, incl. the bugs in rc1...):
                  http://modxcms.com/forums/index.php/topic,47758.msg280528.html#msg280528

                  extension_packages is not documented anywhere - but is very needed for extenders like us. in addition, for whatever unknown reason - using that i got a massive performance gain.. but even if not - it’s simply comfortable.

                  Thanks for the tip. But how do I use extension_packages? Red your post but can’t figure out how to use it smiley
                    • 22295
                    • 153 Posts
                    Quote from: Rogier at May 21, 2010, 08:53 AM

                    Thanks for the tip. But how do I use extension_packages? Red your post but can’t figure out how to use it smiley

                    In System Settings, you create a new setting called "extension_packages", and give it value:
                    package_name:{core_path}components/package_name/model/
                    (you’Re pointing at your model folder that should contain a folder named "package_name" which contains all the compiled php files generated from the xpdo schema you did)

                    note, if you not using the latest svn and you’re on a windows system, see my post on that thread - you’d need to do a small change modx.class.php.

                    This setting simply does $modx->addPackage, so your package it available all around without redeclaring it. this is very useful if you don’t have just one or two snippets who use this model, but it’s all around the application.