Rename survey_manager with SurveyManager + fix queries.

1.10.x
Julio Montoya 10 years ago
parent 52144e08c6
commit 2738abd54a
  1. 4
      main/coursecopy/classes/CourseRestorer.class.php
  2. 1
      main/inc/lib/surveymanager.lib.php
  3. 6
      main/survey/copy_survey.php
  4. 8
      main/survey/create_new_survey.php
  5. 6
      main/survey/fillsurvey.php
  6. 6
      main/survey/generate_link.php
  7. 6
      main/survey/link.php
  8. 4
      main/survey/preview.php
  9. 4
      main/survey/question.php
  10. 8
      main/survey/reporting.php
  11. 139
      main/survey/survey.lib.php
  12. 6
      main/survey/survey.php
  13. 4
      main/survey/survey_invitation.php
  14. 2
      main/survey/survey_invite.php
  15. 16
      main/survey/survey_list.php
  16. 4
      main/survey/survey_question.php
  17. 88
      tests/main/survey/survey.lib.test.php

@ -1877,9 +1877,9 @@ class CourseRestorer
// if the survey is shared => also delete the shared content
if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
survey_manager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
}
$return = survey_manager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
$return = SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
//Insert the new source survey
Database::query($sql);

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Manage the "versioning" of a conditional survey
*

@ -34,14 +34,14 @@ if (Security::check_token('post')) {
Security::clear_token();
$surveyId = intval($_POST['surveys']);
$courseId = Security::remove_XSS($_POST['destination_course']);
$surveyCopyId = survey_manager::copy_survey($surveyId, null, $courseId);
$surveyCopyId = SurveyManager::copy_survey($surveyId, null, $courseId);
// Copy the survey to the target course
survey_manager::empty_survey($surveyCopyId, $courseId);
SurveyManager::empty_survey($surveyCopyId, $courseId);
// Empty the copied survey
Display::display_confirmation_message(get_lang('SurveyCopied'));
}
$surveys = survey_manager::get_surveys(api_get_course_id(), api_get_session_id());
$surveys = SurveyManager::get_surveys(api_get_course_id(), api_get_session_id());
$courses = CourseManager::get_courses_list();
$form = new FormValidator('copy_survey', 'post', 'copy_survey.php?'.api_get_cidreq());
if (!$surveys) {

@ -37,7 +37,7 @@ if (!api_is_allowed_to_edit()) {
// Getting the survey information
$survey_id = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null;
$survey_data = survey_manager::get_survey($survey_id);
$survey_data = SurveyManager::get_survey($survey_id);
// Additional information
$course_id = api_get_course_id();
@ -229,15 +229,15 @@ if ($form->validate()) {
// Exporting the values
$values = $form->exportValues();
// Storing the survey
$return = survey_manager::store_survey($values);
$return = SurveyManager::store_survey($values);
/* // Deleting the shared survey if the survey is getting unshared (this only happens when editing)
if (is_numeric($survey_data['survey_share']) && $values['survey_share']['survey_share'] == 0 && $values['survey_id'] != '') {
survey_manager::delete_survey($survey_data['survey_share'], true);
SurveyManager::delete_survey($survey_data['survey_share'], true);
}
// Storing the already existing questions and options of a survey that gets shared (this only happens when editing)
if ($survey_data['survey_share'] == 0 && $values['survey_share']['survey_share'] !== 0 && $values['survey_id'] != '') {
survey_manager::get_complete_survey_structure($return['id']);
SurveyManager::get_complete_survey_structure($return['id']);
}
*/
if ($return['type'] == 'error') {

@ -106,7 +106,7 @@ if ($invitationcode == 'auto' && isset($_GET['scode'])) {
if (Database :: num_rows($result) > 0) { // Ok
// Check availability
$row = Database :: fetch_array($result, 'ASSOC');
$tempdata = survey_manager :: get_survey($row['survey_id']);
$tempdata = SurveyManager :: get_survey($row['survey_id']);
//exit if survey not available anymore
check_time_availability($tempdata);
// Check for double invitation records (insert should be done once)
@ -181,7 +181,7 @@ if (Database::num_rows($result) > 1) {
}
// Getting the survey information
$survey_data = survey_manager::get_survey($survey_invitation['survey_id']);
$survey_data = SurveyManager::get_survey($survey_invitation['survey_id']);
$survey_data['survey_id'] = $survey_invitation['survey_id'];
// Storing the answers
@ -552,7 +552,7 @@ if (isset($_POST['finish_survey'])) {
Display::display_confirmation_message(get_lang('SurveyFinished'));
echo $survey_data['survey_thanks'];
survey_manager::update_survey_answered(
SurveyManager::update_survey_answered(
$survey_data,
$survey_invitation['user'],
$survey_invitation['survey_code']

@ -12,18 +12,18 @@ if (empty($survey_id)) {
api_not_allowed(true);
}
$survey_data = survey_manager::get_survey($survey_id);
$survey_data = SurveyManager::get_survey($survey_id);
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => strip_tags($survey_data['title']));
Display::display_header(get_lang('Survey'), 'Survey');
if (!survey_manager::survey_generation_hash_available()) {
if (!SurveyManager::survey_generation_hash_available()) {
api_not_allowed(true);
}
$link = survey_manager::generate_survey_link($survey_id, api_get_course_int_id(), api_get_session_id(), api_get_group_id());
$link = SurveyManager::generate_survey_link($survey_id, api_get_course_int_id(), api_get_session_id(), api_get_group_id());
echo '<div class="row">';
echo '<div class="span12" style="text-align:center">';
echo Display::url(get_lang('GenerateSurveyAccessLink'), $link, array('class' => 'btn btn-primary btn-large'));

@ -8,14 +8,14 @@ $survey_id = isset($_REQUEST['i']) ? intval($_REQUEST['i']) : null;
if (empty($survey_id)) {
api_not_allowed(true);
}
if (!survey_manager::survey_generation_hash_available()) {
if (!SurveyManager::survey_generation_hash_available()) {
api_not_allowed(true);
}
$course_info = api_get_course_info_by_id($_REQUEST['c']);
$hash_is_valid = survey_manager::validate_survey_hash($survey_id, $_REQUEST['c'], $_REQUEST['s'], $_REQUEST['g'], $_REQUEST['h']);
$hash_is_valid = SurveyManager::validate_survey_hash($survey_id, $_REQUEST['c'], $_REQUEST['s'], $_REQUEST['g'], $_REQUEST['h']);
if ($hash_is_valid && $course_info) {
$survey_data = survey_manager::get_survey($survey_id, null, $course_info['code']);
$survey_data = SurveyManager::get_survey($survey_id, null, $course_info['code']);
$invitation_code = api_get_unique_id();

@ -52,7 +52,7 @@ if (!isset($_GET['survey_id']) || !is_numeric($_GET['survey_id'])){
// Getting the survey information
$survey_id = intval($_GET['survey_id']);
$survey_data = survey_manager::get_survey($survey_id);
$survey_data = SurveyManager::get_survey($survey_id);
if (empty($survey_data)) {
Display::display_header(get_lang('SurveyPreview'));
@ -68,7 +68,7 @@ if (api_is_allowed_to_edit()) {
$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
}
$courseCode = isset($_GET['cidReq']) ? $_GET['cidReq'] : null;
$surveyAnonymous = survey_manager::get_survey($survey_id, 0, $courseCode);
$surveyAnonymous = SurveyManager::get_survey($survey_id, 0, $courseCode);
$surveyAnonymous = $surveyAnonymous['anonymous'];
if ($surveyAnonymous == 0 && api_is_anonymous()) {
api_not_allowed(true);

@ -48,7 +48,7 @@ $table_user = Database:: get_main_table(TABLE_MAIN_USER);
$course_id = api_get_course_int_id();
// Getting the survey information
$surveyData = survey_manager::get_survey($_GET['survey_id']);
$surveyData = SurveyManager::get_survey($_GET['survey_id']);
if (empty($surveyData)) {
Display :: display_header(get_lang('ToolSurvey'));
@ -146,7 +146,7 @@ if ($_GET['type'] == 'personality') {
// We are editing a question
if (isset($_GET['question_id']) && !empty($_GET['question_id'])) {
$formData = survey_manager::get_question($_GET['question_id']);
$formData = SurveyManager::get_question($_GET['question_id']);
}
$formData = $surveyQuestion->preSave($formData);

@ -15,7 +15,7 @@ require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
$cidReq = api_get_cidreq();
$survey_id = intval($_GET['survey_id']);
$survey_data = survey_manager::get_survey($survey_id);
$survey_data = SurveyManager::get_survey($survey_id);
// Export
/**
@ -66,7 +66,7 @@ if ($survey_data['anonymous'] == 0) {
} else {
$people_filled_full_data = false;
}
$people_filled = survey_manager::get_people_who_filled_survey(
$people_filled = SurveyManager::get_people_who_filled_survey(
$_GET['survey_id'],
$people_filled_full_data
);
@ -74,7 +74,7 @@ $people_filled = survey_manager::get_people_who_filled_survey(
// Checking the parameters
SurveyUtil::check_parameters($people_filled);
$survey_data = survey_manager::get_survey($survey_id);
$survey_data = SurveyManager::get_survey($survey_id);
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
api_get_user_id(),
@ -99,7 +99,7 @@ $table_user = Database:: get_main_table(TABLE_MAIN_USER);
// Getting the survey information
//$survey_data = survey_manager::get_survey($survey_id);
//$survey_data = SurveyManager::get_survey($survey_id);
if (empty($survey_data)) {
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('InvallidSurvey'), false);

@ -2,7 +2,7 @@
/* For licensing terms, see /license.txt */
/**
* Class survey_manager
* Class SurveyManager
* @package chamilo.survey
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University:
* cleanup, refactoring and rewriting large parts (if not all) of the code
@ -12,7 +12,7 @@
* @todo move this file to inc/lib
* @todo use consistent naming for the functions (save vs store for instance)
*/
class survey_manager
class SurveyManager
{
/**
* @param $code
@ -339,12 +339,22 @@ class survey_manager
Database::query($sql);
$survey_id = Database::insert_id();
if ($survey_id > 0) {
$sql = "UPDATE $table_survey SET survey_id = $survey_id WHERE iid = $survey_id";
Database::query($sql);
// Insert into item_property
api_item_property_update(api_get_course_info(), TOOL_SURVEY, $survey_id, 'SurveyAdded', api_get_user_id());
api_item_property_update(
api_get_course_info(),
TOOL_SURVEY,
$survey_id,
'SurveyAdded',
api_get_user_id()
);
}
if ($values['survey_type'] == 1 && !empty($values['parent_id'])) {
survey_manager::copy_survey($values['parent_id'], $survey_id);
SurveyManager::copy_survey($values['parent_id'], $survey_id);
}
$return['message'] = 'SurveyCreatedSuccesfully';
@ -464,6 +474,10 @@ class survey_manager
'".$_course['id']."')";
Database::query($sql);
$return = Database::insert_id();
$sql = "UPDATE $table_survey SET survey_id = $return WHERE iid = $return";
Database::query($sql);
} else {
$sql = "UPDATE $table_survey SET
code = '".Database::escape_string($values['survey_code'])."',
@ -524,7 +538,7 @@ class survey_manager
Database::query($sql);
// Deleting the questions of the survey
survey_manager::delete_all_survey_questions($survey_id, $shared);
SurveyManager::delete_all_survey_questions($survey_id, $shared);
// Update into item_property (delete)
api_item_property_update($course_info, TOOL_SURVEY, $survey_id, 'SurveyDeleted', api_get_user_id());
@ -568,8 +582,17 @@ class survey_manager
Database::insert($table_survey, $params);
$new_survey_id = Database::insert_id();
$sql = "UPDATE $table_survey SET survey_id = $new_survey_id WHERE iid = $new_survey_id";
Database::query($sql);
// Insert into item_property
api_item_property_update(api_get_course_info(), TOOL_SURVEY, $new_survey_id, 'SurveyAdded', api_get_user_id());
api_item_property_update(
api_get_course_info(),
TOOL_SURVEY,
$new_survey_id,
'SurveyAdded',
api_get_user_id()
);
} else {
$new_survey_id = intval($new_survey_id);
}
@ -586,6 +609,9 @@ class survey_manager
);
$insertId = Database::insert($table_survey_question_group, $params);
$sql = "UPDATE $table_survey_question_group SET id = $insertId WHERE iid = $insertId";
Database::query($sql);
$group_id[$row['id']] = $insertId;
}
@ -609,6 +635,10 @@ class survey_manager
'survey_group_sec2' => $row['survey_group_sec2']
);
$insertId = Database::insert($table_survey_question, $params);
$sql = "UPDATE $table_survey_question SET id = $insertId WHERE iid = $insertId";
Database::query($sql);
$question_id[$row['question_id']] = $insertId;
}
@ -626,7 +656,10 @@ class survey_manager
'sort' => $row['sort'],
'value' => $row['value']
);
Database::insert($table_survey_options, $params);
$insertId = Database::insert($table_survey_options, $params);
$sql = "UPDATE $table_survey_options SET question_option_id = $insertId WHERE iid = $insertId";
Database::query($sql);
}
return $new_survey_id;
@ -651,7 +684,7 @@ class survey_manager
$course_id = $courseId ? $courseId : api_get_course_int_id();
$datas = survey_manager::get_survey($survey_id);
$datas = SurveyManager::get_survey($survey_id);
$session_where = '';
if (api_get_session_id() != 0) {
$session_where = ' AND session_id = "'.api_get_session_id().'" ';
@ -692,7 +725,7 @@ class survey_manager
$session_id = $survey_data['session_id'];
// Getting a list with all the people who have filled the survey
$people_filled = survey_manager::get_people_who_filled_survey($survey_id, false, $course_id);
$people_filled = SurveyManager::get_people_who_filled_survey($survey_id, false, $course_id);
$number = intval(count($people_filled));
@ -729,8 +762,8 @@ class survey_manager
*/
public static function get_complete_survey_structure($survey_id, $shared = 0)
{
$structure = survey_manager::get_survey($survey_id, $shared);
$structure['questions'] = survey_manager::get_questions($survey_id);
$structure = SurveyManager::get_survey($survey_id, $shared);
$structure['questions'] = SurveyManager::get_questions($survey_id);
}
/***
@ -946,11 +979,11 @@ class survey_manager
$tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
// Getting all the information of the survey
$survey_data = survey_manager::get_survey($form_content['survey_id']);
$survey_data = SurveyManager::get_survey($form_content['survey_id']);
// Storing the question in the shared database
if (is_numeric($survey_data['survey_share']) && $survey_data['survey_share'] != 0) {
$shared_question_id = survey_manager::save_shared_question($form_content, $survey_data);
$shared_question_id = SurveyManager::save_shared_question($form_content, $survey_data);
$form_content['shared_question_id'] = $shared_question_id;
}
@ -998,6 +1031,11 @@ class survey_manager
)";
Database::query($sql);
$question_id = Database::insert_id();
$sql = "UPDATE $tbl_survey_question SET question_id = $question_id
WHERE iid = $question_id";
Database::query($sql);
$form_content['question_id'] = $question_id;
$return_message = 'QuestionAdded';
@ -1027,7 +1065,9 @@ class survey_manager
display = '".Database::escape_string($form_content['horizontalvertical'])."',
max_value = '".Database::escape_string($maxScore)."'
$additionalsets
WHERE c_id = $course_id AND question_id = ".intval($form_content['question_id'])."
WHERE
c_id = $course_id AND
question_id = ".intval($form_content['question_id'])."
";
Database::query($sql);
$return_message = 'QuestionUpdated';
@ -1045,7 +1085,7 @@ class survey_manager
}
// Storing the options of the question
survey_manager::save_question_options($form_content, $survey_data);
SurveyManager::save_question_options($form_content, $survey_data);
} else {
$return_message = 'PleasFillAllAnswer';
}
@ -1192,10 +1232,10 @@ class survey_manager
Database::query($sql);
// Deleting all the options of the questions of the survey
survey_manager::delete_all_survey_questions_options($survey_id, $shared);
SurveyManager::delete_all_survey_questions_options($survey_id, $shared);
// Deleting all the answers on this survey
survey_manager::delete_all_survey_answers($survey_id);
SurveyManager::delete_all_survey_answers($survey_id);
}
/**
@ -1216,7 +1256,7 @@ class survey_manager
// Table definitions
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
if ($shared) {
survey_manager::delete_shared_survey_question($survey_id, $question_id);
SurveyManager::delete_shared_survey_question($survey_id, $question_id);
}
// Deleting the survey questions
@ -1228,7 +1268,7 @@ class survey_manager
Database::query($sql);
// Deleting the options of the question of the survey
survey_manager::delete_survey_question_option($survey_id, $question_id, $shared);
SurveyManager::delete_survey_question_option($survey_id, $question_id, $shared);
}
/**
@ -1249,7 +1289,7 @@ class survey_manager
$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
// First we have to get the shared_question_id
$question_data = survey_manager::get_question($question_id);
$question_data = SurveyManager::get_question($question_id);
// Deleting the survey questions
$sql = "DELETE FROM $table_survey_question
@ -1282,11 +1322,11 @@ class survey_manager
}
if (is_numeric($survey_data['survey_share']) && $survey_data['survey_share'] != 0) {
survey_manager::save_shared_question_options($form_content, $survey_data);
SurveyManager::save_shared_question_options($form_content, $survey_data);
}
// Table definition
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
// We are editing a question so we first have to remove all the existing options from the database
if (is_numeric($form_content['question_id'])) {
@ -1308,6 +1348,14 @@ class survey_manager
'".Database::escape_string($values)."',
'".Database::escape_string($counter)."')";
Database::query($sql);
$insertId = Database::insert_id();
$sql = "UPDATE $table_survey_question_option
SET question_option_id = $insertId
WHERE iid = $insertId";
Database::query($sql);
$counter++;
}
}
@ -1327,19 +1375,20 @@ class survey_manager
{
if (is_array($form_content) && is_array($form_content['answers'])) {
// Table defintion
$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
// We are editing a question so we first have to remove all the existing options from the database
$sql = "DELETE FROM $table_survey_question_option WHERE question_id = '".Database::escape_string($form_content['shared_question_id'])."'";
$sql = "DELETE FROM $table_survey_question_option
WHERE question_id = '".Database::escape_string($form_content['shared_question_id'])."'";
Database::query($sql);
$counter = 1;
foreach ($form_content['answers'] as & $answer) {
$sql = "INSERT INTO $table_survey_question_option (question_id, survey_id, option_text, sort) VALUES (
'".Database::escape_string($form_content['shared_question_id'])."',
'".Database::escape_string($survey_data['is_shared'])."',
'".Database::escape_string($answer)."',
'".Database::escape_string($counter)."')";
'".Database::escape_string($form_content['shared_question_id'])."',
'".Database::escape_string($survey_data['is_shared'])."',
'".Database::escape_string($answer)."',
'".Database::escape_string($counter)."')";
Database::query($sql);
$counter++;
}
@ -1647,6 +1696,10 @@ class SurveyUtil
'".Database::escape_string($option_value)."'
)";
Database::query($sql);
$insertId = Database::insert_id();
$sql = "UPDATE $table_survey_answer SET answer_id = $insertId WHERE iid = $insertId";
Database::query($sql);
}
/**
@ -1661,7 +1714,7 @@ class SurveyUtil
$error = false;
// Getting the survey data
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$survey_data = SurveyManager::get_survey($_GET['survey_id']);
// $_GET['survey_id'] has to be numeric
if (!is_numeric($_GET['survey_id'])) {
@ -1669,7 +1722,14 @@ class SurveyUtil
}
// $_GET['action']
$allowed_actions = array('overview', 'questionreport', 'userreport', 'comparativereport', 'completereport','deleteuserreport');
$allowed_actions = array(
'overview',
'questionreport',
'userreport',
'comparativereport',
'completereport',
'deleteuserreport'
);
if (isset($_GET['action']) && !in_array($_GET['action'], $allowed_actions)) {
$error = get_lang('ActionNotAllowed');
}
@ -1718,7 +1778,7 @@ class SurveyUtil
$action = isset($_GET['action']) ? $_GET['action'] : null;
// Getting the number of question
$temp_questions_data = survey_manager::get_questions($_GET['survey_id']);
$temp_questions_data = SurveyManager::get_questions($_GET['survey_id']);
// Sorting like they should be displayed and removing the non-answer question types (comment and pagebreak)
$my_temp_questions_data = $temp_questions_data == null ? array() : $temp_questions_data;
@ -2995,7 +3055,7 @@ class SurveyUtil
$allowed_question_types = array('yesno', 'multiplechoice', 'multipleresponse', 'dropdown', 'percentage', 'score');
// Getting all the questions
$questions = survey_manager::get_questions($_GET['survey_id']);
$questions = SurveyManager::get_questions($_GET['survey_id']);
// Actions bar
@ -3047,12 +3107,12 @@ class SurveyUtil
// Getting all the information of the x axis
if (isset($_GET['xaxis']) && is_numeric($_GET['xaxis'])) {
$question_x = survey_manager::get_question($_GET['xaxis']);
$question_x = SurveyManager::get_question($_GET['xaxis']);
}
// Getting all the information of the y axis
if (isset($_GET['yaxis']) && is_numeric($_GET['yaxis'])) {
$question_y = survey_manager::get_question($_GET['yaxis']);
$question_y = SurveyManager::get_question($_GET['yaxis']);
}
if (isset($_GET['xaxis']) && is_numeric($_GET['xaxis']) && isset($_GET['yaxis']) && is_numeric($_GET['yaxis'])) {
@ -3383,7 +3443,7 @@ class SurveyUtil
}
// Getting the survey information
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$survey_data = SurveyManager::get_survey($_GET['survey_id']);
$survey_invitations = SurveyUtil::get_invitations($survey_data['survey_code']);
$already_invited = SurveyUtil::get_invited_users($survey_data['code']);
@ -3391,7 +3451,7 @@ class SurveyUtil
$exclude_users = array();
if ($remindUnAnswered == 1) { // Remind only unanswered users
$reminder = 1;
$exclude_users = survey_manager::get_people_who_filled_survey($_GET['survey_id']);
$exclude_users = SurveyManager::get_people_who_filled_survey($_GET['survey_id']);
}
$counter = 0; // Nr of invitations "sent" (if sendmail option)
@ -3494,7 +3554,10 @@ class SurveyUtil
(!empty($params['user']) || !empty($params['group_id'])) &&
!empty($params['survey_code'])
) {
return Database::insert($table, $params);
$insertedId = Database::insert($table, $params);
$sql = "UPDATE $table SET survey_invitation_id = $insertId WHERE iid = $insertId";
Database::query($sql);
}
return false;
}
@ -3918,7 +3981,7 @@ class SurveyUtil
api_is_element_in_the_session(TOOL_SURVEY, $survey_id)
) {
$return .= '<a href="'.api_get_path(WEB_CODE_PATH).'survey/create_new_survey.php?'.api_get_cidreq().'&amp;action=edit&amp;survey_id='.$survey_id.'">'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>';
if (survey_manager::survey_generation_hash_available()) {
if (SurveyManager::survey_generation_hash_available()) {
$return .= Display::url(
Display::return_icon('new_link.png', get_lang('GenerateSurveyAccessLink'),'',ICON_SIZE_SMALL),
api_get_path(WEB_CODE_PATH).'survey/generate_link.php?survey_id='.$survey_id.'&'.api_get_cidreq()

@ -56,7 +56,7 @@ $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'survey/survey_
if (isset($_GET['survey_id'])) {
$course_code = api_get_course_id();
if ($course_code!=-1) {
$survey_data = survey_manager::get_survey($survey_id);
$survey_data = SurveyManager::get_survey($survey_id);
} else {
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('NotAllowed'), false);
@ -108,11 +108,11 @@ $message_information = isset($_GET['message']) ? Security::remove_XSS($_GET['
if (isset($action)) {
if (($action == 'moveup' || $action == 'movedown') && isset($_GET['question_id'])) {
survey_manager::move_survey_question($my_action_survey,$my_question_id_survey,$my_survey_id_survey);
SurveyManager::move_survey_question($my_action_survey,$my_question_id_survey,$my_survey_id_survey);
Display::display_confirmation_message(get_lang('SurveyQuestionMoved'));
}
if ($action == 'delete' AND is_numeric($_GET['question_id'])) {
survey_manager::delete_survey_question($my_survey_id_survey, $my_question_id_survey, $survey_data['is_shared']);
SurveyManager::delete_survey_question($my_survey_id_survey, $my_question_id_survey, $survey_data['is_shared']);
}
}

@ -40,7 +40,7 @@ if (!isset($_GET['survey_id']) OR !is_numeric($_GET['survey_id'])) {
}
$survey_id = Security::remove_XSS($_GET['survey_id']);
$survey_data = survey_manager::get_survey($survey_id);
$survey_data = SurveyManager::get_survey($survey_id);
if (empty($survey_data)) {
Display :: display_header($tool_name);
@ -70,7 +70,7 @@ if (!is_numeric($survey_id)) {
}
// Getting all the people who have filled this survey
$answered_data = survey_manager::get_people_who_filled_survey($survey_id);
$answered_data = SurveyManager::get_people_who_filled_survey($survey_id);
if ($survey_data['anonymous'] == 1) {
Display::display_normal_message(get_lang('AnonymousSurveyCannotKnowWhoAnswered').' '.count($answered_data).' '.get_lang('PeopleAnswered'));
$answered_data = array();

@ -35,7 +35,7 @@ $course_id = api_get_course_int_id();
// Getting the survey information
$survey_id = Security::remove_XSS($_GET['survey_id']);
$survey_data = survey_manager::get_survey($survey_id);
$survey_data = SurveyManager::get_survey($survey_id);
if (empty($survey_data)) {
Display :: display_header(get_lang('ToolSurvey'));
Display :: display_error_message(get_lang('InvallidSurvey'), false);

@ -70,7 +70,7 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
if ($action == 'copy_survey') {
if (api_is_allowed_to_edit()) {
survey_manager::copy_survey($_GET['survey_id']);
SurveyManager::copy_survey($_GET['survey_id']);
$message = get_lang('Copied');
header('Location: ' . api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?' . api_get_cidreq());
exit;
@ -90,7 +90,7 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
// Action handling: deleting a survey
if ($action == 'delete' && isset($_GET['survey_id'])) {
// Getting the information of the survey (used for when the survey is shared)
$survey_data = survey_manager::get_survey($_GET['survey_id']);
$survey_data = SurveyManager::get_survey($_GET['survey_id']);
if (api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id']) {
// The coach can't delete a survey not belonging to his session
api_not_allowed();
@ -98,10 +98,10 @@ if ($action == 'delete' && isset($_GET['survey_id'])) {
}
// If the survey is shared => also delete the shared content
if (is_numeric($survey_data['survey_share'])) {
survey_manager::delete_survey($survey_data['survey_share'], true);
SurveyManager::delete_survey($survey_data['survey_share'], true);
}
$return = survey_manager::delete_survey($_GET['survey_id']);
$return = SurveyManager::delete_survey($_GET['survey_id']);
if ($return) {
Display::display_confirmation_message(get_lang('SurveyDeleted'), false);
@ -125,7 +125,7 @@ if ($action == 'empty') {
exit;
}
}
$return = survey_manager::empty_survey(intval($_GET['survey_id']));
$return = SurveyManager::empty_survey(intval($_GET['survey_id']));
if ($return) {
Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
} else {
@ -138,13 +138,13 @@ if (isset($_POST['action']) && $_POST['action']) {
if (is_array($_POST['id'])) {
foreach ($_POST['id'] as $key => & $value) {
// getting the information of the survey (used for when the survey is shared)
$survey_data = survey_manager::get_survey($value);
$survey_data = SurveyManager::get_survey($value);
// if the survey is shared => also delete the shared content
if (is_numeric($survey_data['survey_share'])) {
survey_manager::delete_survey($survey_data['survey_share'], true);
SurveyManager::delete_survey($survey_data['survey_share'], true);
}
// delete the actual survey
survey_manager::delete_survey($value);
SurveyManager::delete_survey($value);
}
Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
} else {

@ -26,7 +26,7 @@ class survey_question
$surveyId = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null;
$toolName = Display::return_icon(
survey_manager::icon_question(Security::remove_XSS($_GET['type'])),
SurveyManager::icon_question(Security::remove_XSS($_GET['type'])),
get_lang(ucfirst(Security::remove_XSS($_GET['type']))),
array('align' => 'middle', 'height' => '22px')
).' ';
@ -255,7 +255,7 @@ class survey_question
if (isset($_POST['buttons']) && isset($_POST['buttons']['save'])) {
Session::erase('answer_count');
Session::erase('answer_list');
$message = survey_manager::save_question(
$message = SurveyManager::save_question(
$surveyData,
$formData
);

@ -14,25 +14,25 @@ class TestSurvey extends UnitTestCase {
$this->UnitTestCase('');
}
public function setUp() {
$this->smanager = new survey_manager();
public function setUp() {
$this->smanager = new SurveyManager();
$this->squestion = new question();
$this->syesno = new yesno();
$this->smultiplechoice = new multiplechoice();
$this->spersonality = new personality();
$this->smultipleresponse = new multipleresponse();
$this->smultipleresponse = new multipleresponse();
}
public function tearDown() {
public function tearDown() {
$this-> smanager = null;
$this-> squestion = null;
$this-> syesno = null;
$this->smultiplechoice = null;
$this->personality = null;
$this->multipleresponse = null;
$this->multipleresponse = null;
}
public function testStoreSurvey() {
global $_user,$cidReq;
$values = array(
@ -45,20 +45,20 @@ class TestSurvey extends UnitTestCase {
'survey_introduction' => '',
'survey_thanks' => '',
'survey_type' => '0',
'parent_id' => '0',
'submit_survey' => ''
);
'parent_id' => '0',
'submit_survey' => ''
);
$res = $this->smanager->store_survey($values);
$this->assertTrue($res);
$this->assertTrue(is_array($res));
$this->assertTrue(is_array($res));
}
public function testGetSurvey() {
$course_code = 'COURSETEST';
public function testGetSurvey() {
$course_code = 'COURSETEST';
$survey_id=1;
$res3 = $this->smanager->get_survey($survey_id,0,$course_code);
$this->assertTrue(is_array($res3));
$this->assertTrue(is_array($res3));
}
public function testStoreSharedSurvey() {
@ -73,9 +73,9 @@ class TestSurvey extends UnitTestCase {
'survey_introduction' => 'introduction',
'survey_thanks' => '',
'survey_type' => '1',
'parent_id' => '1',
'submit_survey' => ''
);
'parent_id' => '1',
'submit_survey' => ''
);
$res = $this->smanager->store_shared_survey($values);
$this->assertTrue($res);
//var_dump($res);
@ -98,19 +98,19 @@ class TestSurvey extends UnitTestCase {
$this->assertNotNull($this->squestion->html);
//var_dump($res);
}
public function testYesNoCreateForm() {
$form_content=array();
$res1 = $this->syesno->create_form($form_content);
$this->assertNull($res1);
}
public function testMultipleChoiceCreateForm() {
public function testMultipleChoiceCreateForm() {
$form_content=array();
$res2 = $this->smultiplechoice->create_form($form_content);
$this->assertNull($res2);
$this->assertNull($res2);
}
public function testPersonalityCreateForm() {
$form_content=array();
@ -125,7 +125,7 @@ class TestSurvey extends UnitTestCase {
$this->assertNotNull($this->smultipleresponse->html);
$this->assertTrue($this->smultipleresponse->html);
}
public function testQuestionRenderQuestion() {
ob_start();
$form_content=array();
@ -134,7 +134,7 @@ class TestSurvey extends UnitTestCase {
$this->assertTrue(is_null($res));
ob_end_clean();
}
public function testMultipleChoiseRenderQuestion() {
ob_start();
$form_content=array();
@ -143,7 +143,7 @@ class TestSurvey extends UnitTestCase {
$this->assertNull($this->smultiplechoice->html);
ob_end_clean();
}
public function testYesNoRenderQuestion() {
ob_start();
$form_content=array();
@ -171,7 +171,7 @@ class TestSurvey extends UnitTestCase {
}
//save the survey
public function testCopySurvey() {
$parent_survey = Database::escape_string($parent_survey);
$new_survey_id = '1';
@ -204,7 +204,7 @@ class TestSurvey extends UnitTestCase {
}
//var_dump($res);
}
public function testSaveQuestion() {
$form_content=array();
$res = $this->smanager->save_question($form_content);
@ -237,13 +237,13 @@ class TestSurvey extends UnitTestCase {
$this->assertNull($res);
//var_dump($res);
}
//get the survey
public function testGetPeopleWhoFilledSurvey() {
$survey_id=1;
$all_user_info=false;
$survey_data = survey_manager::get_survey($survey_id);
$survey_data = SurveyManager::get_survey($survey_id);
$result = $this->smanager->get_people_who_filled_survey($survey_id,false);
$this->assertTrue(is_array($result));
//var_dump($result);
@ -263,9 +263,9 @@ class TestSurvey extends UnitTestCase {
$this->assertNull($res);
//var_dump($res);
}
//move the survey
public function testMoveSurveyQuestion() {
$direction='moveup';
$survey_question_id=1;
@ -276,23 +276,23 @@ class TestSurvey extends UnitTestCase {
}
//epmty the survey
public function testEmpty_survey() {
$survey_id=null;
$res = $this->smanager->empty_survey($survey_id);
$this->assertTrue($res);
//var_dump($res);
}
//functions delete
public function testHandleAction() {
$form_content = array('');
$res = $this->squestion->handle_action($form_content);
$this->assertTrue(is_array($res));
//var_dump($res);
}
public function testDeleteAllSurveyQuestions() {
$survey_id=1;
$shared=false;
@ -310,7 +310,7 @@ class TestSurvey extends UnitTestCase {
//var_dump($result);
//var_dump($res);
}
public function testDeleteSharedSurveyQuestion() {
$survey_id=1;
$question_id=01;
@ -318,7 +318,7 @@ class TestSurvey extends UnitTestCase {
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testDeleteSurvey() {
$survey_id=1;
$shared=false;
@ -327,7 +327,7 @@ class TestSurvey extends UnitTestCase {
$this->assertTrue($res);
//var_dump($res);
}
public function testDeleteAllSurveyQuestionsOptions() {
$survey_id=1;
$shared=false;
@ -344,7 +344,7 @@ class TestSurvey extends UnitTestCase {
if(is_bool($result))
$this->assertTrue(is_bool($result));
$this->assertTrue($result === true || $result===false);
$this->assertTrue($result);
$this->assertTrue($result);
//var_dump($result);
}
@ -356,9 +356,9 @@ class TestSurvey extends UnitTestCase {
$this->assertTrue($res === true || $res === false);
//var_dump($res);
}
//Contest the answer
public function testUpdateSurveyAnswered() {
global $user;
$survey_code = 'Survey1';
@ -373,10 +373,10 @@ class TestSurvey extends UnitTestCase {
* This functon only is added to the end of the test and the end of the files in the all test.
*/
/* public function testDeleteCourse() {
global $cidReq;
$resu = CourseManager::delete_course($cidReq);
global $cidReq;
$resu = CourseManager::delete_course($cidReq);
}*/
}
?>

Loading…
Cancel
Save