*/ private array $conditions; /** * @var array> */ private array $steps; /** * @var bool */ private bool $is_active; /** * @var string */ private string $remote_workflow_uuid; /** * Constructor. * * @param int $id Workflow ID. * @param string $name Workflow name. * @param string $trigger Trigger type. * @param array $conditions Conditions array. * @param array $steps Steps array. * @param bool $is_active Whether workflow is active. * @param string $remote_workflow_uuid Remote workflow UUID. */ public function __construct( int $id, string $name, string $trigger, array $conditions = array(), array $steps = array(), bool $is_active = true, string $remote_workflow_uuid = '' ) { $this->id = $id; $this->name = $name; $this->trigger = $trigger; $this->conditions = $conditions; $this->steps = $steps; $this->is_active = $is_active; $this->remote_workflow_uuid = $remote_workflow_uuid; } /** * Create from database row. * * @param object $row Database row. * @return self */ public static function fromRow( object $row ): self { $conditions = array(); if ( ! empty( $row->conditions ) ) { $decoded = json_decode( $row->conditions, true ); $conditions = is_array( $decoded ) ? $decoded : array(); } $steps = array(); if ( ! empty( $row->steps ) ) { $decoded = json_decode( $row->steps, true ); $steps = is_array( $decoded ) ? $decoded : array(); } return new self( (int) $row->id, (string) $row->name, (string) $row->trigger, $conditions, $steps, (bool) $row->is_active, (string) ( $row->remote_workflow_uuid ?? '' ) ); } /** * Get ID. * * @return int */ public function getId(): int { return $this->id; } /** * Get name. * * @return string */ public function getName(): string { return $this->name; } /** * Get trigger. * * @return string */ public function getTrigger(): string { return $this->trigger; } /** * Get conditions. * * @return array */ public function getConditions(): array { return $this->conditions; } /** * Get steps. * * @return array> */ public function getSteps(): array { return $this->steps; } /** * Check if workflow is active. * * @return bool */ public function isActive(): bool { return $this->is_active; } /** * Get the remote workflow UUID. * * @return string */ public function getRemoteWorkflowUuid(): string { return $this->remote_workflow_uuid; } public function getTriggerConfig(): array { return array('active' => $this->isActive()); } }