@@ -46,6 +46,7 @@ class Query
4646 // Order methods
4747 public const TYPE_ORDER_DESC = 'orderDesc ' ;
4848 public const TYPE_ORDER_ASC = 'orderAsc ' ;
49+ public const TYPE_ORDER_RANDOM = 'orderRandom ' ;
4950
5051 // Pagination methods
5152 public const TYPE_LIMIT = 'limit ' ;
@@ -93,6 +94,7 @@ class Query
9394 self ::TYPE_SELECT ,
9495 self ::TYPE_ORDER_DESC ,
9596 self ::TYPE_ORDER_ASC ,
97+ self ::TYPE_ORDER_RANDOM ,
9698 self ::TYPE_LIMIT ,
9799 self ::TYPE_OFFSET ,
98100 self ::TYPE_CURSOR_AFTER ,
@@ -247,6 +249,7 @@ public static function isMethod(string $value): bool
247249 self ::TYPE_NOT_SEARCH ,
248250 self ::TYPE_ORDER_ASC ,
249251 self ::TYPE_ORDER_DESC ,
252+ self ::TYPE_ORDER_RANDOM ,
250253 self ::TYPE_LIMIT ,
251254 self ::TYPE_OFFSET ,
252255 self ::TYPE_CURSOR_AFTER ,
@@ -600,6 +603,16 @@ public static function orderAsc(string $attribute = ''): self
600603 return new self (self ::TYPE_ORDER_ASC , $ attribute );
601604 }
602605
606+ /**
607+ * Helper method to create Query with orderRandom method
608+ *
609+ * @return Query
610+ */
611+ public static function orderRandom (): self
612+ {
613+ return new self (self ::TYPE_ORDER_RANDOM );
614+ }
615+
603616 /**
604617 * Helper method to create Query with limit method
605618 *
@@ -830,13 +843,16 @@ public static function groupByType(array $queries): array
830843 switch ($ method ) {
831844 case Query::TYPE_ORDER_ASC :
832845 case Query::TYPE_ORDER_DESC :
846+ case Query::TYPE_ORDER_RANDOM :
833847 if (!empty ($ attribute )) {
834848 $ orderAttributes [] = $ attribute ;
835849 }
836850
837- $ orderTypes [] = $ method === Query::TYPE_ORDER_ASC
838- ? Database::ORDER_ASC
839- : Database::ORDER_DESC ;
851+ $ orderTypes [] = match ($ method ) {
852+ Query::TYPE_ORDER_ASC => Database::ORDER_ASC ,
853+ Query::TYPE_ORDER_DESC => Database::ORDER_DESC ,
854+ Query::TYPE_ORDER_RANDOM => Database::ORDER_RANDOM ,
855+ };
840856
841857 break ;
842858 case Query::TYPE_LIMIT :
0 commit comments