@@ -653,6 +653,11 @@ public function create($parameters = null)
653653
654654 $ data ['categories ' ] = $ this ->member ->findOrFail (auth ()->user ()->id )->getNewTicketCategories ();
655655
656+ $ data ['a_notifications ' ] = [
657+ 'note ' => ($ data ['a_current ' ]['agent_id ' ] != auth ()->user ()->id ? [$ data ['a_current ' ]['agent_id ' ]] : []),
658+ 'reply ' => ($ data ['a_current ' ]['owner_id ' ] != auth ()->user ()->id ? [$ data ['a_current ' ]['owner_id ' ]] : [])
659+ ];
660+
656661 return view ('panichd::tickets.createedit ' , $ data );
657662 }
658663
@@ -676,8 +681,27 @@ public function edit($id, $parameters = null)
676681 $ data ['categories ' ] = $ this ->member ->findOrFail (auth ()->user ()->id )->getEditTicketCategories ();
677682
678683 $ member = $ this ->member ->find (auth ()->user ()->id );
679- $ data ['comments ' ] = $ ticket ->comments ()->forLevel ($ member ->levelInCategory ($ ticket ->category_id ))->orderBy ('id ' ,'desc ' )->paginate (Setting::grab ('paginate_items ' ));
680684
685+ // Ticket comments
686+ $ all_comments = $ ticket ->comments ();
687+ $ comments = clone $ all_comments ;
688+ $ data ['comments ' ] = $ comments ->forLevel ($ member ->levelInCategory ($ ticket ->category_id ))->orderBy ('id ' ,'desc ' )->paginate (Setting::grab ('paginate_items ' ));
689+
690+ // Default notification recipients
691+ $ all_c = clone $ all_comments ;
692+ $ a_reply = [(!is_null ($ ticket ->owner ) ? $ ticket ->owner ->id : $ ticket ->user_id )];
693+ $ a_note = [$ ticket ->agent ->id ];
694+ foreach ($ all_c ->get () as $ comm ){
695+ if ($ comm ->type == 'reply ' ){
696+ $ a_reply = array_merge ($ a_reply , $ comm ->notifications ->pluck ('member_id ' )->toArray ());
697+ }elseif ($ comm ->type == 'note ' ){
698+ $ a_note = array_merge ($ a_note , $ comm ->notifications ->pluck ('member_id ' )->toArray ());
699+ }
700+ }
701+ $ data ['a_notifications ' ] = [
702+ 'note ' => array_unique ($ a_note ),
703+ 'reply ' => array_unique ($ a_reply )
704+ ];
681705
682706 return view ('panichd::tickets.createedit ' , $ data );
683707 }
@@ -1250,12 +1274,34 @@ public function show($id)
12501274
12511275 $ agent_lists = $ this ->agentList ($ ticket ->category_id );
12521276
1253- $ comments = $ ticket ->comments ()->with ('notifications ' )->forLevel ($ member ->levelInCategory ($ ticket ->category_id ))->orderBy ('id ' ,'desc ' )->paginate (Setting::grab ('paginate_items ' ));
1277+ $ all_comments = $ ticket ->comments ()->with ('notifications ' )->forLevel ($ member ->levelInCategory ($ ticket ->category_id ));
1278+ $ comments = clone $ all_comments ;
1279+ $ comments = $ comments ->orderBy ('id ' ,'desc ' )->paginate (Setting::grab ('paginate_items ' ));
1280+
1281+ $ a_notifications = ['reply ' => [], 'note ' => []];
1282+
1283+ if ($ member ->currentLevel () > 1 && $ member ->canManageTicket ($ ticket ->id )){
1284+ $ all_c = clone $ all_comments ;
1285+ $ a_reply = [(!is_null ($ ticket ->owner ) ? $ ticket ->owner ->id : $ ticket ->user_id )];
1286+ $ a_note = [$ ticket ->agent ->id ];
1287+ foreach ($ all_c ->get () as $ comm ){
1288+ if ($ comm ->type == 'note ' ){
1289+ $ a_note = array_merge ($ a_note , $ comm ->notifications ->pluck ('member_id ' )->toArray ());
1290+ }elseif ($ comm ->type == 'reply ' ){
1291+ $ a_reply = array_merge ($ a_reply , $ comm ->notifications ->pluck ('member_id ' )->toArray ());
1292+ }
1293+ }
1294+
1295+ $ a_notifications = [
1296+ 'note ' => array_unique ($ a_note ),
1297+ 'reply ' => array_unique ($ a_reply )
1298+ ];
1299+ }
12541300
12551301 $ c_members = $ this ->members_collection ($ member , false );
12561302
12571303 $ data = compact ('ticket ' , 'a_reasons ' , 'a_tags_selected ' , 'status_lists ' , 'complete_status_list ' , 'agent_lists ' , 'tag_lists ' ,
1258- 'comments ' , 'c_members ' , 'close_perm ' , 'reopen_perm ' );
1304+ 'comments ' , 'a_notifications ' , ' c_members ' , 'close_perm ' , 'reopen_perm ' );
12591305 $ data ['menu ' ] = 'show ' ;
12601306 return view ('panichd::tickets.show ' , $ data );
12611307 }
0 commit comments