@@ -42,11 +42,117 @@ public function format($subject, array $change_set): ?string
4242
4343 case IAuditStrategy::EVENT_ENTITY_DELETION :
4444 return sprintf ("Attendee (%s) '%s' deleted by user %s " , $ id , $ name , $ this ->getUserInfo ());
45+
46+ case IAuditStrategy::EVENT_COLLECTION_UPDATE :
47+ return $ this ->formatCollectionUpdate ($ subject , $ change_set , $ id , $ name );
48+
49+ case IAuditStrategy::EVENT_MANYTOMANY_ASSOCIATION_UPDATE :
50+ $ is_deletion = $ change_set ['is_deletion ' ] ?? false ;
51+ if ($ is_deletion ) {
52+ return $ this ->formatManyToManyDelete ($ subject , $ change_set , $ id , $ name );
53+ } else {
54+ return $ this ->formatManyToManyUpdate ($ subject , $ change_set , $ id , $ name );
55+ }
4556 }
4657 } catch (\Exception $ ex ) {
4758 Log::warning ("SummitAttendeeAuditLogFormatter error: " . $ ex ->getMessage ());
4859 }
4960
5061 return null ;
5162 }
63+
64+ private function formatManyToManyUpdate (SummitAttendee $ subject , array $ change_set , $ id , $ name ): ?string
65+ {
66+ try {
67+ $ field = $ change_set ['field ' ] ?? 'unknown ' ;
68+ $ targetEntity = $ change_set ['target_entity ' ] ?? 'unknown ' ;
69+ $ added_ids = $ change_set ['added_ids ' ] ?? [];
70+
71+ $ ownerId = $ subject ->getId ();
72+
73+ $ description = sprintf (
74+ " Attendee (%s), Field: %s, Target: %s, Added IDs: %s, by user %s " ,
75+ $ ownerId ,
76+ $ field ,
77+ class_basename ($ targetEntity ),
78+ json_encode ($ added_ids ),
79+ $ this ->getUserInfo ()
80+ );
81+
82+ return $ description ;
83+
84+ } catch (\Exception $ ex ) {
85+ Log::warning ("SummitAttendeeAuditLogFormatter::formatManyToManyUpdate error: " . $ ex ->getMessage ());
86+ return sprintf ("Attendee (%s) '%s' association updated by user %s " , $ id , $ name , $ this ->getUserInfo ());
87+ }
88+ }
89+
90+ private function formatManyToManyDelete (SummitAttendee $ subject , array $ change_set , $ id , $ name ): ?string
91+ {
92+ try {
93+ $ field = $ change_set ['field ' ] ?? 'unknown ' ;
94+ $ targetEntity = $ change_set ['target_entity ' ] ?? 'unknown ' ;
95+ $ removed_ids = $ change_set ['removed_ids ' ] ?? $ change_set ['added_ids ' ] ?? [];
96+
97+ $ description = sprintf (
98+ "Attendee Delete: Field: %s, Target: %s, Cleared IDs: %s, by user %s " ,
99+ $ field ,
100+ class_basename ($ targetEntity ),
101+ json_encode ($ removed_ids ),
102+ $ this ->getUserInfo ()
103+ );
104+
105+ return $ description ;
106+
107+ } catch (\Exception $ ex ) {
108+ Log::warning ("SummitAttendeeAuditLogFormatter::formatManyToManyDelete error: " . $ ex ->getMessage ());
109+ return sprintf ("Attendee (%s) '%s' association deleted by user %s " , $ id , $ name , $ this ->getUserInfo ());
110+ }
111+ }
112+
113+
114+ private function formatCollectionUpdate (SummitAttendee $ subject , array $ change_set , $ id , $ name ): ?string
115+ {
116+ try {
117+ $ details = [];
118+
119+ if (!empty ($ change_set ['tags ' ])) {
120+ $ tags_info = $ change_set ['tags ' ];
121+
122+ $ added = $ tags_info ['added ' ] ?? [];
123+ $ removed = $ tags_info ['removed ' ] ?? [];
124+
125+ $ added_names = array_map (function ($ tag ) {
126+ return $ tag ->getTag () ?? $ tag ->getId ();
127+ }, $ added );
128+
129+ $ removed_names = array_map (function ($ tag ) {
130+ return $ tag ->getTag () ?? $ tag ->getId ();
131+ }, $ removed );
132+
133+ if (!empty ($ added_names )) {
134+ $ details [] = "added tags: [ " . implode (", " , $ added_names ) . "] " ;
135+ }
136+ if (!empty ($ removed_names )) {
137+ $ details [] = "removed tags: [ " . implode (", " , $ removed_names ) . "] " ;
138+ }
139+ }
140+
141+ if (empty ($ details )) {
142+ return sprintf ("Attendee (%s) '%s' collection updated by user %s " , $ id , $ name , $ this ->getUserInfo ());
143+ }
144+
145+ return sprintf (
146+ "Attendee (%s) '%s' tags updated: %s by user %s " ,
147+ $ id ,
148+ $ name ,
149+ implode (", " , $ details ),
150+ $ this ->getUserInfo ()
151+ );
152+
153+ } catch (\Exception $ ex ) {
154+ Log::warning ("SummitAttendeeAuditLogFormatter::formatCollectionUpdate error: " . $ ex ->getMessage ());
155+ return sprintf ("Attendee (%s) '%s' collection updated by user %s " , $ id , $ name , $ this ->getUserInfo ());
156+ }
157+ }
52158}
0 commit comments