Forums / Developer / ezsurvey ext 'forgets' questions (because of php4.4/ez3.7??)

ezsurvey ext 'forgets' questions (because of php4.4/ez3.7??)

Author Message

Marin Orlic

Thursday 18 August 2005 4:15:46 pm

First to mention that I'm using ez 3.7 (because of php 4.4) - I'm not sure that ezsurvey extension is compatible with it (I'll check when I find the time).

What happens is - on a defined survey, all possible answers have the same text.. other fields are also duplicated (for instance if you have a question with 5 possible answers, they're all duplicated versions of the LAST ONE.. always). Survey was first defined on ez3.5 and then migrated to 3.7 and everything was fine for a while.. I can't edit the survey cause this keeps happening.

It works fine on ez 3.6.1, php 4.3.11, all the questions are commited to database properly.

For example,

<?xml version="1.0" encoding="UTF-8"?> 
 <options> 
   <option> 
     <label>abc</label> 
     <value>5</value> 
     <checked>0</checked> 
     <correct>0</correct> 
   </option> 
   <option> 
     <label>abc</label> 
     <value>5</value> 
     <checked>0</checked> 
     <correct>0</correct> 
   </option> 
   <option> 
     <label>abc</label> 
     <value>5</value> 
     <checked>0</checked> 
     <correct>0</correct> 
   </option> 
   <option> 
     <label>abc</label> 
     <value>5</value> 
     <checked>0</checked> 
     <correct>0</correct> 
   </option> 
   <option> 
     <label>abc</label> 
     <value>5</value> 
     <checked>0</checked> 
     <correct>0</correct> 
   </option> 
 </options>

is what can be found in the db.. The extension doesn't allow duplicate values within one question (when editing survey).

How can I check php4.4 compatibility, I got no errors concerning the extension, only parts of eZ (standard PHP Notice: Only variable references should be returned by reference...)

Siniša Šehović

Friday 27 January 2006 6:57:25 am

Hi Marin :-)

Did you find any solution for this problem?

S.

---
If at first you don't succeed, look in the trash for the instructions.

Kristof Coomans

Friday 27 January 2006 9:04:29 am

You will have to take a look at the code where the XML gets generated. I've solved similar problems with some datatypes. For a little article about how I did that, see http://blog.coomanskristof.be/2005/12/23/enhancedselection-fix-for-php-44/.

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Kristof Coomans

Saturday 28 January 2006 2:44:58 am

Try out the following modifications, I think it should work then with PHP 4.4.x (eZ publish 3.7.x):

In <i>modules/survey/classes/ezsurveymultiplechoice.php</i>, replace the method encodeXMLOptions of the eZSurveyMultipleChoice class with the following code:

    function encodeXMLOptions()
    {
        $doc = new eZDOMDocument();
        $root =& $doc->createElementNode( "options" );
        $doc->setRoot( $root );
        
        $options = array();
        $optionLabel = array();
        $optionValue = array();
        $optionChecked = array();
        
        foreach ( $this->Options as $i => $optionArray )
        {
            $options[$i] =& $doc->createElementNode( "option" );
            $optionLabel[$i] =& $doc->createElementNode( "label" );
            $optionLabel[$i]->appendChild( $doc->createTextNode( $optionArray['label'] ) );
            $options[$i]->appendChild( $optionLabel[$i] );

            $optionValue[$i] =& $doc->createElementNode( "value" );
            $optionValue[$i]->appendChild( $doc->createTextNode( $optionArray['value'] ) );
            $options[$i]->appendChild( $optionValue[$i] );

            $optionChecked[$i] =& $doc->createElementNode( "checked" );
            $optionChecked[$i]->appendChild( $doc->createTextNode( $optionArray['checked'] ) );
            $options[$i]->appendChild( $optionChecked[$i] );

            $root->appendChild( $options[$i] );
        }
        $this->Text2 =& $doc->toString();
    }

In <i>modules/survey/classes/ezsurveyreceiver.php</i>, replace the method encodeXMLOptions of the eZSurveyReceiver class with the following code:

    function encodeXMLOptions()
    {
        $doc = new eZDOMDocument();
        $root =& $doc->createElementNode( "options" );
        $doc->setRoot( $root );

        $options = array();
        $optionLabel = array();
        $optionValue = array();
        $optionChecked = array();
        
        foreach ( $this->Options as $i => $optionArray )
        {
            $options[$i] =& $doc->createElementNode( "option" );
            $optionLabel[$i] =& $doc->createElementNode( "label" );
            $optionLabel[$i]->appendChild( $doc->createTextNode( $optionArray['label'] ) );
            $options[$i]->appendChild( $optionLabel[$i] );

            $optionValue[$i] =& $doc->createElementNode( "email" );
            $optionValue[$i]->appendChild( $doc->createTextNode( $optionArray['value'] ) );
            $options[$i]->appendChild( $optionValue[$i] );

            $optionChecked[$i] =& $doc->createElementNode( "checked" );
            $optionChecked[$i]->appendChild( $doc->createTextNode( $optionArray['checked'] ) );
            $options[$i]->appendChild( $optionChecked[$i] );

            $root->appendChild( $options[$i] );
        }
        $this->Text2 =& $doc->toString();
    }

Good luck!

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Siniša Šehović

Monday 30 January 2006 12:59:18 am

Hi Kristof

Thanx for your help!!!

Now ezsurvey works as it should.

Best regards,
S.

---
If at first you don't succeed, look in the trash for the instructions.

Kristof Coomans

Monday 30 January 2006 1:11:17 am

You're welcome! ;-)

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org