WPCodeBin
Beta

[Condition] FluentCRM LIST Condition for Breakdance Builder

PHP Code Snippet
<?php
add_action("breakdance_register_template_types_and_conditions", function () {
\Breakdance\ConditionsAPI\register([
"supports" => ["element_display"],
"slug" => "fluentcrm-condition-dh-lists", // MUST BE UNIQUE
"label" => "Fluent CRM Lists Condition",
"category" => "Randlos Conditions",
"operands" => ["equals"],
// providing a dropdown of values is optional. if 'values' is not provided, a text input will be provided instead of a dropdown
"values" => function () {
$listApi = FluentCrmApi("lists");
$allLists = $listApi->all();
$listlistforBd = [];
for ($i = 0; $i < count($allLists); $i++) {
$listlistforBd[$i] = [
"text" => strval($allLists[$i]->title),
"value" => strval($allLists[$i]->id),
];
}
return [
[
"label" => "FluentCrm Lists",
"items" => $listlistforBd,
],
];
},
/*
when specifying possible values for a dropdown,
you can optionally make the dropdown a multiselect
*/
"allowMultiselect" => true,
/*
this function will be called to evaluate the condition
if it returns true, the element will be shown
if it returns false, the element will be hidden
*/
"callback" => function (string $operand, $value) {
// $myVal = 'item-1'; // usually, you'd get $myVal from somewhere, i.e. global $post; $myVal = $post->ID;
/*
if allowMultiselect is false, $value will be a string.
use it like so:
if ($operand === 'equals') {
return $myVal === $value;
}
if ($operand === 'not equals') {
return $myVal !== $value;
}
*/
/*
in our example, allowMultiselect is true, which means $value will be an array of strings
*/
if ($_GET["email"]) {
$userEmail = $_GET["email"];
$contactApi = FluentCrmApi("contacts");
$contact = $contactApi->getContact($userEmail);
$userlists = $contact->lists;
$myListArray = [];
for ($i = 0; $i < count($userlists); $i++) {
array_push($myListArray, strval($userlists[$i]->id));
}
if ($operand === "equals") {
sort($myListArray);
sort($value);
$listarr3 = array_diff($value, $myListArray);
if (count($listarr3) == 0) {
// all of $arr1 is in $arr2
return true;
} else {
return false;
}
}
return false;
}
return false;
// if ($operand === 'equals') {
// return in_array($myVal, $value);
// }
//
// if ($operand === 'not equals') {
// return !in_array($myVal, $value);
// }
//
// return false;
},
]);
});
?>
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX