Plugin Directory

Changeset 1162710


Ignore:
Timestamp:
05/18/2015 02:00:59 PM (11 years ago)
Author:
awesome-ug
Message:

Beta 12

Location:
questions
Files:
97 added
4 edited

Legend:

Unmodified
Added
Removed
  • questions/trunk/README.txt

    r1162557 r1162710  
    6969== Changelog ==
    7070
     71= 1.0.0 beta 12 =
     72* Fixed exporting bug on exporting multiple choice fields results
     73* Enhanced code structure
     74
    7175= 1.0.0 beta 11 =
    7276* Added message on reaching PHP max_num_fields
  • questions/trunk/components/charts/data-abstraction.php

    r1162557 r1162710  
    3131 
    3232class Questions_AbstractData{
    33     /**
    34      * Initializes the Component.
    35      * @since 1.0.0
    36      */
    37     public function __construct() {
    38     } // end constructor
    39    
    4033   
    4134    /**
     
    4336     * @param array $response_array
    4437     * @return array $ordered_data
     38     * @since 1.0.0
    4539     */
    4640    public static function order_for_charting( $response_array ){
     41       
    4742        global $wpdb, $questions_global;
    4843       
     
    10095    }
    10196   
    102    
    103     public static function lines( $response_array ){
     97    /**
     98     * Prepare data for printing content in lines (e.g. for CSV export)
     99     * @param array $response_array Response array of a survey
     100     * @return array $lines Ordered data prepared to be used in lines
     101     * @since 1.0.0
     102     */
     103    public static function order_in_lines( $response_array ){
     104               
     105        // Only starting if there is any data       
    104106        if( is_array( $response_array ) ):
    105107           
    106             // Getting Headlines
     108            /**
     109             * Getting Headlines by running each element
     110             */
    107111            foreach( $response_array AS $question_id => $question ):
    108112               
    109                 if( $question[ 'sections' ] ):
     113                // If element uses sections
     114                if( array_key_exists( 'sections', $question ) && TRUE == $question[ 'sections' ]):
    110115                    foreach( $question[ 'responses' ] AS $response ):
    111116                        $i = 0;
     
    123128                        endforeach;
    124129                       
    125                         break;                 
    126                     endforeach;
    127 
    128                 elseif( $question[ 'array' ] ):
     130                        break;
     131                    endforeach;
     132               
     133                // If there are more answers than one posssible (e.g. Multiple Choice)
     134                elseif( array_key_exists( 'array', $question ) && TRUE == $question[ 'array' ] ):
     135                   
    129136                    foreach( $question[ 'responses' ] AS $response ):
    130137                        $i = 0;
     
    133140                            $lines[ 0 ][ $question_id . '-' . $i++ ] = self::filter_string( $column );
    134141                        endforeach;
    135                         break;                 
    136                     endforeach;
     142                        break;
     143                    endforeach;
     144                   
     145                // If there is only one value for one element possible
    137146                else:
    138147                    $lines[ 0 ][ $question_id ] = self::filter_string( $question[ 'question' ] );
     
    140149            endforeach;
    141150           
    142             // Getting Content
     151            /**
     152             * Getting content by running each element
     153             */
    143154            foreach( $response_array AS $question_id => $question ):
    144155               
    145                 if( $question[ 'sections' ] ):
     156                // If element uses sections
     157                if( array_key_exists( 'sections', $question ) && TRUE == $question[ 'sections' ] ):
     158                   
    146159                    foreach( $question[ 'responses' ] AS $response_id => $response ):
    147160                        $i = 0;
     
    158171                       
    159172                    endforeach;
    160                 elseif( $question[ 'array' ] ):
    161                     foreach( $question[ 'responses' ] AS $response ):
    162                         $i = 0;
     173                   
     174                // If there are more answers than one posssible (e.g. Multiple Choice)
     175                elseif( array_key_exists( 'array', $question ) && TRUE == $question[ 'array' ] ):
     176                   
     177                    // Running response of each user
     178                    foreach( $question[ 'responses' ] AS $response_id => $response ):
     179                        $i = 0;
     180                       
     181                        // Running each answer of response
    163182                        foreach( $response AS $key => $value ):
    164183                            $lines[ $response_id ][ $question_id . '-' . $i++ ] = self::filter_string( $value );
    165184                        endforeach;
    166                     endforeach;
     185                       
     186                    endforeach;
     187                   
     188                // If there is only one value for one element possible
    167189                else:
     190                   
    168191                    foreach( $question[ 'responses' ]  AS $response_id => $value ):
    169192                        $lines[ $response_id ][ $question_id ] = self::filter_string( $value );
    170193                    endforeach;
     194                   
    171195                endif;
    172196               
     
    179203    }
    180204
     205    /**
     206     * Filtering not wanted chars
     207     * @param string $string The string to filter
     208     * @return string $string The filtered string
     209     * @since 1.0.0
     210     */
    181211    public static function filter_string( $string ){
    182212        $string = utf8_decode( $string );
     
    190220    }
    191221   
     222    /**
     223     * Removing new lines
     224     * @param string $string The string to filter
     225     * @return string $string The filtered string
     226     * @since 1.0.0
     227     */
    192228    public static function remove_new_lines( $string ){
    193229        return trim( preg_replace( '/\s\s+/', ' ', $string ) );
  • questions/trunk/components/core/export.php

    r1128186 r1162710  
    3131 
    3232class Questions_Export{
     33   
    3334    /**
    3435     * Initializes the Component.
     
    4041    } // end constructor
    4142   
     43    /**
     44     * Add export link to the overview page
     45     * @param array $actions Actions links in an array
     46     * @param object $post Post object
     47     * @since 1.0.0
     48     */
    4249    function add_export_link( $actions, $post ){
    4350        if( 'questions' != $post->post_type )
     
    4956    }
    5057   
     58    /**
     59     * Start exporting by evaluating $_GET variables
     60     * @since 1.0.0
     61     */
    5162    function export(){
    5263        global $wpdb, $questions_global;
     
    5869            $survey = new Questions_Survey( $survey_id );
    5970            $export_filename = sanitize_title( $survey->title );
     71            $export_data = $survey->get_responses();
    6072           
    6173            header( "Pragma: public" );
     
    6678            switch( $export_type ){
    6779                case 'CSV':
    68                     $content = $this->get_csv( $survey->get_responses() );
     80                    $content = $this->get_csv( $export_data );
    6981                    $bytes = strlen( $content );
    7082                    $charset = 'UTF-8';
     
    8597        endif;
    8698    }
    87 
     99   
     100    /**
     101     * Getting CSV content
     102     * @param array $response_array Response array of a survey
     103     * @return string $output CSV content
     104     */
    88105    public function get_csv( $response_array ){
    89         $lines = Questions_AbstractData::lines( $response_array );
     106        $lines = Questions_AbstractData::order_in_lines( $response_array );
    90107       
    91108        // Running each question (element without separators etc)
  • questions/trunk/init.php

    r1162557 r1162710  
    44 * Plugin URI:   http://www.awesome.ug
    55 * Description:  Drag & drop your survey/poll with the WordPress Questions plugin.
    6  * Version:      1.0.0 beta 11
     6 * Version:      1.0.0 beta 12
    77 * Author:       awesome.ug
    88 * Author URI:   http://www.awesome.ug
     
    2222    /**
    2323     * Initializes the plugin.
    24      *
    2524     * @since 1.0.0
    2625     */
Note: See TracChangeset for help on using the changeset viewer.