From 7b6b244b4fcbe548d8f50066570ea7c20a198b06 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 17 Mar 2021 15:55:57 +0100 Subject: [PATCH] Remove SurveyTree class, use repository to get survey list. Add migrations, remove c_survey.author use resourceNode.author instead. --- public/main/inc/lib/SurveyTree.php | 125 --------------- public/main/survey/create_new_survey.php | 38 ++--- public/main/survey/survey.lib.php | 32 +--- public/main/survey/surveyUtil.class.php | 53 +++---- .../Schema/V200/Version20180319145700.php | 18 +++ .../Repository/ResourceRepository.php | 19 ++- src/CourseBundle/Entity/CSurvey.php | 143 ++++++++++++------ .../Repository/CSurveyRepository.php | 57 ++++++- 8 files changed, 244 insertions(+), 241 deletions(-) delete mode 100644 public/main/inc/lib/SurveyTree.php diff --git a/public/main/inc/lib/SurveyTree.php b/public/main/inc/lib/SurveyTree.php deleted file mode 100644 index dd573759b2..0000000000 --- a/public/main/inc/lib/SurveyTree.php +++ /dev/null @@ -1,125 +0,0 @@ -surveylist = $list; - $this->plainsurveylist = $plain_array; - } - - /** - * This function gets the parent id of a survey. - * - * @param int $id survey id - * - * @return int survey parent id - * - * @author Julio Montoya , Dokeos - * - * @version September 2008 - */ - public function getParentId($id) - { - $node = $this->plainsurveylist[$id]; - if (is_array($node) && !empty($node['parent_id'])) { - return $node['parent_id']; - } - - return -1; - } - - /** - * This function creates a list of all surveys id. - * - * @param array $list of nodes - * - * @return array with the structure survey_id => survey_name - * - * @author Julio Montoya - * - * @version September 2008 - */ - public function createList($list) - { - $result = []; - if (is_array($list)) { - foreach ($list as $key => $node) { - if (isset($node['children']) && is_array($node['children'])) { - $result[$key] = $node['name']; - $re = self::createList($node['children']); - if (!empty($re)) { - if (is_array($re)) { - foreach ($re as $key => $r) { - $result[$key] = ''.$r; - } - } else { - $result[] = $re; - } - } - } else { - $result[$key] = $node['name']; - } - } - } - - return $result; - } -} diff --git a/public/main/survey/create_new_survey.php b/public/main/survey/create_new_survey.php index a3d5f21d6b..18ff3b43fb 100644 --- a/public/main/survey/create_new_survey.php +++ b/public/main/survey/create_new_survey.php @@ -2,6 +2,8 @@ /* For licensing terms, see /license.txt */ +use Chamilo\CoreBundle\Framework\Container; + /** * @author Patrick Cool , Ghent University: cleanup, * refactoring and rewriting large parts (if not all) of the code @@ -11,8 +13,11 @@ * @todo only the available platform languages should be used => need an * api get_languages and and api_get_available_languages (or a parameter) */ + require_once __DIR__.'/../inc/global.inc.php'; +$repo = Container::getSurveyRepository(); + $_course = api_get_course_info(); $this_section = SECTION_COURSES; $table_gradebook_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); @@ -40,14 +45,14 @@ $gradebook_link_type = 8; $urlname = isset($survey_data['title']) ? strip_tags($survey_data['title']) : null; // Breadcrumbs -if ('add' == $action) { +if ('add' === $action) { $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(), 'name' => get_lang('Survey list'), ]; $tool_name = get_lang('Create survey'); } -if ('edit' == $action && is_numeric($survey_id)) { +if ('edit' === $action && is_numeric($survey_id)) { $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(), 'name' => get_lang('Survey list'), @@ -106,7 +111,7 @@ $form = new FormValidator( $form->addElement('header', $tool_name); // Setting the form elements -if ('edit' == $action && isset($survey_id) && is_numeric($survey_id)) { +if ('edit' === $action && isset($survey_id) && is_numeric($survey_id)) { $form->addElement('hidden', 'survey_id'); } @@ -117,7 +122,7 @@ $survey_code = $form->addElement( ['size' => '20', 'maxlength' => '20', 'autofocus' => 'autofocus'] ); -if ('edit' == $action) { +if ('edit' === $action) { $survey_code->freeze(); $form->applyFilter('survey_code', 'api_strtoupper'); } @@ -215,10 +220,7 @@ if (Gradebook::is_active()) { get_lang('Grade in the assessment tool'), 'onclick="javascript: if (this.checked) { document.getElementById(\'gradebook_options\').style.display = \'block\'; } else { document.getElementById(\'gradebook_options\').style.display = \'none\'; }"' ); - $form->addElement( - 'html', - '