本文整理汇总了PHP中LimeExpressionManager::RevertUpgradeConditionsToRelevance方法的典型用法代码示例。如果您正苦于以下问题:PHP LimeExpressionManager::RevertUpgradeConditionsToRelevance方法的具体用法?PHP LimeExpressionManager::RevertUpgradeConditionsToRelevance怎么用?PHP LimeExpressionManager::RevertUpgradeConditionsToRelevance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LimeExpressionManager
的用法示例。
在下文中一共展示了LimeExpressionManager::RevertUpgradeConditionsToRelevance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fixNumbering
/**
* fixes the numbering of questions
* This can happen if question 1 have subquestion code 1 and have question 11 in same survey and group (then same SGQA)
* @param int $fixnumbering
* @todo can call this function (no $_GET, but getParam) AND do it with Yii
*/
function fixNumbering($iQuestionID, $iSurveyID)
{
Yii::app()->loadHelper("database");
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID);
//Fix a question id - requires renumbering a question
$iQuestionID = (int) $iQuestionID;
$iMaxQID = Question::model()->getMaxId('qid', true);
// Always refresh as we insert new qid's
$iNewQID = $iMaxQID + 1;
// Not sure we can do this in MSSQL ?
$sQuery = "UPDATE {{questions}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
// Update subquestions
$sQuery = "UPDATE {{questions}} SET parent_qid={$iNewQID} WHERE parent_qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Update conditions.. firstly conditions FOR this question
$sQuery = "UPDATE {{conditions}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Update default values
$sQuery = "UPDATE {{defaultvalues}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
$sQuery = "UPDATE {{defaultvalues}} SET sqid={$iNewQID} WHERE sqid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Update quotas
$sQuery = "UPDATE {{quota_members}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Update url params
$sQuery = "UPDATE {{survey_url_parameters}} SET targetqid={$iNewQID} WHERE targetqid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
$sQuery = "UPDATE {{survey_url_parameters}} SET targetsqid={$iNewQID} WHERE targetsqid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Now conditions based upon this question
$sQuery = "SELECT cqid, cfieldname FROM {{conditions}} WHERE cqid={$iQuestionID}";
$sResult = Yii::app()->db->createCommand($sQuery)->query();
foreach ($sResult->readAll() as $row) {
$aSwitcher[] = array("cqid" => $row['cqid'], "cfieldname" => $row['cfieldname']);
}
if (isset($aSwitcher)) {
foreach ($aSwitcher as $aSwitch) {
$sQuery = "UPDATE {{conditions}}\n SET cqid={$iNewQID},\n cfieldname='" . str_replace("X" . $iQuestionID, "X" . $iNewQID, $aSwitch['cfieldname']) . "'\n WHERE cqid={$iQuestionID}";
$sResult = db_execute_assosc($sQuery);
}
}
//Now question_attributes
$sQuery = "UPDATE {{question_attributes}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Now answers
$sQuery = "UPDATE {{answers}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID);
}
示例2: fixNumbering
/**
* fixes the numbering of questions
* @param <type> $fixnumbering
*/
function fixNumbering($fixnumbering, $iSurveyID)
{
Yii::app()->loadHelper("database");
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID);
//Fix a question id - requires renumbering a question
$oldqid = $fixnumbering;
$query = "SELECT qid FROM {{questions}} ORDER BY qid DESC";
$result = dbSelectLimitAssoc($query, 1);
foreach ($result->readAll() as $row) {
$lastqid = $row['qid'];
}
$newqid = $lastqid + 1;
$query = "UPDATE {{questions}} SET qid={$newqid} WHERE qid={$oldqid}";
$result = db_execute_assosc($query);
// Update subquestions
$query = "UPDATE {{questions}} SET parent_qid={$newqid} WHERE parent_qid={$oldqid}";
$result = db_execute_assosc($query);
//Update conditions.. firstly conditions FOR this question
$query = "UPDATE {{conditions}} SET qid={$newqid} WHERE qid={$oldqid}";
$result = db_execute_assosc($query);
//Now conditions based upon this question
$query = "SELECT cqid, cfieldname FROM {{conditions}} WHERE cqid={$oldqid}";
$result = dbExecuteAssoc($query);
foreach ($result->readAll() as $row) {
$switcher[] = array("cqid" => $row['cqid'], "cfieldname" => $row['cfieldname']);
}
if (isset($switcher)) {
foreach ($switcher as $switch) {
$query = "UPDATE {{conditions}}\n SET cqid={$newqid},\n cfieldname='" . str_replace("X" . $oldqid, "X" . $newqid, $switch['cfieldname']) . "'\n WHERE cqid={$oldqid}";
$result = db_execute_assosc($query);
}
}
// TMSW Conditions->Relevance: (1) Call LEM->ConvertConditionsToRelevance()when done. (2) Should relevance for old conditions be removed first?
//Now question_attributes
$query = "UPDATE {{question_attributes}} SET qid={$newqid} WHERE qid={$oldqid}";
$result = db_execute_assosc($query);
//Now answers
$query = "UPDATE {{answers}} SET qid={$newqid} WHERE qid={$oldqid}";
$result = db_execute_assosc($query);
LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID);
}
示例3: fixNumbering
/**
* fixes the numbering of questions
* @global $dbprefix $dbprefix
* @global $connect $connect
* @global $clang $clang
* @param <type> $fixnumbering
*/
function fixNumbering($fixnumbering)
{
global $dbprefix, $connect, $clang, $surveyid;
LimeExpressionManager::RevertUpgradeConditionsToRelevance($surveyid);
//Fix a question id - requires renumbering a question
$oldqid = sanitize_int($fixnumbering);
$query = "SELECT qid FROM {$dbprefix}questions ORDER BY qid DESC";
$result = db_select_limit_assoc($query, 1) or safe_die($query . "<br />" . $connect->ErrorMsg());
while ($row = $result->FetchRow()) {
$lastqid = $row['qid'];
}
$newqid = $lastqid + 1;
$query = "UPDATE {$dbprefix}questions SET qid={$newqid} WHERE qid={$oldqid}";
$result = $connect->Execute($query) or safe_die($query . "<br />" . $connect->ErrorMsg());
// Update subquestions
$query = "UPDATE {$dbprefix}questions SET parent_qid={$newqid} WHERE parent_qid={$oldqid}";
$result = $connect->Execute($query) or safe_die($query . "<br />" . $connect->ErrorMsg());
//Update conditions.. firstly conditions FOR this question
$query = "UPDATE {$dbprefix}conditions SET qid={$newqid} WHERE qid={$oldqid}";
$result = $connect->Execute($query) or safe_die($query . "<br />" . $connect->ErrorMsg());
//Now conditions based upon this question
$query = "SELECT cqid, cfieldname FROM {$dbprefix}conditions WHERE cqid={$oldqid}";
$result = db_execute_assoc($query) or safe_die($query . "<br />" . $connect->ErrorMsg());
while ($row = $result->FetchRow()) {
$switcher[] = array("cqid" => $row['cqid'], "cfieldname" => $row['cfieldname']);
}
if (isset($switcher)) {
foreach ($switcher as $switch) {
$query = "UPDATE {$dbprefix}conditions\n SET cqid={$newqid},\n cfieldname='" . str_replace("X" . $oldqid, "X" . $newqid, $switch['cfieldname']) . "'\n WHERE cqid={$oldqid}";
$result = $connect->Execute($query) or safe_die($query . "<br />" . $connect->ErrorMsg());
}
}
//Now question_attributes
$query = "UPDATE {$dbprefix}question_attributes SET qid={$newqid} WHERE qid={$oldqid}";
$result = $connect->Execute($query) or safe_die($query . "<br />" . $connect->ErrorMsg());
//Now answers
$query = "UPDATE {$dbprefix}answers SET qid={$newqid} WHERE qid={$oldqid}";
$result = $connect->Execute($query) or safe_die($query . "<br />" . $connect->ErrorMsg());
LimeExpressionManager::UpgradeConditionsToRelevance($surveyid);
}
示例4: index
//.........这里部分代码省略.........
$p_method = trim($_POST['method']);
}
}
if (isset($_POST['newscenarionum'])) {
$p_newscenarionum = sanitize_int($_POST['newscenarionum']);
}
//END Sanitizing POSTed data
//include_once("login_check.php");
include_once "database.php";
// Caution (lemeur): database.php uses autoUnescape on all entries in $_POST
// Take care to not use autoUnescape on $_POST variables after this
$br = CHtml::openTag('br /');
//MAKE SURE THAT THERE IS A SID
if (!isset($iSurveyID) || !$iSurveyID) {
$conditionsoutput = $clang->gT("You have not selected a survey") . str_repeat($br, 2);
$conditionsoutput .= CHtml::submitButton($clang->gT("Main admin screen"), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/") . "', '_top')")) . $br;
safeDie($conditionsoutput);
return;
}
if (isset($p_subaction) && $p_subaction == "resetsurveylogic") {
$clang = $this->getController()->lang;
$resetsurveylogicoutput = $br;
$resetsurveylogicoutput .= CHtml::openTag('table', array('class' => 'alertbox'));
$resetsurveylogicoutput .= CHtml::openTag('tr') . CHtml::openTag('td', array('colspan' => '2'));
$resetsurveylogicoutput .= CHtml::tag('font', array('size' => '1'), CHtml::tag('strong', array(), $clang->gT("Reset Survey Logic")));
$resetsurveylogicoutput .= CHtml::closeTag('td') . CHtml::closeTag('tr');
if (!isset($_GET['ok'])) {
$button_yes = CHtml::submitButton($clang->gT("Yes"), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/conditions/sa/index/subaction/resetsurveylogic/surveyid/{$iSurveyID}") . "?ok=Y" . "', '_top')"));
$button_cancel = CHtml::submitButton($clang->gT("Cancel"), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/survey/sa/view/surveyid/{$iSurveyID}") . "', '_top')"));
$messagebox_content = $clang->gT("You are about to delete all conditions on this survey's questions") . "({$iSurveyID})" . $br . $clang->gT("We recommend that before you proceed, you export the entire survey from the main administration screen.") . $br . $clang->gT("Continue?") . $br . $button_yes . $button_cancel;
$this->_renderWrappedTemplate('conditions', array('message' => array('title' => $clang->gT("Warning"), 'message' => $messagebox_content)));
exit;
} else {
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID);
Conditions::model()->deleteRecords("qid in (select qid from {{questions}} where sid={$iSurveyID})");
Yii::app()->session['flashmessage'] = $clang->gT("All conditions in this survey have been deleted.");
$this->getController()->redirect($this->getController()->createUrl('admin/survey/sa/view/surveyid/' . $iSurveyID));
}
}
// MAKE SURE THAT THERE IS A QID
if (!isset($qid) || !$qid) {
$conditionsoutput = $clang->gT("You have not selected a question") . str_repeat($br, 2);
$conditionsoutput .= CHtml::submitButton($clang->gT("Main admin screen"), array('onclick' => "window.open('" . $this->getController()->createUrl("admin/") . "', '_top')")) . $br;
safeDie($conditionsoutput);
return;
}
// If we made it this far, then lets develop the menu items
// add the conditions container table
$extraGetParams = "";
if (isset($qid) && isset($gid)) {
$extraGetParams = "/gid/{$gid}/qid/{$qid}";
}
$conditionsoutput_action_error = "";
// defined during the actions
$markcidarray = array();
if (isset($_GET['markcid'])) {
$markcidarray = explode("-", $_GET['markcid']);
}
//BEGIN PROCESS ACTIONS
// ADD NEW ENTRY IF THIS IS AN ADD
if (isset($p_subaction) && $p_subaction == "insertcondition") {
if (!isset($p_canswers) && !isset($_POST['ConditionConst']) && !isset($_POST['prevQuestionSGQA']) && !isset($_POST['tokenAttr']) && !isset($_POST['ConditionRegexp']) || !isset($p_cquestions) && !isset($p_csrctoken)) {
$conditionsoutput_action_error .= CHtml::script("\n<!--\n alert(\"" . $clang->gT("Your condition could not be added! It did not include the question and/or answer upon which the condition was based. Please ensure you have selected a question and an answer.", "js") . "\")\n //-->\n");
} else {
if (isset($p_cquestions) && $p_cquestions != '') {
$conditionCfieldname = $p_cquestions;
示例5: delete
/**
* Action to delete a question group.
*
* @access public
* @return void
*/
public function delete($iSurveyId, $iGroupId)
{
$iSurveyId = sanitize_int($iSurveyId);
if (Permission::model()->hasSurveyPermission($iSurveyId, 'surveycontent', 'delete')) {
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyId);
$iGroupId = sanitize_int($iGroupId);
$iGroupsDeleted = QuestionGroup::deleteWithDependency($iGroupId, $iSurveyId);
if ($iGroupsDeleted > 0) {
fixSortOrderGroups($iSurveyId);
Yii::app()->setFlashMessage(gT('The question group was deleted.'));
} else {
Yii::app()->setFlashMessage(gT('Group could not be deleted'), 'error');
}
LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyId);
$this->getController()->redirect(array('admin/survey/sa/view/surveyid/' . $iSurveyId));
}
}
示例6: delete
/**
* Function responsible for deleting a question.
*
* @access public
* @param string $action
* @param int $surveyid
* @param int $gid
* @param int $qid
* @return void
*/
public function delete($surveyid, $gid, $qid)
{
$clang = $this->getController()->lang;
$surveyid = sanitize_int($surveyid);
$gid = sanitize_int($gid);
$qid = sanitize_int($qid);
if (hasSurveyPermission($surveyid, 'surveycontent', 'delete')) {
if (!isset($qid)) {
$qid = returnGlobal('qid');
}
LimeExpressionManager::RevertUpgradeConditionsToRelevance(NULL, $qid);
// Check if any other questions have conditions which rely on this question. Don't delete if there are.
// TMSW Conditions->Relevance: Allow such deletes - can warn about missing relevance separately.
$ccresult = Conditions::model()->findAllByAttributes(array('cqid' => $qid));
$cccount = count($ccresult);
// There are conditions dependent on this question
if ($cccount) {
foreach ($ccresult as $ccr) {
$qidarray[] = $ccr->qid;
}
if (isset($qidarray)) {
$qidlist = implode(", ", $qidarray);
}
$message = $clang->gT("Question could not be deleted. There are conditions for other questions that rely on this question. You cannot delete this question until those conditions are removed.");
$message .= "<br /><a href='" . $this->getController()->createUrl("admin/expressions/sa/survey_logic_file/sid/{$surveyid}") . "' >" . $clang->gT("Look at survey logic files") . "</a>.";
$this->getController()->error($message, $this->getController()->createUrl("admin/survey/sa/view/surveyid/{$surveyid}/gid/{$gid}/qid/{$qid}"));
} else {
$row = Questions::model()->findByAttributes(array('qid' => $qid))->attributes;
$gid = $row['gid'];
// See if there are any conditions/attributes/answers/defaultvalues for this question,
// and delete them now as well
Conditions::model()->deleteAllByAttributes(array('qid' => $qid));
Question_attributes::model()->deleteAllByAttributes(array('qid' => $qid));
Answers::model()->deleteAllByAttributes(array('qid' => $qid));
$criteria = new CDbCriteria();
$criteria->addCondition('qid = :qid1 or parent_qid = :qid2');
$criteria->params[':qid1'] = $qid;
$criteria->params[':qid2'] = $qid;
Questions::model()->deleteAll($criteria);
Defaultvalues::model()->deleteAllByAttributes(array('qid' => $qid));
Quota_members::model()->deleteAllByAttributes(array('qid' => $qid));
Questions::model()->updateQuestionOrder($gid, $surveyid);
$qid = "";
$postqid = "";
$_GET['qid'] = "";
}
Yii::app()->session['flashmessage'] = $clang->gT("Question was successfully deleted.");
$this->getController()->redirect($this->getController()->createUrl('admin/survey/sa/view/surveyid/' . $surveyid . '/gid/' . $gid));
} else {
Yii::app()->session['flashmessage'] = $clang->gT("You are not authorized to delete questions.");
$this->getController()->redirect($this->getController()->createUrl('admin/survey/sa/view/surveyid/' . $surveyid . '/gid/' . $gid));
}
}
示例7: elseif
}
$sortorderid--;
$_SESSION['flashmessage'] = $clang->gT("Answer options were successfully saved.");
$action = 'editansweroptions';
} elseif ($action == "updatesubquestions" && bHasSurveyPermission($surveyid, 'surveycontent', 'update')) {
$anslangs = GetAdditionalLanguagesFromSurveyID($surveyid);
$baselang = GetBaseLanguageFromSurveyID($surveyid);
array_unshift($anslangs, $baselang);
$query = "select type from " . db_table_name('questions') . " where qid={$qid}";
$questiontype = $connect->GetOne($query);
// Checked
$qtypes = getqtypelist('', 'array');
$scalecount = $qtypes[$questiontype]['subquestions'];
// First delete any deleted ids
$deletedqids = explode(' ', trim($_POST['deletedqids']));
LimeExpressionManager::RevertUpgradeConditionsToRelevance($surveyid);
foreach ($deletedqids as $deletedqid) {
$deletedqid = (int) $deletedqid;
if ($deletedqid > 0) {
// don't remove undefined
$query = "DELETE FROM " . db_table_name('questions') . " WHERE qid='{$deletedqid}'";
// Checked
if (!($result = $connect->Execute($query))) {
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"" . $clang->gT("Failed to delete answer", "js") . " - " . $query . " - " . $connect->ErrorMsg() . "\")\n //-->\n</script>\n";
}
}
}
//Determine ids by evaluating the hidden field
$rows = array();
$codes = array();
$oldcodes = array();
示例8: question
<?php
$data = LimeExpressionManager::RevertUpgradeConditionsToRelevance();
if (is_null($data)) {
echo "No conditions found in database. Nothing to revert.";
} else {
echo "Found and removed relevance for " . $data . " question(s)";
}
示例9: XMLImportSurvey
//.........这里部分代码省略.........
// Import assessments --------------------------------------------------------
if (isset($xml->assessments)) {
foreach ($xml->assessments->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
if ($insertdata['gid'] > 0) {
$insertdata['gid'] = $aGIDReplacements[(int) $insertdata['gid']];
// remap the qid
}
$insertdata['sid'] = $iNewSID;
// remap the survey id
// now translate any links
$result = Assessment::model()->insertRecords($insertdata) or safeDie($clang->gT("Error") . ": Failed to insert data<br />");
$results['assessments']++;
}
}
// Import quota --------------------------------------------------------------
if (isset($xml->quota)) {
foreach ($xml->quota->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['sid'] = $iNewSID;
// remap the survey id
$oldid = $insertdata['id'];
unset($insertdata['id']);
// now translate any links
$result = Quota::model()->insertRecords($insertdata) or safeDie($clang->gT("Error") . ": Failed to insert data<br />");
$aQuotaReplacements[$oldid] = Yii::app()->db->getCommandBuilder()->getLastInsertID('{{quota}}');
$results['quota']++;
}
}
// Import quota_members ------------------------------------------------------
if (isset($xml->quota_members)) {
foreach ($xml->quota_members->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['sid'] = $iNewSID;
// remap the survey id
$insertdata['qid'] = $aQIDReplacements[(int) $insertdata['qid']];
// remap the qid
$insertdata['quota_id'] = $aQuotaReplacements[(int) $insertdata['quota_id']];
// remap the qid
unset($insertdata['id']);
// now translate any links
$result = Quota_members::model()->insertRecords($insertdata) or safeDie($clang->gT("Error") . ": Failed to insert data<br />");
$results['quotamembers']++;
}
}
// Import quota_languagesettings----------------------------------------------
if (isset($xml->quota_languagesettings)) {
foreach ($xml->quota_languagesettings->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['quotals_quota_id'] = $aQuotaReplacements[(int) $insertdata['quotals_quota_id']];
// remap the qid
unset($insertdata['quotals_id']);
$result = Quota_languagesettings::model()->insertRecords($insertdata) or safeDie($clang->gT("Error") . ": Failed to insert data<br />");
$results['quotals']++;
}
}
// Import survey_url_parameters ----------------------------------------------
if (isset($xml->survey_url_parameters)) {
foreach ($xml->survey_url_parameters->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['sid'] = $iNewSID;
// remap the survey id
if (isset($insertdata['targetsqid']) && $insertdata['targetsqid'] != '') {
$insertdata['targetsqid'] = $aSQIDReplacements[(int) $insertdata['targetsqid']];
// remap the qid
}
if (isset($insertdata['targetqid']) && $insertdata['targetqid'] != '') {
$insertdata['targetqid'] = $aQIDReplacements[(int) $insertdata['targetqid']];
// remap the qid
}
unset($insertdata['id']);
$result = Survey_url_parameters::model()->insertRecord($insertdata) or safeDie($clang->gT("Error") . ": Failed to insert data<br />");
$results['survey_url_parameters']++;
}
}
// Set survey rights
Survey_permissions::model()->giveAllSurveyPermissions(Yii::app()->session['loginID'], $iNewSID);
$aOldNewFieldmap = reverseTranslateFieldNames($iOldSID, $iNewSID, $aGIDReplacements, $aQIDReplacements);
$results['FieldReMap'] = $aOldNewFieldmap;
LimeExpressionManager::SetSurveyId($iNewSID);
translateInsertansTags($iNewSID, $iOldSID, $aOldNewFieldmap);
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iNewSID);
LimeExpressionManager::UpgradeConditionsToRelevance($iNewSID);
return $results;
}
示例10: delete_question
/**
* RPC Routine to delete a question of a survey .
* Returns the id of the deleted question.
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int iQuestionID Id of the question to delete
* @return array|int Id of the deleted Question or status
*/
public function delete_question($sSessionKey, $iQuestionID)
{
if ($this->_checkSessionKey($sSessionKey)) {
$oQuestion = Question::model()->findByAttributes(array('qid' => $iQuestionID));
if (!isset($oQuestion)) {
return array('status' => 'Error: Invalid question ID');
}
$iSurveyID = $oQuestion['sid'];
if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'delete')) {
$oSurvey = Survey::model()->findByPk($iSurveyID);
if ($oSurvey['active'] == 'Y') {
return array('status' => 'Survey is active and not editable');
}
$iGroupID = $oQuestion['gid'];
$oCondition = Condition::model()->findAllByAttributes(array('cqid' => $iQuestionID));
if (count($oCondition) > 0) {
return array('status' => 'Cannot delete Question. Others rely on this question');
}
LimeExpressionManager::RevertUpgradeConditionsToRelevance(NULL, $iQuestionID);
try {
Condition::model()->deleteAllByAttributes(array('qid' => $iQuestionID));
QuestionAttribute::model()->deleteAllByAttributes(array('qid' => $iQuestionID));
Answer::model()->deleteAllByAttributes(array('qid' => $iQuestionID));
$sCriteria = new CDbCriteria();
$sCriteria->addCondition('qid = :qid or parent_qid = :qid');
$sCriteria->params[':qid'] = $iQuestionID;
Question::model()->deleteAll($sCriteria);
DefaultValue::model()->deleteAllByAttributes(array('qid' => $iQuestionID));
QuotaMember::model()->deleteAllByAttributes(array('qid' => $iQuestionID));
Question::updateSortOrder($iGroupID, $iSurveyID);
return (int) $iQuestionID;
} catch (Exception $e) {
return array('status' => 'Error');
}
} else {
return array('status' => 'No permission');
}
} else {
return array('status' => 'Invalid session key');
}
}
示例11: set_question_sub_questions
public function set_question_sub_questions($sSessionKey, $iSurveyID, $iQuestionID, $data)
{
$data_array = unserialize($data);
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]['subquestions'];
//$clang = $this->getController()->lang;
// First delete any deleted ids
//$aDeletedQIDs = explode(' ', trim($data));
$aDeletedQIDs = explode('+', $data_array['deletedqids']);
$iQuestionGroupID = $data_array['gid'];
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID);
$aDeletedQIDs = array_unique($aDeletedQIDs, SORT_NUMERIC);
foreach ($aDeletedQIDs as $iDeletedQID) {
$iDeletedQID = (int) $iDeletedQID;
if ($iDeletedQID > 0) {
// don't remove undefined
$iInsertCount = Question::model()->deleteAllByAttributes(array('qid' => $iDeletedQID));
if (!$iInsertCount) {
return "Failed to delete answer";
}
}
}
//Determine ids by evaluating the hidden field
$aRows = array();
$aCodes = array();
$aOldCodes = array();
foreach ($data_array as $key => $value) {
$key = explode('_', $key);
if ($key[0] == 'answer') {
$aRows[$key[3]][$key[1]][$key[2]] = $value;
}
if ($key[0] == 'code') {
$aCodes[$key[2]][] = $value;
}
if ($key[0] == 'oldcode') {
$aOldCodes[$key[2]][] = $value;
}
}
$aInsertQID = array();
for ($iScaleID = 0; $iScaleID < $iScaleCount; $iScaleID++) {
foreach ($aSurveyLanguages as $sLanguage) {
$iPosition = 0;
$test = '';
foreach ($aRows[$iScaleID][$sLanguage] as $subquestionkey => $subquestionvalue) {
$test .= $subquestionvalue . ', ';
// create a new sub question
if (substr($subquestionkey, 0, 3) != 'new') {
$oSubQuestion = Question::model()->find("qid=:qid AND language=:language", array(":qid" => $subquestionkey, ':language' => $sLanguage));
$oSubQuestion->question_order = $iPosition + 1;
$oSubQuestion->title = $aCodes[$iScaleID][$iPosition];
$oSubQuestion->question = $subquestionvalue;
$oSubQuestion->scale_id = $iScaleID;
// update the old sub questions
} else {
if (!isset($aInsertQID[$iScaleID][$iPosition])) {
$oSubQuestion = new Question();
$oSubQuestion->sid = $iSurveyID;
$oSubQuestion->gid = $iQuestionGroupID;
$oSubQuestion->question_order = $iPosition + 1;
$oSubQuestion->title = $aCodes[$iScaleID][$iPosition];
$oSubQuestion->question = $subquestionvalue;
$oSubQuestion->parent_qid = $iQuestionID;
$oSubQuestion->language = $sLanguage;
$oSubQuestion->scale_id = $iScaleID;
// update old sub questions
} else {
$oSubQuestion = Question::model()->find("qid=:qid AND language=:language", array(":qid" => $aInsertQID[$iScaleID][$iPosition], ':language' => $sLanguage));
if (!$oSubQuestion) {
$oSubQuestion = new Question();
}
$oSubQuestion->sid = $iSurveyID;
$oSubQuestion->gid = $iQuestionGroupID;
$oSubQuestion->question_order = $iPosition + 1;
$oSubQuestion->title = $aCodes[$iScaleID][$iPosition];
$oSubQuestion->question = $subquestionvalue;
$oSubQuestion->parent_qid = $iQuestionID;
$oSubQuestion->language = $sLanguage;
$oSubQuestion->scale_id = $iScaleID;
}
}
$bSubQuestionResult = $oSubQuestion->save();
if ($bSubQuestionResult) {
if (substr($subquestionkey, 0, 3) != 'new' && isset($aOldCodes[$iScaleID][$iPosition]) && $aCodes[$iScaleID][$iPosition] !== $aOldCodes[$iScaleID][$iPosition]) {
Condition::model()->updateAll(array('cfieldname' => '+' . $iSurveyID . 'X' . $iQuestionGroupID . 'X' . $iQuestionID . $aCodes[$iScaleID][$iPosition], 'value' => $aCodes[$iScaleID][$iPosition]), 'cqid=:cqid AND cfieldname=:cfieldname AND value=:value', array(':cqid' => $iQuestionID, ':cfieldname' => $iSurveyID . 'X' . $iQuestionGroupID . 'X' . $iQuestionID, ':value' => $aOldCodes[$iScaleID][$iPosition]));
}
if (!isset($aInsertQID[$iScaleID][$iPosition])) {
$aInsertQID[$iScaleID][$iPosition] = $oSubQuestion->qid;
}
} else {
$aErrors = $oSubQuestion->getErrors();
if (count($aErrors)) {
foreach ($aErrors as $sAttribute => $aStringErrors) {
foreach ($aStringErrors as $sStringErrors) {
//.........这里部分代码省略.........
示例12: XMLImportGroup
//.........这里部分代码省略.........
$results['answers']++;
}
}
// Import questionattributes --------------------------------------------------------------
if (isset($xml->question_attributes)) {
$tablename = $dbprefix . 'question_attributes';
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;
}
// Skip questions with invalid group id
$insertdata['qid'] = $aQIDReplacements[(int) $insertdata['qid']];
// remap the parent_qid
// now translate any links
$query = $connect->GetInsertSQL($tablename, $insertdata);
$result = $connect->Execute($query) or safe_die($clang->gT("Error") . ": Failed to insert data<br />{$query}<br />\n" . $connect->ErrorMsg());
$results['question_attributes']++;
}
}
// Import defaultvalues --------------------------------------------------------------
if (isset($xml->defaultvalues)) {
$tablename = $dbprefix . 'defaultvalues';
$results['defaultvalues'] = 0;
foreach ($xml->defaultvalues->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['qid'] = $aQIDReplacements[(int) $insertdata['qid']];
// remap the qid
if (!isset($aQIDReplacements[(int) $insertdata['sqid']]) || is_null($aQIDReplacements[(int) $insertdata['sqid']])) {
$insertdata['sqid'] = 0;
// defaults for non-array types
} else {
$insertdata['sqid'] = $aQIDReplacements[(int) $insertdata['sqid']];
// remap the subqeustion id
}
// now translate any links
$query = $connect->GetInsertSQL($tablename, $insertdata);
$result = $connect->Execute($query) or safe_die($clang->gT("Error") . ": Failed to insert data<br />" . $query . "<br />\n" . $connect->ErrorMsg());
$results['defaultvalues']++;
}
}
// Import conditions --------------------------------------------------------------
if (isset($xml->conditions)) {
$tablename = $dbprefix . 'conditions';
foreach ($xml->conditions->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
// replace the qid for the new one (if there is no new qid in the $aQIDReplacements array it mean that this condition is orphan -> error, skip this record)
if (isset($aQIDReplacements[$insertdata['qid']])) {
$insertdata['qid'] = $aQIDReplacements[$insertdata['qid']];
// remap the qid
} else {
continue;
}
// a problem with this answer record -> don't consider
if (isset($aQIDReplacements[$insertdata['cqid']])) {
$insertdata['cqid'] = $aQIDReplacements[$insertdata['cqid']];
// remap the qid
} else {
continue;
}
// a problem with this answer record -> don't consider
list($oldcsid, $oldcgid, $oldqidanscode) = explode("X", $insertdata["cfieldname"], 3);
if ($oldcgid != $oldgid) {
// this means that the condition is in another group (so it should not have to be been exported -> skip it
continue;
}
unset($insertdata["cid"]);
// recreate the cfieldname with the new IDs
if (preg_match("/^\\+/", $oldcsid)) {
$newcfieldname = '+' . $newsid . "X" . $newgid . "X" . $insertdata["cqid"] . substr($oldqidanscode, strlen($oldqid));
} else {
$newcfieldname = $newsid . "X" . $newgid . "X" . $insertdata["cqid"] . substr($oldqidanscode, strlen($oldqid));
}
$insertdata["cfieldname"] = $newcfieldname;
if (trim($insertdata["method"]) == '') {
$insertdata["method"] = '==';
}
// now translate any links
$query = $connect->GetInsertSQL($tablename, $insertdata);
$result = $connect->Execute($query) or safe_die($clang->gT("Error") . ": Failed to insert data<br />\$query<br />\n" . $connect->ErrorMsg());
$results['conditions']++;
}
}
LimeExpressionManager::RevertUpgradeConditionsToRelevance($newsid);
LimeExpressionManager::UpgradeConditionsToRelevance($newsid);
$results['newgid'] = $newgid;
$results['labelsets'] = 0;
$results['labels'] = 0;
return $results;
}
示例13: XMLImportSurvey
//.........这里部分代码省略.........
if (preg_match("/^@(.*)@\$/", $insertdata["value"], $cfieldnameInCondValue)) {
if (isset($aOldNewFieldmap[$cfieldnameInCondValue[1]])) {
$newvalue = '@' . $aOldNewFieldmap[$cfieldnameInCondValue[1]] . '@';
$insertdata["value"] = $newvalue;
}
}
// now translate any links
$query = $connect->GetInsertSQL($tablename, $insertdata);
$result = $connect->Execute($query) or safe_die($clang->gT("Error") . ": Failed to insert data<br />{$query}<br />\n" . $connect->ErrorMsg());
$results['conditions']++;
}
}
// Import assessments --------------------------------------------------------------
if (isset($xml->assessments)) {
$tablename = $dbprefix . 'assessments';
foreach ($xml->assessments->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
if ($insertdata['gid'] > 0) {
$insertdata['gid'] = $aGIDReplacements[(int) $insertdata['gid']];
// remap the qid
}
$insertdata['sid'] = $newsid;
// remap the survey id
unset($insertdata['id']);
// now translate any links
$query = $connect->GetInsertSQL($tablename, $insertdata);
$result = $connect->Execute($query) or safe_die($clang->gT("Error") . ": Failed to insert data<br />{$query}<br />\n" . $connect->ErrorMsg());
$results['assessments']++;
}
}
// Import quota --------------------------------------------------------------
if (isset($xml->quota)) {
$tablename = $dbprefix . 'quota';
foreach ($xml->quota->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['sid'] = $newsid;
// remap the survey id
$oldid = $insertdata['id'];
unset($insertdata['id']);
// now translate any links
$query = $connect->GetInsertSQL($tablename, $insertdata);
$result = $connect->Execute($query) or safe_die($clang->gT("Error") . ": Failed to insert data<br />{$query}<br />\n" . $connect->ErrorMsg());
$aQuotaReplacements[$oldid] = $connect->Insert_ID(db_table_name_nq('quota'), "id");
$results['quota']++;
}
}
// Import quota_members --------------------------------------------------------------
if (isset($xml->quota_members)) {
$tablename = $dbprefix . 'quota_members';
foreach ($xml->quota_members->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['sid'] = $newsid;
// remap the survey id
$insertdata['qid'] = $aQIDReplacements[(int) $insertdata['qid']];
// remap the qid
$insertdata['quota_id'] = $aQuotaReplacements[(int) $insertdata['quota_id']];
// remap the qid
unset($insertdata['id']);
// now translate any links
$query = $connect->GetInsertSQL($tablename, $insertdata);
$result = $connect->Execute($query) or safe_die($clang->gT("Error") . ": Failed to insert data<br />{$query}<br />\n" . $connect->ErrorMsg());
$results['quotamembers']++;
}
}
// Import quota_languagesettings --------------------------------------------------------------
if (isset($xml->quota_languagesettings)) {
$tablename = $dbprefix . 'quota_languagesettings';
foreach ($xml->quota_languagesettings->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['quotals_quota_id'] = $aQuotaReplacements[(int) $insertdata['quotals_quota_id']];
// remap the qid
unset($insertdata['quotals_id']);
// now translate any links
$query = $connect->GetInsertSQL($tablename, $insertdata);
$result = $connect->Execute($query) or safe_die($clang->gT("Error") . ": Failed to insert data<br />{$query}<br />\n" . $connect->ErrorMsg());
$results['quotals']++;
}
}
// Set survey rights
GiveAllSurveyPermissions($_SESSION['loginID'], $newsid);
if ($bTranslateInsertansTags) {
TranslateInsertansTags($newsid, $oldsid, $aOldNewFieldmap);
}
LimeExpressionManager::RevertUpgradeConditionsToRelevance($newsid);
LimeExpressionManager::UpgradeConditionsToRelevance($newsid);
LimeExpressionManager::SetSurveyId($newsid);
return $results;
}
示例14: delete
/**
* Function responsible for deleting a question.
*
* @access public
* @param string $action
* @param int $surveyid
* @param int $gid
* @param int $qid
* @return void
*/
public function delete($surveyid, $gid, $qid)
{
$surveyid = sanitize_int($surveyid);
$gid = sanitize_int($gid);
$qid = sanitize_int($qid);
$rqid = $qid;
if (Permission::model()->hasSurveyPermission($surveyid, 'surveycontent', 'delete')) {
if (!isset($qid)) {
$qid = returnGlobal('qid');
}
LimeExpressionManager::RevertUpgradeConditionsToRelevance(NULL, $qid);
// Check if any other questions have conditions which rely on this question. Don't delete if there are.
// TMSW Condition->Relevance: Allow such deletes - can warn about missing relevance separately.
$ccresult = Condition::model()->findAllByAttributes(array('cqid' => $qid));
$cccount = count($ccresult);
// There are conditions dependent on this question
if ($cccount) {
foreach ($ccresult as $ccr) {
$qidarray[] = $ccr->qid;
}
if (isset($qidarray)) {
$qidlist = implode(", ", $qidarray);
}
$message = gT("Question could not be deleted. There are conditions for other questions that rely on this question. You cannot delete this question until those conditions are removed.");
Yii::app()->setFlashMessage($message, 'error');
$this->getController()->redirect(array('admin/survey/sa/listquestions/surveyid/' . $surveyid));
} else {
$row = Question::model()->findByAttributes(array('qid' => $qid))->attributes;
$gid = $row['gid'];
// See if there are any conditions/attributes/answers/defaultvalues for this question,
// and delete them now as well
Condition::model()->deleteAllByAttributes(array('qid' => $qid));
QuestionAttribute::model()->deleteAllByAttributes(array('qid' => $qid));
Answer::model()->deleteAllByAttributes(array('qid' => $qid));
$criteria = new CDbCriteria();
$criteria->addCondition('qid = :qid1 or parent_qid = :qid2');
$criteria->params[':qid1'] = $qid;
$criteria->params[':qid2'] = $qid;
Question::model()->deleteAll($criteria);
DefaultValue::model()->deleteAllByAttributes(array('qid' => $qid));
QuotaMember::model()->deleteAllByAttributes(array('qid' => $qid));
Question::model()->updateQuestionOrder($gid, $surveyid);
$qid = "";
$postqid = "";
$_GET['qid'] = "";
}
Yii::app()->session['flashmessage'] = gT("Question was successfully deleted.");
// remove question from lastVisited
$oCriteria = new CDbCriteria();
$oCriteria->compare('stg_name', 'last_question_%', true, 'AND', false);
$oCriteria->compare('stg_value', $rqid, false, 'AND');
SettingGlobal::model()->deleteAll($oCriteria);
$this->getController()->redirect(array('admin/survey/sa/listquestions/surveyid/' . $surveyid));
} else {
Yii::app()->session['flashmessage'] = gT("You are not authorized to delete questions.");
$this->getController()->redirect(array('admin/survey/sa/listquestions/surveyid/' . $surveyid));
}
}
示例15: index
/**
* Database::index()
*
* @param mixed $action
* @return
*/
function index($sa = null)
{
$action = Yii::app()->request->getPost('action');
$clang = $this->getController()->lang;
$postsid = returnGlobal('sid');
$postgid = returnGlobal('gid');
$postqid = returnGlobal('qid');
$postqaid = returnGlobal('qaid');
$databaseoutput = '';
$surveyid = returnGlobal('sid');
$gid = returnGlobal('gid');
$qid = returnGlobal('qid');
// if $action is not passed, check post data.
if (Yii::app()->getConfig('filterxsshtml') && Yii::app()->session['USER_RIGHT_SUPERADMIN'] != 1) {
$filter = new CHtmlPurifier();
$filter->options = array('URI.AllowedSchemes' => array('http' => true, 'https' => true));
$xssfilter = true;
} else {
$xssfilter = false;
}
if ($action == "updatedefaultvalues" && hasSurveyPermission($surveyid, 'surveycontent', 'update')) {
$questlangs = Survey::model()->findByPk($surveyid)->additionalLanguages;
$baselang = Survey::model()->findByPk($surveyid)->language;
array_unshift($questlangs, $baselang);
Questions::model()->updateAll(array('same_default' => Yii::app()->request->getPost('samedefault') ? 1 : 0), 'sid=:sid ANd qid=:qid', array(':sid' => $surveyid, ':qid' => $qid));
$resrow = Questions::model()->findByAttributes(array('qid' => $qid));
$questiontype = $resrow['type'];
$qtproperties = getQuestionTypeList('', 'array');
if ($qtproperties[$questiontype]['answerscales'] > 0 && $qtproperties[$questiontype]['subquestions'] == 0) {
for ($scale_id = 0; $scale_id < $qtproperties[$questiontype]['answerscales']; $scale_id++) {
foreach ($questlangs as $language) {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_' . $scale_id . '_' . $language))) {
$this->_updateDefaultValues($qid, 0, $scale_id, '', $language, Yii::app()->request->getPost('defaultanswerscale_' . $scale_id . '_' . $language), true);
}
if (!is_null(Yii::app()->request->getPost('other_' . $scale_id . '_' . $language))) {
$this->_updateDefaultValues($qid, 0, $scale_id, 'other', $language, Yii::app()->request->getPost('other_' . $scale_id . '_' . $language), true);
}
}
}
}
if ($qtproperties[$questiontype]['subquestions'] > 0) {
foreach ($questlangs as $language) {
$sqresult = Questions::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'parent_qid' => $qid, 'language' => $language, 'scale_id' => 0));
for ($scale_id = 0; $scale_id < $qtproperties[$questiontype]['subquestions']; $scale_id++) {
foreach ($sqresult as $aSubquestionrow) {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_' . $scale_id . '_' . $language . '_' . $aSubquestionrow['qid']))) {
$this->_updateDefaultValues($qid, $aSubquestionrow['qid'], $scale_id, '', $language, Yii::app()->request->getPost('defaultanswerscale_' . $scale_id . '_' . $language . '_' . $aSubquestionrow['qid']), true);
}
}
}
}
}
if ($qtproperties[$questiontype]['answerscales'] == 0 && $qtproperties[$questiontype]['subquestions'] == 0) {
foreach ($questlangs as $language) {
if (!is_null(Yii::app()->request->getPost('defaultanswerscale_0_' . $language . '_0'))) {
$this->_updateDefaultValues($postqid, 0, 0, '', $language, Yii::app()->request->getPost('defaultanswerscale_0_' . $language . '_0'), true);
}
}
}
Yii::app()->session['flashmessage'] = $clang->gT("Default value settings were successfully saved.");
LimeExpressionManager::SetDirtyFlag();
if ($databaseoutput != '') {
echo $databaseoutput;
} else {
$this->getController()->redirect($this->getController()->createUrl('admin/survey/sa/view/surveyid/' . $surveyid . '/gid/' . $gid . '/qid/' . $qid));
}
}
if ($action == "updateansweroptions" && hasSurveyPermission($surveyid, 'surveycontent', 'update')) {
Yii::app()->loadHelper('database');
$anslangs = Survey::model()->findByPk($surveyid)->additionalLanguages;
$baselang = Survey::model()->findByPk($surveyid)->language;
$alllanguages = $anslangs;
array_unshift($alllanguages, $baselang);
$resrow = Questions::model()->findByAttributes(array('qid' => $qid));
$questiontype = $resrow['type'];
// Checked)
$qtypes = getQuestionTypeList('', 'array');
$scalecount = $qtypes[$questiontype]['answerscales'];
$count = 0;
$invalidCode = 0;
$duplicateCode = 0;
//require_once("../classes/inputfilter/class.inputfilter_clean.php");
//$myFilter = new InputFilter('','',1,1,1);
//First delete all answers
Answers::model()->deleteAllByAttributes(array('qid' => $qid));
LimeExpressionManager::RevertUpgradeConditionsToRelevance($surveyid);
for ($scale_id = 0; $scale_id < $scalecount; $scale_id++) {
$maxcount = (int) Yii::app()->request->getPost('answercount_' . $scale_id);
for ($sortorderid = 1; $sortorderid < $maxcount; $sortorderid++) {
$code = sanitize_paranoid_string(Yii::app()->request->getPost('code_' . $sortorderid . '_' . $scale_id));
if (Yii::app()->request->getPost('oldcode_' . $sortorderid . '_' . $scale_id)) {
$oldcode = sanitize_paranoid_string(Yii::app()->request->getPost('oldcode_' . $sortorderid . '_' . $scale_id));
if ($code !== $oldcode) {
Conditions::model()->updateAll(array('value' => $code), 'cqid=:cqid AND value=:value', array(':cqid' => $qid, ':value' => $oldcode));
//.........这里部分代码省略.........