On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Good day. There is a journal site. Installed MODX 2.2.7, Articles 1.6.0, MIDX latest. For each issue of the journal, a container is created in Articles, to which articles are added. I want to make a database of authors who will be added to different articles of the journal. Each author should have involvement in the University (accordingly, there must be a ready list of them). In addition, for each author there must be fields Surname, Initials, Email, University, ORCID. Now I tried to implement it through midxdb like this:

    XML:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <model package="authors" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
        <object class="myAuthor" table="my_authors" extends="xPDOSimpleObject">
            <field key="surname" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="initials" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="email" dbtype="text" phptype="string" null="false" default="" />
    		<field key="orcid" dbtype="text" phptype="string" null="false" default="" />
    
            <field key="university" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="mod_user" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" />
    		
    		<field key="resource_id" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
    		<field key="resource_ids" dbtype="text" phptype="string" null="false" default="" />
    
            <field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
    
            <field key="createdon" dbtype="datetime" phptype="datetime" null="true"/> 
    
            <aggregate alias="University" class="myUniversity" local="university" foreign="id" cardinality="one" owner="foreign" />
            <aggregate alias="User" class="modUser" local="mod_user" foreign="id" cardinality="one" owner="foreign" />
    		<aggregate alias="Resource" class="modResource" local="resource_id" foreign="id" cardinality="one" owner="foreign" />
        </object>
    
        <object class="myUniversity" table="my_universities" extends="xPDOSimpleObject">
            <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
            <field key="abb" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
    		<field key="address" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
    		<field key="country" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
    
            <field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
    
            <field key="createdon" dbtype="datetime" phptype="datetime" null="true"/> 
    
            <composite alias="Authors" class="myAuthor" local="id" foreign="university" cardinality="many" owner="local" />
        </object>
    </model>


    Export JSON:

    {
      "formtabs":[
        {
          "MIGX_id":7,
          "caption":"Info",
          "print_before_tabs":"0",
          "fields":[
            {
              "MIGX_id":23,
              "field":"surname",
              "caption":"\u0424\u0430\u043c\u0438\u043b\u0438\u044f",
              "description":"",
              "description_is_code":"0",
              "inputTV":"",
              "inputTVtype":"",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":1
            },
    		{
              "MIGX_id":24,
              "field":"initials",
              "caption":"\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u044b",
              "description":"",
              "description_is_code":"0",
              "inputTV":"",
              "inputTVtype":"",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":2
            },
            {
              "MIGX_id":25,
              "field":"email",
              "caption":"\u041f\u043e\u0447\u0442\u0430",
              "description":"",
              "description_is_code":"0",
              "inputTV":"",
              "inputTVtype":"email",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":3
            },
            {
              "MIGX_id":27,
              "field":"university",
              "caption":"\u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442",
              "description":"",
              "description_is_code":"0",
              "inputTV":"",
              "inputTVtype":"listbox",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"@SELECT '' AS `name` ,'' AS `id` FROM `[[+PREFIX]]my_universities` UNION SELECT `name`,`id` FROM `[[+PREFIX]]my_universities` WHERE `deleted` = 0",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":4
            },
            {
              "MIGX_id":28,
              "field":"mod_user",
              "caption":"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c",
              "description":"",
              "description_is_code":"0",
              "inputTV":"select-user",
              "inputTVtype":"",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":5
            }
          ],
          "pos":1
        }
      ],
      "contextmenus":"update||recall_remove_delete",
      "actionbuttons":"addItem||toggletrash",
      "columnbuttons":"",
      "filters":[
            {
                "MIGX_id":1,
                "name":"search",
                "label":"search",
                "emptytext":"Seatch bu surname...",
                "type":"textbox",
                "getlistwhere":{
                    "surname:LIKE":"%[[+search]]%",
                    "OR:university:LIKE":"%[[+search]]%"
                },
                "getcomboprocessor":"",
                "combotextfield":"",
                "comboidfield":"",
                "comboparent":"",
                "default":""
            }
        ],
      "extended":{
        "migx_add":"",
        "disable_add_item":"",
        "add_items_directly":"",
        "formcaption":"",
        "update_win_title":"",
        "win_id":"authors",
        "maxRecords":"",
        "addNewItemAt":"bottom",
        "multiple_formtabs":"",
        "multiple_formtabs_label":"",
        "multiple_formtabs_field":"",
        "multiple_formtabs_optionstext":"",
        "multiple_formtabs_optionsvalue":"",
        "actionbuttonsperrow":4,
        "winbuttonslist":"",
        "extrahandlers":"",
        "filtersperrow":4,
        "packageName":"authors",
        "classname":"myAuthor",
        "task":"",
        "getlistsort":"",
        "getlistsortdir":"",
        "sortconfig":"",
        "gridpagesize":"",
        "use_custom_prefix":"0",
        "prefix":"",
        "grid":"",
        "gridload_mode":1,
        "check_resid":1,
        "check_resid_TV":"",
        "join_alias":"",
        "has_jointable":"yes",
        "getlistwhere":"",
        "joins":[
          {
            "alias":"University",
            "selectfields":"name"
          }
        ],
        "hooksnippets":"",
        "cmpmaincaption":"\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0411\u0414 \u005c\u0022\u0410\u0432\u0442\u043e\u0440\u044b\u002c \u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u044b\u005c",
        "cmptabcaption":"\u0410\u0432\u0442\u043e\u0440\u044b",
        "cmptabdescription":"\u041c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0430\u0432\u0442\u043e\u0440\u043e\u0432",
        "cmptabcontroller":"",
        "winbuttons":"",
        "onsubmitsuccess":"",
        "submitparams":""
      },
      "columns":[
        {
          "MIGX_id":2,
          "header":"id",
          "dataIndex":"id",
          "width":"",
          "sortable":"false",
          "show_in_grid":"0",
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":1,
          "header":"\u0424\u0430\u043c\u0438\u043b\u0438\u044f",
          "dataIndex":"surname",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
    	{  
    	  "MIGX_id":6,
          "header":"\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u044b",
          "dataIndex":"initials",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":5,
          "header":"\u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442",
          "dataIndex":"University_name",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":3,
          "header":"deleted",
          "dataIndex":"deleted",
          "width":"",
          "sortable":"false",
          "show_in_grid":"0",
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":4,
          "header":"published",
          "dataIndex":"published",
          "width":"",
          "sortable":"false",
          "show_in_grid":"0",
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        }
      ]
    }


    The database was created. When displaying TV there is a table in which I can add authors. I do not know how to implement adding each individual author from a table to a specific article from the container. Also, the table is not displayed at all with "check_resid": 1. In DB, after adding author, his resource_id - 0.

    How can I resolve this problem? Thanks in advance!
    • Up
      • MIGX might be a good option, but you might look at the ClassExtender extra, which will let you extend the modResource object and put those fields in a custom table. I think it will display them on the Articles form. It will be more difficult if you want to add multiple users for a single article, though. The Article object extends modResource, so it should work, though you may need some custom code to retrieve them. I've never tested it with Articles, but I believe it would work.

        You may also want to have your class extend xPDOSimpleObject, which will give it an autoincrement 'id' 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