Provides wrapper methods for symfony's GenericEvent.
/** * Receives notifications of points events. * * @param GenericEvent $event * @return void */ public function update(GenericEvent $event) { $params = $event->getArguments(); $method = str_replace('.', '_', $event->getName()); $this->{$method}($params); $this->em->flush(); }
/** * Trigger actions on Classified event * * @param ClassifiedsEvent $event */ public function onClassifiedEvent(GenericEvent $event) { $params = $event->getArguments(); $announcement = $params['announcement']; if (isset($announcement)) { foreach ($params as $key => $value) { switch ($key) { case 'notification': $this->adsService->sendNotificationEmail($value[0], $value[1], $announcement); break; case 'status': if ($value) { $this->adsService->activateClassified($announcement); } else { $this->adsService->deactivateClassified($announcement); } $this->cacheService->clearNamespace('announcements'); break; case 'contact': $this->adsService->sendMessageToAuthor($announcement, $value); break; default: break; } } } }
public function remove(GenericEvent $event) { if ($event->getArgument('plugin_name') != 'newscoop/meteoblue-plugin-bundle') { return; } $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em); $tool->dropSchema($this->getClasses(), true); }
/** * Update community ticker * * @param GenericEvent $event * @return void */ public function update(GenericEvent $event) { $params = $event->getArguments(); $user = array_key_exists('user', $params) ? $params['user'] : null; unset($params['user']); $this->getRepository()->save(new CommunityTickerEvent(), array('event' => $event->getName(), 'user' => $user, 'params' => $params)); $this->em->flush(); }
public function testUpdate() { $this->em->expects($this->once())->method('getRepository')->with($this->equalTo('Newscoop\\Entity\\Events\\CommunityTickerEvent'))->will($this->returnValue($this->repository)); $this->em->expects($this->once())->method('flush')->with(); $this->repository->expects($this->once())->method('save')->with(); $event = new GenericEvent($this, array('user' => 1, 'params' => array('title' => 'Test'))); $event->setName('event.test'); $this->service->update($event); }
public function testUpdate() { $this->repository->expects($this->once())->method('save')->with($this->isInstanceOf('Newscoop\\Entity\\AuditEvent'), $this->contains('test')); $this->em->expects($this->once())->method('getRepository')->with($this->equalTo('Newscoop\\Entity\\AuditEvent'))->will($this->returnValue($this->repository)); $this->em->expects($this->once())->method('flush')->with(); $event = new GenericEvent($this); $event->setName('event.test'); $this->service->update($event); }
/** * Update audit * * @param GenericEvent $event * @return void */ public function update(GenericEvent $event) { list($resource, $action) = explode('.', $event->getName()); $user = isset($event['user']) ? $event['user'] : $this->userService->getCurrentUser(); $params = $event->getArguments(); $auditEvent = new AuditEvent(); $values = array('user' => $user, 'action' => $action, 'resource_id' => !empty($params['id']) ? $params['id'] : null, 'resource_type' => $resource, 'resource_diff' => !empty($params['diff']) ? $params['diff'] : null, 'resource_title' => !empty($params['title']) ? $params['title'] : null); $this->em->getRepository('Newscoop\\Entity\\AuditEvent')->save($auditEvent, $values); $this->em->flush(); }
/** * Handles delete event for articles. Unlink article from entry and * unpublishes entry. * * @param Newscoop\EventDispatcher\Events\GenericEvent $event */ public function delete(GenericEvent $event) { $eventCaller = $event->getSubject(); $arguments = $event->getArguments(); if ($eventCaller instanceof \Article) { $entry = $this->em->getRepository('Newscoop\\IngestPluginBundle\\Entity\\Feed\\Entry')->findOneByArticleId($eventCaller->getArticleNumber()); if ($entry !== null) { $entry->setArticleId(NULL); $entry->setPublished(NULL); $this->em->persist($entry); $this->em->flush(); } } }
/** * Receives notifications of points events. * * @param GenericEvent $event * @return void */ public function update(GenericEvent $event) { $params = $event->getArguments(); $action = str_replace('.', '_', $event->getName()); $user = $params['user']; if (is_int($user)) { $user_repo = $this->em->getRepository('Newscoop\\Entity\\User'); $user = $user_repo->find($user); } if (empty($user)) { return; } $points = $user->getPoints(); $points_action = $this->getRepository()->getPointValueForAction($action); $user->setPoints($points + $points_action); $this->em->flush(); }
/** * Receives notifications of points events. * * @param GenericEvent $event * @return void */ public function update(GenericEvent $event) { $params = $event->getArguments(); $attribute_name = str_replace(".", "_", $event->getName()); $user = $params['user']; if (is_int($user)) { $user_repo = $this->em->getRepository('Newscoop\\Entity\\User'); $user = $user_repo->find($user); } if (empty($user)) { return; } $attribute_value = $user->getAttribute($attribute_name); $attribute_value = isset($attribute_value) ? $attribute_value + 1 : 1; $user->addAttribute($attribute_name, $attribute_value); $this->em->flush(); }
/** * Sends an emails with the informations about expiring * subscription. * * @param GenericEvent $event */ public function sendSubscriptionExpirationEmail(GenericEvent $event) { $subscription = $event->getSubject(); $this->sendValidatedNotification(Emails::SUBSCRIPTION_EXPIRATION, $subscription); if (!$subscription->getNotifySentLevelOne()) { $this->notificationsService->setSentDateTimeOnLevelOne($subscription); } else { $this->notificationsService->setSentDateTimeOnLevelTwo($subscription); } }
/** * Receives notifications of points events. * * @param GenericEvent $event * * @return void */ public function update(GenericEvent $event) { $params = $event->getArguments(); $method = str_replace('.', '_', $event->getName()); $this->{$method}($params); $this->em->flush(); $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache'); $cacheService->clearNamespace('comment'); }