From e9dc663c0fc7604375c437337ddd35ac416deae8 Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Fri, 15 Nov 2024 08:59:50 -0700 Subject: [PATCH] Add random annotation set transform Signed-off-by: Justin Georgi --- includes/GlModelTransformOutput.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/includes/GlModelTransformOutput.php b/includes/GlModelTransformOutput.php index e91dd42..6d7167d 100644 --- a/includes/GlModelTransformOutput.php +++ b/includes/GlModelTransformOutput.php @@ -116,6 +116,18 @@ class GlModelTransformOutput extends MediaTransformOutput { //Apply any request transformations if ($this->transform) { + if (in_array('rand',$this->transform)) { + $subKey = array_search('rand',$this->transform); + $subs = is_numeric($this->transform[$subKey + 1]) ? $this->transform[$subKey + 1] : count($annotations); + $keys = array_keys($annotations); + shuffle($keys); + $keys = array_slice($keys, 0 , $subs); + $newAnnot = array(); + foreach ($keys as $key) { + $newAnnot[$key] = $annotations[$key]; + } + $annotations = $newAnnot; + } if (in_array('alpha',$this->transform)) { ksort($annotations); }