本文整理汇总了PHP中questionAttributes函数的典型用法代码示例。如果您正苦于以下问题:PHP questionAttributes函数的具体用法?PHP questionAttributes怎么用?PHP questionAttributes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了questionAttributes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upgrade_question_attributes148
function upgrade_question_attributes148()
{
global $modifyoutput, $dbprefix;
$sDBPrefix = $dbprefix;
$sSurveyQuery = "SELECT sid FROM {$sDBPrefix}surveys";
$oSurveyResult = db_execute_assoc($sSurveyQuery);
foreach ($oSurveyResult->FetchRow() as $aSurveyRow) {
$surveyid = $aSurveyRow['sid'];
$languages = array_merge(array(GetBaseLanguageFromSurveyID($surveyid)), GetAdditionalLanguagesFromSurveyID($surveyid));
$sAttributeQuery = "select q.qid,attribute,value from {$sDBPrefix}question_attributes qa , {$sDBPrefix}questions q where q.qid=qa.qid and sid={$surveyid}";
$oAttributeResult = db_execute_assoc($sAttributeQuery);
$aAllAttributes = questionAttributes(true);
foreach ($oAttributeResult->FetchRow() as $aAttributeRow) {
if (isset($aAllAttributes[$aAttributeRow['attribute']]['i18n']) && $aAllAttributes[$aAttributeRow['attribute']]['i18n']) {
modify_database("delete from {$sDBPrefix}question_attributes where qid={$aAttributeRow['qid']} and attribute='{$aAttributeRow['attribute']}'");
echo $modifyoutput;
flush();
@ob_flush();
foreach ($languages as $language) {
$sAttributeInsertQuery = "insert into {$sDBPrefix}question_attributes (qid,attribute,value,language) VALUES({$aAttributeRow['qid']},'{$aAttributeRow['attribute']}','{$aAttributeRow['value']}','{$language}' )";
modify_database("", $sAttributeInsertQuery);
echo $modifyoutput;
flush();
@ob_flush();
}
}
}
}
}
示例2: XMLImportSurvey
//.........这里部分代码省略.........
$aQIDReplacements[$oldsqid] = $newsqid;
// add old and new qid to the mapping array
} else {
switchMSSQLIdentityInsert('questions', false);
}
$results['subquestions']++;
}
}
// Import answers ------------------------------------------------------------
if (isset($xml->answers)) {
foreach ($xml->answers->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
if (!in_array($insertdata['language'], $aLanguagesSupported) || !isset($aQIDReplacements[(int) $insertdata['qid']])) {
continue;
}
$insertdata['qid'] = $aQIDReplacements[(int) $insertdata['qid']];
// remap the parent_qid
// now translate any links
if ($bTranslateInsertansTags) {
$insertdata['answer'] = translateLinks('survey', $iOldSID, $iNewSID, $insertdata['answer']);
}
if ($insertdata) {
XSSFilterArray($insertdata);
}
$result = Answers::model()->insertRecords($insertdata) or safeDie($clang->gT("Error") . ": Failed to insert data<br />");
$results['answers']++;
}
}
// Import questionattributes -------------------------------------------------
if (isset($xml->question_attributes)) {
$aAllAttributes = questionAttributes(true);
foreach ($xml->question_attributes->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
unset($insertdata['qaid']);
if (!isset($aQIDReplacements[(int) $insertdata['qid']])) {
continue;
}
$insertdata['qid'] = $aQIDReplacements[(int) $insertdata['qid']];
// remap the qid
if ($iDBVersion < 148 && isset($aAllAttributes[$insertdata['attribute']]['i18n']) && $aAllAttributes[$insertdata['attribute']]['i18n']) {
foreach ($aLanguagesSupported as $sLanguage) {
$insertdata['language'] = $sLanguage;
if ($insertdata) {
XSSFilterArray($insertdata);
}
$result = Question_attributes::model()->insertRecords($insertdata) or safeDie($clang->gT("Error") . ": Failed to insert data<br />");
}
} else {
$result = Question_attributes::model()->insertRecords($insertdata) or safeDie($clang->gT("Error") . ": Failed to insert data<br />");
}
$results['question_attributes']++;
}
}
// Import defaultvalues ------------------------------------------------------
if (isset($xml->defaultvalues)) {
$results['defaultvalues'] = 0;
foreach ($xml->defaultvalues->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
示例3: TSVImportSurvey
/**
* Import survey from an TSV file template that does not require or allow assigning of GID or QID values.
* NOTE: This currently only supports import of one language
* @global type $connect
* @global type $dbprefix
* @global type $clang
* @global type $timeadjust
* @param type $sFullFilePath
* @return type
*
* @author TMSWhite
*/
function TSVImportSurvey($sFullFilePath)
{
$clang = Yii::app()->lang;
$insertdata = array();
$results = array();
$results['error'] = false;
$baselang = 'en';
// TODO set proper default
$encoding = '';
$handle = fopen($sFullFilePath, 'r');
$bom = fread($handle, 2);
rewind($handle);
$aAttributeList = questionAttributes();
// Excel tends to save CSV as UTF-16, which PHP does not properly detect
if ($bom === chr(0xff) . chr(0xfe) || $bom === chr(0xfe) . chr(0xff)) {
// UTF16 Byte Order Mark present
$encoding = 'UTF-16';
} else {
$file_sample = fread($handle, 1000) + 'e';
//read first 1000 bytes
// + e is a workaround for mb_string bug
rewind($handle);
$encoding = mb_detect_encoding($file_sample, 'UTF-8, UTF-7, ASCII, EUC-JP,SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP');
}
if ($encoding && $encoding != 'UTF-8') {
stream_filter_append($handle, 'convert.iconv.' . $encoding . '/UTF-8');
}
$file = stream_get_contents($handle);
fclose($handle);
// fix Excel non-breaking space
$file = str_replace("0xC20xA0", ' ', $file);
$filelines = explode("\n", $file);
$row = array_shift($filelines);
$headers = explode("\t", $row);
$rowheaders = array();
foreach ($headers as $header) {
$rowheaders[] = trim($header);
}
// remove BOM from the first header cell, if needed
$rowheaders[0] = preg_replace("/^\\W+/", "", $rowheaders[0]);
if (preg_match('/class$/', $rowheaders[0])) {
$rowheaders[0] = 'class';
// second attempt to remove BOM
}
$adata = array();
foreach ($filelines as $rowline) {
$rowarray = array();
$row = explode("\t", $rowline);
for ($i = 0; $i < count($rowheaders); ++$i) {
$val = isset($row[$i]) ? $row[$i] : '';
// if Excel was used, it surrounds strings with quotes and doubles internal double quotes. Fix that.
if (preg_match('/^".*"$/', $val)) {
$val = str_replace('""', '"', substr($val, 1, -1));
}
$rowarray[$rowheaders[$i]] = $val;
}
$adata[] = $rowarray;
}
$results['defaultvalues'] = 0;
$results['answers'] = 0;
$results['surveys'] = 0;
$results['languages'] = 0;
$results['questions'] = 0;
$results['subquestions'] = 0;
$results['question_attributes'] = 0;
$results['groups'] = 0;
$results['importwarnings'] = array();
// these aren't used here, but are needed to avoid errors in post-import display
$results['assessments'] = 0;
$results['quota'] = 0;
$results['quotamembers'] = 0;
$results['quotals'] = 0;
// collect information about survey and its language settings
$surveyinfo = array();
$surveyls = array();
foreach ($adata as $row) {
switch ($row['class']) {
case 'S':
if (isset($row['text']) && $row['name'] != 'datecreated') {
$surveyinfo[$row['name']] = $row['text'];
}
break;
case 'SL':
if (!isset($surveyls[$row['language']])) {
$surveyls[$row['language']] = array();
}
if (isset($row['text'])) {
$surveyls[$row['language']][$row['name']] = $row['text'];
//.........这里部分代码省略.........
示例4: upgradeQuestionAttributes148
function upgradeQuestionAttributes148()
{
$sSurveyQuery = "SELECT sid FROM {{surveys}}";
$oSurveyResult = dbExecuteAssoc($sSurveyQuery);
$aAllAttributes = questionAttributes(true);
foreach ($oSurveyResult->readAll() as $aSurveyRow) {
$iSurveyID = $aSurveyRow['sid'];
$aLanguages = array_merge(array(Survey::model()->findByPk($iSurveyID)->language), Survey::model()->findByPk($iSurveyID)->additionalLanguages);
$sAttributeQuery = "select q.qid,attribute,value from {{question_attributes}} qa , {{questions}} q where q.qid=qa.qid and sid={$iSurveyID}";
$oAttributeResult = dbExecuteAssoc($sAttributeQuery);
foreach ($oAttributeResult->readAll() as $aAttributeRow) {
if (isset($aAllAttributes[$aAttributeRow['attribute']]['i18n']) && $aAllAttributes[$aAttributeRow['attribute']]['i18n']) {
Yii::app()->getDb()->createCommand("delete from {{question_attributes}} where qid={$aAttributeRow['qid']} and attribute='{$aAttributeRow['attribute']}'")->execute();
foreach ($aLanguages as $sLanguage) {
$sAttributeInsertQuery = "insert into {{question_attributes}} (qid,attribute,value,language) VALUES({$aAttributeRow['qid']},'{$aAttributeRow['attribute']}','{$aAttributeRow['value']}','{$sLanguage}' )";
modifyDatabase("", $sAttributeInsertQuery);
}
}
}
}
}
示例5: getAdvancedSettingsWithValues
/**
* This function returns an array of the advanced attributes for the particular question
* including their values set in the database
*
* @access public
* @param int $iQuestionID The question ID - if 0 then all settings will use the default value
* @param string $sQuestionType The question type
* @param int $iSurveyID
* @param string $sLanguage If you give a language then only the attributes for that language are returned
* @return array
*/
public function getAdvancedSettingsWithValues($iQuestionID, $sQuestionType, $iSurveyID, $sLanguage = null)
{
if (is_null($sLanguage)) {
$aLanguages = array_merge(array(Survey::model()->findByPk($iSurveyID)->language), Survey::model()->findByPk($iSurveyID)->additionalLanguages);
} else {
$aLanguages = array($sLanguage);
}
if ($iQuestionID) {
$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;
}
}
}
$aAttributeNames = questionAttributes();
$aAttributeNames = $aAttributeNames[$sQuestionType];
uasort($aAttributeNames, 'categorySort');
foreach ($aAttributeNames as $iKey => $aAttribute) {
if ($aAttribute['i18n'] == false) {
if (isset($aAttributeValues[$aAttribute['name']])) {
$aAttributeNames[$iKey]['value'] = $aAttributeValues[$aAttribute['name']];
} else {
$aAttributeNames[$iKey]['value'] = $aAttribute['default'];
}
} else {
foreach ($aLanguages as $sLanguage) {
if (isset($aAttributeValues[$aAttribute['name']][$sLanguage])) {
$aAttributeNames[$iKey][$sLanguage]['value'] = $aAttributeValues[$aAttribute['name']][$sLanguage];
} else {
$aAttributeNames[$iKey][$sLanguage]['value'] = $aAttribute['default'];
}
}
}
}
return $aAttributeNames;
}
示例6: index
//.........这里部分代码省略.........
// Language Exists, BUT ITS NOT ON THE SURVEY ANYMORE.
$esrow->delete();
} else {
$questlangs[$esrow->language] = 99;
}
if ($esrow->language == $baselang) {
$esrow = $esrow->attributes;
$basesettings = array('question_order' => $esrow['question_order'], 'other' => $esrow['other'], 'mandatory' => $esrow['mandatory'], 'type' => $esrow['type'], 'title' => $esrow['title'], 'preg' => $esrow['preg'], 'question' => $esrow['question'], 'help' => $esrow['help']);
}
}
if (!$egresult) {
$this->getController()->error('Invalid question id');
}
while (list($key, $value) = each($questlangs)) {
if ($value != 99) {
Questions::model()->insert(array('qid' => $qid, 'sid' => $surveyid, 'gid' => $gid, 'type' => $basesettings['type'], 'title' => $basesettings['title'], 'question' => $basesettings['question'], 'preg' => $basesettings['preg'], 'help' => $basesettings['help'], 'other' => $basesettings['other'], 'mandatory' => $basesettings['mandatory'], 'question_order' => $basesettings['question_order'], 'language' => $key));
}
}
$eqresult = Questions::model()->with('groups')->together()->findByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'qid' => $qid, 'language' => $baselang));
} else {
// This is needed to properly color-code content if it contains replacements
LimeExpressionManager::StartProcessingPage(false, Yii::app()->baseUrl, true);
// so can click on syntax highlighting to edit questions
}
$qtypelist = getQuestionTypeList('', 'array');
$qDescToCode = 'qDescToCode = {';
$qCodeToInfo = 'qCodeToInfo = {';
foreach ($qtypelist as $qtype => $qdesc) {
$qDescToCode .= " '{$qdesc['description']}' : '{$qtype}', \n";
$qCodeToInfo .= " '{$qtype}' : '" . ls_json_encode($qdesc) . "', \n";
}
$aData['qTypeOutput'] = "{$qDescToCode} 'null':'null' }; \n {$qCodeToInfo} 'null':'null' };";
if (!$adding) {
$eqrow = array_merge($eqresult->attributes, $eqresult->groups->attributes);
// Todo: handler in case that record is not found
if ($copying) {
$eqrow['title'] = '';
}
} else {
$eqrow['language'] = $baselang;
$eqrow['title'] = '';
$eqrow['question'] = '';
$eqrow['help'] = '';
$eqrow['type'] = 'T';
$eqrow['lid'] = 0;
$eqrow['lid1'] = 0;
$eqrow['gid'] = $gid;
$eqrow['other'] = 'N';
$eqrow['mandatory'] = 'N';
$eqrow['preg'] = '';
$eqrow['relevance'] = 1;
$eqrow['group_name'] = '';
}
$aData['eqrow'] = $eqrow;
$aData['surveyid'] = $surveyid;
$aData['gid'] = $gid;
if (!$adding) {
$criteria = new CDbCriteria();
$criteria->addColumnCondition(array('sid' => $surveyid, 'gid' => $gid, 'qid' => $qid));
$criteria->params[':lang'] = $baselang;
$criteria->addCondition('language != :lang');
$aqresult = Questions::model()->findAll($criteria);
$aData['aqresult'] = $aqresult;
}
$aData['clang'] = $clang;
$aData['action'] = $action;
$sumresult1 = Survey::model()->findByPk($surveyid);
if (is_null($sumresult1)) {
$this->getController()->error('Invalid Survey ID');
}
$surveyinfo = $sumresult1->attributes;
$surveyinfo = array_map('flattenText', $surveyinfo);
$aData['activated'] = $activated = $surveyinfo['active'];
if ($activated != "Y") {
// Prepare selector Class for javascript function : TODO with or without picture
$selectormodeclass = 'full';
if (Yii::app()->session['questionselectormode'] == 'none') {
$selectormodeclass = 'none';
}
$aData['selectormodeclass'] = $selectormodeclass;
}
if (!$adding) {
$qattributes = questionAttributes();
} else {
$qattributes = array();
}
if ($adding) {
// Get the questions for this group
$baselang = Survey::model()->findByPk($surveyid)->language;
$oqresult = Questions::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $baselang, 'parent_qid' => 0), array('order' => 'question_order'));
$aData['oqresult'] = $oqresult;
}
$this->getController()->_js_admin_includes(Yii::app()->getConfig('adminscripts') . 'questions.js');
$aViewUrls['editQuestion_view'][] = $aData;
$aViewUrls['questionJavascript_view'][] = array('type' => $eqrow['type']);
} else {
include 'accessDenied.php';
}
$this->_renderWrappedTemplate('survey/Question', $aViewUrls, $aData);
}
示例7: elseif
$_SESSION['flashmessage'] = $clang->gT("Default value settings were successfully saved.");
LimeExpressionManager::SetDirtyFlag();
} elseif ($action == "updatequestion" && bHasSurveyPermission($surveyid, 'surveycontent', 'update')) {
LimeExpressionManager::RevertUpgradeConditionsToRelevance($surveyid);
$cqquery = "SELECT type, gid FROM " . db_table_name('questions') . " WHERE qid={$postqid}";
$cqresult = db_execute_assoc($cqquery) or safe_die("Couldn't get question type to check for change<br />" . $cqquery . "<br />" . $connect->ErrorMsg());
// Checked
$cqr = $cqresult->FetchRow();
$oldtype = $cqr['type'];
$oldgid = $cqr['gid'];
if ($filterxsshtml) {
require_once "../classes/inputfilter/class.inputfilter_clean.php";
$myFilter = new InputFilter('', '', 1, 1, 1);
}
// Remove invalid question attributes on saving
$qattributes = questionAttributes();
$attsql = "delete from " . db_table_name('question_attributes') . " where qid='{$postqid}' and ";
if (isset($qattributes[$_POST['type']])) {
$validAttributes = $qattributes[$_POST['type']];
foreach ($validAttributes as $validAttribute) {
$attsql .= 'attribute<>' . db_quoteall($validAttribute['name']) . " and ";
}
}
$attsql .= '1=1';
db_execute_assoc($attsql) or safe_die("Couldn't delete obsolete question attributes<br />" . $attsql . "<br />" . $connect->ErrorMsg());
// Checked
//now save all valid attributes
$validAttributes = $qattributes[$_POST['type']];
foreach ($validAttributes as $validAttribute) {
if (isset($_POST[$validAttribute['name']])) {
if ($filterxsshtml) {
示例8: index
//.........这里部分代码省略.........
} else {
$oldqid = $qr1['qid'];
unset($qr1['qid']);
}
$qr1['gid'] = $iQuestionGroupID;
$iInsertID = Question::model()->insertRecords($qr1);
if (!isset($qr1['qid'])) {
$aSQIDMappings[$oldqid] = $iInsertID;
}
}
}
if (returnGlobal('copyanswers') == "Y") {
$r1 = Answer::model()->getAnswers(returnGlobal('oldqid'));
$aAnswerOptions = $r1->readAll();
foreach ($aAnswerOptions as $qr1) {
Answer::model()->insertRecords(array('qid' => $iQuestionID, 'code' => $qr1['code'], 'answer' => $qr1['answer'], 'assessment_value' => $qr1['assessment_value'], 'sortorder' => $qr1['sortorder'], 'language' => $qr1['language'], 'scale_id' => $qr1['scale_id']));
}
}
/**
* Copy attribute
*/
if (returnGlobal('copyattributes') == "Y") {
$oOldAttributes = QuestionAttribute::model()->findAll("qid=:qid", array("qid" => returnGlobal('oldqid')));
foreach ($oOldAttributes as $oOldAttribute) {
$attribute = new QuestionAttribute();
$attribute->qid = $iQuestionID;
$attribute->value = $oOldAttribute->value;
$attribute->attribute = $oOldAttribute->attribute;
$attribute->language = $oOldAttribute->language;
$attribute->save();
}
}
// Since 2.5, user can edit attribute while copying
$qattributes = questionAttributes();
$validAttributes = $qattributes[Yii::app()->request->getPost('type')];
$aLanguages = array_merge(array(Survey::model()->findByPk($iSurveyID)->language), Survey::model()->findByPk($iSurveyID)->additionalLanguages);
foreach ($validAttributes as $validAttribute) {
if ($validAttribute['i18n']) {
foreach ($aLanguages as $sLanguage) {
$value = Yii::app()->request->getPost($validAttribute['name'] . '_' . $sLanguage);
$iInsertCount = QuestionAttribute::model()->findAllByAttributes(array('attribute' => $validAttribute['name'], 'qid' => $iQuestionID, 'language' => $sLanguage));
if (count($iInsertCount) > 0) {
if ($value != '') {
QuestionAttribute::model()->updateAll(array('value' => $value), 'attribute=:attribute AND qid=:qid AND language=:language', array(':attribute' => $validAttribute['name'], ':qid' => $iQuestionID, ':language' => $sLanguage));
} else {
QuestionAttribute::model()->deleteAll('attribute=:attribute AND qid=:qid AND language=:language', array(':attribute' => $validAttribute['name'], ':qid' => $iQuestionID, ':language' => $sLanguage));
}
} elseif ($value != '') {
$attribute = new QuestionAttribute();
$attribute->qid = $iQuestionID;
$attribute->value = $value;
$attribute->attribute = $validAttribute['name'];
$attribute->language = $sLanguage;
$attribute->save();
}
}
} else {
$value = Yii::app()->request->getPost($validAttribute['name']);
if ($validAttribute['name'] == 'multiflexible_step' && trim($value) != '') {
$value = floatval($value);
if ($value == 0) {
$value = 1;
}
}
$iInsertCount = QuestionAttribute::model()->findAllByAttributes(array('attribute' => $validAttribute['name'], 'qid' => $iQuestionID));
if (count($iInsertCount) > 0) {
示例9: index
//.........这里部分代码省略.........
$qr1['parent_qid'] = $iQuestionID;
if (isset($aSQIDMappings[$qr1['qid']])) {
$qr1['qid'] = $aSQIDMappings[$qr1['qid']];
} else {
$oldqid = $qr1['qid'];
unset($qr1['qid']);
}
$qr1['gid'] = $iQuestionGroupID;
$iInsertID = Question::model()->insertRecords($qr1);
if (!isset($qr1['qid'])) {
$aSQIDMappings[$oldqid] = $iInsertID;
}
}
}
if (returnGlobal('copyanswers') == "Y") {
$r1 = Answer::model()->getAnswers(returnGlobal('oldqid'));
$aAnswerOptions = $r1->readAll();
foreach ($aAnswerOptions as $qr1) {
Answer::model()->insertRecords(array('qid' => $iQuestionID, 'code' => $qr1['code'], 'answer' => $qr1['answer'], 'assessment_value' => $qr1['assessment_value'], 'sortorder' => $qr1['sortorder'], 'language' => $qr1['language'], 'scale_id' => $qr1['scale_id']));
}
}
if (returnGlobal('copyattributes') == "Y") {
$oOldAttributes = QuestionAttribute::model()->findAll("qid=:qid", array("qid" => returnGlobal('oldqid')));
foreach ($oOldAttributes as $oOldAttribute) {
$attribute = new QuestionAttribute();
$attribute->qid = $iQuestionID;
$attribute->value = $oOldAttribute->value;
$attribute->attribute = $oOldAttribute->attribute;
$attribute->language = $oOldAttribute->language;
$attribute->save();
}
}
} else {
$qattributes = questionAttributes();
$validAttributes = $qattributes[Yii::app()->request->getPost('type')];
$aLanguages = array_merge(array(Survey::model()->findByPk($iSurveyID)->language), Survey::model()->findByPk($iSurveyID)->additionalLanguages);
foreach ($validAttributes as $validAttribute) {
if ($validAttribute['i18n']) {
foreach ($aLanguages as $sLanguage) {
$value = Yii::app()->request->getPost($validAttribute['name'] . '_' . $sLanguage);
$iInsertCount = QuestionAttribute::model()->findAllByAttributes(array('attribute' => $validAttribute['name'], 'qid' => $iQuestionID, 'language' => $sLanguage));
if (count($iInsertCount) > 0) {
if ($value != '') {
QuestionAttribute::model()->updateAll(array('value' => $value), 'attribute=:attribute AND qid=:qid AND language=:language', array(':attribute' => $validAttribute['name'], ':qid' => $iQuestionID, ':language' => $sLanguage));
} else {
QuestionAttribute::model()->deleteAll('attribute=:attribute AND qid=:qid AND language=:language', array(':attribute' => $validAttribute['name'], ':qid' => $iQuestionID, ':language' => $sLanguage));
}
} elseif ($value != '') {
$attribute = new QuestionAttribute();
$attribute->qid = $iQuestionID;
$attribute->value = $value;
$attribute->attribute = $validAttribute['name'];
$attribute->language = $sLanguage;
$attribute->save();
}
}
} else {
$value = Yii::app()->request->getPost($validAttribute['name']);
if ($validAttribute['name'] == 'multiflexible_step' && trim($value) != '') {
$value = floatval($value);
if ($value == 0) {
$value = 1;
}
}
$iInsertCount = QuestionAttribute::model()->findAllByAttributes(array('attribute' => $validAttribute['name'], 'qid' => $iQuestionID));
if (count($iInsertCount) > 0) {
示例10: index
//.........这里部分代码省略.........
// so can click on syntax highlighting to edit questions
}
$qtypelist = getQuestionTypeList('', 'array');
$qDescToCode = 'qDescToCode = {';
$qCodeToInfo = 'qCodeToInfo = {';
foreach ($qtypelist as $qtype => $qdesc) {
$qDescToCode .= " '{$qdesc['description']}' : '{$qtype}', \n";
$qCodeToInfo .= " '{$qtype}' : '" . ls_json_encode($qdesc) . "', \n";
}
$aData['qTypeOutput'] = "{$qDescToCode} 'null':'null' }; \n {$qCodeToInfo} 'null':'null' };";
if (!$adding) {
if (is_object($eqresult->groups)) {
$eqrow = array_merge($eqresult->attributes, $eqresult->groups->attributes);
} else {
$eqrow = $eqresult->attributes;
}
// Todo: handler in case that record is not found
if ($copying) {
$eqrow['title'] = '';
}
} else {
$eqrow['language'] = $baselang;
$eqrow['title'] = '';
$eqrow['question'] = '';
$eqrow['help'] = '';
$eqrow['type'] = 'T';
$eqrow['lid'] = 0;
$eqrow['lid1'] = 0;
$eqrow['gid'] = $gid;
$eqrow['other'] = 'N';
$eqrow['mandatory'] = 'N';
$eqrow['preg'] = '';
$eqrow['relevance'] = 1;
$eqrow['group_name'] = '';
}
$eqrow['conditions_number'] = Condition::Model()->count("qid=:qid", array('qid' => $qid));
if ($eqrow['modulename'] != null) {
$oQuestionModule = Question::getQuestionModule($esrow['modulename']);
$questionTitle = (array) $oQuestionModule->title;
$questionModuleName = (array) $oQuestionModule->modulename;
$eqrow['modulename'] = $questionModuleName[0];
$eqrow['moduletitle'] = $questionTitle[0];
}
$aData['eqrow'] = $eqrow;
$aData['surveyid'] = $surveyid;
$aData['gid'] = $gid;
if (!$adding) {
$criteria = new CDbCriteria();
$criteria->addColumnCondition(array('sid' => $surveyid, 'gid' => $gid, 'qid' => $qid));
$criteria->params[':lang'] = $baselang;
$criteria->addCondition('language != :lang');
$aqresult = Question::model()->findAll($criteria);
$aData['aqresult'] = $aqresult;
}
$aData['action'] = $action;
$sumresult1 = Survey::model()->findByPk($surveyid);
if (is_null($sumresult1)) {
$this->getController()->error('Invalid Survey ID');
}
$surveyinfo = $sumresult1->attributes;
$surveyinfo = array_map('flattenText', $surveyinfo);
$aData['activated'] = $activated = $surveyinfo['active'];
if ($activated != "Y") {
// Prepare selector Class for javascript function
if (Yii::app()->session['questionselectormode'] !== 'default') {
$selectormodeclass = Yii::app()->session['questionselectormode'];
} else {
$selectormodeclass = getGlobalSetting('defaultquestionselectormode', 'default');
}
$aData['selectormodeclass'] = $selectormodeclass;
}
if (!$adding) {
$qattributes = questionAttributes();
} else {
$qattributes = array();
}
if ($adding) {
// Get the questions for this group
$baselang = Survey::model()->findByPk($surveyid)->language;
$oqresult = Question::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $baselang, 'parent_qid' => 0), array('order' => 'question_order'));
$aData['oqresult'] = $oqresult;
}
App()->getClientScript()->registerScriptFile(App()->getAssetManager()->publish(ADMIN_SCRIPT_PATH . 'questions.js'));
$aData['sValidateUrl'] = $adding || $copying ? $this->getController()->createUrl('admin/questions', array('sa' => 'ajaxValidate', 'surveyid' => $surveyid)) : $this->getController()->createUrl('admin/questions', array('sa' => 'ajaxValidate', 'surveyid' => $surveyid, 'qid' => $qid));
$aData['addlanguages'] = Survey::model()->findByPk($surveyid)->additionalLanguages;
$aViewUrls['editQuestion_view'][] = $aData;
$aViewUrls['questionJavascript_view'][] = array('type' => $eqrow['type']);
} else {
include 'accessDenied.php';
}
$aData['ajaxDatas']['sValidateUrl'] = isset($aData['sValidateUrl']) ? $aData['sValidateUrl'] : $this->getController()->createUrl('admin/questions', array('sa' => 'ajaxValidate', 'surveyid' => $surveyid));
$aData['ajaxDatas']['qTypeOutput'] = $aData['qTypeOutput'];
///////////
// sidemenu
$aData['sidemenu']['state'] = false;
$aData['sidemenu']['explorer']['state'] = true;
$aData['sidemenu']['explorer']['gid'] = isset($gid) ? $gid : false;
$aData['sidemenu']['explorer']['qid'] = isset($qid) ? $qid : false;
$this->_renderWrappedTemplate('survey/Question', $aViewUrls, $aData);
}
示例11: getQuestionAttributeValues
/**
* Returns a flat array with all question attributes for the question only (and the qid we gave it)!
* @param $iQID The question ID
* @return array$bOrderByNative=>value, attribute=>value} or false if the question ID does not exist (anymore)
*/
function getQuestionAttributeValues($iQID)
{
static $cache = array();
static $availableattributesarr = null;
$iQID = sanitize_int($iQID);
if (isset($cache[$iQID])) {
return $cache[$iQID];
}
$row = Questions::model()->findByAttributes(array('qid' => $iQID));
//, 'parent_qid' => 0), array('group' => 'type')
if (empty($row)) {
$cache[$iQID] = false;
return false;
} else {
$row = $row->getAttributes();
}
$type = $row['type'];
$surveyid = $row['sid'];
$aLanguages = array_merge((array) Survey::model()->findByPk($surveyid)->language, Survey::model()->findByPk($surveyid)->additionalLanguages);
//Now read available attributes, make sure we do this only once per request to save
//processing cycles and memory
if (is_null($availableattributesarr)) {
$availableattributesarr = questionAttributes();
}
if (isset($availableattributesarr[$type])) {
$aAvailableAttributes = $availableattributesarr[$type];
} else {
$cache[$iQID] = array();
return array();
}
$aResultAttributes = array();
foreach ($aAvailableAttributes as $attribute) {
if ($attribute['i18n']) {
foreach ($aLanguages as $sLanguage) {
$aResultAttributes[$attribute['name']][$sLanguage] = $attribute['default'];
}
} else {
$aResultAttributes[$attribute['name']] = $attribute['default'];
}
}
$result = Question_attributes::model()->findAllByAttributes(array('qid' => $iQID));
foreach ($result as $row) {
$row = $row->attributes;
if (!isset($aAvailableAttributes[$row['attribute']])) {
continue;
// Sort out attributes not belonging to this question
}
if (!$aAvailableAttributes[$row['attribute']]['i18n']) {
$aResultAttributes[$row['attribute']] = $row['value'];
} elseif (!empty($row['language'])) {
$aResultAttributes[$row['attribute']][$row['language']] = $row['value'];
}
}
$cache[$iQID] = $aResultAttributes;
return $aResultAttributes;
}
示例12: returnglobal
$surveyid = returnglobal('sid');
if ($match == 1) {
$language = GetBaseLanguageFromSurveyID($surveyid);
} else {
$language = null;
}
$resultdata = getlabelsets($language);
echo json_encode($resultdata);
}
if ($action == "ajaxquestionattributes") {
$thissurvey = getSurveyInfo($surveyid);
$type = returnglobal('question_type');
if (isset($qid)) {
$attributesettings = getQuestionAttributes($qid);
}
$availableattributes = questionAttributes();
if (isset($availableattributes[$type])) {
uasort($availableattributes[$type], 'CategorySort');
$ajaxoutput = '';
$currentfieldset = '';
foreach ($availableattributes[$type] as $qa) {
if (isset($attributesettings[$qa['name']])) {
$value = $attributesettings[$qa['name']];
} else {
$value = $qa['default'];
}
if ($currentfieldset != $qa['category']) {
if ($currentfieldset != '') {
$ajaxoutput .= '</ul></fieldset>';
}
$ajaxoutput .= "<fieldset>\n";
示例13: getQuestionAttributes
/**
*
* Returns a flat array with all question attributes for the question only (and the qid we gave it)!
* @author: c_schmitz
* @param $qid The question ID
* @param $type optional The question type - saves a DB query if you provide it
* @return array{attribute=>value , attribute=>value} or false if the question ID does not exist (anymore)
*/
function getQuestionAttributes($qid, $type = '')
{
static $cache = array();
static $availableattributesarr = null;
if (isset($cache[$qid])) {
return $cache[$qid];
}
if ($type == '') {
$query = "SELECT type FROM " . db_table_name('questions') . " WHERE qid={$qid} and parent_qid=0 group by type";
$result = db_execute_assoc($query) or safe_die("Error finding question attributes");
//Checked
$row = $result->FetchRow();
if ($row === false) {
$cache[$qid] = false;
return false;
}
$type = $row['type'];
}
//Now read available attributes, make sure we do this only once per request to save
//processing cycles and memory
if (is_null($availableattributesarr)) {
$availableattributesarr = questionAttributes();
}
if (isset($availableattributesarr[$type])) {
$availableattributes = $availableattributesarr[$type];
} else {
$cache[$qid] = array();
return array();
}
foreach ($availableattributes as $attribute) {
$defaultattributes[$attribute['name']] = $attribute['default'];
}
$setattributes = array();
$qid = sanitize_int($qid);
$query = "SELECT attribute, value FROM " . db_table_name('question_attributes') . " WHERE qid={$qid}";
$result = db_execute_assoc($query) or safe_die("Error finding question attributes");
//Checked
$setattributes = array();
while ($row = $result->FetchRow()) {
$setattributes[$row['attribute']] = $row['value'];
}
//echo "<pre>";print_r($qid_attributes);echo "</pre>";
$qid_attributes = array_merge($defaultattributes, $setattributes);
$cache[$qid] = $qid_attributes;
return $qid_attributes;
}
示例14: index
//.........这里部分代码省略.........
if (returnGlobal('copysubquestions') == "Y") {
$aSQIDMappings = array();
$r1 = Questions::model()->getSubQuestions(returnGlobal('oldqid'));
while ($qr1 = $r1->read()) {
$qr1['parent_qid'] = $qid;
if (isset($aSQIDMappings[$qr1['qid']])) {
$qr1['qid'] = $aSQIDMappings[$qr1['qid']];
} else {
$oldqid = $qr1['qid'];
unset($qr1['qid']);
}
$qr1['gid'] = $postgid;
$iInsertID = Questions::model()->insertRecords($qr1);
if (!isset($qr1['qid'])) {
$aSQIDMappings[$oldqid] = $iInsertID;
}
}
}
if (returnGlobal('copyanswers') == "Y") {
$r1 = Answers::model()->getAnswers(returnGlobal('oldqid'));
while ($qr1 = $r1->read()) {
Answers::model()->insertRecords(array('qid' => $qid, 'code' => $qr1['code'], 'answer' => $qr1['answer'], 'sortorder' => $qr1['sortorder'], 'language' => $qr1['language'], 'scale_id' => $qr1['scale_id']));
}
}
if (returnGlobal('copyattributes') == "Y") {
$r1 = Question_attributes::model()->getQuestionAttributes(returnGlobal('oldqid'));
while ($qr1 = $r1->read()) {
$qr1['qid'] = $qid;
unset($qr1['qaid']);
Question_attributes::model()->insertRecords($qr1);
}
}
} else {
$qattributes = questionAttributes();
$validAttributes = $qattributes[Yii::app()->request->getPost('type')];
$aLanguages = array_merge(array(Survey::model()->findByPk($surveyid)->language), Survey::model()->findByPk($surveyid)->additionalLanguages);
foreach ($validAttributes as $validAttribute) {
if ($validAttribute['i18n']) {
foreach ($aLanguages as $sLanguage) {
// TODO sanitise XSS
$value = Yii::app()->request->getPost($validAttribute['name'] . '_' . $sLanguage);
$result = Question_attributes::model()->findAllByAttributes(array('attribute' => $validAttribute['name'], 'qid' => $qid, 'language' => $sLanguage));
if (count($result) > 0) {
if ($value != '') {
Question_attributes::model()->updateAll(array('value' => $value), 'attribute=:attribute AND qid=:qid AND language=:language', array(':attribute' => $validAttribute['name'], ':qid' => $qid, ':language' => $sLanguage));
} else {
Question_attributes::model()->deleteAll('attribute=:attribute AND qid=:qid AND language=:language', array(':attribute' => $validAttribute['name'], ':qid' => $qid, ':language' => $sLanguage));
}
} elseif ($value != '') {
$attribute = new Question_attributes();
$attribute->qid = $qid;
$attribute->value = $value;
$attribute->attribute = $validAttribute['name'];
$attribute->language = $sLanguage;
$attribute->save();
}
}
} else {
$value = Yii::app()->request->getPost($validAttribute['name']);
if ($validAttribute['name'] == 'multiflexible_step' && trim($value) != '') {
$value = floatval($value);
if ($value == 0) {
$value = 1;
}
}
$result = Question_attributes::model()->findAllByAttributes(array('attribute' => $validAttribute['name'], 'qid' => $qid));
示例15: 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;
}