예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     $sql = 'DELETE FROM UserNotificationSettings';
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $conn = $app['phraseanet.appbox']->get_connection();
     $sql = 'SELECT * FROM usr_settings
             WHERE prop LIKE "notification_%"';
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $n = 0;
     $em = $app['EM'];
     foreach ($rs as $row) {
         if (null === ($user = $this->loadUser($app['EM'], $row['usr_id']))) {
             continue;
         }
         $userSetting = new UserNotificationSetting();
         $userSetting->setName($row['prop']);
         $userSetting->setValue($row['value']);
         $userSetting->setUser($user);
         $em->persist($userSetting);
         $n++;
         if ($n % 200 === 0) {
             $em->flush();
             $em->clear();
         }
     }
     $em->flush();
     $em->clear();
     return true;
 }
예제 #2
0
 /**
  * Sets a notification setting for a user.
  *
  * @param User   $user
  * @param string $name
  * @param string $value
  */
 public function setNotificationSetting(User $user, $name, $value)
 {
     if ($user->getNotificationSettings()->containsKey($name)) {
         $user->getNotificationSettings()->get($name)->setValue((bool) $value);
     } else {
         $userSetting = new UserNotificationSetting();
         $userSetting->setUser($user);
         $userSetting->setName($name);
         $userSetting->setValue($value);
         $user->addNotificationSettings($userSetting);
     }
     $this->manager->update($user);
 }
 /**
  * {@inheritDoc}
  */
 public function setValue($value)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setValue', array($value));
     return parent::setValue($value);
 }