/**
  * @param OnFlushEventArgs $event
  */
 public function onFlush(OnFlushEventArgs $event)
 {
     $em = $event->getEntityManager();
     $uow = $em->getUnitOfWork();
     foreach ($uow->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof User) {
             $userSettings = new UserSettings();
             $userSettings->setUser($entity);
             $em->persist($userSettings);
             $uow->computeChangeSet($em->getClassMetadata(UserSettings::clazz()), $userSettings);
         }
         if ($entity instanceof Group) {
             $groupSettings = new GroupSettings();
             $groupSettings->setGroup($entity);
             $em->persist($groupSettings);
             $uow->computeChangeSet($em->getClassMetadata(GroupSettings::clazz()), $groupSettings);
         }
     }
     foreach ($uow->getScheduledEntityDeletions() as $entity) {
         if ($entity instanceof User) {
             $query = $em->createQuery(sprintf('DELETE FROM %s us WHERE us.user = ?0', UserSettings::clazz()));
             $query->execute(array($entity));
         }
         if ($entity instanceof Group) {
             $query = $em->createQuery(sprintf('DELETE FROM %s us WHERE us.group = ?0', GroupSettings::clazz()));
             $query->execute(array($entity));
         }
     }
 }
 protected function getEntityClass()
 {
     return GroupSettings::clazz();
 }
 /**
  * @deprecated  Use DashboardManager class methods instead
  *
  * @return array
  */
 public function getUserDashboards()
 {
     /** @var EntityManager $em */
     $em = $this->container->get('doctrine.orm.entity_manager');
     /** @var User $user */
     $user = $this->container->get('security.token_storage')->getToken()->getUser();
     $settings = [];
     foreach ($user->getGroups() as $group) {
         /** @var GroupSettings $groupSettings */
         $groupSettings = $em->getRepository(GroupSettings::clazz())->findOneBy(array('group' => $group));
         if ($groupSettings) {
             $settings[] = $groupSettings->getDashboardSettings();
         }
     }
     /** @var UserSettings $userSettings */
     $userSettings = $em->getRepository(UserSettings::clazz())->findOneBy(array('user' => $user));
     if ($userSettings) {
         $settings[] = $userSettings->getDashboardSettings();
     }
     $dashboards = [];
     $defaults = [];
     foreach ($settings as $data) {
         $dashboards = array_merge($dashboards, $data['hasAccess']);
         if ($data['defaultDashboard']) {
             $defaults[] = $data['defaultDashboard'];
         }
     }
     if (!count($dashboards)) {
         $dashboards = [];
         $default = null;
     } else {
         $default = count($defaults) ? $defaults[count($defaults) - 1] : null;
     }
     return [$default, $dashboards];
 }