22
33namespace OCA \Workspace \Service \Formatter ;
44
5+ use OCA \Workspace \Service \Dto \WorkspaceDto ;
56use OCA \Workspace \Service \Group \GroupFormatter ;
67use OCA \Workspace \Service \Group \UserGroup ;
78use OCP \IGroupManager ;
@@ -20,25 +21,13 @@ public function __construct(
2021 /**
2122 * @param array $workspace
2223 * @param array $folderInfo
23- * @return array
24+ * @return WorkspaceDto
2425 */
25- public function format (array $ workspace , array $ folderInfo ): array {
26- $ space = [
27- 'id ' => $ workspace ['id ' ] ?? null ,
28- 'color ' => $ workspace ['color_code ' ] ?? null ,
29- 'groupfolderId ' => $ workspace ['groupfolder_id ' ] ?? null ,
30- 'isOpen ' => false ,
31- 'name ' => $ workspace ['name ' ] ?? null ,
32- 'quota ' => $ folderInfo ['quota ' ] ?? null ,
33- 'size ' => $ folderInfo ['size ' ] ?? null ,
34- 'managers ' => null ,
35- 'users ' => (object )[],
36- 'usersCount ' => self ::NO_USERS ,
37- ];
38-
26+ public function format (array $ workspace , array $ folderInfo ): WorkspaceDto {
3927 $ wsGroups = [];
4028 $ addedGroups = [];
4129 $ gids = array_keys ($ folderInfo ['groups ' ] ?? []);
30+ $ usersCount = self ::NO_USERS ;
4231
4332 foreach ($ gids as $ gid ) {
4433 $ group = $ this ->groupManager ->get ($ gid );
@@ -59,13 +48,23 @@ public function format(array $workspace, array $folderInfo): array {
5948 }
6049
6150 if (UserGroup::isWorkspaceUserGroupId ($ gid )) {
62- $ space [ ' usersCount ' ] = $ group ->count ();
51+ $ usersCount = $ group ->count ();
6352 }
6453 }
6554
66- $ space ['groups ' ] = GroupFormatter::formatGroups ($ wsGroups );
67- $ space ['added_groups ' ] = (object )GroupFormatter::formatGroups ($ addedGroups );
68-
69- return $ space ;
55+ return new WorkspaceDto (
56+ id: $ workspace ['id ' ] ?? null ,
57+ color: $ workspace ['color_code ' ] ?? null ,
58+ groupfolderId: $ workspace ['groupfolder_id ' ] ?? null ,
59+ isOpen: false ,
60+ name: $ workspace ['name ' ] ?? null ,
61+ quota: $ folderInfo ['quota ' ] ?? null ,
62+ size: $ folderInfo ['size ' ] ?? null ,
63+ managers: null ,
64+ users: (object )[],
65+ usersCount: $ usersCount ,
66+ groups: GroupFormatter::formatGroups ($ wsGroups ),
67+ addedGroups: (object )GroupFormatter::formatGroups ($ addedGroups )
68+ );
7069 }
7170}
0 commit comments