diff --git a/README.md b/README.md index c8d4e04..d6681c6 100644 --- a/README.md +++ b/README.md @@ -1 +1,138 @@ # NotificationBundle + +## Information + +The bundle provides a facility to generate notifications (email, database, flash) in Symfony projects. + +## How to use + - Step 1 : Create an entity which extends our Notification model (might be optionnal) + - Step 2 : Create factory class which implements NotificationFactoryInterface which will create Notification + - Step 3 : Create some notification rules (see: "Configuration Reference") + +### Step 1 : +Create an entity which extends our Notification model (might be optionnal) +```php +users = new ArrayCollection(); + } +} +``` +### Step 2 : +Create factory class which implements NotificationFactoryInterface which will create Notification +```php +nrc = $nrc; + $this->trc = $trc; + $this->em = $em; + $this->twig = $twig; + $this->translator = $translator; + } + + /** + * @param NotificationEvent $event + * @param array $rule + */ + public function create(NotificationEvent $event, array $rule) + { + $entity = $event->getEntity(); + $parameters = $event->getParameters(); + $templateResolver = $this->trc->getResolver($rule['template_resolver']); + $template = $templateResolver->resolve($entity, $rule); + + if($template) + { + $content = $this->twig->render($template, array( + 'entity' => $entity, + 'parameters' => $parameters + )); + + /*Resolver users to notify*/ + $resolver = $this->nrc->getResolver($rule['resolver']); + $users = $resolver->resolve($entity, array('someOptionnalData' => 'data')); + + $notification + ->setTargetClass(ClassUtils::getClass($entity)) + ->setTargetId($entity->getId()) + ->setContent($content) + ->setUsers($users) + ; + + $this->em->persist($notification); + $this->em->flush(); + } + } +} +``` +## Configuration Reference + +```php +numerique1_notification: + factory_class: Acme\NotificationBundle\Factory\NotificationFactory + notification_class: Acme\NotificationBundle\Entity\Notification + notifications: + acme: + class: Acme\UserBundle\Entity\User + rules: + - { + event: 'numerique1.notification.event.entity_post_update', + route: 'Acme\UserBundle\Controller\UserController::updateUserAction', #Default: '*' + template: 'AcmeUserBundle:Notification:update.html.twig', #Default: false + template_resolver: 'numerique1_notification.default_template_resolver' #Default / resolve template + resolver: 'numerique1_notification.default_users_resolver' #Default / resolve users which will be notify + } + +```