/** * RPC routine to export statistics of a survey to a user. * Returns string - base64 encoding of the statistics. * * @access public * @param string $sSessionKey Auth credentials * @param int $iSurveyID Id of the Survey * @param string $docType Type of documents the exported statistics should be * @param string $sLanguage Optional language of the survey to use * @param string $graph Create graph option * @param int|array $groupIDs An OPTIONAL array (ot a single int) containing the groups we choose to generate statistics from * @return string Base64 encoded string with the statistics file */ public function export_statistics($sSessionKey, $iSurveyID, $docType = 'pdf', $sLanguage = null, $graph = '0', $groupIDs = null) { Yii::app()->loadHelper('admin/statistics'); $tempdir = Yii::app()->getConfig("tempdir"); if (!$this->_checkSessionKey($sSessionKey)) { return array('status' => 'Invalid session key'); } $oSurvey = Survey::model()->findByPk($iSurveyID); if (!isset($oSurvey)) { return array('status' => 'Error: Invalid survey ID'); } if (!Permission::model()->hasSurveyPermission($iSurveyID, 'statistics', 'read')) { return array('status' => 'Error: No Permission'); } $aAdditionalLanguages = array_filter(explode(" ", $oSurvey->additional_languages)); if (is_null($sLanguage) || !in_array($sLanguage, $aAdditionalLanguages)) { $sLanguage = $oSurvey->language; } $oAllQuestions = Question::model()->getQuestionList($iSurveyID, $sLanguage); if (!isset($oAllQuestions)) { return array('status' => 'No available data'); } if ($groupIDs != null) { if (is_int($groupIDs)) { $groupIDs = array($groupIDs); } if (is_array($groupIDs)) { //check that every value of the array belongs to the survey defined $aGroups = QuestionGroup::model()->findAllByAttributes(array('sid' => $iSurveyID)); foreach ($aGroups as $group) { $validGroups[] = $group['gid']; } $groupIDs = array_intersect($groupIDs, $validGroups); if (empty($groupIDs)) { return array('status' => 'Error: Invalid group ID'); } foreach ($oAllQuestions as $key => $aQuestion) { if (!in_array($aQuestion['gid'], $groupIDs)) { unset($oAllQuestions[$key]); } } } else { return array('status' => 'Error: Invalid group ID'); } } if (!isset($oAllQuestions)) { return array('status' => 'No available data'); } usort($oAllQuestions, 'groupOrderThenQuestionOrder'); $aSummary = createCompleteSGQA($iSurveyID, $oAllQuestions, $sLanguage); $helper = new statistics_helper(); switch ($docType) { case 'pdf': $sTempFile = $helper->generate_statistics($iSurveyID, $aSummary, $aSummary, $graph, $docType, 'F', $sLanguage); $sResult = file_get_contents($sTempFile); unlink($sTempFile); break; case 'xls': $sTempFile = $helper->generate_statistics($iSurveyID, $aSummary, $aSummary, '0', $docType, 'F', $sLanguage); $sResult = file_get_contents($sTempFile); unlink($sTempFile); break; case 'html': $sResult = $helper->generate_statistics($iSurveyID, $aSummary, $aSummary, '0', $docType, 'DD', $sLanguage); break; } return base64_encode($sResult); }
function actionAction($surveyid, $language = null) { $sLanguage = $language; ob_start(function ($buffer, $phase) { App()->getClientScript()->render($buffer); App()->getClientScript()->reset(); return $buffer; }); ob_implicit_flush(false); $iSurveyID = (int) $surveyid; //$postlang = returnglobal('lang'); Yii::import('application.libraries.admin.progressbar', true); Yii::app()->loadHelper("admin/statistics"); Yii::app()->loadHelper('database'); Yii::app()->loadHelper('surveytranslator'); App()->getClientScript()->registerPackage('jqueryui'); App()->getClientScript()->registerPackage('jquery-touch-punch'); App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "survey_runtime.js"); $data = array(); if (!isset($iSurveyID)) { $iSurveyID = returnGlobal('sid'); } else { $iSurveyID = (int) $iSurveyID; } if (!$iSurveyID) { //This next line ensures that the $iSurveyID value is never anything but a number. safeDie('You have to provide a valid survey ID.'); } if ($iSurveyID) { $actresult = Survey::model()->findAll('sid = :sid AND active = :active', array(':sid' => $iSurveyID, ':active' => 'Y')); //Checked if (count($actresult) == 0) { safeDie('You have to provide a valid survey ID.'); } else { $surveyinfo = getSurveyInfo($iSurveyID); // CHANGE JSW_NZ - let's get the survey title for display $thisSurveyTitle = $surveyinfo["name"]; // CHANGE JSW_NZ - let's get css from individual template.css - so define path $thisSurveyCssPath = getTemplateURL($surveyinfo["template"]); if ($surveyinfo['publicstatistics'] != 'Y') { safeDie('The public statistics for this survey are deactivated.'); } //check if graphs should be shown for this survey if ($surveyinfo['publicgraphs'] == 'Y') { $publicgraphs = 1; } else { $publicgraphs = 0; } } } //we collect all the output within this variable $statisticsoutput = ''; //for creating graphs we need some more scripts which are included here //True -> include //False -> forget about charts if (isset($publicgraphs) && $publicgraphs == 1) { require_once APPPATH . 'third_party/pchart/pchart/pChart.class'; require_once APPPATH . 'third_party/pchart/pchart/pData.class'; require_once APPPATH . 'third_party/pchart/pchart/pCache.class'; $MyCache = new pCache(Yii::app()->getConfig("tempdir") . DIRECTORY_SEPARATOR); //$currentuser is created as prefix for pchart files if (isset($_SERVER['REDIRECT_REMOTE_USER'])) { $currentuser = $_SERVER['REDIRECT_REMOTE_USER']; } else { if (session_id()) { $currentuser = substr(session_id(), 0, 15); } else { $currentuser = "******"; } } } // Set language for questions and labels to base language of this survey if ($sLanguage == null || !in_array($sLanguage, Survey::model()->findByPk($iSurveyID)->getAllLanguages())) { $sLanguage = Survey::model()->findByPk($iSurveyID)->language; } else { $sLanguage = sanitize_languagecode($sLanguage); } //set survey language for translations SetSurveyLanguage($iSurveyID, $sLanguage); //Create header sendCacheHeaders(); $condition = false; $sitename = Yii::app()->getConfig("sitename"); $data['surveylanguage'] = $sLanguage; $data['sitename'] = $sitename; $data['condition'] = $condition; $data['thisSurveyCssPath'] = $thisSurveyCssPath; /* * only show questions where question attribute "public_statistics" is set to "1" */ $query = "SELECT q.* , group_name, group_order FROM {{questions}} q, {{groups}} g, {{question_attributes}} qa\n WHERE g.gid = q.gid AND g.language = :lang1 AND q.language = :lang2 AND q.sid = :surveyid AND q.qid = qa.qid AND q.parent_qid = 0 AND qa.attribute = 'public_statistics'"; $databasetype = Yii::app()->db->getDriverName(); if ($databasetype == 'mssql' || $databasetype == "sqlsrv" || $databasetype == "dblib") { $query .= " AND CAST(CAST(qa.value as varchar) as int)='1'\n"; } else { $query .= " AND qa.value='1'\n"; } //execute query $result = Yii::app()->db->createCommand($query)->bindParam(":lang1", $sLanguage, PDO::PARAM_STR)->bindParam(":lang2", $sLanguage, PDO::PARAM_STR)->bindParam(":surveyid", $iSurveyID, PDO::PARAM_INT)->queryAll(); //store all the data in $rows $rows = $result; //SORT IN NATURAL ORDER! usort($rows, 'groupOrderThenQuestionOrder'); //put the question information into the filter array foreach ($rows as $row) { //store some column names in $filters array $filters[] = array($row['qid'], $row['gid'], $row['type'], $row['title'], $row['group_name'], flattenText($row['question'])); } //number of records for this survey $totalrecords = 0; //count number of answers $query = "SELECT count(*) FROM {{survey_" . intval($iSurveyID) . "}}"; //if incompleted answers should be filtert submitdate has to be not null //this setting is taken from config-defaults.php if (Yii::app()->getConfig("filterout_incomplete_answers") == true) { $query .= " WHERE {{survey_" . intval($iSurveyID) . "}}.submitdate is not null"; } $result = Yii::app()->db->createCommand($query)->queryAll(); //$totalrecords = total number of answers foreach ($result as $row) { $totalrecords = reset($row); } //this is the array which we need later... $summary = array(); //...while this is the array from copy/paste which we don't want to replace because this is a nasty source of error $allfields = array(); //---------- CREATE SGQA OF ALL QUESTIONS WHICH USE "PUBLIC_STATISTICS" ---------- /* * let's go through the filter array which contains * ['qid'], ['gid'], ['type'], ['title'], ['group_name'], ['question']; */ $currentgroup = ''; // use to check if there are any question with public statistics if (isset($filters)) { foreach ($filters as $flt) { //SGQ identifier $myfield = "{$iSurveyID}X{$flt[1]}X{$flt[0]}"; //let's switch through the question type for each question switch ($flt[2]) { case "K": // Multiple Numerical // Multiple Numerical case "Q": // Multiple Short Text //get answers $query = "SELECT title as code, question as answer FROM {{questions}} WHERE parent_qid=:flt_0 AND language = :lang ORDER BY question_order"; $result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $sLanguage, PDO::PARAM_STR)->queryAll(); //go through all the (multiple) answers foreach ($result as $row) { $myfield2 = $flt[2] . $myfield . reset($row); $allfields[] = $myfield2; } break; case "A": // ARRAY OF 5 POINT CHOICE QUESTIONS // ARRAY OF 5 POINT CHOICE QUESTIONS case "B": // ARRAY OF 10 POINT CHOICE QUESTIONS // ARRAY OF 10 POINT CHOICE QUESTIONS case "C": // ARRAY OF YES\No\gT("Uncertain") QUESTIONS // ARRAY OF YES\No\gT("Uncertain") QUESTIONS case "E": // ARRAY OF Increase/Same/Decrease QUESTIONS // ARRAY OF Increase/Same/Decrease QUESTIONS case "F": // FlEXIBLE ARRAY // FlEXIBLE ARRAY case "H": // ARRAY (By Column) //get answers $query = "SELECT title as code, question as answer FROM {{questions}} WHERE parent_qid=:flt_0 AND language = :lang ORDER BY question_order"; $result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $sLanguage, PDO::PARAM_STR)->queryAll(); //go through all the (multiple) answers foreach ($result as $row) { $myfield2 = $myfield . reset($row); $allfields[] = $myfield2; } break; // all "free text" types (T, U, S) get the same prefix ("T") // all "free text" types (T, U, S) get the same prefix ("T") case "T": // Long free text // Long free text case "U": // Huge free text // Huge free text case "S": // Short free text $myfield = "T{$myfield}"; $allfields[] = $myfield; break; case ";": //ARRAY (Multi Flex) (Text) //ARRAY (Multi Flex) (Text) case ":": //ARRAY (Multi Flex) (Numbers) $query = "SELECT title, question FROM {{questions}} WHERE parent_qid=:flt_0 AND language=:lang AND scale_id = 0 ORDER BY question_order"; $result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $sLanguage, PDO::PARAM_STR)->queryAll(); foreach ($result as $row) { $fquery = "SELECT * FROM {{questions}} WHERE parent_qid = :flt_0 AND language = :lang AND scale_id = 1 ORDER BY question_order, title"; $fresult = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $sLanguage, PDO::PARAM_STR)->queryAll(); foreach ($fresult as $frow) { $myfield2 = $myfield . reset($row) . "_" . $frow['title']; $allfields[] = $myfield2; } } break; case "R": //RANKING //get some answers $query = "SELECT code, answer FROM {{answers}} WHERE qid = :flt_0 AND language = :lang ORDER BY sortorder, answer"; $result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $sLanguage, PDO::PARAM_STR)->queryAll(); //get number of answers $count = count($result); //loop through all answers. if there are 3 items to rate there will be 3 statistics for ($i = 1; $i <= $count; $i++) { $myfield2 = "R" . $myfield . $i . "-" . strlen($i); $allfields[] = $myfield2; } break; //Boilerplate questions are only used to put some text between other questions -> no analysis needed //Boilerplate questions are only used to put some text between other questions -> no analysis needed case "X": //This is a boilerplate question and it has no business in this script break; case "1": // MULTI SCALE //get answers $query = "SELECT title, question FROM {{questions}} WHERE parent_qid = :flt_0 AND language = :lang ORDER BY question_order"; $result = Yii::app()->db->createCommand($query)->bindParam(":flt_0", $flt[0], PDO::PARAM_INT)->bindParam(":lang", $sLanguage, PDO::PARAM_STR)->queryAll(); //loop through answers foreach ($result as $row) { //----------------- LABEL 1 --------------------- $myfield2 = $myfield . $row['title'] . "#0"; $allfields[] = $myfield2; //----------------- LABEL 2 --------------------- $myfield2 = $myfield . $row['title'] . "#1"; $allfields[] = $myfield2; } //end WHILE -> loop through all answers break; case "P": //P - Multiple choice with comments //P - Multiple choice with comments case "M": //M - Multiple choice //M - Multiple choice case "N": //N - Numerical input //N - Numerical input case "D": //D - Date $myfield2 = $flt[2] . $myfield; $allfields[] = $myfield2; break; default: //Default settings $allfields[] = $myfield; break; } //end switch -> check question types and create filter forms } //end foreach -> loop through all questions with "public_statistics" enabled } // end if -> for removing the error message in case there are no filters $summary = $allfields; // Get the survey inforamtion $thissurvey = getSurveyInfo($surveyid, $sLanguage); //SET THE TEMPLATE DIRECTORY $data['sTemplatePath'] = $surveyinfo['template']; // surveyinfo=getSurveyInfo and if survey don't exist : stop before. //---------- CREATE STATISTICS ---------- $redata = compact(array_keys(get_defined_vars())); doHeader(); echo templatereplace(file_get_contents(getTemplatePath($data['sTemplatePath']) . DIRECTORY_SEPARATOR . "startpage.pstpl"), array(), $redata); //some progress bar stuff // Create progress bar which is shown while creating the results $prb = new ProgressBar(); $prb->pedding = 2; // Bar Pedding $prb->brd_color = "#404040 #dfdfdf #dfdfdf #404040"; // Bar Border Color $prb->setFrame(); // set ProgressBar Frame $prb->frame['left'] = 50; // Frame position from left $prb->frame['top'] = 80; // Frame position from top $prb->addLabel('text', 'txt1', gT("Please wait ...")); // add Text as Label 'txt1' and value 'Please wait' $prb->addLabel('percent', 'pct1'); // add Percent as Label 'pct1' $prb->addButton('btn1', gT('Go back'), '?action=statistics&sid=' . $iSurveyID); // add Button as Label 'btn1' and action '?restart=1' //progress bar starts with 35% $process_status = 35; $prb->show(); // show the ProgressBar // 1: Get list of questions with answers chosen //"Getting Questions and Answer ..." is shown above the bar $prb->setLabelValue('txt1', gT('Getting questions and answers ...')); $prb->moveStep(5); // creates array of post variable names for (reset($_POST); $key = key($_POST); next($_POST)) { $postvars[] = $key; } $data['thisSurveyTitle'] = $thisSurveyTitle; $data['totalrecords'] = $totalrecords; $data['summary'] = $summary; //show some main data at the beginnung // CHANGE JSW_NZ - let's allow html formatted questions to show //push progress bar from 35 to 40 $process_status = 40; //Show Summary results if (isset($summary) && $summary) { //"Generating Summaries ..." is shown above the progress bar $prb->setLabelValue('txt1', gT('Generating summaries ...')); $prb->moveStep($process_status); //let's run through the survey // Fixed bug 3053 with array_unique $runthrough = array_unique($summary); //loop through all selected questions foreach ($runthrough as $rt) { //update progress bar if ($process_status < 100) { $process_status++; } $prb->moveStep($process_status); } // end foreach -> loop through all questions $helper = new statistics_helper(); $statisticsoutput .= $helper->generate_statistics($iSurveyID, $summary, $summary, $publicgraphs, 'html', null, $sLanguage, false); } //end if -> show summary results $data['statisticsoutput'] = $statisticsoutput; //done! set progress bar to 100% if (isset($prb)) { $prb->setLabelValue('txt1', gT('Completed')); $prb->moveStep(100); $prb->hide(); } $redata = compact(array_keys(get_defined_vars())); $data['redata'] = $redata; Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . 'statistics_user.js'); $this->renderPartial('/statistics_user_view', $data); //output footer echo getFooter(); //Delete all Session Data Yii::app()->session['finished'] = true; }
/** * Returns a simple list of values in a particular column, that meet the requirements of the SQL */ function listcolumn($surveyid, $column, $sortby = "", $sortmethod = "", $sorttype = "") { Yii::app()->loadHelper('admin/statistics'); $helper = new statistics_helper(); $aData['data'] = $helper->_listcolumn($surveyid, $column, $sortby, $sortmethod, $sorttype); $aData['surveyid'] = $surveyid; $aData['column'] = $column; $aData['sortby'] = $sortby; $aData['sortmethod'] = $sortmethod; $aData['sorttype'] = $sorttype; App()->getClientScript()->reset(); $this->getController()->render('export/statistics_browse_view', $aData); }
/** * Render satistics for users */ public function simpleStatistics($surveyid) { $usegraph = 1; $iSurveyId = sanitize_int($surveyid); $aData['surveyid'] = $iSurveyId; $showcombinedresults = 0; $maxchars = 50; $statisticsoutput = ''; $cr_statisticsoutput = ''; // Set language for questions and answers to base language of this survey $language = Survey::model()->findByPk($surveyid)->language; $summary = array(); $summary[0] = "datestampE"; $summary[1] = "datestampG"; $summary[2] = "datestampL"; $summary[3] = "idG"; $summary[4] = "idL"; // 1: Get list of questions from survey $rows = Question::model()->getQuestionList($surveyid, $language); //SORT IN NATURAL ORDER! usort($rows, 'groupOrderThenQuestionOrder'); // The questions to display (all question) foreach ($rows as $row) { $type = $row['type']; if ($type == "T" || $type == "N") { $summary[] = $type . $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid']; } switch ($type) { // Double scale cases case ":": $qidattributes = getQuestionAttributeValues($row['qid']); if (!$qidattributes['input_boxes']) { $qid = $row['qid']; $results = Question::model()->getQuestionsForStatistics('*', "parent_qid='{$qid}' AND language = '{$language}' AND scale_id = 0", 'question_order, title'); $fresults = Question::model()->getQuestionsForStatistics('*', "parent_qid='{$qid}' AND language = '{$language}' AND scale_id = 1", 'question_order, title'); foreach ($results as $row1) { foreach ($fresults as $row2) { $summary[] = $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid'] . $row1['title'] . '_' . $row2['title']; } } } break; case "1": $qid = $row['qid']; $results = Question::model()->getQuestionsForStatistics('*', "parent_qid='{$qid}' AND language = '{$language}'", 'question_order, title'); foreach ($results as $row1) { $summary[] = $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid'] . $row1['title'] . '#0'; $summary[] = $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid'] . $row1['title'] . '#1'; } break; case "R": //RANKING $qid = $row['qid']; $results = Question::model()->getQuestionsForStatistics('title, question', "parent_qid='{$qid}' AND language = '{$language}'", 'question_order'); $count = count($results); //loop through all answers. if there are 3 items to rate there will be 3 statistics for ($i = 1; $i <= $count; $i++) { $summary[] = $type . $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid'] . '-' . $i; } break; // Cases with subquestions // Cases with subquestions case "A": case "F": // FlEXIBLE ARRAY // FlEXIBLE ARRAY case "H": // ARRAY (By Column) // ARRAY (By Column) case "E": case "B": case "C": //loop through all answers. if there are 3 items to rate there will be 3 statistics $qid = $row['qid']; $results = Question::model()->getQuestionsForStatistics('title, question', "parent_qid='{$qid}' AND language = '{$language}'", 'question_order'); foreach ($results as $row1) { $summary[] = $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid'] . $row1['title']; } break; // Cases with subanwsers, need a question type as first letter // Cases with subanwsers, need a question type as first letter case "P": //P - Multiple choice with comments //P - Multiple choice with comments case "M": //M - Multiple choice //M - Multiple choice case "S": $summary[] = $type . $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid']; break; // Not shown (else would only show 'no answer' ) // Not shown (else would only show 'no answer' ) case "K": case "*": case "D": case "T": // Long free text // Long free text case "U": // Huge free text // Huge free text case "|": // File Upload, we don't show it // File Upload, we don't show it case "N": case "Q": case ';': break; default: $summary[] = $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid']; break; } } // ----------------------------------- END FILTER FORM --------------------------------------- Yii::app()->loadHelper('admin/statistics'); $helper = new statistics_helper(); $showtextinline = isset($_POST['showtextinline']) ? 1 : 0; $aData['showtextinline'] = $showtextinline; //Show Summary results $aData['usegraph'] = $usegraph; $outputType = 'html'; $statlang = returnGlobal('statlang'); $statisticsoutput .= $helper->generate_simple_statistics($surveyid, $summary, $summary, $usegraph, $outputType, 'DD', $statlang); $aData['sStatisticsLanguage'] = $statlang; $aData['output'] = $statisticsoutput; $aData['summary'] = $summary; $aData['oStatisticsHelper'] = $helper; $aData['menu']['expertstats'] = true; //Call the javascript file App()->getClientScript()->registerScriptFile(App()->getAssetManager()->publish(ADMIN_SCRIPT_PATH . 'statistics.js')); App()->getClientScript()->registerScriptFile(App()->getAssetManager()->publish(ADMIN_SCRIPT_PATH . 'json-js/json2.min.js')); echo $this->_renderWrappedTemplate('export', 'statistics_user_view', $aData); }
/** * RPC routine to export statistics of a survey to a user. * Returns string - base64 encoding of the statistics. * * @access public * @param string $sSessionKey Auth credentials * @param int $iSurveyID Id of the Survey * @param string $docType Type of documents the exported statistics should be * @param string $sLanguage Optional language of the survey to use * @param string $graph Create graph option * @param int|array $groupIDs An OPTIONAL array (ot a single int) containing the groups we choose to generate statistics from * @return string Base64 encoded string with the statistics file */ public function export_statistics($sSessionKey, $iSurveyID, $docType = 'pdf', $sLanguage = null, $graph = '0', $groupIDs = null) { Yii::app()->loadHelper('admin/statistics'); $tempdir = Yii::app()->getConfig("tempdir"); if (!$this->_checkSessionKey($sSessionKey)) { return array('status' => 'Invalid session key'); } $oSurvey = Survey::model()->findByPk($iSurveyID); if (!isset($oSurvey)) { return array('status' => 'Error: Invalid survey ID'); } if (Survey::model()->findByPk($iSurveyID)->owner_id != $_SESSION['loginID']) { return array('status' => 'Error: No Permission'); } $aAdditionalLanguages = array_filter(explode(" ", $oSurvey->additional_languages)); if (is_null($sLanguage) || !in_array($sLanguage, $aAdditionalLanguages)) { $sLanguage = $oSurvey->language; } if ($groupIDs != null) { if (is_int($groupIDs)) { $groupIDs = array($groupIDs); } if (is_array($groupIDs)) { //check that every value of the array belongs to the survey defined $aGroups = Groups::model()->findAllByAttributes(array('sid' => $iSurveyID)); foreach ($aGroups as $group) { $validGroups[] = $group['gid']; } $groupIDs = array_intersect($groupIDs, $validGroups); if (empty($groupIDs)) { return array('status' => 'Error: Invalid group ID'); } //and then get all the questions for these groups $criteria = new CDbCriteria(); $criteria->addInCondition('gid', $groupIDs); $criteria->addCondition('sid = ' . $iSurveyID); $criteria->addCondition('parent_qid = 0'); $criteria->addCondition('language = :lang'); $criteria->params[':lang'] = $sLanguage; $oAllQuestions = Questions::model()->findAll($criteria); } else { return array('status' => 'Error: Invalid group ID'); } } else { $oAllQuestions = Questions::model()->findAllByAttributes(array('sid' => $iSurveyID, 'parent_qid' => '0', 'language' => $sLanguage)); } usort($oAllQuestions, 'groupOrderThenQuestionOrder'); $aSummary = createCompleteSGQA($iSurveyID, $oAllQuestions, $sLanguage); $helper = new statistics_helper(); switch ($docType) { case 'pdf': $sTempFile = $helper->generate_statistics($iSurveyID, $aSummary, $aSummary, $graph, $docType, 'F', $sLanguage); $sResult = file_get_contents($sTempFile); unlink($sTempFile); break; case 'xls': $sTempFile = $helper->generate_statistics($iSurveyID, $aSummary, $aSummary, '0', $docType, 'F', $sLanguage); $sResult = file_get_contents($sTempFile); unlink($sTempFile); break; case 'html': $sResult = $helper->generate_statistics($iSurveyID, $aSummary, $aSummary, '0', $docType, 'DD', $sLanguage); break; } return base64_encode($sResult); }
/** * Render satistics for users */ public function simpleStatistics($surveyid) { $iSurveyId = sanitize_int($surveyid); $aData['surveyid'] = $iSurveyId; $showcombinedresults = 0; $maxchars = 50; $statisticsoutput = ''; $cr_statisticsoutput = ''; // Set language for questions and answers to base language of this survey $language = Survey::model()->findByPk($surveyid)->language; $summary = array(); $summary[0] = "datestampE"; $summary[1] = "datestampG"; $summary[2] = "datestampL"; $summary[3] = "idG"; $summary[4] = "idL"; // 1: Get list of questions from survey $rows = Question::model()->getQuestionList($surveyid, $language); //SORT IN NATURAL ORDER! usort($rows, 'groupOrderThenQuestionOrder'); // The questions to display (all question) foreach ($rows as $row) { $type = $row['type']; if ($type == "M" || $type == "P" || $type == "T" || $type == "S" || $type == "Q" || $type == "R" || $type == "|" || $type == "" || $type == "N" || $type == "K" || $type == "D") { $summary[] = $type . $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid']; } else { $summary[] = $iSurveyId . 'X' . $row['gid'] . 'X' . $row['qid']; } } // ----------------------------------- END FILTER FORM --------------------------------------- Yii::app()->loadHelper('admin/statistics'); $helper = new statistics_helper(); $showtextinline = isset($_POST['showtextinline']) ? 1 : 0; $aData['showtextinline'] = $showtextinline; //Show Summary results $usegraph = 1; $aData['usegraph'] = $usegraph; $outputType = 'html'; $statlang = returnGlobal('statlang'); $statisticsoutput .= $helper->generate_simple_statistics($surveyid, $summary, $summary, $usegraph, $outputType, 'DD', $statlang); $aData['usegraph'] = 1; $aData['sStatisticsLanguage'] = $statlang; $aData['output'] = $statisticsoutput; $aData['summary'] = $summary; $aData['oStatisticsHelper'] = $helper; $aData['menu']['expertstats'] = true; //Call the javascript file App()->getClientScript()->registerScriptFile(App()->getAssetManager()->publish(ADMIN_SCRIPT_PATH . 'statistics.js')); App()->getClientScript()->registerScriptFile(App()->getAssetManager()->publish(ADMIN_SCRIPT_PATH . 'json-js/json2.min.js')); echo $this->_renderWrappedTemplate('export', 'statistics_user_view', $aData); }