本文整理汇总了PHP中QuestionAttribute::model方法的典型用法代码示例。如果您正苦于以下问题:PHP QuestionAttribute::model方法的具体用法?PHP QuestionAttribute::model怎么用?PHP QuestionAttribute::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QuestionAttribute
的用法示例。
在下文中一共展示了QuestionAttribute::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Database::index()
*
* @param mixed $sa
* @return
*/
function index($sa = null)
{
$sAction = Yii::app()->request->getPost('action');
$iSurveyID = isset($_POST['sid']) ? $_POST['sid'] : returnGlobal('sid');
$iQuestionGroupID = returnGlobal('gid');
$iQuestionID = returnGlobal('qid');
// TODO: This variable seems to be never set or used in any function call?
$sDBOutput = '';
$oFixCKeditor = new LSYii_Validators();
$oFixCKeditor->fixCKeditor = true;
$oFixCKeditor->xssfilter = false;
if ($sAction == "updatedefaultvalues" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
$aSurveyLanguages = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
array_unshift($aSurveyLanguages, $sBaseLanguage);
Question::model()->updateAll(array('same_default' => Yii::app()->request->getPost('samedefault') ? 1 : 0), 'sid=:sid ANd qid=:qid', array(':sid' => $iSurveyID, ':qid' => $iQuestionID));
$arQuestion = Question::model()->findByAttributes(array('qid' => $iQuestionID));
$sQuestionType = $arQuestion['type'];
$aQuestionTypeList = getQuestionTypeList('', 'array');
if ($aQuestionTypeList[$sQuestionType]['answerscales'] > 0 && $aQuestionTypeList[$sQuestionType]['subquestions'] == 0) {
for ($iScaleID = 0; $iScaleID < $aQuestionTypeList[$sQuestionType]['answerscales']; $iScaleID++) {
foreach ($aSurveyLanguages as $sLanguage) {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage))) {
$this->_updateDefaultValues($iQuestionID, 0, $iScaleID, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage), true);
}
if (!is_null(Yii::app()->request->getPost('other_' . $iScaleID . '_' . $sLanguage))) {
$this->_updateDefaultValues($iQuestionID, 0, $iScaleID, 'other', $sLanguage, Yii::app()->request->getPost('other_' . $iScaleID . '_' . $sLanguage), true);
}
}
}
}
if ($aQuestionTypeList[$sQuestionType]['subquestions'] > 0) {
foreach ($aSurveyLanguages as $sLanguage) {
$arQuestions = Question::model()->findAllByAttributes(array('sid' => $iSurveyID, 'gid' => $iQuestionGroupID, 'parent_qid' => $iQuestionID, 'language' => $sLanguage, 'scale_id' => 0));
for ($iScaleID = 0; $iScaleID < $aQuestionTypeList[$sQuestionType]['subquestions']; $iScaleID++) {
foreach ($arQuestions as $aSubquestionrow) {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage . '_' . $aSubquestionrow['qid']))) {
$this->_updateDefaultValues($iQuestionID, $aSubquestionrow['qid'], $iScaleID, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage . '_' . $aSubquestionrow['qid']), true);
}
}
}
}
}
if ($aQuestionTypeList[$sQuestionType]['answerscales'] == 0 && $aQuestionTypeList[$sQuestionType]['subquestions'] == 0) {
foreach ($aSurveyLanguages as $sLanguage) {
// Qick and dirty insert for yes/no defaul value
// write the the selectbox option, or if "EM" is slected, this value to table
if ($sQuestionType == 'Y') {
/// value for all langs
if (Yii::app()->request->getPost('samedefault') == 1) {
$sLanguage = $aSurveyLanguages[0];
// turn
} else {
$sCurrentLang = $sLanguage;
// edit the next lines
}
if (Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage) == 'EM') {
// Case EM, write expression to database
$this->_updateDefaultValues($iQuestionID, 0, 0, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage . '_EM'), true);
} else {
// Case "other", write list value to database
$this->_updateDefaultValues($iQuestionID, 0, 0, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage), true);
}
///// end yes/no
} else {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage . '_0'))) {
$this->_updateDefaultValues($iQuestionID, 0, 0, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage . '_0'), true);
}
}
}
}
Yii::app()->session['flashmessage'] = gT("Default value settings were successfully saved.");
LimeExpressionManager::SetDirtyFlag();
if ($sDBOutput != '') {
echo $sDBOutput;
} else {
if (Yii::app()->request->getPost('close-after-save') === 'true') {
$this->getController()->redirect(array('admin/questions/sa/view/surveyid/' . $iSurveyID . '/gid/' . $iQuestionGroupID . '/qid/' . $iQuestionID));
}
$this->getController()->redirect(array('admin/questions/sa/editdefaultvalues/surveyid/' . $iSurveyID . '/gid/' . $iQuestionGroupID . '/qid/' . $iQuestionID));
}
}
if ($sAction == "updateansweroptions" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
Yii::app()->loadHelper('database');
$aSurveyLanguages = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
array_unshift($aSurveyLanguages, $sBaseLanguage);
$arQuestion = Question::model()->findByAttributes(array('qid' => $iQuestionID));
$sQuestionType = $arQuestion['type'];
// Checked)
$aQuestionTypeList = getQuestionTypeList('', 'array');
$iScaleCount = $aQuestionTypeList[$sQuestionType]['answerscales'];
//First delete all answers
Answer::model()->deleteAllByAttributes(array('qid' => $iQuestionID));
//.........这里部分代码省略.........
示例2: do_array_dual
function do_array_dual($ia)
{
global $thissurvey;
$aLastMoveResult = LimeExpressionManager::GetLastMoveResult();
$aMandatoryViolationSubQ = $aLastMoveResult['mandViolation'] && $ia[6] == 'Y' ? explode("|", $aLastMoveResult['unansweredSQs']) : array();
$repeatheadings = Yii::app()->getConfig("repeatheadings");
$minrepeatheadings = Yii::app()->getConfig("minrepeatheadings");
$extraclass = "";
$answertypeclass = "";
// Maybe not
$caption = "";
// Just leave empty, are replaced after
$inputnames = array();
$labelans1 = array();
$labelans = array();
/*
* Get Question Attributes
*/
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
// Get questions and answers by defined order
if ($aQuestionAttributes['random_order'] == 1) {
$ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY " . dbRandom();
} else {
$ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY question_order";
}
$ansresult = dbExecuteAssoc($ansquery);
//Checked
$aSubQuestions = $ansresult->readAll();
$anscount = count($aSubQuestions);
$lquery = "SELECT * FROM {{answers}} WHERE scale_id=0 AND qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY sortorder, code";
$lresult = dbExecuteAssoc($lquery);
//Checked
$aAnswersScale0 = $lresult->readAll();
$lquery1 = "SELECT * FROM {{answers}} WHERE scale_id=1 AND qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY sortorder, code";
$lresult1 = dbExecuteAssoc($lquery1);
//Checked
$aAnswersScale1 = $lresult1->readAll();
// Set attributes
if ($aQuestionAttributes['use_dropdown'] == 1) {
$useDropdownLayout = true;
$extraclass .= " dropdown-list";
$answertypeclass .= " dropdown";
$doDualScaleFunction = "doDualScaleDropDown";
// javascript funtion to lauch at end of answers
$caption = gT("A table with a subquestion on each row, with two answers to provide on each line. Please select the answers.");
} else {
$useDropdownLayout = false;
$extraclass .= " radio-list";
$answertypeclass .= " radio";
$doDualScaleFunction = "doDualScaleRadio";
$caption = gT("A table with one subquestion on each row and two answers to provide on each row. The related answer options are in the top table header row.");
}
if (ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings'] != "")) {
$repeatheadings = intval($aQuestionAttributes['repeat_headings']);
$minrepeatheadings = 0;
}
$leftheader = trim($aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? $leftheader = $aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']] : '';
$rightheader = trim($aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '' ? $aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']] : '';
$answerwidth = trim($aQuestionAttributes['answer_width']) != '' ? $aQuestionAttributes['answer_width'] : 20;
// Find if we have rigth and center text
$sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=" . $ia[0] . " and scale_id=0 AND question like '%|%'";
$rigthCount = Yii::app()->db->createCommand($sQuery)->queryScalar();
$rightexists = $rigthCount > 0;
// $right_exists: flag to find out if there are any right hand answer parts. leaving right column but don't force with
$sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=" . $ia[0] . " and scale_id=0 AND question like '%|%|%'";
$centerCount = Yii::app()->db->createCommand($sQuery)->queryScalar();
$centerexists = $centerCount > 0;
// $center_exists: flag to find out if there are any center hand answer parts. leaving center column but don't force with
// Label and code for input
foreach ($aAnswersScale0 as $lrow) {
$labels0[] = array('code' => $lrow['code'], 'title' => $lrow['answer']);
}
foreach ($aAnswersScale1 as $lrow) {
$labels1[] = array('code' => $lrow['code'], 'title' => $lrow['answer']);
}
if (count($aAnswersScale0) > 0 && $anscount) {
$answer = "";
$fn = 1;
// Used by repeat_heading
// No drop-down
if ($useDropdownLayout === false) {
$aData = array();
$aData['answertypeclass'] = $answertypeclass;
$columnswidth = 100 - $answerwidth;
$labelans0 = array();
$labelans1 = array();
$labelcode0 = array();
$labelcode1 = array();
foreach ($aAnswersScale0 as $lrow) {
$labelans0[] = $lrow['answer'];
$labelcode0[] = $lrow['code'];
}
foreach ($aAnswersScale1 as $lrow) {
$labelans1[] = $lrow['answer'];
$labelcode1[] = $lrow['code'];
}
$numrows = count($labelans0) + count($labelans1);
// Add needed row and fill some boolean: shownoanswer, rightexists, centerexists
$shownoanswer = $ia[6] != "Y" && SHOW_NO_ANSWER == 1;
if ($shownoanswer) {
//.........这里部分代码省略.........
示例3: index
/**
* Database::index()
*
* @param mixed $sa
* @return
*/
function index($sa = null)
{
$sAction = Yii::app()->request->getPost('action');
$clang = $this->getController()->lang;
$iSurveyID = returnGlobal('sid');
$iQuestionGroupID = returnGlobal('gid');
$iQuestionID = returnGlobal('qid');
$sDBOutput = '';
if (Yii::app()->getConfig('filterxsshtml') && !Permission::model()->hasGlobalPermission('superadmin', 'read')) {
$oPurifier = new CHtmlPurifier();
$oPurifier->options = array('URI.AllowedSchemes' => array('http' => true, 'https' => true));
$bXSSFilter = true;
} else {
$bXSSFilter = false;
}
if ($sAction == "updatedefaultvalues" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
$aSurveyLanguages = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
array_unshift($aSurveyLanguages, $sBaseLanguage);
Question::model()->updateAll(array('same_default' => Yii::app()->request->getPost('samedefault') ? 1 : 0), 'sid=:sid ANd qid=:qid', array(':sid' => $iSurveyID, ':qid' => $iQuestionID));
$arQuestion = Question::model()->findByAttributes(array('qid' => $iQuestionID));
$sQuestionType = $arQuestion['type'];
$aQuestionTypeList = getQuestionTypeList('', 'array');
if ($aQuestionTypeList[$sQuestionType]['answerscales'] > 0 && $aQuestionTypeList[$sQuestionType]['subquestions'] == 0) {
for ($iScaleID = 0; $iScaleID < $aQuestionTypeList[$sQuestionType]['answerscales']; $iScaleID++) {
foreach ($aSurveyLanguages as $sLanguage) {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage))) {
$this->_updateDefaultValues($iQuestionID, 0, $iScaleID, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage), true);
}
if (!is_null(Yii::app()->request->getPost('other_' . $iScaleID . '_' . $sLanguage))) {
$this->_updateDefaultValues($iQuestionID, 0, $iScaleID, 'other', $sLanguage, Yii::app()->request->getPost('other_' . $iScaleID . '_' . $sLanguage), true);
}
}
}
}
if ($aQuestionTypeList[$sQuestionType]['subquestions'] > 0) {
foreach ($aSurveyLanguages as $sLanguage) {
$arQuestions = Question::model()->findAllByAttributes(array('sid' => $iSurveyID, 'gid' => $iQuestionGroupID, 'parent_qid' => $iQuestionID, 'language' => $sLanguage, 'scale_id' => 0));
for ($iScaleID = 0; $iScaleID < $aQuestionTypeList[$sQuestionType]['subquestions']; $iScaleID++) {
foreach ($arQuestions as $aSubquestionrow) {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage . '_' . $aSubquestionrow['qid']))) {
$this->_updateDefaultValues($iQuestionID, $aSubquestionrow['qid'], $iScaleID, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage . '_' . $aSubquestionrow['qid']), true);
}
}
}
}
}
if ($aQuestionTypeList[$sQuestionType]['answerscales'] == 0 && $aQuestionTypeList[$sQuestionType]['subquestions'] == 0) {
foreach ($aSurveyLanguages as $sLanguage) {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage . '_0'))) {
$this->_updateDefaultValues($iQuestionID, 0, 0, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage . '_0'), true);
}
}
}
Yii::app()->session['flashmessage'] = $clang->gT("Default value settings were successfully saved.");
LimeExpressionManager::SetDirtyFlag();
if ($sDBOutput != '') {
echo $sDBOutput;
} else {
$this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iSurveyID . '/gid/' . $iQuestionGroupID . '/qid/' . $iQuestionID));
}
}
if ($sAction == "updateansweroptions" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
Yii::app()->loadHelper('database');
$aSurveyLanguages = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
array_unshift($aSurveyLanguages, $sBaseLanguage);
$arQuestion = Question::model()->findByAttributes(array('qid' => $iQuestionID));
$sQuestionType = $arQuestion['type'];
// Checked)
$aQuestionTypeList = getQuestionTypeList('', 'array');
$iScaleCount = $aQuestionTypeList[$sQuestionType]['answerscales'];
//First delete all answers
Answer::model()->deleteAllByAttributes(array('qid' => $iQuestionID));
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID);
for ($iScaleID = 0; $iScaleID < $iScaleCount; $iScaleID++) {
$iMaxCount = (int) Yii::app()->request->getPost('answercount_' . $iScaleID);
for ($iSortOrderID = 1; $iSortOrderID < $iMaxCount; $iSortOrderID++) {
$sCode = sanitize_paranoid_string(Yii::app()->request->getPost('code_' . $iSortOrderID . '_' . $iScaleID));
if (Yii::app()->request->getPost('oldcode_' . $iSortOrderID . '_' . $iScaleID)) {
$sOldCode = sanitize_paranoid_string(Yii::app()->request->getPost('oldcode_' . $iSortOrderID . '_' . $iScaleID));
if ($sCode !== $sOldCode) {
Condition::model()->updateAll(array('value' => $sCode), 'cqid=:cqid AND value=:value', array(':cqid' => $iQuestionID, ':value' => $sOldCode));
}
}
$iAssessmentValue = (int) Yii::app()->request->getPost('assessment_' . $iSortOrderID . '_' . $iScaleID);
foreach ($aSurveyLanguages as $sLanguage) {
$sAnswerText = Yii::app()->request->getPost('answer_' . $sLanguage . '_' . $iSortOrderID . '_' . $iScaleID);
if ($bXSSFilter) {
$sAnswerText = $oPurifier->purify($sAnswerText);
} else {
$sAnswerText = html_entity_decode($sAnswerText, ENT_QUOTES, "UTF-8");
}
// Fix bug with FCKEditor saving strange BR types
//.........这里部分代码省略.........
示例4: index
/**
* Database::index()
*
* @param mixed $sa
* @return
*/
function index($sa = null)
{
$sAction = Yii::app()->request->getPost('action');
$iSurveyID = returnGlobal('sid');
$iQuestionGroupID = returnGlobal('gid');
$iQuestionID = returnGlobal('qid');
$sDBOutput = '';
$oFixCKeditor = new LSYii_Validators();
$oFixCKeditor->fixCKeditor = true;
$oFixCKeditor->xssfilter = false;
if ($sAction == "updatedefaultvalues" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
$aSurveyLanguages = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
array_unshift($aSurveyLanguages, $sBaseLanguage);
Question::model()->updateAll(array('same_default' => Yii::app()->request->getPost('samedefault') ? 1 : 0), 'sid=:sid ANd qid=:qid', array(':sid' => $iSurveyID, ':qid' => $iQuestionID));
$arQuestion = Question::model()->findByAttributes(array('qid' => $iQuestionID));
$sQuestionType = $arQuestion['type'];
$aQuestionTypeList = getQuestionTypeList('', 'array');
if ($aQuestionTypeList[$sQuestionType]['answerscales'] > 0 && $aQuestionTypeList[$sQuestionType]['subquestions'] == 0) {
for ($iScaleID = 0; $iScaleID < $aQuestionTypeList[$sQuestionType]['answerscales']; $iScaleID++) {
foreach ($aSurveyLanguages as $sLanguage) {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage))) {
$this->_updateDefaultValues($iQuestionID, 0, $iScaleID, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage), true);
}
if (!is_null(Yii::app()->request->getPost('other_' . $iScaleID . '_' . $sLanguage))) {
$this->_updateDefaultValues($iQuestionID, 0, $iScaleID, 'other', $sLanguage, Yii::app()->request->getPost('other_' . $iScaleID . '_' . $sLanguage), true);
}
}
}
}
if ($aQuestionTypeList[$sQuestionType]['subquestions'] > 0) {
foreach ($aSurveyLanguages as $sLanguage) {
$arQuestions = Question::model()->findAllByAttributes(array('sid' => $iSurveyID, 'gid' => $iQuestionGroupID, 'parent_qid' => $iQuestionID, 'language' => $sLanguage, 'scale_id' => 0));
for ($iScaleID = 0; $iScaleID < $aQuestionTypeList[$sQuestionType]['subquestions']; $iScaleID++) {
foreach ($arQuestions as $aSubquestionrow) {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage . '_' . $aSubquestionrow['qid']))) {
$this->_updateDefaultValues($iQuestionID, $aSubquestionrow['qid'], $iScaleID, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_' . $iScaleID . '_' . $sLanguage . '_' . $aSubquestionrow['qid']), true);
}
}
}
}
}
if ($aQuestionTypeList[$sQuestionType]['answerscales'] == 0 && $aQuestionTypeList[$sQuestionType]['subquestions'] == 0) {
foreach ($aSurveyLanguages as $sLanguage) {
// Qick and dirty insert for yes/no defaul value
// write the the selectbox option, or if "EM" is slected, this value to table
if ($sQuestionType == 'Y') {
/// value for all langs
if (Yii::app()->request->getPost('samedefault') == 1) {
$sLanguage = $aSurveyLanguages[0];
// turn
} else {
$sCurrentLang = $sLanguage;
// edit the next lines
}
if (Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage) == 'EM') {
// Case EM, write expression to database
$this->_updateDefaultValues($iQuestionID, 0, 0, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage . '_EM'), true);
} else {
// Case "other", write list value to database
$this->_updateDefaultValues($iQuestionID, 0, 0, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage), true);
}
///// end yes/no
} else {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage . '_0'))) {
$this->_updateDefaultValues($iQuestionID, 0, 0, '', $sLanguage, Yii::app()->request->getPost('defaultanswerscale_0_' . $sLanguage . '_0'), true);
}
}
}
}
Yii::app()->session['flashmessage'] = gT("Default value settings were successfully saved.");
LimeExpressionManager::SetDirtyFlag();
if ($sDBOutput != '') {
echo $sDBOutput;
} else {
$this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iSurveyID . '/gid/' . $iQuestionGroupID . '/qid/' . $iQuestionID));
}
}
if ($sAction == "updateansweroptions" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
Yii::app()->loadHelper('database');
$aSurveyLanguages = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
array_unshift($aSurveyLanguages, $sBaseLanguage);
$arQuestion = Question::model()->findByAttributes(array('qid' => $iQuestionID));
$sQuestionType = $arQuestion['type'];
// Checked)
$aQuestionTypeList = getQuestionTypeList('', 'array');
$iScaleCount = $aQuestionTypeList[$sQuestionType]['answerscales'];
//First delete all answers
Answer::model()->deleteAllByAttributes(array('qid' => $iQuestionID));
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID);
for ($iScaleID = 0; $iScaleID < $iScaleCount; $iScaleID++) {
$iMaxCount = (int) Yii::app()->request->getPost('answercount_' . $iScaleID);
for ($iSortOrderID = 1; $iSortOrderID < $iMaxCount; $iSortOrderID++) {
//.........这里部分代码省略.........
示例5: deleteAllById
public static function deleteAllById($questionsIds)
{
if (!is_array($questionsIds)) {
$questionsIds = array($questionsIds);
}
Yii::app()->db->createCommand()->delete(Condition::model()->tableName(), array('in', 'qid', $questionsIds));
Yii::app()->db->createCommand()->delete(QuestionAttribute::model()->tableName(), array('in', 'qid', $questionsIds));
Yii::app()->db->createCommand()->delete(Answer::model()->tableName(), array('in', 'qid', $questionsIds));
Yii::app()->db->createCommand()->delete(Question::model()->tableName(), array('in', 'parent_qid', $questionsIds));
Yii::app()->db->createCommand()->delete(Question::model()->tableName(), array('in', 'qid', $questionsIds));
Yii::app()->db->createCommand()->delete(DefaultValue::model()->tableName(), array('in', 'qid', $questionsIds));
Yii::app()->db->createCommand()->delete(QuotaMember::model()->tableName(), array('in', 'qid', $questionsIds));
}
示例6: get_question_properties
/**
* RPC Routine to return properties of a question of a survey.
* Returns string
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iQuestionID Id of the question to get properties
* @param array $aQuestionSettings The properties to get
* @param string $sLanguage Optional parameter language for multilingual questions
* @return array The requested values
*/
public function get_question_properties($sSessionKey, $iQuestionID, $aQuestionSettings, $sLanguage = NULL)
{
if ($this->_checkSessionKey($sSessionKey)) {
Yii::app()->loadHelper("surveytranslator");
$oQuestion = Question::model()->findByAttributes(array('qid' => $iQuestionID));
if (!isset($oQuestion)) {
return array('status' => 'Error: Invalid questionid');
}
$iSurveyID = $oQuestion->sid;
if (Permission::model()->hasSurveyPermission($iSurveyID, 'survey', 'read')) {
if (is_null($sLanguage)) {
$sLanguage = Survey::model()->findByPk($iSurveyID)->language;
}
if (!array_key_exists($sLanguage, getLanguageDataRestricted())) {
return array('status' => 'Error: Invalid language');
}
$oQuestion = Question::model()->findByAttributes(array('qid' => $iQuestionID, 'language' => $sLanguage));
if (!isset($oQuestion)) {
return array('status' => 'Error: Invalid questionid');
}
$aBasicDestinationFields = Question::model()->tableSchema->columnNames;
array_push($aBasicDestinationFields, 'available_answers');
array_push($aBasicDestinationFields, 'subquestions');
array_push($aBasicDestinationFields, 'attributes');
array_push($aBasicDestinationFields, 'attributes_lang');
array_push($aBasicDestinationFields, 'answeroptions');
array_push($aBasicDestinationFields, 'defaultvalue');
$aQuestionSettings = array_intersect($aQuestionSettings, $aBasicDestinationFields);
if (empty($aQuestionSettings)) {
return array('status' => 'No valid Data');
}
$aResult = array();
foreach ($aQuestionSettings as $sPropertyName) {
if ($sPropertyName == 'available_answers' || $sPropertyName == 'subquestions') {
$oSubQuestions = Question::model()->findAllByAttributes(array('parent_qid' => $iQuestionID, 'language' => $sLanguage), array('order' => 'title'));
if (count($oSubQuestions) > 0) {
$aData = array();
foreach ($oSubQuestions as $oSubQuestion) {
if ($sPropertyName == 'available_answers') {
$aData[$oSubQuestion['title']] = $oSubQuestion['question'];
} else {
$aData[$oSubQuestion['qid']]['title'] = $oSubQuestion['title'];
$aData[$oSubQuestion['qid']]['question'] = $oSubQuestion['question'];
$aData[$oSubQuestion['qid']]['scale_id'] = $oSubQuestion['scale_id'];
}
}
$aResult[$sPropertyName] = $aData;
} else {
$aResult[$sPropertyName] = 'No available answers';
}
} else {
if ($sPropertyName == 'attributes') {
$oAttributes = QuestionAttribute::model()->findAllByAttributes(array('qid' => $iQuestionID, 'language' => null), array('order' => 'attribute'));
if (count($oAttributes) > 0) {
$aData = array();
foreach ($oAttributes as $oAttribute) {
$aData[$oAttribute['attribute']] = $oAttribute['value'];
}
$aResult['attributes'] = $aData;
} else {
$aResult['attributes'] = 'No available attributes';
}
} else {
if ($sPropertyName == 'attributes_lang') {
$oAttributes = QuestionAttribute::model()->findAllByAttributes(array('qid' => $iQuestionID, 'language' => $sLanguage), array('order' => 'attribute'));
if (count($oAttributes) > 0) {
$aData = array();
foreach ($oAttributes as $oAttribute) {
$aData[$oAttribute['attribute']] = $oAttribute['value'];
}
$aResult['attributes_lang'] = $aData;
} else {
$aResult['attributes_lang'] = 'No available attributes';
}
} else {
if ($sPropertyName == 'answeroptions') {
$oAttributes = Answer::model()->findAllByAttributes(array('qid' => $iQuestionID, 'language' => $sLanguage), array('order' => 'sortorder'));
if (count($oAttributes) > 0) {
$aData = array();
foreach ($oAttributes as $oAttribute) {
$aData[$oAttribute['code']]['answer'] = $oAttribute['answer'];
$aData[$oAttribute['code']]['assessment_value'] = $oAttribute['assessment_value'];
$aData[$oAttribute['code']]['scale_id'] = $oAttribute['scale_id'];
}
$aResult['answeroptions'] = $aData;
} else {
$aResult['answeroptions'] = 'No available answer options';
}
} else {
//.........这里部分代码省略.........
示例7: deleteSurvey
/**
* Deletes a survey and all its data
*
* @access public
* @param int $iSurveyID
* @param bool @recursive
* @return void
*/
public function deleteSurvey($iSurveyID, $recursive = true)
{
Survey::model()->deleteByPk($iSurveyID);
if ($recursive == true) {
if (tableExists("{{survey_" . intval($iSurveyID) . "}}")) {
Yii::app()->db->createCommand()->dropTable("{{survey_" . intval($iSurveyID) . "}}");
}
if (tableExists("{{survey_" . intval($iSurveyID) . "_timings}}")) {
Yii::app()->db->createCommand()->dropTable("{{survey_" . intval($iSurveyID) . "_timings}}");
}
if (tableExists("{{tokens_" . intval($iSurveyID) . "}}")) {
Yii::app()->db->createCommand()->dropTable("{{tokens_" . intval($iSurveyID) . "}}");
}
/* Remove User/global settings part : need Question and QuestionGroup*/
// Settings specific for this survey
$oCriteria = new CDbCriteria();
$oCriteria->compare('stg_name', 'last_%', true, 'AND', false);
$oCriteria->compare('stg_value', $iSurveyID, false, 'AND');
SettingGlobal::model()->deleteAll($oCriteria);
// Settings specific for this survey, 2nd part
$oCriteria = new CDbCriteria();
$oCriteria->compare('stg_name', 'last_%' . $iSurveyID . '%', true, 'AND', false);
SettingGlobal::model()->deleteAll($oCriteria);
// All Group id from this survey for ALL users
$aGroupId = CHtml::listData(QuestionGroup::model()->findAll(array('select' => 'gid', 'condition' => 'sid=:sid', 'params' => array(':sid' => $iSurveyID))), 'gid', 'gid');
$oCriteria = new CDbCriteria();
$oCriteria->compare('stg_name', 'last_question_gid_%', true, 'AND', false);
if (Yii::app()->db->getDriverName() == 'pgsql') {
$oCriteria->addInCondition('CAST(stg_value as ' . App()->db->schema->getColumnType("integer") . ')', $aGroupId);
} else {
$oCriteria->addInCondition('stg_value', $aGroupId);
}
SettingGlobal::model()->deleteAll($oCriteria);
// All Question id from this survey for ALL users
$aQuestionId = CHtml::listData(Question::model()->findAll(array('select' => 'qid', 'condition' => 'sid=:sid', 'params' => array(':sid' => $iSurveyID))), 'qid', 'qid');
$oCriteria = new CDbCriteria();
$oCriteria->compare('stg_name', 'last_question_%', true, 'OR', false);
if (Yii::app()->db->getDriverName() == 'pgsql') {
$oCriteria->addInCondition('CAST(stg_value as ' . App()->db->schema->getColumnType("integer") . ')', $aQuestionId);
} else {
$oCriteria->addInCondition('stg_value', $aQuestionId);
}
SettingGlobal::model()->deleteAll($oCriteria);
$oResult = Question::model()->findAllByAttributes(array('sid' => $iSurveyID));
foreach ($oResult as $aRow) {
Answer::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
Condition::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
QuestionAttribute::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
DefaultValue::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
}
Question::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
Assessment::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
QuestionGroup::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
SurveyLanguageSetting::model()->deleteAllByAttributes(array('surveyls_survey_id' => $iSurveyID));
Permission::model()->deleteAllByAttributes(array('entity_id' => $iSurveyID, 'entity' => 'survey'));
SavedControl::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
SurveyURLParameter::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
//Remove any survey_links to the CPDB
SurveyLink::model()->deleteLinksBySurvey($iSurveyID);
Quota::model()->deleteQuota(array('sid' => $iSurveyID), true);
}
}
示例8: checkCompletedQuota
/**
* checkCompletedQuota() returns matched quotas information for the current response
* @param integer $surveyid - Survey identification number
* @param bool $return - set to true to return information, false do the quota
* @return array|void - nested array, Quotas->Members->Fields, includes quota information matched in session.
*/
function checkCompletedQuota($surveyid, $return = false)
{
/* Check if session is set */
if (!isset(App()->session['survey_' . $surveyid]['srid'])) {
return;
}
/* Check is Response is already submitted : only when "do" the quota: allow to send information about quota */
$oResponse = Response::model($surveyid)->findByPk(App()->session['survey_' . $surveyid]['srid']);
if (!$return && $oResponse && !is_null($oResponse->submitdate)) {
return;
}
static $aMatchedQuotas;
// EM call 2 times quotas with 3 lines of php code, then use static.
if (!$aMatchedQuotas) {
$aMatchedQuotas = array();
$quota_info = $aQuotasInfo = getQuotaInformation($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']);
// $aQuotasInfo have an 'active' key, we don't use it ?
if (!$aQuotasInfo || empty($aQuotasInfo)) {
return $aMatchedQuotas;
}
// OK, we have some quota, then find if this $_SESSION have some set
$aPostedFields = explode("|", Yii::app()->request->getPost('fieldnames', ''));
// Needed for quota allowing update
foreach ($aQuotasInfo as $aQuotaInfo) {
if (count($aQuotaInfo['members']) === 0) {
continue;
}
$iMatchedAnswers = 0;
$bPostedField = false;
// Array of field with quota array value
$aQuotaFields = array();
// Array of fieldnames with relevance value : EM fill $_SESSION with default value even is unrelevant (em_manager_helper line 6548)
$aQuotaRelevantFieldnames = array();
// To count number of hidden questions
$aQuotaQid = array();
foreach ($aQuotaInfo['members'] as $aQuotaMember) {
$aQuotaFields[$aQuotaMember['fieldname']][] = $aQuotaMember['value'];
$aQuotaRelevantFieldnames[$aQuotaMember['fieldname']] = isset($_SESSION['survey_' . $surveyid]['relevanceStatus'][$aQuotaMember['qid']]) && $_SESSION['survey_' . $surveyid]['relevanceStatus'][$aQuotaMember['qid']];
$aQuotaQid[] = $aQuotaMember['qid'];
}
$aQuotaQid = array_unique($aQuotaQid);
// For each field : test if actual responses is in quota (and is relevant)
foreach ($aQuotaFields as $sFieldName => $aValues) {
$bInQuota = isset($_SESSION['survey_' . $surveyid][$sFieldName]) && in_array($_SESSION['survey_' . $surveyid][$sFieldName], $aValues);
if ($bInQuota && $aQuotaRelevantFieldnames[$sFieldName]) {
$iMatchedAnswers++;
}
if (in_array($sFieldName, $aPostedFields)) {
// Need only one posted value
$bPostedField = true;
}
}
// Condition to count quota : Answers are the same in quota + an answer is submitted at this time (bPostedField) OR all questions is hidden (bAllHidden)
$bAllHidden = QuestionAttribute::model()->countByAttributes(array('qid' => $aQuotaQid), 'attribute=:attribute', array(':attribute' => 'hidden')) == count($aQuotaQid);
if ($iMatchedAnswers == count($aQuotaFields) && ($bPostedField || $bAllHidden)) {
if ($aQuotaInfo['qlimit'] == 0) {
// Always add the quota if qlimit==0
$aMatchedQuotas[] = $aQuotaInfo;
} else {
$iCompleted = getQuotaCompletedCount($surveyid, $aQuotaInfo['id']);
if (!is_null($iCompleted) && (int) $iCompleted >= (int) $aQuotaInfo['qlimit']) {
// This remove invalid quota and not completed
$aMatchedQuotas[] = $aQuotaInfo;
}
}
}
}
}
if ($return) {
return $aMatchedQuotas;
}
if (empty($aMatchedQuotas)) {
return;
}
// Now we have all the information we need about the quotas and their status.
// We need to construct the page and do all needed action
$aSurveyInfo = getSurveyInfo($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']);
$oTemplate = Template::model()->getInstance('', $surveyid);
$sTemplatePath = $oTemplate->path;
$sTemplateViewPath = $oTemplate->viewPath;
$sClientToken = isset($_SESSION['survey_' . $surveyid]['token']) ? $_SESSION['survey_' . $surveyid]['token'] : "";
// $redata for templatereplace
$aDataReplacement = array('thissurvey' => $aSurveyInfo, 'clienttoken' => $sClientToken, 'token' => $sClientToken);
// We take only the first matched quota, no need for each
$aMatchedQuota = $aMatchedQuotas[0];
// If a token is used then mark the token as completed, do it before event : this allow plugin to update token information
$event = new PluginEvent('afterSurveyQuota');
$event->set('surveyId', $surveyid);
$event->set('responseId', $_SESSION['survey_' . $surveyid]['srid']);
// We allways have a responseId
$event->set('aMatchedQuotas', $aMatchedQuotas);
// Give all the matched quota : the first is the active
App()->getPluginManager()->dispatchEvent($event);
$blocks = array();
//.........这里部分代码省略.........
示例9: _checkintegrity
/**
* This function checks the LimeSurvey database for logical consistency and returns an according array
* containing all issues in the particular tables.
* @returns Array with all found issues.
*/
protected function _checkintegrity()
{
$clang = Yii::app()->lang;
/*** Plainly delete survey permissions if the survey or user does not exist ***/
$users = User::model()->findAll();
$uids = array();
foreach ($users as $user) {
$uids[] = $user['uid'];
}
$oCriteria = new CDbCriteria();
$oCriteria->addNotInCondition('uid', $uids, 'OR');
$surveys = Survey::model()->findAll();
$sids = array();
foreach ($surveys as $survey) {
$sids[] = $survey['sid'];
}
$oCriteria->addNotInCondition('entity_id', $sids, 'OR');
$oCriteria->addCondition("entity='survey'");
Permission::model()->deleteAll($oCriteria);
// Deactivate surveys that have a missing response table
foreach ($surveys as $survey) {
if ($survey['active'] == 'Y' && !tableExists("{{survey_{$survey['sid']}}}")) {
Survey::model()->updateByPk($survey['sid'], array('active' => 'N'));
}
}
unset($surveys);
// Fix subquestions
fixSubquestions();
/*** Check for active survey tables with missing survey entry and rename them ***/
$sDBPrefix = Yii::app()->db->tablePrefix;
$sQuery = dbSelectTablesLike('{{survey}}\\_%');
$aResult = dbQueryOrFalse($sQuery);
foreach ($aResult->readAll() as $aRow) {
$sTableName = substr(reset($aRow), strlen($sDBPrefix));
if ($sTableName == 'survey_links' || $sTableName == 'survey_url_parameters') {
continue;
}
$aTableName = explode('_', $sTableName);
if (isset($aTableName[1]) && ctype_digit($aTableName[1])) {
$iSurveyID = $aTableName[1];
if (!in_array($iSurveyID, $sids)) {
$sDate = date('YmdHis') . rand(1, 1000);
$sOldTable = "survey_{$iSurveyID}";
$sNewTable = "old_survey_{$iSurveyID}_{$sDate}";
try {
$deactivateresult = Yii::app()->db->createCommand()->renameTable("{{{$sOldTable}}}", "{{{$sNewTable}}}");
} catch (CDbException $e) {
die('Couldn\'t make backup of the survey table. Please try again. The database reported the following error:<br />' . htmlspecialchars($e) . '<br />');
}
}
}
}
/*** Check for active token tables with missing survey entry ***/
$aResult = dbQueryOrFalse(dbSelectTablesLike('{{tokens}}\\_%'));
foreach ($aResult->readAll() as $aRow) {
$sTableName = substr(reset($aRow), strlen($sDBPrefix));
$iSurveyID = substr($sTableName, strpos($sTableName, '_') + 1);
if (!in_array($iSurveyID, $sids)) {
$sDate = date('YmdHis') . rand(1, 1000);
$sOldTable = "tokens_{$iSurveyID}";
$sNewTable = "old_tokens_{$iSurveyID}_{$sDate}";
try {
$deactivateresult = Yii::app()->db->createCommand()->renameTable("{{{$sOldTable}}}", "{{{$sNewTable}}}");
} catch (CDbException $e) {
die('Couldn\'t make backup of the survey table. Please try again. The database reported the following error:<br />' . htmlspecialchars($e) . '<br />');
}
}
}
/**********************************************************************/
/* Check conditions */
/**********************************************************************/
$okQuestion = array();
$sQuery = 'SELECT cqid,cid,cfieldname FROM {{conditions}}';
$aConditions = Yii::app()->db->createCommand($sQuery)->queryAll();
foreach ($aConditions as $condition) {
if ($condition['cqid'] != 0) {
// skip case with cqid=0 for codnitions on {TOKEN:EMAIL} for instance
if (!array_key_exists($condition['cqid'], $okQuestion)) {
$iRowCount = Question::model()->countByAttributes(array('qid' => $condition['cqid']));
if (Question::model()->hasErrors()) {
safeDie(Question::model()->getError());
}
if (!$iRowCount) {
$aDelete['conditions'][] = array('cid' => $condition['cid'], 'reason' => $clang->gT('No matching CQID'));
} else {
$okQuestion[$condition['cqid']] = $condition['cqid'];
}
}
}
if ($condition['cfieldname']) {
if (preg_match('/^\\+{0,1}[0-9]+X[0-9]+X*$/', $condition['cfieldname'])) {
// only if cfieldname isn't Tag such as {TOKEN:EMAIL} or any other token
list($surveyid, $gid, $rest) = explode('X', $condition['cfieldname']);
$iRowCount = count(QuestionGroup::model()->findAllByAttributes(array('gid' => $gid)));
if (QuestionGroup::model()->hasErrors()) {
//.........这里部分代码省略.........
示例10: activateSurvey
/**
* Function to activate a survey
* @param int $iSurveyID The Survey ID
* @param bool $simulate
* @return string
*/
function activateSurvey($iSurveyID, $simulate = false)
{
$aTableDefinition = array();
$bCreateSurveyDir = false;
// Specify case sensitive collations for the token
$sCollation = '';
if (Yii::app()->db->driverName == 'mysqli' | Yii::app()->db->driverName == 'mysqli') {
$sCollation = " COLLATE 'utf8_bin'";
}
if (Yii::app()->db->driverName == 'sqlsrv' | Yii::app()->db->driverName == 'dblib' | Yii::app()->db->driverName == 'mssql') {
$sCollation = " COLLATE SQL_Latin1_General_CP1_CS_AS";
}
//Check for any additional fields for this survey and create necessary fields (token and datestamp)
$arSurvey = Survey::model()->findByAttributes(array('sid' => $iSurveyID));
//Get list of questions for the base language
$sFieldMap = createFieldMap($iSurveyID, 'full', true, false, $arSurvey->language);
//For each question, create the appropriate field(s)
foreach ($sFieldMap as $j => $aRow) {
switch ($aRow['type']) {
case 'seed':
$aTableDefinition[$aRow['fieldname']] = "string(31)";
break;
case 'startlanguage':
$aTableDefinition[$aRow['fieldname']] = "string(20) NOT NULL";
break;
case 'id':
$aTableDefinition[$aRow['fieldname']] = "pk";
break;
case "startdate":
case "datestamp":
$aTableDefinition[$aRow['fieldname']] = "datetime NOT NULL";
break;
case "submitdate":
$aTableDefinition[$aRow['fieldname']] = "datetime";
break;
case "lastpage":
$aTableDefinition[$aRow['fieldname']] = "integer";
break;
case "N":
//Numerical
//Numerical
case "K":
//Multiple Numerical
$aTableDefinition[$aRow['fieldname']] = "decimal (30,10)";
break;
case "S":
//SHORT TEXT
$aTableDefinition[$aRow['fieldname']] = "text";
break;
case "L":
//LIST (RADIO)
//LIST (RADIO)
case "!":
//LIST (DROPDOWN)
//LIST (DROPDOWN)
case "M":
//Multiple choice
//Multiple choice
case "P":
//Multiple choice with comment
//Multiple choice with comment
case "O":
//DROPDOWN LIST WITH COMMENT
if ($aRow['aid'] != 'other' && strpos($aRow['aid'], 'comment') === false && strpos($aRow['aid'], 'othercomment') === false) {
$aTableDefinition[$aRow['fieldname']] = "string(5)";
} else {
$aTableDefinition[$aRow['fieldname']] = "text";
}
break;
case "U":
//Huge text
//Huge text
case "Q":
//Multiple short text
//Multiple short text
case "T":
//LONG TEXT
//LONG TEXT
case ";":
//Multi Flexi
//Multi Flexi
case ":":
//Multi Flexi
$aTableDefinition[$aRow['fieldname']] = "text";
break;
case "D":
//DATE
$aTableDefinition[$aRow['fieldname']] = "datetime";
break;
case "5":
//5 Point Choice
//5 Point Choice
case "G":
//Gender
//.........这里部分代码省略.........
示例11: setMultipleAttributes
/**
* Set attributes for multiple questions
*/
public function setMultipleAttributes()
{
$aQidsAndLang = json_decode($_POST['sItems']);
// List of question ids to update
$iSid = Yii::app()->request->getPost('sid');
// The survey (for permission check)
$aAttributesToUpdate = json_decode($_POST['aAttributesToUpdate']);
// The list of attributes to updates
// TODO: this should be get from the question model
$aValidQuestionTypes = str_split($_POST['aValidQuestionTypes']);
// The valid question types for thoses attributes
// Calling th model
QuestionAttribute::model()->setMultiple($iSid, $aQidsAndLang, $aAttributesToUpdate, $aValidQuestionTypes);
}
示例12: setQuestion
/**
*
* @param iPlugin $plugin
* @param string $key
* @param mixed data Default value to return if key could not be found.
* @param string $model Optional model name to which the data was attached.
* @param int $id Optional id of the model instance to which the data was attached.
* @param string $language Optional language identifier used for storing the setting.
*
* @return boolean
*/
protected function setQuestion(iPlugin $plugin, $key, $data, $model, $id, $language)
{
$baseAttributes = array('sid', 'code', 'qid', 'gid', 'sortorder', 'relevance', 'questiontype', 'randomization');
// Some keys are stored in the actual question table not in the attributes table.
if (in_array($key, $baseAttributes)) {
if ($data == '') {
$data = null;
}
$result = $this->setQuestionBase($id, $key, $data);
} else {
$attributes = array('qid' => $id, 'attribute' => $key, 'language' => $language);
$record = QuestionAttribute::model()->findByAttributes($attributes);
if (is_null($record)) {
// New setting
$record = QuestionAttribute::model()->populateRecord($attributes);
$record->setIsNewRecord(true);
}
// Serialize arrays and objects only for question attributes..
if (is_array($data) || is_object($data)) {
$record->value = json_encode($data);
$record->serialized = true;
} else {
$record->value = $data;
$record->serialized = false;
}
$result = $record->save();
}
return $result;
}
示例13: getQuestionAttributes
/**
* Returns Question attribute array name=>value
*
* @access public
* @param int $iQuestionID
* @return array
*/
public function getQuestionAttributes($iQuestionID)
{
$iQuestionID = (int) $iQuestionID;
static $aQuestionAttributesStatic = array();
// TODO : replace by Yii::app()->cache
// Limit the size of the attribute cache due to memory usage
$aQuestionAttributesStatic = array_splice($aQuestionAttributesStatic, -1000, null, true);
if (isset($aQuestionAttributesStatic[$iQuestionID])) {
return $aQuestionAttributesStatic[$iQuestionID];
}
$aQuestionAttributes = array();
$oQuestion = Question::model()->find("qid=:qid", array('qid' => $iQuestionID));
// Maybe take parent_qid attribute before this qid attribute
if ($oQuestion) {
$aLanguages = array_merge(array(Survey::model()->findByPk($oQuestion->sid)->language), Survey::model()->findByPk($oQuestion->sid)->additionalLanguages);
// Get all atribute set for this question
$sType = $oQuestion->type;
$aAttributeNames = questionAttributes();
$aAttributeNames = $aAttributeNames[$sType];
$oAttributeValues = QuestionAttribute::model()->findAll("qid=:qid", array('qid' => $iQuestionID));
$aAttributeValues = array();
foreach ($oAttributeValues as $oAttributeValue) {
if ($oAttributeValue->language) {
$aAttributeValues[$oAttributeValue->attribute][$oAttributeValue->language] = $oAttributeValue->value;
} else {
$aAttributeValues[$oAttributeValue->attribute] = $oAttributeValue->value;
}
}
// Fill with aQuestionAttributes with default attribute or with aAttributeValues
// Can not use array_replace due to i18n
foreach ($aAttributeNames as $aAttribute) {
if ($aAttribute['i18n'] == false) {
if (isset($aAttributeValues[$aAttribute['name']])) {
$aQuestionAttributes[$aAttribute['name']] = $aAttributeValues[$aAttribute['name']];
} else {
$aQuestionAttributes[$aAttribute['name']] = $aAttribute['default'];
}
} else {
foreach ($aLanguages as $sLanguage) {
if (isset($aAttributeValues[$aAttribute['name']][$sLanguage])) {
$aQuestionAttributes[$aAttribute['name']][$sLanguage] = $aAttributeValues[$aAttribute['name']][$sLanguage];
} else {
$aQuestionAttributes[$aAttribute['name']][$sLanguage] = $aAttribute['default'];
}
}
}
}
} else {
return false;
// return false but don't set $aQuestionAttributesStatic[$iQuestionID]
}
$aQuestionAttributesStatic[$iQuestionID] = $aQuestionAttributes;
return $aQuestionAttributes;
}
示例14: deleteSurvey
/**
* Deletes a survey and all its data
*
* @access public
* @param int $iSurveyID
* @param bool @recursive
* @return void
*/
public function deleteSurvey($iSurveyID, $recursive = true)
{
Survey::model()->deleteByPk($iSurveyID);
if ($recursive == true) {
if (tableExists("{{survey_" . intval($iSurveyID) . "}}")) {
Yii::app()->db->createCommand()->dropTable("{{survey_" . intval($iSurveyID) . "}}");
}
if (tableExists("{{survey_" . intval($iSurveyID) . "_timings}}")) {
Yii::app()->db->createCommand()->dropTable("{{survey_" . intval($iSurveyID) . "_timings}}");
}
if (tableExists("{{tokens_" . intval($iSurveyID) . "}}")) {
Yii::app()->db->createCommand()->dropTable("{{tokens_" . intval($iSurveyID) . "}}");
}
$oResult = Question::model()->findAllByAttributes(array('sid' => $iSurveyID));
foreach ($oResult as $aRow) {
Answer::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
Condition::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
QuestionAttribute::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
DefaultValue::model()->deleteAllByAttributes(array('qid' => $aRow['qid']));
}
Question::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
Assessment::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
QuestionGroup::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
SurveyLanguageSetting::model()->deleteAllByAttributes(array('surveyls_survey_id' => $iSurveyID));
Permission::model()->deleteAllByAttributes(array('entity_id' => $iSurveyID, 'entity' => 'survey'));
SavedControl::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
SurveyURLParameter::model()->deleteAllByAttributes(array('sid' => $iSurveyID));
//Remove any survey_links to the CPDB
SurveyLink::model()->deleteLinksBySurvey($iSurveyID);
Quota::model()->deleteQuota(array('sid' => $iSurveyID), true);
}
}
示例15: do_array_dual
function do_array_dual($ia)
{
global $thissurvey;
$aLastMoveResult = LimeExpressionManager::GetLastMoveResult();
$aMandatoryViolationSubQ = $aLastMoveResult['mandViolation'] && $ia[6] == 'Y' ? explode("|", $aLastMoveResult['unansweredSQs']) : array();
$repeatheadings = Yii::app()->getConfig("repeatheadings");
$minrepeatheadings = Yii::app()->getConfig("minrepeatheadings");
$extraclass = "";
$answertypeclass = "";
// Maybe not
$caption = "";
// Just leave empty, are replaced after
$inputnames = array();
$labelans1 = array();
$labelans = array();
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
if ($aQuestionAttributes['random_order'] == 1) {
$ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY " . dbRandom();
} else {
$ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia['0']} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' and scale_id=0 ORDER BY question_order";
}
$ansresult = dbExecuteAssoc($ansquery);
//Checked
$aSubQuestions = $ansresult->readAll();
$anscount = count($aSubQuestions);
$lquery = "SELECT * FROM {{answers}} WHERE scale_id=0 AND qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY sortorder, code";
$lresult = dbExecuteAssoc($lquery);
//Checked
$aAnswersScale0 = $lresult->readAll();
$lquery1 = "SELECT * FROM {{answers}} WHERE scale_id=1 AND qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY sortorder, code";
$lresult1 = dbExecuteAssoc($lquery1);
//Checked
$aAnswersScale1 = $lresult1->readAll();
if ($aQuestionAttributes['use_dropdown'] == 1) {
$useDropdownLayout = true;
$extraclass .= " dropdown-list";
$answertypeclass .= " dropdown";
$doDualScaleFunction = "doDualScaleDropDown";
// javascript funtion to lauch at end of answers
$caption = gT("An array with sub-question on each line, with 2 answers to provide on each line. You have to select the answer.");
} else {
$useDropdownLayout = false;
$extraclass .= " radio-list";
$answertypeclass .= " radio";
$doDualScaleFunction = "doDualScaleRadio";
$caption = gT("An array with sub-question on each line, with 2 answers to provide on each line. The answers are contained in the table header. ");
}
if (ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings'] != "")) {
$repeatheadings = intval($aQuestionAttributes['repeat_headings']);
$minrepeatheadings = 0;
}
if (trim($aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$leftheader = $aQuestionAttributes['dualscale_headerA'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
} else {
$leftheader = '';
}
if (trim($aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
$rightheader = $aQuestionAttributes['dualscale_headerB'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
} else {
$rightheader = '';
}
if (trim($aQuestionAttributes['answer_width']) != '') {
$answerwidth = $aQuestionAttributes['answer_width'];
} else {
$answerwidth = 20;
}
// Find if we have rigth and center text
// TODO move "|" to attribute
$sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=" . $ia[0] . " and scale_id=0 AND question like '%|%'";
$rigthCount = Yii::app()->db->createCommand($sQuery)->queryScalar();
$rightexists = $rigthCount > 0;
// $right_exists: flag to find out if there are any right hand answer parts. leaving right column but don't force with
$sQuery = "SELECT count(question) FROM {{questions}} WHERE parent_qid=" . $ia[0] . " and scale_id=0 AND question like '%|%|%'";
$centerCount = Yii::app()->db->createCommand($sQuery)->queryScalar();
$centerexists = $centerCount > 0;
// $center_exists: flag to find out if there are any center hand answer parts. leaving center column but don't force with
// Label and code for input
foreach ($aAnswersScale0 as $lrow) {
$labels0[] = array('code' => $lrow['code'], 'title' => $lrow['answer']);
}
foreach ($aAnswersScale1 as $lrow) {
$labels1[] = array('code' => $lrow['code'], 'title' => $lrow['answer']);
}
if (count($aAnswersScale0) > 0 && $anscount) {
$answer = "";
$fn = 1;
// Used by repeat_heading
if ($useDropdownLayout === false) {
$columnswidth = 100 - $answerwidth;
foreach ($aAnswersScale0 as $lrow) {
$labelans0[] = $lrow['answer'];
$labelcode0[] = $lrow['code'];
}
foreach ($aAnswersScale1 as $lrow) {
$labelans1[] = $lrow['answer'];
$labelcode1[] = $lrow['code'];
}
$numrows = count($labelans0) + count($labelans1);
// Add needed row and fill some boolean: shownoanswer, rightexists, centerexists
$shownoanswer = $ia[6] != "Y" && SHOW_NO_ANSWER == 1;
//.........这里部分代码省略.........