public function unSubscribe(UserInterface $user, UuidInterface $object)
 {
     $className = $this->getClassResolver()->resolveClassName('Notification\\Entity\\SubscriptionInterface');
     $criteria = ['user' => $user->getId(), 'object' => $object->getId()];
     $subscription = $this->getObjectManager()->getRepository($className)->findOneBy($criteria);
     if (is_object($subscription)) {
         $this->objectManager->remove($subscription);
     }
 }
Exemple #2
0
 /**
  * @return string
  */
 public function subMenuItem()
 {
     /* @var Partial */
     $partial = $this->getView()->plugin('partial');
     $template = $this->isSubscribed ? 'opt-out' : 'opt-in';
     return $partial('notification/subscription/' . $template . '/sub-menu-item', ['object' => $this->object->getId(), 'emailsActive' => $this->emailsActive]);
 }
 public function findMetadataByObjectAndKeyAndValue(UuidInterface $object, $key, $value)
 {
     if (!is_string($key)) {
         throw new Exception\InvalidArgumentException(sprintf('Expected parameter 2 to be string but got %s', gettype($key)));
     }
     if (!is_string($value)) {
         throw new Exception\InvalidArgumentException(sprintf('Expected parameter 3 to be string but got %s', gettype($value)));
     }
     $key = $this->findKeyByName($key);
     $className = $this->getClassResolver()->resolveClassName('Metadata\\Entity\\MetadataInterface');
     $criteria = ['object' => $object->getId(), 'key' => $key->getId(), 'value' => $value];
     $entity = $this->getObjectManager()->getRepository($className)->findOneBy($criteria);
     if (!is_object($entity)) {
         throw new Exception\MetadataNotFoundException(sprintf('Could not find metadata by object `%s`, key `%s` and value `%s`', $object->getId(), $key, $value));
     }
     return $entity;
 }
 public function findDiscussionsOn(UuidInterface $uuid, $archived = null)
 {
     $className = $this->getClassResolver()->resolveClassName($this->entityInterface);
     $objectRepository = $this->getObjectManager()->getRepository($className);
     $criteria = ['object' => $uuid->getId()];
     if ($archived !== null) {
         $criteria['archived'] = $archived;
     }
     $discussions = $objectRepository->findBy($criteria);
     foreach ($discussions as $discussion) {
         $this->assertGranted('discussion.get', $discussion);
     }
     $collection = new ArrayCollection($discussions);
     return $this->sortDiscussions($collection);
 }
Exemple #5
0
 public function getForm($type, UuidInterface $object, TaxonomyTermInterface $forum = null)
 {
     $view = $this->getView();
     $queries = ['query' => ['redirect' => $view->serverUrl(true)]];
     switch ($type) {
         case 'discussion':
             $form = clone $this->discussionForm;
             $form->setAttribute('action', $view->url('discussion/discussion/start', ['on' => $object->getId()], $queries));
             return $form;
             break;
         case 'comment':
             $form = clone $this->commentForm;
             $form->setAttribute('action', $view->url('discussion/discussion/comment', ['discussion' => $object->getId()], $queries));
             return $form;
             break;
         default:
             throw new RuntimeException();
     }
 }
 public function findAliasByObject(UuidInterface $uuid)
 {
     /* @var $entity Entity\AliasInterface */
     $criteria = ['uuid' => $uuid->getId()];
     $order = ['timestamp' => 'DESC'];
     $results = $this->getAliasRepository()->findBy($criteria, $order);
     $entity = current($results);
     if (!is_object($entity)) {
         throw new Exception\AliasNotFoundException();
     }
     return $entity;
 }