|
|
|
@ -684,6 +684,7 @@ class SurveyManager |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* Copy given survey to a new (optional) given survey ID |
|
|
|
* @param int $survey_id |
|
|
|
* @param int $survey_id |
|
|
|
* @param int $new_survey_id |
|
|
|
* @param int $new_survey_id |
|
|
|
* @param int $targetCourseId |
|
|
|
* @param int $targetCourseId |
|
|
|
@ -1495,7 +1496,7 @@ class SurveyManager |
|
|
|
* @param int $survey_id the id of the survey |
|
|
|
* @param int $survey_id the id of the survey |
|
|
|
* @param int $question_id the id of the question |
|
|
|
* @param int $question_id the id of the question |
|
|
|
* @param bool $shared |
|
|
|
* @param bool $shared |
|
|
|
* |
|
|
|
* @return mixed False on error, true if the question could be deleted |
|
|
|
* @todo also delete the answers to this question |
|
|
|
* @todo also delete the answers to this question |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University |
|
|
|
@ -1518,12 +1519,15 @@ class SurveyManager |
|
|
|
$sql = "DELETE FROM $table |
|
|
|
$sql = "DELETE FROM $table |
|
|
|
WHERE |
|
|
|
WHERE |
|
|
|
c_id = $course_id AND |
|
|
|
c_id = $course_id AND |
|
|
|
survey_id='".$survey_id."' AND |
|
|
|
survey_id = $survey_id AND |
|
|
|
question_id='".$question_id."'"; |
|
|
|
question_id = $question_id"; |
|
|
|
Database::query($sql); |
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
if (false == $result) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
// Deleting the options of the question of the survey |
|
|
|
// Deleting the options of the question of the survey |
|
|
|
self::delete_survey_question_option($survey_id, $question_id, $shared); |
|
|
|
self::delete_survey_question_option($survey_id, $question_id, $shared); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -2116,7 +2120,7 @@ class SurveyManager |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* This function copy survey specifying course id and session id where will be copied. |
|
|
|
* Copy survey specifying course ID and session ID where will be copied. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param int $surveyId |
|
|
|
* @param int $surveyId |
|
|
|
* @param int $targetCourseId target course id |
|
|
|
* @param int $targetCourseId target course id |
|
|
|
@ -2245,6 +2249,85 @@ class SurveyManager |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Copy/duplicate one question (into the same survey). |
|
|
|
|
|
|
|
* Note: Relies on the question iid to find all necessary info. |
|
|
|
|
|
|
|
* @param int $questionId |
|
|
|
|
|
|
|
* @return int The new question's iid, or 0 on error |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static function copyQuestion($questionId) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (empty($questionId)) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$questionId = (int) $questionId; |
|
|
|
|
|
|
|
$questionTable = Database::get_course_table(TABLE_SURVEY_QUESTION); |
|
|
|
|
|
|
|
$optionsTable = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get questions |
|
|
|
|
|
|
|
$sql = "SELECT * FROM $questionTable WHERE iid = $questionId"; |
|
|
|
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
|
|
|
if (false == $res) { |
|
|
|
|
|
|
|
// Could not find this question |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$row = Database::fetch_array($res, 'ASSOC'); |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'c_id' => $row['c_id'], |
|
|
|
|
|
|
|
'survey_id' => $row['survey_id'], |
|
|
|
|
|
|
|
'survey_question' => trim($row['survey_question'])."'", |
|
|
|
|
|
|
|
'survey_question_comment' => $row['survey_question_comment'], |
|
|
|
|
|
|
|
'type' => $row['type'], |
|
|
|
|
|
|
|
'display' => $row['display'], |
|
|
|
|
|
|
|
'shared_question_id' => $row['shared_question_id'], |
|
|
|
|
|
|
|
'max_value' => $row['max_value'], |
|
|
|
|
|
|
|
'survey_group_pri' => $row['survey_group_pri'], |
|
|
|
|
|
|
|
'survey_group_sec1' => $row['survey_group_sec1'], |
|
|
|
|
|
|
|
'survey_group_sec2' => $row['survey_group_sec2'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
if (api_get_configuration_value('allow_required_survey_questions')) { |
|
|
|
|
|
|
|
if (isset($row['is_required'])) { |
|
|
|
|
|
|
|
$params['is_required'] = $row['is_required']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Get question position |
|
|
|
|
|
|
|
$sqlSort = "SELECT max(sort) as sort FROM $questionTable |
|
|
|
|
|
|
|
WHERE survey_id = ".$row['survey_id']; |
|
|
|
|
|
|
|
$resSort = Database::query($sqlSort); |
|
|
|
|
|
|
|
$rowSort = Database::fetch_assoc($resSort); |
|
|
|
|
|
|
|
$params['sort'] = $rowSort['sort'] + 1; |
|
|
|
|
|
|
|
// Insert the new question |
|
|
|
|
|
|
|
$insertId = Database::insert($questionTable, $params); |
|
|
|
|
|
|
|
if (false == $insertId) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Normalize question_id with iid |
|
|
|
|
|
|
|
$sql = "UPDATE $questionTable |
|
|
|
|
|
|
|
SET question_id = iid |
|
|
|
|
|
|
|
WHERE iid = $insertId"; |
|
|
|
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get questions options |
|
|
|
|
|
|
|
$sql = "SELECT * FROM $optionsTable WHERE question_id = $questionId"; |
|
|
|
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
|
|
|
while ($row = Database::fetch_assoc($res)) { |
|
|
|
|
|
|
|
$params = [ |
|
|
|
|
|
|
|
'c_id' => $row['c_id'], |
|
|
|
|
|
|
|
'question_id' => $insertId, |
|
|
|
|
|
|
|
'survey_id' => $row['survey_id'], |
|
|
|
|
|
|
|
'option_text' => $row['option_text'], |
|
|
|
|
|
|
|
'sort' => $row['sort'], |
|
|
|
|
|
|
|
'value' => $row['value'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
$optionId = Database::insert($optionsTable, $params); |
|
|
|
|
|
|
|
if ($optionId) { |
|
|
|
|
|
|
|
$sql = "UPDATE $optionsTable SET question_option_id = $optionId WHERE iid = $optionId"; |
|
|
|
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $insertId; |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param array $surveyData |
|
|
|
* @param array $surveyData |
|
|
|
* |
|
|
|
* |
|
|
|
|