+ /**
+ * {@inheritdoc}
+ */
+ public function getRoles(): array {
+ //Get the unique roles list by id
+ return array_unique(array_reduce(
+ //Cast groups as array
+ $this->groups->toArray(),
+ //Reduce to an array of id => group tuples
+ function ($array, $group) {
+ $array[$group->getId()] = $group->getRole();
+ return $array;
+ },
+ //Init with empty array
+ //XXX: on registration, add each group present in rapsys_user.default.group array to user
+ //XXX: see vendor/rapsys/userbundle/Controller/DefaultController.php +450
+ []
+ ));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRole(): ?string {
+ //Retrieve roles
+ $roles = $this->getRoles();
+
+ //With roles array empty
+ if ($roles === []) {
+ //Return null
+ return null;
+ }
+
+ //Return the role with max id
+ //XXX: should be rewriten if it change in your configuration
+ return $roles[array_reduce(
+ array_keys($roles),
+ function($cur, $id) {
+ if ($cur === null || $id > $cur) {
+ return $id;
+ }
+ return $cur;
+ },
+ null
+ )];