protected function _category($from, $to, $action)
{
if ($action == self::ACT_CONVERT_TO_OBJECT) {
$to->category = !empty($from->catId) ? ['id' => $from->catId] : null;
} else {
if ($action == self::ACT_CONVERT_TO_ENTITY) {
$categoryId = ApiController::getBareId($from, 'category');
if (!empty($categoryId)) {
if (!is_numeric($categoryId)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid identifier of the category");
}
$to->catId = $categoryId;
} else {
$to->catId = null;
}
} else {
if ($action == self::ACT_GET_FILTER_CRITERIA) {
if (empty($from->category)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid identifier of the category");
}
return [['catId' => ApiController::getBareId($from, 'category')]];
}
}
}
}