• Resolved Iulia Cazan

    (@iulia-cazan)


    Would it be possible to have a new type of operator something like in_reverse and in_i_reverse that would just reverse the order of variables when applying the logic?

    I was looking at how the logic is applied for the UserData and I am not able to match correctly the users with the in and in_i operators. I am not saying there is an error, this works perfectly for everything else. My use-case is a bit different, and I would need your help with this if it’s possible.

    It goes like this:
    – Let’s say I have UserData.custom_attribute that contains something like this val1,val2,val3.
    – I would need then to configure the custom rule to be true for any user with custom_attribute containing val1.
    – So, in this case, I would need that the applied logic to use the parameters in the other order (I am referring to this part ( 'in_i' => function($a, $b){ which only looks for a to be contained inside b and not the other way around).

    Basically, what I am asking is can we have a new operator type that is doing “variable contains the value” instead of “variable can be found in the value”?

    {"in_i": [ {"var":"UserData.custom_attribute"}, "some_value" ] }
    {"in_i_reverse": [ "some_value", {"var":"UserData.custom_attribute"} ] }

    Thank you very much!
    Iulia

    • This topic was modified 4 years, 7 months ago by Iulia Cazan.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Logic Hop

    (@logichop)

    Great suggestion! We’ll add it to our short-term roadmap and see if we can roll this out by mid-May.

    Thread Starter Iulia Cazan

    (@iulia-cazan)

    That would be amazing, thank you!

    In the meanwhile, I was able to create/assess some custom condition by extending the plugin with a new filter right before the operators in JsonLogic apply method (around line 54) so that the functionality will either return a pre-computed condition match or resume the regular check. Do you think you could include such a filter in the next release as well? It could give more flexibility.

    
    // Allow for more flexible conditions checks from outside of the plugin.
    $maybe_return = apply_filters( 'apply_custom_external_logic', null, $logic, $data );
    if ( ! is_null( $maybe_return ) ) {
    	// This means the logic was assessed externaly.
    	return $maybe_return;
    }
    
    • This reply was modified 4 years, 6 months ago by Iulia Cazan.
    Plugin Author Logic Hop

    (@logichop)

    Hi Lulia,

    The current “in” method does the following:

    'in' => function($a, $b){
    	if (empty($a) || empty($b)) return false;
    	if(is_array($b)) return in_array($a, $b);
    	if(is_string($b)) return strpos($b, $a) !== false;
    	return false;
    },

    For “in_reverse” would you be looking for:

    'in_reverse' => function($a, $b){
    	if (empty($a) || empty($b)) return false;
    	if(is_array($a)) return in_array($b, $a);
    	if(is_string($a)) return strpos($a, $b) !== false;
    	return false;
    },

    Thanks!

    Thread Starter Iulia Cazan

    (@iulia-cazan)

    Yes. That is exactly how the new operator would be used. Thank you!

    Plugin Author Logic Hop

    (@logichop)

    We’ve added the new logic types in_reverse and in_reverse_i (and a few more) and also the filter you requested, now titled logichop_apply_custom_logic.

    Hope that’s helpful – Thanks!

    Thread Starter Iulia Cazan

    (@iulia-cazan)

    Hi,

    This is awesome, thank you! I upgraded and I see the conditions in the code.

    I was wondering if these should get reflected also in the Logic Hop Local Storage options when trying to create the custom conditions, I can’t seem to locate these there, maybe there is a cache or need to upgrade the addon too.

    Please advise.

    Regards,
    Iulia

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Would it be possible to have a new type of operator’ is closed to new replies.