Output_properties in MIGX CMP?

Hey,

i want to set the output property delimiter to , in my CMP.
Input TV type is listbox-multiple

Is this possible without using a “helper-TV”? Just inside the CMP?

Do you use MIGXdb to create your CMP (Custom Manager Page) or did you write your own code?

I wrote my schema, created the package via MIGX and created the tables via MIGX.
CMP (formtabs, fields, etc.) created via MIGX CMP.

I’m not really sure, but as far as I can tell, it’s not possible to define output_properties in the MIGX config.

If you use migxLoopCollection to output the data, then the simplest solution is probably to use an output modifier like replace in the template.

[[+myfield:replace=`||==,`]]

That’s what I am doing atm. But doesn’t seem to work for filtering like this:
where=`{"myfield:replace=`||==,`:find_in_set":[[*id]]}

myfield contains IDs which I want to check against the current resource ID.

Again I’m not sure, but my understanding is, that find_in_set can only be used for JSON data (using getImageList) and not with MIGXdb and migxLoopCollection.

Maybe you have to write your own query to read and filter the data.

Thanks @halftrainedharry I will play around with that some more…

I did some testing and something like this seems to work.

[[migxLoopCollection?
	...
	&where=`FIND_IN_SET([[*id]], REPLACE(myfield, '||', ',')) > 0`
]]

To make it more performant (and get rid of the REPLACE(myfield, '||', ',') part above), you probably have to write “aftersave” and “aftergetfields” hook-snippets to make sure that the data is saved in the database with a comma as a separator (instead of ||).

1 Like

Very nice, thank you!
What happens if myfield holds these values: 10||103||310 and the [[*id]] is 10 ?

I’m not sure I understand your question.

If myfield = 10||103||310 and [[*id]] = 10, then the row should be in the result of the query.
If myfield = 103||310 and [[*id]] = 10, then the row is NOT in the query result.

The MySQL function FIND_IN_SET() returns the position of a string within a list of strings.
The query SELECT FIND_IN_SET("10", "10,103,310") returns 1, because 10 is found at position 1.
SELECT FIND_IN_SET("10", "103,10,310") returns 2, because 10 is found at position 2.
SELECT FIND_IN_SET("10", "103,310") returns 0, because 10 is not in the list.

REPLACE("10||103||310", '||', ',') is just used to convert 10||103||310 to 10,103,310.


You could use PhpMyAdmin (or something similar) to test if it works.

-- only return rows with 10 in the list
SELECT * FROM `modx_mytable` WHERE FIND_IN_SET('10', REPLACE(myfield, '||', ',')) > 0
-- return the position of 10 in the set for all the rows
SELECT *, FIND_IN_SET('10', REPLACE(myfield, '||', ',')) AS set_position FROM `modx_mytable` 
1 Like

Thanks for the explanation, that makes sense.
I thought this would behave similar to tvFilters in a pdoResources call.

tvFilters=`myTV==%[[*id]]%`

myTV = 10||103||310
[[*id]] = 10

results in NOT only 10. So the logic would be something like this… which breaks when u got an ID of 10999 - you get the point. But that was discussed here a million times before :wink:

&tvFilters=`myTV==%[[*id]]%, myTV!=%0[[*id]]%,myTV!=%1[[*id]]%,myTV!=%2[[*id]]%,myTV!=%3[[*id]]%,myTV!=%4[[*id]]%,myTV!=%5[[*id]]%,myTV!=%6[[*id]]%,myTV!=%7[[*id]]%,myTV!=%8[[*id]]%,myTV!=%9[[*id]]%,myTV!=%[[*id]]0%,myTV!=%[[*id]]1%,myTV!=%[[*id]]2%,myTV!=%[[*id]]3%,myTV!=%[[*id]]4%,myTV!=%[[*id]]5%,myTV!=%[[*id]]6%,myTV!=%[[*id]]7%,myTV!=%[[*id]]8%,myTV!=%[[*id]]9%`

as discussed many times, for cases like that, it would probably be better to have a connection table between resources and your custom table, that stores all connections between the two tables

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.