55use Doctrine \ORM \Event \LifecycleEventArgs ;
66use Hackzilla \Bundle \TicketBundle \Entity \Ticket ;
77use Hackzilla \Bundle \TicketBundle \Entity \TicketMessage ;
8- use Symfony \Component \DependencyInjection \ContainerInterface ;
98
109class UserLoad
1110{
12- protected $ container ;
11+ protected $ userRepository ;
1312
14- public function __construct (ContainerInterface $ container )
13+ public function __construct ($ userRepository )
1514 {
16- $ this ->container = $ container ;
15+ $ this ->userRepository = $ userRepository ;
1716 }
1817
1918 public function getSubscribedEvents ()
@@ -26,18 +25,18 @@ public function getSubscribedEvents()
2625 public function postLoad (LifecycleEventArgs $ args )
2726 {
2827 $ entity = $ args ->getEntity ();
29- $ userManager = $ this -> container -> get ( ' hackzilla_ticket.user_manager ' );
28+ $ userRepository = $ args -> getEntityManager ()-> getRepository ( $ this -> userRepository );
3029
3130 if ($ entity instanceof Ticket) {
3231 if (\is_null ($ entity ->getUserCreatedObject ())) {
33- $ entity ->setUserCreated ($ userManager -> getUserById ($ entity ->getUserCreated ()));
32+ $ entity ->setUserCreated ($ userRepository -> find ($ entity ->getUserCreated ()));
3433 }
3534 if (\is_null ($ entity ->getLastUserObject ())) {
36- $ entity ->setLastUser ($ userManager -> getUserById ($ entity ->getLastUser ()));
35+ $ entity ->setLastUser ($ userRepository -> find ($ entity ->getLastUser ()));
3736 }
3837 } elseif ($ entity instanceof TicketMessage) {
3938 if (\is_null ($ entity ->getUserObject ())) {
40- $ entity ->setUser ($ userManager -> getUserById ($ entity ->getUser ()));
39+ $ entity ->setUser ($ userRepository -> find ($ entity ->getUser ()));
4140 }
4241 }
4342 }
0 commit comments