2022-07-19 09:26:24 +02:00
< ? php
include_once APP . 'Model/WorkflowModules/WorkflowBaseModule.php' ;
class Module_published_if extends WorkflowBaseLogicModule
{
public $id = 'published-if' ;
public $name = 'IF :: Published' ;
public $description = 'Published IF / ELSE condition block. The `then` output will be used if the encoded conditions is satisfied, otherwise the `else` output will be used.' ;
public $icon = 'code-branch' ;
public $inputs = 1 ;
public $outputs = 2 ;
public $html_template = 'if' ;
2022-07-20 15:19:33 +02:00
public $expect_misp_core_format = true ;
2022-07-19 09:26:24 +02:00
public $params = [];
private $operators = [
'equals' => 'Event is published' ,
'not_equals' => 'Event is not published' ,
];
public function __construct ()
{
parent :: __construct ();
$this -> params = [
[
2022-07-27 15:41:21 +02:00
'id' => 'condition' ,
2022-07-19 09:26:24 +02:00
'label' => 'Condition' ,
2022-07-27 15:41:21 +02:00
'type' => 'select' ,
2022-07-19 09:26:24 +02:00
'default' => 'equals' ,
'options' => $this -> operators ,
],
];
}
public function exec ( array $node , WorkflowRoamingData $roamingData , array & $errors = []) : bool
{
parent :: exec ( $node , $roamingData , $errors );
$params = $this -> getParamsWithValues ( $node );
2022-07-27 15:41:21 +02:00
$operator = $params [ 'condition' ][ 'value' ];
2022-07-19 09:26:24 +02:00
$data = $roamingData -> getData ();
$path = 'Event.published' ;
$is_published = ! empty ( Hash :: get ( $data , $path ));
$eval = $this -> evaluateCondition ( $is_published , $operator , true );
return $eval ;
}
}