Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- json_decode() expects parameter 1 to be string
- public function actionUpdateVoteOnce(){
- $postdata = '[
- {"mobile": "145682796533",
- "answers" : [{"id" : "104", "is_mcq" : "1", "option" : "voteCount4", "freeText" : ""},
- {"id" : "105", "is_mcq" : "1", "option" : "voteCount4", "freeText" : ""},
- {"id" : "106", "is_mcq" : "1", "option" : "voteCount4", "freeText" : ""},
- {"id" : "109", "is_mcq" : "0", "option" : "", "freeText" : "Test loop 2"}]
- }]';
- $records = json_decode($postdata);
- $mobile = $records[0]->mobile;
- foreach ($records[0]->answers as $rec) {
- $is_mcq = $rec->{'is_mcq'};
- if ($is_mcq == 1){
- $id = $rec->{'id'};
- $ans = $rec->{'option'};
- $voteData = array();
- $record = Vote::model()->findByPk($id);
- if ($record) {
- $record->total = ($record->total) + 1;
- $record->$ans = ($record->$ans) + 1;
- $record->save();
- }
- array_push($voteData, $record);
- $outObj = array('success' => true, 'data' => $voteData, 'info' => 'Ok');
- echo CJSON::encode($outObj);
- } elseif($is_mcq == 0){
- $freeAns = $rec->{'freeText'};
- $id = $rec->{'id'};
- $rec = new VoteFreetoType;
- $rec->q_id = $id;
- $rec->answer = $freeAns;
- $rec->mobile = $mobile;
- $rec->date = date("Y-m-d H:i:s");
- $rec->save();
- $outObj = array('success' => true, 'info' => 'Ok');
- echo CJSON::encode($outObj);
- }
- }
- }
- $postdata= json_decode($_REQUEST);
Add Comment
Please, Sign In to add comment