We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 52936
    • 1 Posts
    Hi,

    i have set up a cmp with help of migxdb (2.9.6-pl in modx 2.5.1-pl). I use custom tables with an aggregate to modResource: my custom class "employees" has a many to many relation to class modResource. Thus, in my Formtabs I have a field with input tv type "listbox-multiple". It fetches the pagetitles of a certain parents' resources. It works well an the relations are saved to my join table. The only problem: when I edit an employee the related resources are not marked selected in my listbox-multiple.

    I read every documentation/thread available, but can't get the point of what i'm missing. I hope someone could give me a hint. Thanks in advance everybody who gives a look! Here is my code:

    <?xml version="1.0" encoding="UTF-8"?>
    <model package="berlin" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
        <object class="Employees" table="ber_employees" extends="xPDOSimpleObject">
    		<field key="positions_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" index="index" />
    		<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" />
    
    		<index alias="positions_id" name="positions_id" primary="false" unique="false" type="BTREE" >
    			<column key="positions_id" length="" collation="A" null="false" />
    		</index>
            <aggregate alias="Position" class="Positions" local="positions_id" foreign="id" cardinality="one" owner="foreign" />
            <composite alias="EmployeeResource" class="EmployeesResources" local="id" foreign="employees_id" cardinality="many" owner="local" />
        </object>
    
        <object class="Positions" table="ber_positions" extends="xPDOSimpleObject">
    		<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" />
    	</object>
    
        <object class="EmployeesResources" table="ber_employees_resources" extends="xPDOSimpleObject">
            <field key="employees_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" index="index" />
            <field key="resources_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" />
    
            <index alias="employees_id" name="employees_id" primary="false" unique="false" type="BTREE" >
                <column key="employees_id" length="" collation="A" null="false" />
                <column key="resources_id" length="" collation="A" null="false" />
            </index>
            <aggregate alias="Employee" class="Employees" local="employees_id" foreign="id" cardinality="one" owner="foreign" />
            <aggregate alias="Resource" class="modResource" local="resources_id" foreign="id" cardinality="one" owner="foreign" />
        </object>
    
    </model>
    


    MIGX-config "Employees:
    {
      "formtabs":[
        {
          "MIGX_id":4,
          "caption":"Neuer Ansprechpartner",
          "print_before_tabs":"0",
          "fields":[
            {
              "MIGX_id":34,
              "field":"resources_id",
              "caption":"Zuordnung zu Seite",
              "description":"",
              "description_is_code":"0",
              "inputTV":"",
              "inputTVtype":"listbox-multiple",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"@CHUNK test",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":1
            },
            {
              "MIGX_id":6,
              "field":"positions_id",
              "caption":"Funktion",
              "description":"",
              "description_is_code":"0",
              "inputTV":"",
              "inputTVtype":"listbox",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"@EVAL return '--- w\u00e4hlen ---==||' . $modx->runSnippet('migxLoopCollection',array('packageName'=>'berlin','classname'=>'Positions','tpl'=>'@CODE:[[+name]]==[[+id]]','outputSeparator'=>'||'));",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":2
            },
            {
              "MIGX_id":7,
              "field":"name",
              "caption":"Name",
              "description":"",
              "description_is_code":"0",
              "inputTV":"",
              "inputTVtype":"",
              "validation":"",
              "configs":"",
              "restrictive_condition":"",
              "display":"",
              "sourceFrom":"config",
              "sources":"",
              "inputOptionValues":"",
              "default":"",
              "useDefaultIfEmpty":"0",
              "pos":3
            }
          ],
          "pos":1
        }
      ],
      "contextmenus":"update||remove",
      "actionbuttons":"addItem",
      "columnbuttons":"update",
      "filters":"",
      "extended":{
        "migx_add":"Neuer Ansprechpartner",
        "disable_add_item":"",
        "add_items_directly":"",
        "formcaption":"",
        "update_win_title":"",
        "win_id":"employees",
        "maxRecords":"",
        "addNewItemAt":"bottom",
        "multiple_formtabs":"",
        "multiple_formtabs_label":"",
        "multiple_formtabs_field":"",
        "multiple_formtabs_optionstext":"",
        "multiple_formtabs_optionsvalue":"",
        "actionbuttonsperrow":4,
        "winbuttonslist":"",
        "extrahandlers":"",
        "filtersperrow":4,
        "packageName":"berlin",
        "classname":"Employees",
        "task":"",
        "getlistsort":"",
        "getlistsortdir":"",
        "sortconfig":"",
        "gridpagesize":"",
        "use_custom_prefix":"0",
        "prefix":"",
        "grid":"",
        "gridload_mode":2,
        "check_resid":1,
        "check_resid_TV":"",
        "join_alias":"",
        "has_jointable":"yes",
        "getlistwhere":"",
        "joins":[
          {
            "alias":"Position"
          },
          {
            "alias":"EmployeeResource"
          }
        ],
        "hooksnippets":{
          "aftersave":"EmployeesResourcesAftersave"
        },
        "cmpmaincaption":"Ansprechpartner",
        "cmptabcaption":"Ansprechpartner",
        "cmptabdescription":"Ansprechpartner",
        "cmptabcontroller":"",
        "winbuttons":"",
        "onsubmitsuccess":"",
        "submitparams":""
      },
      "columns":[
        {
          "MIGX_id":3,
          "header":"Id",
          "dataIndex":"id",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "customrenderer":"",
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":4,
          "header":"Funktion",
          "dataIndex":"Position_name",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "customrenderer":"",
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        },
        {
          "MIGX_id":2,
          "header":"Name",
          "dataIndex":"name",
          "width":"",
          "sortable":"false",
          "show_in_grid":1,
          "customrenderer":"",
          "renderer":"",
          "clickaction":"",
          "selectorconfig":"",
          "renderchunktpl":"",
          "renderoptions":"",
          "editor":""
        }
      ]
    }
    


    Snippet code that populates the listbox-multiple (MIGX-ID 34 in config obove) via @CHUNK test

    Here I'm uncertain how to write the code to tell the superbox to show related resources as selected. I wonder where and when I should getch the related resources_id and how to write the proper placeholder [[+selected]] (??) in that situation.

    $joins='';
    if($_REQUEST['object_id'] != 'new') {
    	$joins = '{
    		"alias":"EmployeeResource",
    		"classname":"EmployeesResources",
    		"on":"EmployeeResource.employees_id='.$_REQUEST['object_id'].'",
    		"selectfields":"resources_id"
    		}';
    }
    
    $o = $modx->runSnippet(
    	'migxLoopCollection',
    	[
    		'classname'=>'modResource',
    		'selectfields'=>'id,pagetitle',
    		'where'=>'{"parent":"51"}',
    		'joins'=>'[' . $joins . ']',
    		'tpl'=>'@CODE:[[+pagetitle]]==[[+id]]',
    		'outputSeparator'=>'||',
    		'debug'=>'1'
    	]
    );
    return '--- wählen ---==0||' . $o;
    



    Regards,
    Harald