public function _trigger($from, $to, $action)
{
switch ($action) {
case static::ACT_CONVERT_TO_OBJECT:
/* @var $from OrchestrationRule */
switch ($from->eventName) {
case '*':
$to->trigger = ['triggerType' => static::TRIGGER_ALL_EVENTS];
break;
default:
$to->trigger = ['triggerType' => static::TRIGGER_SINGLE_EVENT, 'event' => ['id' => $from->eventName]];
break;
}
break;
case static::ACT_CONVERT_TO_ENTITY:
/* @var $to OrchestrationRule */
if (empty($from->trigger->triggerType)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed trigger type");
}
switch ($from->trigger->triggerType) {
case static::TRIGGER_ALL_EVENTS:
$to->eventName = '*';
break;
case static::TRIGGER_SINGLE_EVENT:
if (!($event = ApiController::getBareId($from->trigger, 'event'))) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property trigger:id");
}
$to->eventName = $event;
break;
default:
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Unexpected trigger type");
}
break;
case static::ACT_GET_FILTER_CRITERIA:
return [['eventName' => $from->trigger]];
}
}