本文整理汇总了PHP中fixSortOrderGroups函数的典型用法代码示例。如果您正苦于以下问题:PHP fixSortOrderGroups函数的具体用法?PHP fixSortOrderGroups怎么用?PHP fixSortOrderGroups使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fixSortOrderGroups函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: CSVImportSurvey
//.........这里部分代码省略.........
if ($grouprowdata['sid'] != $iOldSID) {
$results['fatalerror'] = $clang->gT("A group in the CSV/SQL file is not part of the same survey. The import of the survey was stopped.") . "<br />\n";
return $results;
}
$grouprowdata['sid'] = $iNewSID;
// remember group id
$oldgid = $grouprowdata['gid'];
//update/remove the old group id
if (isset($aGIDReplacements[$oldgid])) {
$grouprowdata['gid'] = $aGIDReplacements[$oldgid];
} else {
unset($grouprowdata['gid']);
}
// Everything set - now insert it
$grouprowdata = array_map('convertCSVReturnToReturn', $grouprowdata);
// translate internal links
if ($bTranslateLinks) {
$grouprowdata['group_name'] = translateLinks('survey', $iOldSID, $iNewSID, $grouprowdata['group_name']);
$grouprowdata['description'] = translateLinks('survey', $iOldSID, $iNewSID, $grouprowdata['description']);
}
if (isset($grouprowdata['gid'])) {
switchMSSQLIdentityInsert('groups', true);
}
$gres = Groups::model()->insertRecords($grouprowdata) or safeDie($clang->gT('Error') . ": Failed to insert group<br />\\<br />\n");
if (isset($grouprowdata['gid'])) {
switchMSSQLIdentityInsert('groups', false);
}
if (!isset($grouprowdata['gid'])) {
$aGIDReplacements[$oldgid] = Yii::app()->db->createCommand('Select LAST_INSERT_ID()')->query()->read();
$aGIDReplacements[$oldgid] = $aGIDReplacements[$oldgid]['LAST_INSERT_ID()'];
}
}
// Fix sortorder of the groups - if users removed groups manually from the csv file there would be gaps
fixSortOrderGroups($iNewSID);
}
// GROUPS is DONE
// Import questions
if (isset($questionarray) && $questionarray) {
$qafieldorders = convertCSVRowToArray($questionarray[0], ',', '"');
unset($questionarray[0]);
foreach ($questionarray as $qa) {
$qacfieldcontents = convertCSVRowToArray($qa, ',', '"');
$questionrowdata = array_combine($qafieldorders, $qacfieldcontents);
$questionrowdata = array_map('convertCSVReturnToReturn', $questionrowdata);
$questionrowdata["type"] = strtoupper($questionrowdata["type"]);
// Skip not supported languages
if (!in_array($questionrowdata['language'], $aLanguagesSupported)) {
continue;
}
// replace the sid
$questionrowdata["sid"] = $iNewSID;
// Skip if gid is invalid
if (!isset($aGIDReplacements[$questionrowdata['gid']])) {
continue;
}
$questionrowdata["gid"] = $aGIDReplacements[$questionrowdata['gid']];
if (isset($aQIDReplacements[$questionrowdata['qid']])) {
$questionrowdata['qid'] = $aQIDReplacements[$questionrowdata['qid']];
} else {
$oldqid = $questionrowdata['qid'];
unset($questionrowdata['qid']);
}
unset($oldlid1);
unset($oldlid2);
if (isset($questionrowdata['lid']) && $questionrowdata['lid'] > 0) {
$oldlid1 = $questionrowdata['lid'];
示例2: 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));
}
}
示例3: set_group_properties
/**
* RPC Routine to set group properties.
*
* @access public
* @param string $sSessionKey Auth credentials
* @param integer $iGroupID - ID of the survey
* @param array|struct $aGroupData - An array with the particular fieldnames as keys and their values to set on that particular survey
* @return array Of succeeded and failed modifications according to internal validation.
*/
public function set_group_properties($sSessionKey, $iGroupID, $aGroupData)
{
if ($this->_checkSessionKey($sSessionKey)) {
$oGroup = QuestionGroup::model()->findByAttributes(array('gid' => $iGroupID));
if (is_null($oGroup)) {
return array('status' => 'Error: Invalid group ID');
}
if (Permission::model()->hasSurveyPermission($oGroup->sid, 'survey', 'update')) {
$aResult = array();
// Remove fields that may not be modified
unset($aGroupData['sid']);
unset($aGroupData['gid']);
// Remove invalid fields
$aDestinationFields = array_flip(QuestionGroup::model()->tableSchema->columnNames);
$aGroupData = array_intersect_key($aGroupData, $aDestinationFields);
$aGroupAttributes = $oGroup->getAttributes();
if (empty($aGroupData)) {
return array('status' => 'No valid Data');
}
foreach ($aGroupData as $sFieldName => $sValue) {
//all dependencies this group has
$has_dependencies = getGroupDepsForConditions($oGroup->sid, $iGroupID);
//all dependencies on this group
$depented_on = getGroupDepsForConditions($oGroup->sid, "all", $iGroupID, "by-targgid");
//We do not allow groups with dependencies to change order - that would lead to broken dependencies
if ((isset($has_dependencies) || isset($depented_on)) && $sFieldName == 'group_order') {
$aResult[$sFieldName] = 'Group with dependencies - Order cannot be changed';
continue;
}
$oGroup->setAttribute($sFieldName, $sValue);
try {
// save the change to database - one by one to allow for validation to work
$bSaveResult = $oGroup->save();
fixSortOrderGroups($oGroup->sid);
$aResult[$sFieldName] = $bSaveResult;
//unset failed values
if (!$bSaveResult) {
$oGroup->{$sFieldName} = $aGroupAttributes[$sFieldName];
}
} catch (Exception $e) {
//unset values that cause exception
$oGroup->{$sFieldName} = $aGroupAttributes[$sFieldName];
}
}
return $aResult;
} else {
return array('status' => 'No permission');
}
} else {
return array('status' => 'Invalid Session key');
}
}
示例4: db_table_name
// Checked
$connect->Execute("DELETE FROM {$dbprefix}defaultvalues WHERE qid={$row['qid']}");
// Checked
$connect->Execute("DELETE FROM {$dbprefix}quota_members WHERE qid={$qid}");
}
}
$query = "DELETE FROM " . db_table_name('assessments') . " WHERE sid={$surveyid} AND gid={$gid}";
$result = $connect->Execute($query) or safe_die($connect->ErrorMsg());
// Checked
$query = "DELETE FROM " . db_table_name('groups') . " WHERE sid={$surveyid} AND gid={$gid}";
$result = $connect->Execute($query) or safe_die($connect->ErrorMsg());
// Checked
if ($result) {
$gid = "";
$groupselect = getgrouplist($gid);
fixSortOrderGroups($surveyid);
$_SESSION['flashmessage'] = $clang->gT("The question group was deleted.");
} else {
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"" . $clang->gT("Group could not be deleted", "js") . "\n{$error}\")\n //-->\n</script>\n";
}
LimeExpressionManager::UpgradeConditionsToRelevance($surveyid);
} elseif ($action == "insertquestion" && bHasSurveyPermission($surveyid, 'surveycontent', 'create')) {
$baselang = GetBaseLanguageFromSurveyID($postsid);
if (strlen($_POST['title']) < 1) {
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n " . "alert(\"" . $clang->gT("The question could not be added. You must enter at least enter a question code.", "js") . "\")\n " . "//-->\n</script>\n";
} else {
if (!isset($_POST['lid']) || $_POST['lid'] == '') {
$_POST['lid'] = "0";
}
if (!isset($_POST['lid1']) || $_POST['lid1'] == '') {
$_POST['lid1'] = "0";
示例5: delete
/**
* Action to delete a question group.
*
* @access public
* @return void
*/
public function delete($iSurveyId, $iGroupId)
{
$iSurveyId = sanitize_int($iSurveyId);
if (hasSurveyPermission($iSurveyId, 'surveycontent', 'delete')) {
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyId);
$iGroupId = sanitize_int($iGroupId);
$clang = $this->getController()->lang;
$iGroupsDeleted = Groups::deleteWithDependency($iGroupId, $iSurveyId);
if ($iGroupsDeleted !== 1) {
fixSortOrderGroups($iSurveyId);
Yii::app()->user->setFlash('flashmessage', $clang->gT('The question group was deleted.'));
} else {
Yii::app()->user->setFlash('flashmessage', $clang->gT('Group could not be deleted'));
}
$this->getController()->redirect($this->getController()->createUrl('admin/survey/sa/view/surveyid/' . $iSurveyId));
LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyId);
}
}
示例6: importGroup
//.........这里部分代码省略.........
// QESTIONS is DONE
$this->debugLsrc("wir sind in " . __FILE__ . " - " . __FUNCTION__ . " Line " . __LINE__ . ", OK ");
// do ANSWERS
if (isset($answerarray) && $answerarray) {
foreach ($answerarray as $aa) {
$aacfieldcontents = convertCSVRowToArray($aa, ',', '"');
$answerrowdata = array_combine($answerfieldnames, $aacfieldcontents);
// Skip not supported languages
if (!in_array($answerrowdata['language'], $surveylanguages)) {
continue;
}
// replace the qid for the new one (if there is no new qid in the $newqids array it mean that this answer is orphan -> error, skip this record)
if (isset($newqids[$answerrowdata["qid"]])) {
$answerrowdata["qid"] = $newqids[$answerrowdata["qid"]];
} else {
continue;
}
// a problem with this answer record -> don't consider
// Everything set - now insert it
$answerrowdata = array_map('convertCsvreturn2return', $answerrowdata);
// translate internal links
$answerrowdata['answer'] = translink('survey', $oldsid, $newsid, $answerrowdata['answer']);
$newvalues = array_values($answerrowdata);
$newvalues = array_map(array(&$connect, "qstr"), $newvalues);
// quote everything accordingly
$ainsert = "insert INTO {$dbprefix}answers (" . implode(',', array_keys($answerrowdata)) . ") VALUES (" . implode(',', $newvalues) . ")";
$ares = $connect->Execute($ainsert) or $this->debugLsrc("Error: " . "Failed to insert answer\n{$ainsert}\n" . $connect->ErrorMsg());
$countanswers++;
}
}
// ANSWERS is DONE
$this->debugLsrc("wir sind in " . __FILE__ . " - " . __FUNCTION__ . " Line " . __LINE__ . ", OK ");
// Fix question group sortorder
fixSortOrderGroups($surveyid);
$baselang = GetBaseLanguageFromSurveyID($surveyid);
$cdresult = db_execute_assoc("SELECT gid FROM " . db_table_name('groups') . " WHERE sid='{$surveyid}' AND language='{$baselang}' ORDER BY group_order, group_name");
$position = 0;
while ($cdrow = $cdresult->FetchRow()) {
$cd2query = "UPDATE " . db_table_name('groups') . " SET group_order='{$position}' WHERE gid='{$cdrow['gid']}' ";
$cd2result = $connect->Execute($cd2query) or $this->debugLsrc("Couldn't update group_order{$cd2query}" . $connect->ErrorMsg());
//Checked
$position++;
}
//... and for the questions inside the groups
// get all group ids and fix questions inside each group
$gquery = "SELECT gid FROM {$dbprefix}groups where sid={$newsid} group by gid ORDER BY gid";
//Get last question added (finds new qid)
$gres = db_execute_assoc($gquery);
while ($grow = $gres->FetchRow()) {
//fixsortorderQuestions(0,$grow['gid']);
$qid = sanitize_int(0);
$gid = sanitize_int($grow['gid']);
$baselang = GetBaseLanguageFromSurveyID($surveyid);
if ($gid == 0) {
$result = db_execute_assoc("SELECT gid FROM " . db_table_name('questions') . " WHERE qid='{$qid}' and language='{$baselang}'");
//Checked
$row = $result->FetchRow();
$gid = $row['gid'];
}
$cdresult = db_execute_assoc("SELECT qid FROM " . db_table_name('questions') . " WHERE gid='{$gid}' and language='{$baselang}' ORDER BY question_order, title ASC");
//Checked
$position = 0;
while ($cdrow = $cdresult->FetchRow()) {
$cd2query = "UPDATE " . db_table_name('questions') . " SET question_order='{$position}' WHERE qid='{$cdrow['qid']}' ";
$cd2result = $connect->Execute($cd2query) or $this->debugLsrc("Couldn't update question_order{$cd2query}" . $connect->ErrorMsg());
//Checked
示例7: CSVImportSurvey
//.........这里部分代码省略.........
//Now an additional integrity check if there are any groups not belonging into this survey
if ($grouprowdata['sid'] != $oldsid)
{
$results['fatalerror'] = $clang->gT("A group in the CSV/SQL file is not part of the same survey. The import of the survey was stopped.")."<br />\n";
return $results;
}
$grouprowdata['sid']=$newsid;
// remember group id
$oldgid=$grouprowdata['gid'];
//update/remove the old group id
if (isset($aGIDReplacements[$oldgid]))
$grouprowdata['gid'] = $aGIDReplacements[$oldgid];
else
unset($grouprowdata['gid']);
// Everything set - now insert it
$grouprowdata=array_map('convertCsvreturn2return', $grouprowdata);
// translate internal links
$grouprowdata['group_name']=translink('survey', $oldsid, $newsid, $grouprowdata['group_name']);
$grouprowdata['description']=translink('survey', $oldsid, $newsid, $grouprowdata['description']);
if (isset($grouprowdata['gid'])) db_switchIDInsert('groups',true);
$tablename=$dbprefix.'groups';
$ginsert = $connect->GetinsertSQL($tablename,$grouprowdata);
$gres = $connect->Execute($ginsert) or safe_die($clang->gT('Error').": Failed to insert group<br />\n$ginsert<br />\n".$connect->ErrorMsg());
if (isset($grouprowdata['gid'])) db_switchIDInsert('groups',false);
//GET NEW GID
if (!isset($grouprowdata['gid'])) {$aGIDReplacements[$oldgid]=$connect->Insert_ID("{$dbprefix}groups","gid");}
}
// Fix sortorder of the groups - if users removed groups manually from the csv file there would be gaps
fixSortOrderGroups($newsid);
}
// GROUPS is DONE
// Import questions
if (isset($questionarray) && $questionarray)
{
$qafieldorders=convertCSVRowToArray($questionarray[0],',','"');
unset($questionarray[0]);
foreach ($questionarray as $qa)
{
$qacfieldcontents=convertCSVRowToArray($qa,',','"');
$questionrowdata=array_combine($qafieldorders,$qacfieldcontents);
$questionrowdata=array_map('convertCsvreturn2return', $questionrowdata);
$questionrowdata["type"]=strtoupper($questionrowdata["type"]);
// Skip not supported languages
if (!in_array($questionrowdata['language'],$aLanguagesSupported))
continue;
// replace the sid
$questionrowdata["sid"] = $newsid;
// Skip if gid is invalid
if (!isset($aGIDReplacements[$questionrowdata['gid']])) continue;
$questionrowdata["gid"] = $aGIDReplacements[$questionrowdata['gid']];
if (isset($aQIDReplacements[$questionrowdata['qid']]))
{
$questionrowdata['qid']=$aQIDReplacements[$questionrowdata['qid']];
}
else
{
$oldqid=$questionrowdata['qid'];
unset($questionrowdata['qid']);
示例8: CSVImportGroup
//.........这里部分代码省略.........
$query = $connect->GetInsertSQL($tablename, $questionrowdata);
if (isset($questionrowdata['qid'])) {
db_switchIDInsert('questions', true);
}
$qres = $connect->Execute($query) or safe_die("Error: Failed to insert subquestion <br />{$query}<br />" . $connect->ErrorMsg());
if (!isset($questionrowdata['qid'])) {
$aSQIDReplacements[$answerrowdata['code'] . $answerrowdata['qid']] = $connect->Insert_ID("{$dbprefix}questions", "qid");
} else {
db_switchIDInsert('questions', false);
}
$results['subquestions']++;
// also convert default values subquestions for multiple choice
if ($answerrowdata['default_value'] == 'Y' && ($oldquestion['newtype'] == 'M' || $oldquestion['newtype'] == 'P')) {
$insertdata = array();
$insertdata['qid'] = $newqid;
$insertdata['sqid'] = $aSQIDReplacements[$answerrowdata['code']];
$insertdata['language'] = $answerrowdata['language'];
$insertdata['defaultvalue'] = 'Y';
$tablename = $dbprefix . 'defaultvalues';
$query = $connect->GetInsertSQL($tablename, $insertdata);
$qres = $connect->Execute($query) or safe_die("Error: Failed to insert defaultvalue <br />{$query}<br />\n" . $connect->ErrorMsg());
}
} else {
unset($answerrowdata['default_value']);
$tablename = $dbprefix . 'answers';
$query = $connect->GetInsertSQL($tablename, $answerrowdata);
$ares = $connect->Execute($query) or safe_die("Error: Failed to insert answer<br />{$query}<br />\n" . $connect->ErrorMsg());
$results['answers']++;
}
}
}
// ANSWERS is DONE
// Fix sortorder of the groups - if users removed groups manually from the csv file there would be gaps
fixSortOrderGroups($surveyid);
//... and for the questions inside the groups
// get all group ids and fix questions inside each group
$gquery = "SELECT gid FROM {$dbprefix}groups where sid={$newsid} group by gid ORDER BY gid";
//Get last question added (finds new qid)
$gres = db_execute_assoc($gquery);
while ($grow = $gres->FetchRow()) {
fixsortorderQuestions($grow['gid'], $newsid);
}
}
$results['question_attributes'] = 0;
// Finally the question attributes - it is called just once and only if there was a question
if (isset($question_attributesarray) && $question_attributesarray) {
//ONLY DO THIS IF THERE ARE QUESTION_ATTRIBUES
$fieldorders = convertCSVRowToArray($question_attributesarray[0], ',', '"');
unset($question_attributesarray[0]);
foreach ($question_attributesarray as $qar) {
$fieldcontents = convertCSVRowToArray($qar, ',', '"');
$qarowdata = array_combine($fieldorders, $fieldcontents);
// replace the qid for the new one (if there is no new qid in the $aQIDReplacements array it mean that this attribute is orphan -> error, skip this record)
if (isset($aQIDReplacements[$qarowdata["qid"]])) {
$qarowdata["qid"] = $aQIDReplacements[$qarowdata["qid"]];
} else {
continue;
}
// a problem with this answer record -> don't consider
unset($qarowdata["qaid"]);
$tablename = "{$dbprefix}question_attributes";
$qainsert = $connect->GetInsertSQL($tablename, $qarowdata);
$result = $connect->Execute($qainsert);
if ($result !== false) {
$results['question_attributes']++;
}