Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter preetee

    (@preetee)

    Dear all,

    I have managed to retrieve my data via the following, hope this help someone

    <?php
    class WpProQuiz_Controller_Participant extends WpProQuiz_Controller_Controller {
    
    public function route() {
    
    		$quizId = $_GET['id'];
    		$action = isset($_GET['action']) ? $_GET['action'] : 'showParticipantlist';
    		$this->showParticipantlist($quizId);		
    
    	}
    
     public static function showParticipantlist($quizId) {
       $obj = new WpProQuiz_Model_Participant();
       $view = new WpProQuiz_View_Participant();
       $items = array();
       $participantlist = $obj->fetchparicipantlist($quizId);
      $participantlist=json_decode($participantlist,true);
    
        $member=array();
       foreach ($participantlist  as $data) {
    	   	foreach ($data  as $key=>$value) {
    	   	 	if($key=='registrationtime'){
    	   	 		$value=WpProQuiz_Helper_Until::convertTime($value,'Y/m/d g:i A');
    	   	 		$member['Date']=$value;
    	   			}	
    
                if($key=='form_data')
                 {
    
                 $formData=str_replace("{",'',$value);
                 $formData=str_replace("}",'',$formData);
    
                  $formData=explode(',',$formData);
                 //echo "<pre>" , print_r( $formData) , "</pre>";
                   for($i=0;$i<=count($formData);$i++){
              	 foreach ($formData as $key => $value) {
    
                    $value=strstr($value, ":");            
    
                    $data=explode(" ",$value);
    
                    	 if($key==0)
                    		$member['Surname']=str_replace(":",'',$value);
                    	 if($key==1)
    	                 	$member['Name']=str_replace(":",'',$value);
    	                 if($key==2)
    	                	$member['Nationality']=str_replace(":",'',$value);
    	                 if($key==3)
    	                 	$member['Email address']=str_replace(":",'',$value);
    
                    }
    
                   }
                }
                if($key=='score'){
                	$member['score']=$value;
                } 
    
           }
            foreach ($member as $key => $value) {
     echo $key .'=>'. $value.'<br/>';
     }
    
          }     
    
        }
    
    }
    
    ?>
    Thread Starter preetee

    (@preetee)

    Dear all,

    I was able to retrieve the list of all participants with their respective score and date of participation with the following query

    SELECT  create_time  AS registrationtime, form_data, user_id, SUM( points ) AS score
    FROM <code>wp_wp_pro_quiz_statistic_ref</code> AS ref
    LEFT JOIN <code>wp_wp_pro_quiz_statistic</code> AS stat ON ref.statistic_ref_id = stat.statistic_ref_id
    WHERE quiz_id =3
    GROUP BY ref.statistic_ref_id
    ORDER BY create_time ASC

    RESULT OF THE QUERY

    registrationtime  |  form_data  | user_id | score
    1383642471  {"9":"sds","10":"sds","11":"sds","12":"[email protected]	1 	2
    1383642491  {"9":"re","10":"test","11":"test1","12":"[email protected]	1 	6
    
    1383642410  {"9":"steeds","10":"sdrsrss","11":"sereds","12":"[email protected]	1 	4

    In the following class WpProQuiz_Model_Participant it return an array

    <?php
    class WpProQuiz_Model_Participant extends WpProQuiz_Model_Mapper {
    
        public function fetchparicipantlist($quizId) {
    
    		$r = array();
    
    		$results = $this->_wpdb->get_results(
    			$this->_wpdb->prepare(
    				"SELECT
    				 	create_time AS registrationtime,
    
    				    form_data,user_id,SUM(points) as score
    				 FROM
    				 	{$this->_tableStatisticRef} AS ref
                     LEFT JOIN
                     	 wp_wp_pro_quiz_statistic AS stat
                     ON ref.statistic_ref_id = stat.statistic_ref_id
    				 WHERE
    				 	quiz_id = %d
    				 GROUP BY ref.statistic_ref_id
    				 ORDER BY
    				 	create_time ASC
    				 "
    			, $quizId)
    		, ARRAY_A);
    
    		return json_encode($results);

    In my controller

    <?php
    class WpProQuiz_Controller_Participant extends WpProQuiz_Controller_Controller
    {
    
        public function route()
        {
    
            $quizId = $_GET['id'];
            $action = isset($_GET['action']) ? $_GET['action'] : 'showParticipantlist';
            $this->showParticipantlist($quizId);
    
        }
    
        public static function showParticipantlist($quizId)
        {
    
            $obj             = new WpProQuiz_Model_Participant();
            $view            = new WpProQuiz_View_Participant();
            $items           = array();
            $participantlist = $obj->fetchparicipantlist($quizId);
            $participantlist = json_decode($participantlist, true);
    
            $member = array();
            foreach ($participantlist as $data) {
                foreach ($data as $key => $value) {
                    echo "
    <pre>", print_r($data), "</pre>
    ";
                    if ($key == 'registrationtime') {
                        $value          = WpProQuiz_Helper_Until::convertTime($value, 'Y/m/d g:i A');
                        $member['Date'] = $value;
                    }
    
                    if ($key == 'form_data') {
    
                        $formData = str_replace("{", '', $value);
                        $formData = str_replace("}", '', $formData);
                         $formData = explode(',',$formData);
                        foreach ($formData as $key => $value) {
                            $formvalues = explode(':', $value);
                            foreach ($formvalues as $key => $value) {
    
                                if ($key == 0)
                                    unset($formvalues[$value]);
    
                                else {
                                    $member['Surname']       = $value;
                                    $member['Name']          = $value;
                                    $member['Nationality']   = $value;
                                    $member['Email address'] = $value;
                                  //  echo "
    <pre>", print_r($member, 1), "</pre>
    ";
                                }
    
                            }
    
                        }
                    }
    
                }
    
            }
    
        }
    
    }
    
    ?>

    Am unable to store the values for each participant form values in the member array

    I need to export these data in excel format
    EXCEL SHEET format

    Date of registration|surname|name|nationality|Email address|score

    Thanks for kind help and response

    Thread Starter preetee

    (@preetee)

    Dear Wisecapt

    Good news i resolved the issue..was turning crazy..but i think madness turns to bring buld of light on my head ??

    To resolve this issue
    I have change add GROUP BY sf.statistic_ref_id in the class file
    named WpProQuiz_Model_StatisticRefMapper in the following function

    public function fetchByRefId($refIdUserId, $quizId, $avg = FALSE) {
    		$where = $avg ? 'sf.user_id = %d' : 'sf.statistic_ref_id = %d';
    		$results = $this->_wpdb->get_results(
    			$this->_wpdb->prepare(
    				"SELECT
    					sf.*,
    					MIN(sf.create_time) AS min_create_time,
    					MAX(sf.create_time) AS max_create_time
    				FROM
    					{$this->_tableStatisticRef} AS sf
    				WHERE
    					{$where} AND sf.quiz_id = %d
                    GROUP BY sf.statistic_ref_id"
    			, $refIdUserId, $quizId)
    		, ARRAY_A);
    
    		foreach ($results as $row) {
    			$row['form_data'] = $row['form_data'] === null ? null : @json_decode($row['form_data'], true);
    
    			return  new WpProQuiz_Model_StatisticRefModel($row);
    		}
    	}

    Let’s me know about your feedback.
    Take care

    Thread Starter preetee

    (@preetee)

    Dear Wisecapt,

    Thank you for replying back.:)
    In fact the issue is due the version of mysql version on production server which is 5.0.45 .
    The php version on production server 5.2.4

    On local development side, the script is working perfectly with mysql version 5.5.24 and php version 5.4.3.
    When i tried to switch with php version 5.2.4 on locally it works
    then i switch with mysql version 5.0.45 locally as well, then i got the same 500 Internal error .

    In my firebug,

    POST

    Parametersapplication/x-www-form-urlencoded
    action	wp_pro_quiz_admin_ajax
    data[avg]	0
    data[quizId]	2
    data[refId]	9
    data[userId]	0
    func	statisticLoadUser
    Source
    action=wp_pro_quiz_admin_ajax&func=statisticLoadUser&data%5BquizId%5D=2&data%5BuserId%5D=0&data%5BrefId%5D=9&data%5Bavg%5D=0

    RESPONSE

    <div id='error'>
    			<p class='wpdberror'><strong>WordPress database error:</strong> [Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause]<br />
    			<code>SELECT
    					sf.*,
    					MIN(sf.create_time) AS min_create_time,
    					MAX(sf.create_time) AS max_create_time
    				FROM
    					wp_wp_pro_quiz_statistic_ref AS sf
    				WHERE
    					sf.statistic_ref_id = 9 AND sf.quiz_id = 2</code></p>
    			</div><br />
    <b>Fatal error</b>:  Call to a member function getUserId() on a non-object in <b>C:\wamp\www\test\wp-content\plugins\wp-pro-quiz\lib\controller\WpProQuiz_Controller_Statistics.php</b> on line <b>701</b><br />

    Thank you for you kind help.

    Thread Starter preetee

    (@preetee)

    Dear Wisecapt,

    Where is the get_userdata found in??

    In the statistic controller,function ajaxLoadStatisticUser there is this line
    $userInfo = get_userdata($view->statisticModel->getUserId());
    am wondering where is the implementation of this method as it take in as parameter the userid.

    Is this causing the 500 error message? O.o..

    Thank you once again for response

    Thread Starter preetee

    (@preetee)

    Dear Wisecapt,

    I have look into the article and tried to find who whether there is a script error or permission issues causing this issue. Unfortunately i can’t find.

    I even maximise php memory as some people to resolve,but in vain.:(

    This is driving nut and i need to deliver this work by friday .Would really grateful to get some shared information on how to resolve this issue.

    Thank you for responding back

    Thread Starter preetee

    (@preetee)

    You must deactivate the autostart option O.o simply so that invalid messages dont show up even before clicking on the start quiz button for register user form

Viewing 7 replies - 1 through 7 (of 7 total)