first, here is a solution, which seems to work to get listbox-multiple-items to your connection-table.
There was some typos in your schema, so I post it here again:
[note] I've changed the packagename to migxproducts! You need to change that back, also in the MIGX - configuration, I've posted
<?xml version="1.0" encoding="UTF-8"?>
<model package="migxproducts" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
<object class="ProductInfo" table="product_infos" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" index="index" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<composite alias="ProductsApplication" class="ProductApplication" local="id" foreign="product" cardinality="many" owner="local" />
</object>
<object class="Application" table="applications" extends="xPDOSimpleObject">
<field key="application" dbtype="varchar" precision="100" phptype="string" null="false" default="" index="index" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<composite alias="ProductsApplication" class="ProductApplication" local="id" foreign="application" cardinality="many" owner="local" />
</object>
<object class="ProductApplication" table="product_applications" extends="xPDOSimpleObject">
<field key="product" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
<field key="application" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
<column key="id" collation="A" null="false" />
</index>
<aggregate alias="Product" class="ProductInfo" local="product" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="Application" class="Application" local="application" foreign="id" cardinality="one" owner="foreign" />
</object>
</model>
this is my setup:
{
"formtabs":[
{
"MIGX_id":26,
"caption":"product",
"print_before_tabs":"0",
"fields":[
{
"MIGX_id":182,
"field":"applications",
"caption":"",
"description":"",
"description_is_code":"0",
"inputTV":"",
"inputTVtype":"listbox-multiple",
"validation":"",
"configs":"",
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"@EVAL return $modx->runSnippet('migxLoopCollection',array('packageName'=>'migxproducts','classname'=>'Application','tpl'=>'@CODE:[[+application]]==[[+id]]','outputSeparator'=>'||'));",
"default":"@EVAL return $modx->runSnippet('getProductApplicationList');",
"pos":1
},
{
"MIGX_id":180,
"field":"name",
"caption":"Name",
"description":"",
"description_is_code":"0",
"inputTV":"",
"inputTVtype":"",
"validation":"",
"configs":"",
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":"",
"pos":2
},
{
"MIGX_id":183,
"field":"handle_applications",
"caption":"",
"description":"",
"description_is_code":"0",
"inputTV":"",
"inputTVtype":"hidden",
"validation":"",
"configs":"",
"restrictive_condition":"",
"display":"",
"sourceFrom":"config",
"sources":"",
"inputOptionValues":"",
"default":1,
"pos":3
}
],
"pos":1
}
],
"contextmenus":"update||remove",
"actionbuttons":"addItem",
"columnbuttons":"",
"filters":"",
"extended":{
"migx_add":"",
"formcaption":"",
"update_win_title":"",
"win_id":"migxproducts",
"maxRecords":"",
"addNewItemAt":"bottom",
"multiple_formtabs":"",
"actionbuttonsperrow":4,
"winbuttonslist":"",
"extrahandlers":"",
"filtersperrow":4,
"packageName":"migxproducts",
"classname":"ProductInfo",
"task":"migxproducts",
"getlistsort":"",
"getlistsortdir":"",
"use_custom_prefix":"0",
"prefix":"",
"grid":"",
"gridload_mode":1,
"check_resid":1,
"check_resid_TV":"",
"join_alias":"",
"has_jointable":"yes",
"getlistwhere":"",
"joins":"",
"cmpmaincaption":"",
"cmptabcaption":"",
"cmptabdescription":"",
"cmptabcontroller":"",
"winbuttons":"",
"onsubmitsuccess":"",
"submitparams":""
},
"columns":[
{
"MIGX_id":1,
"header":"ID",
"dataIndex":"id",
"width":"",
"sortable":"false",
"show_in_grid":1,
"renderer":"",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"",
"renderoptions":""
},
{
"MIGX_id":2,
"header":"Name",
"dataIndex":"name",
"width":"",
"sortable":"false",
"show_in_grid":1,
"renderer":"",
"clickaction":"",
"selectorconfig":"",
"renderchunktpl":"",
"renderoptions":""
}
]
}
note this lines
"inputOptionValues":"@EVAL return $modx->runSnippet('migxLoopCollection',array('packageName'=>'migxproducts','classname'=>'Application','tpl'=>'@CODE:[[+application]]==[[+id]]','outputSeparator'=>'||'));",
"default":"@EVAL return $modx->runSnippet('getProductApplicationList');",
"pos":1
and the hidden handle_applications - field, which tells the save-function to handle the applications - input-options
this is the snippet getProductApplicationList to get the current values into the default-value of the multiple-listbox
<?php
$product = $_POST['object_id'];
$classname = 'ProductApplication';
$c = $modx->newQuery($classname);
$c->where(array('product'=>$product));
$ids = array();
if ($collection = $modx->getCollection($classname,$c)){
foreach ($collection as $object){
$ids[] = $object->get('application');
}
}
return implode('||',$ids);
I've extented the save-function of the ProductInfo-class, so no custom-update-processor is needed
<?php
class ProductInfo extends xPDOSimpleObject
{
public function save($cacheFlag = null)
{
$result = parent::save($cacheFlag);
$handle_applications = $this->get('handle_applications');
if ($handle_applications) {
$application_ids = explode('||', $this->get('applications'));
$applications = array();
foreach ($application_ids as $id){
$applications[$id] = $id;
}
if ($existing_applications = $this->getMany('ProductsApplication')) {
foreach ($existing_applications as $application_object) {
$id = $application_object->get('application');
if (array_key_exists($id, $applications)) {
unset($applications[$id]);
} else {
$application_object->remove();
}
}
}
foreach ($applications as $application) {
if (!empty($application) && $application_object = $this->xpdo->newObject('ProductApplication')) {
$application_object->set('product', $this->get('id'));
$application_object->set('application', $application);
$application_object->save();
}
}
}
return $result;
}
}
[ed. note: Bruno17 last edited this post 12 years, 4 months ago.]