Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-17992

eZ Survey needs post completion hook

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Obsolete
    • Icon: Medium Medium
    • None
    • 4.4.0
    • None

    Description

      We have clients wanting to inject eZ Survey result information into external services. There is no suitable hook in eZ Survey to perform this operation except for in the mail template. Even then, the available variables are limited; for example, you don't have access to the ezsurveyresult ID if you want to queue injections to external services (using ezpending_actions). Here is a simple framework to support any number of post completion operations based on any of the information available after completing a survey.

      1. extension/ezsurvey/datatypes/ezsurvey/ezsurveytype.php
      ~ Line 417 after $survey->executeBeforeLastRedirect

      /* Start hook code for performing additional operations */
      $surveyINI = eZINI::instance( 'ezsurvey.ini' );
      $surveyCompletionHandlers = $surveyINI->variable( 'SurveyHooks', 'SurveyCompletionHandlers' );
      if( !empty( $surveyCompletionHandlers ) )
      {
          foreach( $surveyCompletionHandlers as $surveyCompletionHandler )
          {
              // Load handler
              if( class_exists( $surveyCompletionHandler ) )
              {
                  $impl = new $surveyCompletionHandler();
                  $impl->executeBeforeSurveyCompletion( $result, $survey, $node, $contentobjectAttributeID );
              }
          }
      }
      /* End hook code for performing additional operations */
      

      2. extension/ezsurvey/settings/ezsurvey.ini.append.php

      # SurveyCompletionHandlers must have the function executeBeforeSurveyCompletion( $result, $survey, $node, $contentobjectAttributeID );
      # [SurveyHooks]
      # SurveyCompletionHandlers[]=ExampleCompletionHandlerClass
      

      3. Then, in your own extension:

      extension/generic/settings/ezsurvey.ini.append.php
      [SurveyHooks]
      SurveyCompletionHandlers[]=GenericeZSurveyCompletionHandler

      4. extension/generic/classes/genericezsurveycompletionhandler.php:

      class GenericeZSurveyCompletionHandler
      {
          public static function executeBeforeSurveyCompletion( $result, $survey, $node, $contentobjectAttributeID )
          {
              // Run all code here
              
              // Some test code just to verify that your code is being run:
              $log = new eZLog();
              $log->write( 'Survey completion fired!', 'survey_completion.log' );
              
              return true;
          }
      }
      

      Attachments

        Activity

          People

            unknown unknown
            3427b0be-ab4e-4614-8af1-1719f7f23944@accounts.ibexa.co Peter Keung
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: