Exemplo n.º 1
0
 /**
  * Determines if we're dealing with the required Resource
  * before dispatching to actions
  *
  * @param Event $e
  * @return mixed|void
  */
 public function dispatch(Event $e)
 {
     switch ($e->getName()) {
         case 'create.post':
         case 'update.post':
         case 'patch.post':
             /**
              * Redirect client to newly created resource
              */
             $controller = $e->getTarget();
             if ($controller instanceof ResourceController) {
                 $resource = $controller->getResource();
                 if ($resource instanceof Resource) {
                     $model = $e->getParam('resource');
                     if ($model instanceof ResourceJsonModel) {
                         $object = $model->getPayload();
                         if ($object instanceof BackendResourceInterface) {
                             $e->stopPropagation(true);
                             $response = $controller->redirect()->toRoute('api/default', array('resource' => $resource->getIdentifier(), 'id' => $object->getId()));
                             return $response;
                             //@TODO remove until fixed CORS redirect
                         }
                     }
                 }
             }
             break;
     }
 }
Exemplo n.º 2
0
 public function onBootstrap(Event $e)
 {
     $app = $e->getApplication();
     Utility::setSM($app->getServiceManager());
     TransactionUtility::setSM($app->getServiceManager());
     UnitCalcUtility::setSM($app->getServiceManager());
 }
 public function onUpdate(Event $e)
 {
     /* @var $term TaxonomyTermInterface */
     $term = $e->getParam('term');
     $instance = $term->getInstance();
     $this->logEvent('taxonomy/term/update', $instance, $term);
 }
Exemplo n.º 4
0
 /**
  * Initialize event listener
  * @param \Zend\EventManager\Event $e
  * @return void
  */
 public function initListener(Event $e)
 {
     $app = $e->getParam('application');
     $eventListener = new Listener();
     $eventListener->setServiceManager($app->getServiceManager());
     $app->getEventManager()->attachAggregate($eventListener);
 }
 /**
  * @param array|null $resource
  * @param Request    $request
  * @param Response   $response
  */
 public function __invoke(Event $event)
 {
     $resource = $event->getParam('resource');
     $response = $event->getParam('response');
     $body = $this->renderView($resource, $response);
     $response->setBody($body);
 }
 public function onDispatch(Event $event)
 {
     $controller = $event->getTarget();
     if (!$controller instanceof AbstractController) {
         return;
     }
     $entity = $controller->getEntity();
     if (!$entity) {
         return;
     }
     $terms = $entity->getTaxonomyTerms();
     if ($terms->isEmpty()) {
         foreach ($entity->getParents('link') as $parent) {
             $terms = $parent->getTaxonomyTerms();
             if (!$terms->isEmpty()) {
                 break;
             }
         }
     }
     $term = $this->strategy->findBranch($terms);
     if ($term) {
         /* @var $navigationFactory DefaultNavigationFactory */
         $navigationFactory = $controller->getServiceLocator()->get('Navigation\\Factory\\DefaultNavigationFactory');
         $params = ['term' => $term->getId(), 'controller' => 'Taxonomy\\Controller\\GetController', 'action' => 'index'];
         $routeMatch = new RouteMatch($params);
         $routeMatch->setMatchedRouteName('taxonomy/term/get');
         $navigationFactory->setRouteMatch($routeMatch);
     }
 }
Exemplo n.º 7
0
 /**
  * Add Client Id and Client Secret to Request Parameters
  *
  * @throws Exception\InvalidArgumentException
  */
 public function preSend(Event $e)
 {
     $this->request = $e->getTarget();
     $headers = $this->request->getHeaders();
     $params = array('Authorization' => 'OAuth ' . $this->getOauthString());
     $headers->addHeaders($params);
 }
 public function onCreate(Event $e)
 {
     $entity = $e->getParam('entity');
     $user = $this->getUserManager()->getUserFromAuthenticator();
     $instance = $this->getInstanceManager()->getInstanceFromRequest();
     $this->logEvent('entity/create', $instance, $entity);
 }
Exemplo n.º 9
0
 public function onBootstrap(Event $e)
 {
     $sm = $e->getApplication()->getServiceManager();
     $em = $sm->get('doctrine.entitymanager.orm_default');
     $vcard = $sm->get('vcard');
     $vcard->setEm($em);
 }
Exemplo n.º 10
0
 public function clearCache($id)
 {
     $event = new Event();
     $event->setParam('id', $id);
     $result = $this->getEventManager()->trigger('clear', $event);
     return $result->last();
 }
Exemplo n.º 11
0
 public function onTrash(Event $e)
 {
     $object = $e->getParam('object');
     $user = $this->getUserManager()->getUserFromAuthenticator();
     $instance = $this->getInstanceManager()->getInstanceFromRequest();
     $this->logEvent('uuid/trash', $instance, $object);
 }
Exemplo n.º 12
0
 public function onCancelSingle(Event $event)
 {
     $booking = $event->getTarget();
     $reservations = $this->reservationManager->getBy(['bid' => $booking->need('bid')], 'date ASC', 1);
     $reservation = current($reservations);
     $square = $this->squareManager->get($booking->need('sid'));
     $user = $this->userManager->get($booking->need('uid'));
     $dateRangerHelper = $this->dateRangeHelper;
     $reservationTimeStart = explode(':', $reservation->need('time_start'));
     $reservationTimeEnd = explode(':', $reservation->need('time_end'));
     $reservationStart = new \DateTime($reservation->need('date'));
     $reservationStart->setTime($reservationTimeStart[0], $reservationTimeStart[1]);
     $reservationEnd = new \DateTime($reservation->need('date'));
     $reservationEnd->setTime($reservationTimeEnd[0], $reservationTimeEnd[1]);
     $subject = sprintf($this->t('Your %s-booking has been cancelled'), $this->optionManager->get('subject.square.type'));
     $message = sprintf($this->t('we have just cancelled %s %s, %s for you.'), $this->optionManager->get('subject.square.type'), $square->need('name'), $dateRangerHelper($reservationStart, $reservationEnd));
     if ($user->getMeta('notification.bookings', 'true') == 'true') {
         $this->userMailService->send($user, $subject, $message);
     }
     if ($this->optionManager->get('client.contact.email.user-notifications')) {
         $backendSubject = sprintf($this->t('%s\'s %s-booking has been cancelled'), $user->need('alias'), $this->optionManager->get('subject.square.type'));
         $addendum = sprintf($this->t('Originally sent to %s (%s).'), $user->need('alias'), $user->need('email'));
         $this->backendMailService->send($backendSubject, $message, array(), $addendum);
     }
 }
Exemplo n.º 13
0
 public function testTriggerSetsTarget()
 {
     $event = new Event();
     $this->assertNull($event->getTarget());
     Reflection::invoke($this->sut, 'trigger', array($event));
     $this->assertSame($this->sut, $event->getTarget());
 }
Exemplo n.º 14
0
 /**
  * {@inheritDoc}
  */
 public function updateSchema(Event $e)
 {
     $moduleVersion = $e->getParam('version');
     // Set extra model
     $extraModel = Pi::model('extra', $this->module);
     $extraTable = $extraModel->getTable();
     $extraAdapter = $extraModel->getAdapter();
     // Set news story model
     $newsStoryModel = Pi::model('story', 'news');
     $newsStoryTable = $newsStoryModel->getTable();
     $newsStoryAdapter = $newsStoryModel->getAdapter();
     // Update to version 0.1.5
     if (version_compare($moduleVersion, '0.1.5', '<')) {
         // Update value
         $select = $extraModel->select();
         $rowSet = $extraModel->selectWith($select);
         foreach ($rowSet as $row) {
             // Set time
             $time = $row->time_end ? $row->time_end : $row->time_start;
             // Update time_publish
             $newsStoryModel->update(array('time_publish' => $time), array('id' => $row->id));
         }
     }
     // Update to version 0.4.1
     if (version_compare($moduleVersion, '0.4.1', '<')) {
         // Alter table field `register_discount`
         $sql = sprintf("ALTER TABLE %s ADD `register_discount` TEXT", $extraTable);
         try {
             $extraAdapter->query($sql, 'execute');
         } catch (\Exception $exception) {
             $this->setResult('db', array('status' => false, 'message' => 'Table alter query failed: ' . $exception->getMessage()));
             return false;
         }
     }
 }
Exemplo n.º 15
0
 /**
  * Check other modules and register comments if available
  *
  * @param Event $e
  * @return void
  */
 public function checkModules(Event $e)
 {
     $module = $e->getParam('module');
     $modules = Pi::registry('module')->read();
     if (isset($modules['comment'])) {
         unset($modules['comment']);
     }
     $moduleList = array_keys($modules);
     foreach ($moduleList as $mod) {
         $options = Pi::service('module')->loadMeta($mod, 'comment', true);
         if (empty($options)) {
             continue;
         }
         /*
         if (is_string($options)) {
             $optionsFile = sprintf(
                 '%s/%s/config/%s',
                 Pi::path('module'),
                 Pi::service('module')->directory($mod),
                 $options
             );
             $options = include $optionsFile;
             if (empty($options) || !is_array($options)) {
                 continue;
             }
         }
         */
         $resourceHandler = new CommentResource($options);
         $e->setParam('module', $mod);
         $resourceHandler->setEvent($e);
         $resourceHandler->installAction();
     }
     $e->setParam('module', $module);
 }
Exemplo n.º 16
0
 public function postUpdate(Event $e)
 {
     $model = Pi::model($module = $e->getParam('directory') . '/test');
     $data = array('message' => sprintf(__('The module is updated on %s'), date('Y-m-d H:i:s')));
     $model->insert($data);
     $this->setResult('post-update', array('status' => true, 'message' => sprintf('Called from %s', __METHOD__)));
 }
Exemplo n.º 17
0
 /**
  * Update module table schema
  *
  * @param Event $e
  *
  * @return bool
  */
 public function updateSchema(Event $e)
 {
     $moduleVersion = $e->getParam('version');
     $updator = new Schema\Updator110($this);
     $result = $updator->upgrade($moduleVersion);
     return $result;
 }
Exemplo n.º 18
0
    /**
     * Determine if the given entity is DB-connected, and, if so, recast to a DbConnectedRestServiceEntity
     *
     * @param  \Zend\EventManager\Event $e
     * @return null|DbConnectedRestServiceEntity
     */
    public static function onFetch($e)
    {
        $entity = $e->getParam('entity', false);
        if (!$entity) {
            // No entity; nothing to do
            return;
        }

        $config = $e->getParam('config', array());
        if (!isset($config['zf-apigility'])
            || !isset($config['zf-apigility']['db-connected'])
            || !isset($config['zf-apigility']['db-connected'][$entity->resourceClass])
        ) {
            // No DB-connected configuration for this service; nothing to do
            return;
        }
        $config = $config['zf-apigility']['db-connected'][$entity->resourceClass];

        if (!isset($config['table_service'])) {
            $config['table_service'] = sprintf('%s\\Table', $entity->resourceClass);
        }

        $dbConnectedEntity = new DbConnectedRestServiceEntity();
        $dbConnectedEntity->exchangeArray(array_merge($entity->getArrayCopy(), $config));

        // If no override resource class is present, remove it from the returned entity
        if ($e->getParam('fetch', true) && ! isset($config['resource_class'])) {
            $dbConnectedEntity->exchangeArray(array('resource_class' => null));
        }

        return $dbConnectedEntity;
    }
Exemplo n.º 19
0
 public function onBootstrap(Event $e)
 {
     $sm = $e->getApplication()->getServiceManager();
     $em = $sm->get('doctrine.entitymanager.orm_default');
     $geoname = $sm->get('geoname');
     $geoname->setEm($em)->registerCron();
 }
 /**
  * Gets executed on 'start'
  *
  * @param Event $e
  * @return void
  */
 public function onStart(Event $e)
 {
     $instance = $e->getParam('instance');
     $discussion = $e->getParam('discussion');
     $params = [['name' => 'on', 'value' => $e->getParam('on')]];
     $this->logEvent('discussion/create', $instance, $discussion, $params);
 }
Exemplo n.º 21
0
 public function checkUserExists(Event $e, $username)
 {
     $sm = $e->getTarget()->getServiceManager();
     $mapper = $sm->get('apiuser_user_mapper');
     $userObject = $mapper->findByUsername($username);
     return $userObject ? true : false;
 }
 public function onLoadModules(Event $e)
 {
     $moduleManager = $e->getTarget();
     $modules = $moduleManager->getModules();
     // Hier kommt die Superglobal $_ENV rein
     $moduleManager->setModules($modules);
 }
 public function onInject(Event $e)
 {
     $object = $e->getParam('object');
     if ($object instanceof InstanceProviderInterface && $object instanceof UuidInterface) {
         $this->logEvent('license/object/set', $object->getInstance(), $object);
     }
 }
Exemplo n.º 24
0
 /**
  * @param Event $e
  */
 public function edit(Event $e)
 {
     /* @var $model \UthandoCommon\Model\ModelInterface */
     $model = $e->getParam('model');
     if ($model->has('dateModified')) {
         $model->setDateModified();
     }
 }
 /**
  * @param Event $e
  */
 public function generateIdentityToken(Event $e)
 {
     $user = $e->getParam('entity');
     if ($user instanceof IdentityExistAwareInterface && $user instanceof ActiveRecordInterface) {
         $user->generateIdentityExistToken();
         $user->save();
     }
 }
 /**
  * Sets the query parameters to the paginator
  * 
  * @param Event $event Event
  * 
  * @return void
  */
 public function setData(Event $event)
 {
     $paginator = $event->getParam('paginator');
     if ($paginator instanceof Paginator) {
         $controller = $event->getTarget();
         $paginator->setData($controller->params()->fromQuery());
     }
 }
Exemplo n.º 27
0
 public function onBootstrap(Event $event)
 {
     $application = $event->getApplication();
     $serviceManager = $application->getServiceManager();
     $view = $serviceManager->get('view');
     $twigStrategy = $serviceManager->get('ViewTwigStrategy');
     $view->getEventManager()->attach($twigStrategy, 100);
 }
Exemplo n.º 28
0
 public function onUnLink(Event $e)
 {
     $entity = $e->getParam('entity');
     $user = $this->getUserManager()->getUserFromAuthenticator();
     $instance = $this->getInstanceManager()->getInstanceFromRequest();
     $params = [['name' => 'parent', 'value' => $e->getParam('parent')]];
     $this->logEvent('entity/link/remove', $instance, $entity, $params);
 }
 /**
  * @param Event $e
  * @throws \Instance\Exception\RuntimeException
  */
 public function onBypass(Event $e)
 {
     $target = $e->getTarget();
     if (!$target instanceof InstanceProviderInterface) {
         throw new Exception\RuntimeException(sprintf('Expected instance of InstanceProviderInterface but got %s.', is_object($target) ? get_class($target) : gettype($target)));
     }
     $this->instanceManager->switchInstance($target->getInstance());
 }
 public function onRenderEntity(EventManagerEvent $e)
 {
     $entity = $e->getParam('entity');
     if (!$entity->entity instanceof Pages) {
         return;
     }
     $entity->getLinks()->add(HalLink::factory(array('rel' => 'images', 'route' => array('name' => 'application.rest.images', 'params' => ['page_id' => $entity->entity->getUuid()]))));
 }