/**
     * 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;
    }
 /**
  * @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);
 }
 /**
  * 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);
 }
 public function onReject(Event $e)
 {
     $revision = $e->getParam('revision');
     $repository = $e->getParam('repository');
     $instance = $repository->getInstance();
     $reason = $e->getParam('reason');
     $this->logEvent('entity/revision/reject', $instance, $revision, [['name' => 'repository', 'value' => $repository], ['name' => 'reason', 'value' => $reason]]);
 }
예제 #5
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);
 }
 public function onCreate(Event $e)
 {
     $entity = $e->getParam('entity');
     $data = $e->getParam('data');
     if (array_key_exists('taxonomy', $data)) {
         $options = $data['taxonomy'];
         $this->getTaxonomyManager()->associateWith($options['term'], $entity);
     }
 }
 /**
  * Gets executed on page create
  *
  * @param Event $e
  * @return void
  */
 public function onUpdate(Event $e)
 {
     /* @var $repository PageRepositoryInterface */
     $slug = $e->getParam('slug');
     $repository = $e->getParam('repository');
     $url = $e->getTarget()->url()->fromRoute('page/view', ['page' => $repository->getId()], null, null, false);
     $alias = $this->getAliasManager()->createAlias($url, $slug, $slug . '-' . $repository->getId(), $repository, $repository->getInstance());
     $this->getAliasManager()->flush($alias);
 }
 public function onDissociate(Event $e)
 {
     /* @var $term TaxonomyTermInterface */
     $term = $e->getParam('term');
     $object = $e->getParam('object');
     if ($object instanceof TaxonomyTermAwareInterface && $object instanceof UuidInterface) {
         $this->removeMetadata($object, $term);
     }
 }
예제 #9
0
 /**
  * @param Event $params
  */
 public function onCreateFile(Event $params)
 {
     $file = $params->getParam('file');
     if (!$file instanceof ImageInterface) {
         return;
     }
     $fileInfoArray = $params->getParam('fileInfoArray');
     list($width, $height) = getimagesize($fileInfoArray['tmp_name']);
     $file->setWidth($width)->setHeight($height);
 }
예제 #10
0
파일: Module.php 프로젝트: bb-drummer/Zcmf
 public function initializeView(Event $e)
 {
     $app = $e->getParam('application');
     $locator = $app->getLocator();
     $config = $e->getParam('modules')->getMergedConfig();
     $view = $this->getView($app, $config);
     $viewListener = $this->getViewListener($view, $config);
     $app->events()->attachAggregate($viewListener);
     $events = StaticEventManager::getInstance();
     $viewListener->registerStaticListeners($events, $locator);
 }
예제 #11
0
 /**
  * Perform an ACL check when a AuthorizedDirectObject is dispatched.
  *
  * @param \Zend\Mvc\MvcEvent $event
  * @return null|array
  */
 public function onDispatchDirect(Event $event)
 {
     $object = $event->getParam('object');
     $method = $event->getParam('rpc')->getMethod();
     // Check ACL
     if ($object instanceof \JaztecAcl\Direct\AuthorizedDirectObject) {
         if (!$object->checkAcl($method)) {
             $event->stopPropagation(true);
             return $object->notAllowed();
         }
     }
 }
예제 #12
0
 /**
  * @param Event $params
  */
 public function onCreateFile(Event $params)
 {
     /* @var $file FileInterface */
     $file = $params->getParam('file');
     $fileInfoArray = $params->getParam('fileInfoArray');
     $pathGenerator = $params->getParam('pathGenerator');
     $pathGenerator = $pathGenerator ? $this->normalizePathGenerator($pathGenerator) : $this->getDefaultPathGenerator();
     $path = $this->getPath($pathGenerator, $file);
     $folder = $this->getUploadFolderByPath($path);
     $file->setFolder($folder);
     $file->setBasename($fileInfoArray['name']);
 }
 public function onStartSubscribe(Event $e)
 {
     if (isset($e->getParam('data')['subscription'])) {
         $params = $e->getParam('data');
         $param = $params['subscription'];
         if ($param['subscribe'] === '1') {
             $user = $e->getParam('author');
             $discussion = $e->getParam('discussion');
             $notifyMailman = $param['mailman'] === '1' ? true : false;
             $this->subscribe($user, $discussion, $notifyMailman);
         }
     }
 }
 public function onCommitRevision(Event $e)
 {
     $repository = $e->getParam('repository');
     $data = $e->getParam('data');
     $user = $e->getParam('author');
     foreach ($data as $params) {
         if (is_array($params) && array_key_exists('subscription', $params)) {
             $param = $params['subscription'];
             if ($param['subscribe'] === '1') {
                 $notifyMailman = $param['mailman'] === '1' ? true : false;
                 $this->subscribe($user, $repository, $notifyMailman);
             }
         }
     }
 }
예제 #15
0
파일: Update.php 프로젝트: pi-module/event
 /**
  * {@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;
         }
     }
 }
 public function onInject(Event $e)
 {
     $object = $e->getParam('object');
     if ($object instanceof InstanceProviderInterface && $object instanceof UuidInterface) {
         $this->logEvent('license/object/set', $object->getInstance(), $object);
     }
 }
예제 #17
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;
     }
 }
예제 #18
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);
 }
 public function onUpdate(Event $e)
 {
     /* @var $term TaxonomyTermInterface */
     $term = $e->getParam('term');
     $instance = $term->getInstance();
     $this->logEvent('taxonomy/term/update', $instance, $term);
 }
예제 #20
0
 public function onTrash(Event $e)
 {
     $object = $e->getParam('object');
     $user = $this->getUserManager()->getUserFromAuthenticator();
     $instance = $this->getInstanceManager()->getInstanceFromRequest();
     $this->logEvent('uuid/trash', $instance, $object);
 }
 public function onCreate(Event $e)
 {
     $entity = $e->getParam('entity');
     $user = $this->getUserManager()->getUserFromAuthenticator();
     $instance = $this->getInstanceManager()->getInstanceFromRequest();
     $this->logEvent('entity/create', $instance, $entity);
 }
 public function menuItemForm(Event $e)
 {
     $data = $e->getParam('data');
     $model = $e->getParam('model');
     $form = $e->getParam('form');
     if (isset($data['menuId'])) {
         $menuId = $data['menuId'];
     } elseif ($model) {
         $menuId = $model->getMenuId();
     } elseif ($form) {
         $menuId = $form->get('menuId')->getValue();
     }
     if (isset($menuId)) {
         $form->get('position')->setMenuId($menuId);
     }
 }
예제 #23
0
파일: Install.php 프로젝트: Andyyang1981/pi
 /**
  * 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);
 }
예제 #24
0
파일: Update.php 프로젝트: Andyyang1981/pi
 /**
  * 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;
 }
예제 #25
0
파일: Update.php 프로젝트: pi-module/demo
 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__)));
 }
 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()]))));
 }
 /**
  * @param Event $e
  */
 public function generateIdentityToken(Event $e)
 {
     $user = $e->getParam('entity');
     if ($user instanceof IdentityExistAwareInterface && $user instanceof ActiveRecordInterface) {
         $user->generateIdentityExistToken();
         $user->save();
     }
 }
 public function setBusinessSlug(Event $e)
 {
     $data = $e->getParam('data');
     if (!$data['slug']) {
         $data['slug'] = $data['company'];
     }
     $e->setParam('data', $data);
 }
 /**
  * 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());
     }
 }
예제 #30
0
 /**
  * @param Event $e
  */
 public function edit(Event $e)
 {
     /* @var $model \UthandoCommon\Model\ModelInterface */
     $model = $e->getParam('model');
     if ($model->has('dateModified')) {
         $model->setDateModified();
     }
 }