/** * Sets the surveylist and the plainsurveylist */ public function __construct() { // Database table definitions $table_survey = Database::get_course_table(TABLE_SURVEY); $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); $table_user = Database::get_main_table(TABLE_MAIN_USER); // searching $search_restriction = SurveyUtil::survey_search_restriction(); if ($search_restriction) { $search_restriction = ' AND ' . $search_restriction; } $course_id = api_get_course_int_id(); $sql = "SELECT\n survey.survey_id,\n survey.parent_id,\n survey_version,\n survey.code as name\n\t\t\t\tFROM {$table_survey} survey\n\t\t\t\tLEFT JOIN {$table_survey_question} survey_question\n\t\t\t\tON survey.survey_id = survey_question.survey_id , {$table_user} user\n\t\t\t\tWHERE\n\t\t\t\t\tsurvey.c_id \t\t\t= {$course_id} AND\n\t\t\t\t\tsurvey_question.c_id \t= {$course_id} AND\n\t\t\t\t\tsurvey.author \t\t\t= user.user_id\n\t\t\t\tGROUP BY survey.survey_id"; $res = Database::query($sql); $surveys_parents = array(); $refs = array(); $list = array(); $plain_array = array(); while ($survey = Database::fetch_array($res, 'ASSOC')) { $plain_array[$survey['survey_id']] = $survey; $surveys_parents[] = $survey['survey_version']; $thisref =& $refs[$survey['survey_id']]; $thisref['parent_id'] = $survey['parent_id']; $thisref['name'] = $survey['name']; $thisref['id'] = $survey['survey_id']; $thisref['survey_version'] = $survey['survey_version']; if ($survey['parent_id'] == 0) { $list[$survey['survey_id']] =& $thisref; } else { $refs[$survey['parent_id']]['children'][$survey['survey_id']] =& $thisref; } } $this->surveylist = $list; $this->plainsurveylist = $plain_array; }
/** * This function gets all the survey data that is to be displayed in the sortable table * * @param int $from * @param int $number_of_items * @param int $column * @param string $direction * @param bool $isDrh * @return unknown * * @author Patrick Cool <*****@*****.**>, Ghent University * @author Julio Montoya <*****@*****.**>, Beeznest - Adding intvals * @version January 2007 */ static function get_survey_data($from, $number_of_items, $column, $direction, $isDrh = false) { $table_survey = Database::get_course_table(TABLE_SURVEY); $table_user = Database::get_main_table(TABLE_MAIN_USER); $table_survey_question = Database::get_course_table(TABLE_SURVEY_QUESTION); $_user = api_get_user_info(); // Searching $search_restriction = SurveyUtil::survey_search_restriction(); if ($search_restriction) { $search_restriction = ' AND ' . $search_restriction; } $from = intval($from); $number_of_items = intval($number_of_items); $column = intval($column); if (!in_array(strtolower($direction), array('asc', 'desc'))) { $direction = 'asc'; } // Condition for the session $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id); $course_id = api_get_course_int_id(); $sql = "SELECT\n\t\t\t\t\tsurvey.survey_id AS col0,\n\t\t\t\t\tsurvey.title AS col1,\n\t\t\t\t\tsurvey.code AS col2,\n\t\t\t\t\tcount(survey_question.question_id) AS col3,\n\t\t\t\t\t" . (api_is_western_name_order() ? "CONCAT(user.firstname, ' ', user.lastname)" : "CONCAT(user.lastname, ' ', user.firstname)") . "\tAS col4,\n\t\t\t\t\tsurvey.avail_from AS col5,\n\t\t\t\t\tsurvey.avail_till AS col6,\n\t\t\t\t\tsurvey.invited AS col7,\n\t\t\t\t\tsurvey.anonymous AS col8,\n\t\t\t\t\tsurvey.survey_id AS col9,\n\t\t\t\t\tsurvey.session_id AS session_id,\n\t\t\t\t\tsurvey.answered,\n\t\t\t\t\tsurvey.invited\n\t\t\t\t FROM {$table_survey} survey\n LEFT JOIN {$table_survey_question} survey_question\n ON (survey.survey_id = survey_question.survey_id AND survey_question.c_id = {$course_id})\n LEFT JOIN {$table_user} user\n ON (survey.author = user.user_id)\n\t\t\t\t WHERE survey.c_id = {$course_id}\n\t\t\t\t {$search_restriction}\n\t\t\t\t {$condition_session} "; $sql .= " GROUP BY survey.survey_id"; $sql .= " ORDER BY col{$column} {$direction} "; $sql .= " LIMIT {$from},{$number_of_items}"; $res = Database::query($sql); $surveys = array(); $array = array(); while ($survey = Database::fetch_array($res)) { $array[0] = $survey[0]; $array[1] = Display::url($survey[1], api_get_path(WEB_CODE_PATH) . 'survey/survey.php?survey_id=' . $survey[0] . '&' . api_get_cidreq()); // Validation when belonging to a session $session_img = api_get_session_image($survey['session_id'], $_user['status']); $array[2] = $survey[2] . $session_img; $array[3] = $survey[3]; $array[4] = $survey[4]; $array[5] = $survey[5]; $array[6] = $survey[6]; $array[7] = Display::url($survey['answered'], api_get_path(WEB_CODE_PATH) . 'survey/survey_invitation.php?view=answered&survey_id=' . $survey[0] . '&' . api_get_cidreq()) . ' / ' . Display::url($survey['invited'], api_get_path(WEB_CODE_PATH) . 'survey/survey_invitation.php?view=invited&survey_id=' . $survey[0] . '&' . api_get_cidreq()); $array[8] = $survey[8]; $array[9] = $survey[9]; if ($isDrh) { $array[1] = $survey[1]; $array[7] = strip_tags($array[7]); } $surveys[] = $array; } return $surveys; }