try { $data =
$this->
Request()->
getParams();
if (empty($data['id'
])) { throw new NotFoundException('The emotion must exist before previewing it.'
);
} $data['previewId'
] =
$data['id'
];
$data['previewSecret'
] = Random::
getAlphanumericString(32
);
$data['active'
] = false;
$previewEmotion =
$this->
findPreviewEmotion((int) $data['id'
]);
if ($previewEmotion) { $previewEmotion->
getElements()->
clear();
$this->
getManager()->
flush($previewEmotion);
$data['id'
] =
$previewEmotion->
getId();
} else { unset($data['id'
]);
} $emotion =
$this->
saveEmotion($data);