/** * Updates default setting or creates new setting for the user * * @param string $option Option * @param string|int $value Value * @param User $user User * * @return void */ private function updateOrCreateSetting($option, $value, $user) { $qb = $this->em->createQueryBuilder(); $setting = $qb->select('s')->from('Newscoop\\EditorBundle\\Entity\\Settings', 's')->where($qb->expr()->isNull('s.user'))->andWhere('s.option = :option')->setParameter('option', $option)->getQuery()->getOneOrNullResult(); if ($setting && $setting->getIsGlobal()) { $setting->setValue($value); return; } $setting = new Settings(); $setting->setOption($option); $setting->setValue($value); $setting->setUser($user); $this->em->persist($setting); }
/** * Setting up new default settings, when isGlobal is set to true for given setting, * there will be the possibility to change this setting for all users. * * @param array $settings Array of settings * @param bool $isGlobal If edit settings for all users */ private function setUpSettings($settings, $isGlobal = false) { $qb = $this->em->createQueryBuilder(); foreach ($settings as $option => $value) { $setting = $this->em->getRepository('Newscoop\\EditorBundle\\Entity\\Settings')->createQueryBuilder('s')->select('s')->where($qb->expr()->isNull('s.user'))->andWhere('s.option = :option')->setParameter('option', $option)->getQuery()->getOneOrNullResult(); if (!$setting) { $setting = new Settings(); $setting->setOption($option); $setting->setValue($value); $setting->setUser(null); $setting->setIsGlobal($isGlobal); $this->em->persist($setting); } else { $setting->setValue($value); } } $this->em->flush(); }