From 53f6ecf63fabafc309b636008bbe99b00da1253e Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 18 Dec 2019 17:10:29 +0100 Subject: [PATCH] Remove unused code, fix PHP errors, adding psalm config file. --- psalm.xml | 163 +++ .../Entity/Resource/AbstractResource.php | 3 +- src/CoreBundle/Framework/PageController.php | 1157 ----------------- src/CoreBundle/Hook/HookEvent.php | 2 +- .../Hook/HookMyStudentsLpTracking.php | 1 + src/CoreBundle/Hook/HookObserver.php | 2 +- .../Repository/ResourceRepository.php | 19 +- .../Authorization/Voter/GroupVoter.php | 16 - .../Settings/CourseSettingsSchema.php | 18 - src/CoreBundle/ToolChain.php | 35 - src/CourseBundle/Admin/CourseAdmin.php | 9 +- src/UserBundle/Entity/User.php | 2 +- .../BuildAttributeFormChoicesListener.php | 116 -- .../BuildAttributeValueFormListener.php | 100 -- .../BuildAttributeFormSubscriber.php | 65 - .../BuildAttributeValueFormSubscriber.php | 83 -- src/UserBundle/Form/Type/AttributeType.php | 65 - .../Form/Type/AttributeTypeChoiceType.php | 58 - .../Form/Type/AttributeValueType.php | 114 -- .../Form/Type/RegistrationFormType.php | 134 -- src/UserBundle/Form/UserType.php | 103 -- src/UserBundle/Repository/UserRepository.php | 25 - src/UserBundle/Security/FOSUBUserProvider.php | 76 -- 23 files changed, 182 insertions(+), 2184 deletions(-) create mode 100644 psalm.xml delete mode 100644 src/CoreBundle/Framework/PageController.php delete mode 100644 src/UserBundle/Form/EventListener/BuildAttributeFormChoicesListener.php delete mode 100644 src/UserBundle/Form/EventListener/BuildAttributeValueFormListener.php delete mode 100644 src/UserBundle/Form/EventSubscriber/BuildAttributeFormSubscriber.php delete mode 100644 src/UserBundle/Form/EventSubscriber/BuildAttributeValueFormSubscriber.php delete mode 100644 src/UserBundle/Form/Type/AttributeType.php delete mode 100644 src/UserBundle/Form/Type/AttributeTypeChoiceType.php delete mode 100644 src/UserBundle/Form/Type/AttributeValueType.php delete mode 100644 src/UserBundle/Form/Type/RegistrationFormType.php delete mode 100644 src/UserBundle/Form/UserType.php delete mode 100644 src/UserBundle/Security/FOSUBUserProvider.php diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000000..7e66be5a5b --- /dev/null +++ b/psalm.xml @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/CoreBundle/Entity/Resource/AbstractResource.php b/src/CoreBundle/Entity/Resource/AbstractResource.php index e57bc84ab2..743b7283c7 100644 --- a/src/CoreBundle/Entity/Resource/AbstractResource.php +++ b/src/CoreBundle/Entity/Resource/AbstractResource.php @@ -26,7 +26,8 @@ abstract class AbstractResource * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="CASCADE") */ public $resourceNode; - //abstract public function getResourceName(): string; + + abstract public function getResourceName(): string; /** * @return $this diff --git a/src/CoreBundle/Framework/PageController.php b/src/CoreBundle/Framework/PageController.php deleted file mode 100644 index affb2e976b..0000000000 --- a/src/CoreBundle/Framework/PageController.php +++ /dev/null @@ -1,1157 +0,0 @@ - - * - * @todo move functions in the Template class, remove this class. - */ -class PageController -{ - public $maxPerPage = 5; - - /** - * Returns an online help block read from the home/home_menu_[lang].html - * file. - * - * @return string HTML block - */ - public function returnHelp() - { - $home = api_get_home_path(); - $user_selected_language = api_get_language_isocode(); - $sys_path = api_get_path(SYS_PATH); - $platformLanguage = api_get_setting('language.platform_language'); - - if (!isset($user_selected_language)) { - $user_selected_language = $platformLanguage; - } - $home_menu = @(string) file_get_contents($sys_path.$home.'home_menu_'.$user_selected_language.'.html'); - if (!empty($home_menu)) { - $home_menu_content = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu))); - $this->show_right_block( - get_lang('Help'), - null, - 'help_block', - ['content' => $home_menu_content] - ); - } - } - - /** - * Returns an HTML block with links to the skills tools. - * - * @return string HTML
block - */ - public function returnSkillsLinks() - { - if ('true' == api_get_setting('skill.allow_skills_tool')) { - $content = []; - $content[] = [ - 'title' => get_lang('My skills'), - 'href' => api_get_path(WEB_CODE_PATH).'social/skills_wheel.php', - ]; - - if ('true' == api_get_setting('skill.allow_hr_skills_management') - || api_is_platform_admin()) { - $content[] = [ - 'title' => get_lang('Manage skills'), - 'href' => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php', - ]; - } - $this->show_right_block(get_lang('Skills'), $content, 'skill_block'); - } - } - - /** - * Returns an HTML block with the notice, as found in the - * home/home_notice_[lang].html file. - * - * @return string HTML
block - */ - public function returnNotice() - { - $sys_path = api_get_path(SYS_PATH); - $user_selected_language = api_get_language_isocode(); - $home = api_get_home_path(); - - // Notice - $home_notice = @(string) file_get_contents($sys_path.$home.'home_notice_'.$user_selected_language.'.html'); - if (empty($home_notice)) { - $home_notice = @(string) file_get_contents($sys_path.$home.'home_notice.html'); - } - - if (!empty($home_notice)) { - $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice))); - $home_notice = Display::div($home_notice, ['class' => 'homepage_notice']); - - $this->show_right_block(get_lang('Notice'), null, 'notice_block', ['content' => $home_notice]); - } - } - - /** - * Returns the received content packaged in
block, with the title as - *

. - * - * @param string $title Title to include as h4 - * @param string $content Longer content to show (usually a
    list) - * @param string $id ID to be added to the HTML attributes for the block - * @param array $params Array of attributes to add to the HTML block - * - * @return string HTML
    block - * - * @todo use the menu builder - */ - public function show_right_block($title, $content, $id, $params = null) - { - if (!empty($id)) { - $params['id'] = $id; - } - $block_menu = [ - 'id' => $params['id'], - 'title' => $title, - 'elements' => $content, - 'content' => isset($params['content']) ? $params['content'] : null, - ]; - - //$app['template']->assign($id, $block_menu); - } - - /** - * Returns a content search form in an HTML
    , pointing at the - * main/search/ directory. If search_enabled is not set, then it returns - * an empty string. - * - * @return string HTML
    block showing the search form, or an empty string if search not enabled - */ - public function return_search_block() - { - $html = ''; - if ('true' == api_get_setting('search.search_enabled')) { - $html .= ''; - $html .= $this->show_right_block(get_lang('Search'), $search_content, 'search_block'); - } - - return $html; - } - - /** - * Return the homepage, including announcements. - * - * @return string The portal's homepage as an HTML string - */ - public function returnHomePage() - { - // Including the page for the news - $html = null; - $home = api_get_path(SYS_DATA_PATH).api_get_home_path(); - $home_top_temp = null; - - if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\.html$/', $_GET['include'])) { - $open = @(string) file_get_contents(api_get_path(SYS_PATH).$home.$_GET['include']); - $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); - } else { - $user_selected_language = api_get_user_language(); - - if (!file_exists($home.'home_news_'.$user_selected_language.'.html')) { - if (file_exists($home.'home_top.html')) { - $home_top_temp = file($home.'home_top.html'); - } else { - //$home_top_temp = file('home/'.'home_top.html'); - } - if (!empty($home_top_temp)) { - $home_top_temp = implode('', $home_top_temp); - } - } else { - if (file_exists($home.'home_top_'.$user_selected_language.'.html')) { - $home_top_temp = file_get_contents($home.'home_top_'.$user_selected_language.'.html'); - } else { - $home_top_temp = file_get_contents($home.'home_top.html'); - } - } - - if (empty($home_top_temp) && api_is_platform_admin()) { - //$home_top_temp = get_lang('

    Congratulations! You have successfully installed your e-learning portal!

    You can now complete the installation by following three easy steps:

    1. Configure you portal by going to the administration section, and select the Portal -> Configuration settings entry.
    2. Add some life to your portal by creating users and/or training. You can do that by inviting new people to create their accounts or creating them yourself through the administration's Users and Training sections.
    3. Edit this page through the Edit portal homepage entry in the administration section.

    You can always find more information about this software on our website: http://www.chamilo.org.

    Have fun, and don't hesitate to join the community and give us feedback through our forum.

    '); - } - $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp); - if (!empty($open)) { - $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open))); - } - } - - return $html; - } - - /** - * Returns an HTML block with classes (if show_groups_to_users is true). - * - * @return string A list of links to users classes tools, or an empty string if show_groups_to_users is disabled - */ - public function return_classes_block() - { - $html = ''; - if ('true' == api_get_setting('show_groups_to_users')) { - $usergroup = new Usergroup(); - $usergroup_list = $usergroup->get_usergroup_by_user(api_get_user_id()); - $classes = ''; - if (!empty($usergroup_list)) { - foreach ($usergroup_list as $group_id) { - $data = $usergroup->get($group_id); - $data['name'] = Display::url( - $data['name'], - api_get_path(WEB_CODE_PATH).'user/classes.php?id='.$data['id'] - ); - $classes .= Display::tag('li', $data['name']); - } - } - if (api_is_platform_admin()) { - $classes .= Display::tag( - 'li', - Display::url(get_lang('Add classes'), api_get_path(WEB_CODE_PATH).'admin/usergroups.php?action=add') - ); - } - if (!empty($classes)) { - $classes = Display::tag('ul', $classes, ['class' => 'nav nav-list']); - $html .= $this->show_right_block(get_lang('Classes'), $classes, 'classes_block'); - } - } - - return $html; - } - - /** - * Prepares a block with all the pending exercises in all courses. - * - * @param array $personal_course_list Array of courses (arrays) of the user - */ - public function return_exercise_block($personal_course_list, $tpl) - { - $exercise_list = []; - if (!empty($personal_course_list)) { - foreach ($personal_course_list as $course_item) { - $course_code = $course_item['c']; - $session_id = $course_item['id_session']; - - $exercises = ExerciseLib::get_exercises_to_be_taken($course_code, $session_id); - - foreach ($exercises as $exercise_item) { - $exercise_item['course_code'] = $course_code; - $exercise_item['session_id'] = $session_id; - $exercise_item['tms'] = api_strtotime($exercise_item['end_time'], 'UTC'); - - $exercise_list[] = $exercise_item; - } - } - if (!empty($exercise_list)) { - $exercise_list = ArrayClass::msort($exercise_list, 'tms'); - $my_exercise = $exercise_list[0]; - $url = Display::url( - $my_exercise['title'], - api_get_path( - WEB_CODE_PATH - ).'exercise/overview.php?exerciseId='.$my_exercise['id'].'&cidReq='.$my_exercise['course_code'].'&id_session='.$my_exercise['session_id'] - ); - $tpl->assign('exercise_url', $url); - $tpl->assign( - 'exercise_end_date', - api_convert_and_format_date($my_exercise['end_time'], DATE_FORMAT_SHORT) - ); - } - } - } - - /** - * Display list of courses in a category. - * (for anonymous users). - * - * @version 1.1 - * - * @author Patrick Cool , Ghent University - refactoring and code cleaning - * @author Julio Montoya , Beeznest template modifs - */ - public function return_courses_in_categories() - { - $result = ''; - $stok = Security::get_token(); - - // Initialization. - $user_identified = (api_get_user_id() > 0 && !api_is_anonymous()); - $web_course_path = api_get_path(WEB_COURSE_PATH); - $category = Database::escape_string($_GET['category']); - $setting_show_also_closed_courses = 'true' == api_get_setting('show_closed_courses'); - - // Database table definitions. - $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE); - $main_category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY); - - $categoryId = null; - $courseCategory = \CourseCategory::getCategory($_GET['category']); - $categoryCondition = 'category_code IS NULL'; - - if (!empty($courseCategory)) { - $categoryId = $courseCategory['id']; - $categoryCondition = "category_code = $categoryId"; - } - - // Get list of courses in category $category. - $sql_get_course_list = "SELECT * FROM $main_course_table cours - WHERE $categoryCondition - ORDER BY title, UPPER(visual_code)"; - - // Showing only the courses of the current access_url_id. - if (api_is_multiple_url_enabled()) { - $url_access_id = api_get_current_access_url_id(); - if (-1 != $url_access_id) { - $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); - $sql_get_course_list = "SELECT * FROM $main_course_table as course INNER JOIN $tbl_url_rel_course as url_rel_course - ON (url_rel_course.c_id = course.id) - WHERE access_url_id = $url_access_id AND $categoryCondition ORDER BY title, UPPER(visual_code)"; - } - } - - // Removed: AND cours.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' - $sql_result_courses = Database::query($sql_get_course_list); - - while ($course_result = Database::fetch_array($sql_result_courses)) { - $course_list[] = $course_result; - } - - $platform_visible_courses = ''; - // $setting_show_also_closed_courses - if ($user_identified) { - if ($setting_show_also_closed_courses) { - $platform_visible_courses = ''; - } else { - $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' OR t3.visibility='".COURSE_VISIBILITY_OPEN_PLATFORM."' )"; - } - } else { - if ($setting_show_also_closed_courses) { - $platform_visible_courses = ''; - } else { - $platform_visible_courses = " AND (t3.visibility='".COURSE_VISIBILITY_OPEN_WORLD."' )"; - } - } - $sqlGetSubCatList = " - SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse - FROM $main_category_table t1 - LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id - LEFT JOIN $main_course_table t3 ON (t3.category_id = t1.id $platform_visible_courses) - WHERE t1.parent_id ".(empty($category) ? 'IS NULL' : "='$category'").' - GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name'; - - // Showing only the category of courses of the current access_url_id - if (api_is_multiple_url_enabled()) { - $url_access_id = api_get_current_access_url_id(); - if (-1 != $url_access_id) { - $tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); - $sqlGetSubCatList = " - SELECT t1.name,t1.code,t1.parent_id,t1.children_count,COUNT(DISTINCT t3.code) AS nbCourse - FROM $main_category_table t1 - LEFT JOIN $main_category_table t2 ON t1.code=t2.parent_id - LEFT JOIN $main_course_table t3 ON (t3.category_id = t1.id $platform_visible_courses) - INNER JOIN $tbl_url_rel_course as url_rel_course - ON (url_rel_course.c_id = t3.id) - WHERE access_url_id = $url_access_id AND t1.parent_id ".(empty($category) ? 'IS NULL' : "='$category'").' - GROUP BY t1.name,t1.code,t1.parent_id,t1.children_count ORDER BY t1.tree_pos, t1.name'; - } - } - - $resCats = Database::query($sqlGetSubCatList); - $thereIsSubCat = false; - if (Database::num_rows($resCats) > 0) { - $htmlListCat = Display::page_header(get_lang('Categories')); - $htmlListCat .= '
      '; - while ($catLine = Database::fetch_array($resCats)) { - if ($catLine['code'] != $category) { - $category_has_open_courses = $this->category_has_open_courses($catLine['code']); - if ($category_has_open_courses) { - // The category contains courses accessible to anonymous visitors. - $htmlListCat .= '
    • '; - $htmlListCat .= ''.$catLine['name'].''; - if ('true' == api_get_setting('show_number_of_courses')) { - $htmlListCat .= ' ('.$catLine['nbCourse'].' '.get_lang('Courses').')'; - } - $htmlListCat .= '
    • '; - $thereIsSubCat = true; - } elseif ($catLine['children_count'] > 0) { - // The category has children, subcategories. - $htmlListCat .= '
    • '; - $htmlListCat .= ''.$catLine['name'].''; - $htmlListCat .= '
    • '; - $thereIsSubCat = true; - } elseif ('true' == api_get_setting('show_empty_course_categories')) { - /* End changed code to eliminate the (0 courses) after empty categories. */ - $htmlListCat .= '
    • '; - $htmlListCat .= $catLine['name']; - $htmlListCat .= '
    • '; - $thereIsSubCat = true; - } // Else don't set thereIsSubCat to true to avoid printing things if not requested. - } else { - $htmlTitre = '

      '; - if ('true' == api_get_setting('show_back_link_on_top_of_tree')) { - $htmlTitre .= '<< '.get_lang('Categories Overview').''; - } - if (!is_null($catLine['parent_id']) || - ('true' != api_get_setting('show_back_link_on_top_of_tree') && - !is_null($catLine['code'])) - ) { - $htmlTitre .= '<< '.get_lang('Up').''; - } - $htmlTitre .= '

      '; - if ('' != $category && !is_null($catLine['code'])) { - $htmlTitre .= '

      '.$catLine['name'].'

      '; - } else { - $htmlTitre .= '

      '.get_lang('Categories').'

      '; - } - } - } - $htmlListCat .= '
    '; - } - $result .= $htmlTitre; - if ($thereIsSubCat) { - $result .= $htmlListCat; - } - while ($categoryName = Database::fetch_array($resCats)) { - $result .= '

    '.$categoryName['name']."

    \n"; - } - $numrows = Database::num_rows($sql_result_courses); - $courses_list_string = ''; - $courses_shown = 0; - if ($numrows > 0) { - $courses_list_string .= Display::page_header(get_lang('Course list')); - $courses_list_string .= '
      '; - - if (api_get_user_id()) { - $courses_of_user = $this->get_courses_of_user(api_get_user_id()); - } - - foreach ($course_list as $course) { - // $setting_show_also_closed_courses - if (!$setting_show_also_closed_courses) { - // If we do not show the closed courses - // we only show the courses that are open to the world (to everybody) - // and the courses that are open to the platform (if the current user is a registered user. - if (($user_identified && COURSE_VISIBILITY_OPEN_PLATFORM == $course['visibility']) || (COURSE_VISIBILITY_OPEN_WORLD == $course['visibility'])) { - ++$courses_shown; - $courses_list_string .= "
    • \n"; - $courses_list_string .= ''.$course['title'].'
      '; - $course_details = []; - if ('true' == - api_get_setting('course.display_coursecode_in_courselist')) { - $course_details[] = $course['visual_code']; - } - if ('true' == - api_get_setting('course.display_teacher_in_courselist')) { - $course_details[] = $course['tutor_name']; - } - if ('true' == - api_get_setting('display.show_different_course_language') && $course['course_language'] != api_get_setting( - 'language.platform_language' - ) - ) { - $course_details[] = $course['course_language']; - } - $courses_list_string .= implode(' - ', $course_details); - $courses_list_string .= "
    • \n"; - } - } else { - // We DO show the closed courses. - // The course is accessible if (link to the course homepage): - // 1. the course is open to the world (doesn't matter if the user is logged in or not): $course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD); - // 2. the user is logged in and the course is open to the world or open to the platform: ($user_identified && $course['visibility'] == COURSE_VISIBILITY_OPEN_PLATFORM); - // 3. the user is logged in and the user is subscribed to the course and the course visibility is not COURSE_VISIBILITY_CLOSED; - // 4. the user is logged in and the user is course admin of te course (regardless of the course visibility setting); - // 5. the user is the platform admin api_is_platform_admin(). - // - ++$courses_shown; - $courses_list_string .= "
    • \n"; - if (COURSE_VISIBILITY_OPEN_WORLD == $course['visibility'] - || ($user_identified && COURSE_VISIBILITY_OPEN_PLATFORM == $course['visibility']) - || ($user_identified && key_exists( - $course['code'], - $courses_of_user - ) && COURSE_VISIBILITY_CLOSED != $course['visibility']) - || '1' == $courses_of_user[$course['code']]['status'] - || api_is_platform_admin() - ) { - $courses_list_string .= ''; - } - $courses_list_string .= $course['title']; - if (COURSE_VISIBILITY_OPEN_WORLD == $course['visibility'] - || ($user_identified && COURSE_VISIBILITY_OPEN_PLATFORM == $course['visibility']) - || ($user_identified && key_exists( - $course['code'], - $courses_of_user - ) && COURSE_VISIBILITY_CLOSED != $course['visibility']) - || '1' == $courses_of_user[$course['code']]['status'] - || api_is_platform_admin() - ) { - $courses_list_string .= '
      '; - } - $course_details = []; - if ('true' == api_get_setting('course.display_coursecode_in_courselist')) { - $course_details[] = $course['visual_code']; - } - if ('true' == api_get_setting('course.display_teacher_in_courselist')) { - $course_details[] = $course['tutor_name']; - } - if ('true' == api_get_setting( - 'display.show_different_course_language' - ) && $course['course_language'] != api_get_setting( - 'language.platform_language' - ) - ) { - $course_details[] = $course['course_language']; - } - if ('true' == api_get_setting( - 'show_different_course_language' - ) && $course['course_language'] != api_get_setting( - 'language.platform_language' - ) - ) { - $course_details[] = $course['course_language']; - } - - $courses_list_string .= implode(' - ', $course_details); - // We display a subscription link if: - // 1. it is allowed to register for the course and if the course is not already in the courselist of the user and if the user is identiefied - // 2. - if ($user_identified && !array_key_exists($course['code'], $courses_of_user)) { - if ('1' == $course['subscribe']) { - $courses_list_string .= '
      '; - $courses_list_string .= ''; - $courses_list_string .= ''; - $courses_list_string .= ''.get_lang('Subscribe').' -
      '; - } else { - $courses_list_string .= '
      '.get_lang('Subscribing not allowed'); - } - } - $courses_list_string .= '
    • '; - } //end else - } // end foreach - $courses_list_string .= '
    '; - } - if ($courses_shown > 0) { - // Only display the list of courses and categories if there was more than - // 0 courses visible to the world (we're in the anonymous list here). - $result .= $courses_list_string; - } - if ('' != $category) { - $result .= '

    '.Display :: return_icon('back.png', get_lang('Categories Overview')).get_lang('Categories Overview').'

    '; - } - - return $result; - } - - /** - * @param int $user_id - * @param string $filter - * @param int $page - * - * @return bool - */ - public function returnMyCourseCategories($user_id, $filter, $page) - { - if (empty($user_id)) { - return false; - } - $loadDirs = 'true' == api_get_setting('document.show_documents_preview') ? true : false; - $start = ($page - 1) * $this->maxPerPage; - - $nbResults = (int) CourseManager::displayPersonalCourseCategories($user_id, $filter, $loadDirs, true); - - $html = CourseManager::displayPersonalCourseCategories( - $user_id, - $filter, - $loadDirs, - false, - $start, - $this->maxPerPage - ); - - $adapter = new FixedAdapter($nbResults, []); - $pagerfanta = new Pagerfanta($adapter); - $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default - $pagerfanta->setCurrentPage($page); // 1 by default - - $this->app['pagerfanta.view.router.name'] = 'userportal'; - $this->app['pagerfanta.view.router.params'] = [ - 'filter' => $filter, - 'type' => 'courses', - 'page' => $page, - ]; - $this->app['template']->assign('pagination', $pagerfanta); - - return $html; - } - - public function returnSpecialCourses($user_id, $filter, $page) - { - if (empty($user_id)) { - return false; - } - - $loadDirs = 'true' == api_get_setting('document.show_documents_preview') ? true : false; - $start = ($page - 1) * $this->maxPerPage; - - $nbResults = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, true); - - $html = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage); - if (!empty($html)) { - $adapter = new FixedAdapter($nbResults, []); - $pagerfanta = new Pagerfanta($adapter); - $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default - $pagerfanta->setCurrentPage($page); // 1 by default - $this->app['pagerfanta.view.router.name'] = 'userportal'; - $this->app['pagerfanta.view.router.params'] = [ - 'filter' => $filter, - 'type' => 'courses', - 'page' => $page, - ]; - $this->app['template']->assign('pagination', $pagerfanta); - } - - return $html; - } - - /** - * The most important function here, prints the session and course list (user_portal.php). - * - * @param int $user_id - * @param string $filter - * @param int $page - * - * @return string HTML list of sessions and courses - */ - public function returnCourses($user_id, $filter, $page) - { - if (empty($user_id)) { - return false; - } - - $loadDirs = 'true' == api_get_setting('document.show_documents_preview') ? true : false; - $start = ($page - 1) * $this->maxPerPage; - - return; - $nbResults = CourseManager::displayCourses( - $user_id, - $filter, - $loadDirs, - true - ); - - $html = CourseManager::displayCourses( - $user_id, - $filter, - $loadDirs, - false, - $start, - $this->maxPerPage - ); - - if (!empty($html)) { - $adapter = new FixedAdapter($nbResults, []); - $pagerfanta = new Pagerfanta($adapter); - $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default - $pagerfanta->setCurrentPage($page); // 1 by default - - /* - Original pagination construction - $view = new TwitterBootstrapView(); - $routeGenerator = function($page) use ($app, $filter) { - return $app['url_generator']->generate('userportal', array( - 'filter' => $filter, - 'type' => 'courses', - 'page' => $page) - ); - }; - $pagination = $view->render($pagerfanta, $routeGenerator, array( - 'proximity' => 3, - )); - */ - //Pagination using the pagerfanta silex service provider - /*$this->app['pagerfanta.view.router.name'] = 'userportal'; - $this->app['pagerfanta.view.router.params'] = array( - 'filter' => $filter, - 'type' => 'courses', - 'page' => $page - ); - $this->app['template']->assign('pagination', $pagerfanta);*/ - // {{ pagerfanta(my_pager, 'twitter_bootstrap3') }} - } - - return $html; - } - - public function returnSessionsCategories($user_id, $filter, $page) - { - if (empty($user_id)) { - return false; - } - - $load_history = isset($filter) && 'history' == $filter ? true : false; - - $start = ($page - 1) * $this->maxPerPage; - - $nbResults = UserManager::getCategories($user_id, false, true, true); - $session_categories = UserManager::getCategories( - $user_id, - false, - false, - true, - $start, - $this->maxPerPage - ); - - $html = null; - //Showing history title - if ($load_history) { - $html .= Display::page_subheader(get_lang('Courses history')); - if (empty($session_categories)) { - $html .= get_lang('You have no session in your sessions history'); - } - } - - $load_directories_preview = 'true' == api_get_setting('document.show_documents_preview') ? true : false; - $sessions_with_category = $html; - - if (isset($session_categories) && !empty($session_categories)) { - foreach ($session_categories as $session_category) { - $session_category_id = $session_category['session_category']['id']; - - // All sessions included in - $count_courses_session = 0; - $html_sessions = ''; - foreach ($session_category['sessions'] as $session) { - $session_id = $session['session_id']; - - // Don't show empty sessions. - if (count($session['courses']) < 1) { - continue; - } - - $html_courses_session = ''; - $count = 0; - foreach ($session['courses'] as $course) { - if ('false' == api_get_setting('session.hide_courses_in_sessions')) { - $html_courses_session .= CourseManager::get_logged_user_course_html($course, $session_id); - } - ++$count_courses_session; - ++$count; - } - - $params = []; - if ($count > 0) { - $params['icon'] = Display::return_icon( - 'window_list.png', - $session['session_name'], - ['id' => 'session_img_'.$session_id], - ICON_SIZE_LARGE - ); - - //Default session name - $session_link = $session['session_name']; - $params['link'] = null; - - if ('true' == api_get_setting('session.session_page_enabled') && !api_is_drh()) { - //session name with link - $session_link = Display::tag( - 'a', - $session['session_name'], - ['href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id] - ); - $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id; - } - - $params['title'] = $session_link; - - $moved_status = \SessionManager::getSessionChangeUserReason( - isset($session['moved_status']) ? $session['moved_status'] : '' - ); - $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null; - - $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status; - $params['dates'] = \SessionManager::parseSessionDates( - $session - ); - - if (api_is_platform_admin()) { - $params['right_actions'] = ''.Display::return_icon( - 'edit.png', - get_lang('Edit'), - ['align' => 'absmiddle'], - ICON_SIZE_SMALL - ).''; - } - $html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session; - } - } - - if ($count_courses_session > 0) { - $params = []; - $params['icon'] = Display::return_icon( - 'folder_blue.png', - $session_category['session_category']['name'], - [], - ICON_SIZE_LARGE - ); - - if (api_is_platform_admin()) { - $params['right_actions'] = ''.Display::return_icon( - 'edit.png', - get_lang('Edit'), - [], - ICON_SIZE_SMALL - ).''; - } - - $params['title'] = $session_category['session_category']['name']; - - if (api_is_platform_admin()) { - $params['link'] = api_get_path( - WEB_CODE_PATH - ).'admin/session_category_edit.php?&id='.$session_category['session_category']['id']; - } - - $session_category_start_date = $session_category['session_category']['date_start']; - $session_category_end_date = $session_category['session_category']['date_end']; - - if (!empty($session_category_start_date) && '0000-00-00' != $session_category_start_date && !empty($session_category_end_date) && '0000-00-00' != $session_category_end_date) { - $params['subtitle'] = sprintf( - get_lang('From %s to %s'), - $session_category['session_category']['date_start'], - $session_category['session_category']['date_end'] - ); - } else { - if (!empty($session_category_start_date) && '0000-00-00' != $session_category_start_date) { - $params['subtitle'] = get_lang('From').' '.$session_category_start_date; - } - if (!empty($session_category_end_date) && '0000-00-00' != $session_category_end_date) { - $params['subtitle'] = get_lang('Until').' '.$session_category_end_date; - } - } - $sessions_with_category .= CourseManager::course_item_parent( - CourseManager::course_item_html($params, true), - $html_sessions - ); - } - } - - //Pagination - $adapter = new FixedAdapter($nbResults, []); - $pagerfanta = new Pagerfanta($adapter); - $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default - $pagerfanta->setCurrentPage($page); // 1 by default - - $this->app['pagerfanta.view.router.name'] = 'userportal'; - $this->app['pagerfanta.view.router.params'] = [ - 'filter' => $filter, - 'type' => 'sessioncategories', - 'page' => $page, - ]; - $this->app['template']->assign('pagination', $pagerfanta); - } - - return $sessions_with_category; - } - - /** - * @param int $user_id - * @param string $filter current|history - * @param int $page - * - * @return bool|string|null - */ - public function returnSessions($user_id, $filter, $page) - { - if (empty($user_id)) { - return false; - } - - $loadHistory = isset($filter) && 'history' == $filter ? true : false; - - /*$app['session_menu'] = function ($app) use ($loadHistory) { - $menu = $app['knp_menu.factory']->createItem( - 'root', - array( - 'childrenAttributes' => array( - 'class' => 'nav nav-tabs', - 'currentClass' => 'active' - ) - ) - ); - - $current = $menu->addChild( - get_lang('Current'), - array( - 'route' => 'userportal', - 'routeParameters' => array( - 'filter' => 'current', - 'type' => 'sessions' - ) - ) - ); - $history = $menu->addChild( - get_lang('Courses history'), - array( - 'route' => 'userportal', - 'routeParameters' => array( - 'filter' => 'history', - 'type' => 'sessions' - ) - ) - ); - //@todo use URIVoter - if ($loadHistory) { - $history->setCurrent(true); - } else { - $current->setCurrent(true); - } - - return $menu; - };*/ - - //@todo move this in template - //$app['knp_menu.menus'] = array('actions_menu' => 'session_menu'); - - $start = ($page - 1) * $this->maxPerPage; - - if ($loadHistory) { - // Load sessions in category in *history*. - $nbResults = (int) UserManager::get_sessions_by_category( - $user_id, - true, - true, - true, - null, - null, - 'no_category' - ); - - $session_categories = UserManager::get_sessions_by_category( - $user_id, - true, - false, - true, - $start, - $this->maxPerPage, - 'no_category' - ); - } else { - // Load sessions in category. - $nbResults = (int) UserManager::get_sessions_by_category( - $user_id, - false, - true, - false, - null, - null, - 'no_category' - ); - - $session_categories = UserManager::get_sessions_by_category( - $user_id, - false, - false, - false, - $start, - $this->maxPerPage, - 'no_category' - ); - } - - $html = null; - - // Showing history title - if ($loadHistory) { - // $html .= Display::page_subheader(get_lang('Courses history')); - if (empty($session_categories)) { - $html .= get_lang('You have no session in your sessions history'); - } - } - - $load_directories_preview = 'true' === api_get_setting('document.show_documents_preview') ? true : false; - $sessions_with_no_category = $html; - - if (isset($session_categories) && !empty($session_categories)) { - foreach ($session_categories as $session_category) { - $session_category_id = $session_category['session_category']['id']; - - // Sessions does not belong to a session category - if (0 == $session_category_id) { - // Independent sessions - if (isset($session_category['sessions'])) { - foreach ($session_category['sessions'] as $session) { - $session_id = $session['session_id']; - - // Don't show empty sessions. - if (count($session['courses']) < 1) { - continue; - } - - // Courses inside the current session. - $date_session_start = $session['access_start_date']; - $date_session_end = $session['access_end_date']; - $coachAccessStartDate = $session['coach_access_start_date']; - $coachAccessEndDate = $session['coach_access_end_date']; - - $session_now = time(); - $count_courses_session = 0; - $count_courses_session = 0; - - // Loop course content - $html_courses_session = []; - $atLeastOneCourseIsVisible = false; - - foreach ($session['courses'] as $course) { - $is_coach_course = api_is_coach($session_id, $course['real_id']); - $allowed_time = 0; - - // Read only and accessible - if ('false' == api_get_setting('session.hide_courses_in_sessions')) { - $courseUserHtml = CourseManager::get_logged_user_course_html( - $course, - $session_id, - $load_directories_preview - ); - - if (isset($courseUserHtml[1])) { - $course_session = $courseUserHtml[1]; - $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : ''; - $html_courses_session[] = $course_session; - } - } - ++$count_courses_session; - } - - if ($count_courses_session > 0) { - $params = []; - - $params['icon'] = Display::return_icon( - 'window_list.png', - $session['session_name'], - ['id' => 'session_img_'.$session_id], - ICON_SIZE_LARGE - ); - $params['is_session'] = true; - //Default session name - $session_link = $session['session_name']; - $params['link'] = null; - - if ('true' == api_get_setting('session.session_page_enabled') && !api_is_drh()) { - //session name with link - $session_link = Display::tag( - 'a', - $session['session_name'], - [ - 'href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id, - ] - ); - $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id; - } - - $params['title'] = $session_link; - - $moved_status = \SessionManager::getSessionChangeUserReason( - $session['moved_status'] ?? '' - ); - $moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null; - - $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status; - //$params['dates'] = $session['date_message']; - - $params['dates'] = \SessionManager::parseSessionDates($session); - $params['right_actions'] = ''; - if (api_is_platform_admin()) { - $params['right_actions'] .= - Display::url( - Display::return_icon( - 'edit.png', - get_lang('Edit'), - ['align' => 'absmiddle'], - ICON_SIZE_SMALL - ), - api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$session_id - ); - } - - if ('false' == api_get_setting('session.hide_courses_in_sessions')) { - // $params['extra'] .= $html_courses_session; - } - $courseDataToString = CourseManager::parseCourseListData($html_courses_session); - $sessions_with_no_category .= CourseManager::course_item_parent( - CourseManager::course_item_html($params, true), - $courseDataToString - ); - } - } - } - } - } - - /*$adapter = new FixedAdapter($nbResults, array()); - $pagerfanta = new Pagerfanta($adapter); - $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default - $pagerfanta->setCurrentPage($page); // 1 by default - - $this->app['pagerfanta.view.router.name'] = 'userportal'; - $this->app['pagerfanta.view.router.params'] = array( - 'filter' => $filter, - 'type' => 'sessions', - 'page' => $page - ); - $this->app['template']->assign('pagination', $pagerfanta);*/ - } - - return $sessions_with_no_category; - } - - /** - * @param array $items - */ - public function returnNavigationLinks($items) - { - // Main navigation section. - // Tabs that are deactivated are added here. - if (!empty($items)) { - $content = ''; - $this->show_right_block(get_lang('Main navigation'), null, 'navigation_block', ['content' => $content]); - } - } -} diff --git a/src/CoreBundle/Hook/HookEvent.php b/src/CoreBundle/Hook/HookEvent.php index 6026692f94..c6029c03c4 100644 --- a/src/CoreBundle/Hook/HookEvent.php +++ b/src/CoreBundle/Hook/HookEvent.php @@ -95,7 +95,7 @@ abstract class HookEvent implements HookEventInterface $class = get_called_class(); return new $class($entityManager); - } catch (Exception $e) { + } catch (\Exception $e) { return null; } } diff --git a/src/CoreBundle/Hook/HookMyStudentsLpTracking.php b/src/CoreBundle/Hook/HookMyStudentsLpTracking.php index da90a92d55..a7cc9f819d 100644 --- a/src/CoreBundle/Hook/HookMyStudentsLpTracking.php +++ b/src/CoreBundle/Hook/HookMyStudentsLpTracking.php @@ -5,6 +5,7 @@ namespace Chamilo\CoreBundle\Hook; use Chamilo\CoreBundle\Hook\Interfaces\HookMyStudentsLpTrackingEventInterface; +use Chamilo\CoreBundle\Hook\Interfaces\HookMyStudentsLpTrackingObserverInterface; use Doctrine\ORM\EntityManager; /** diff --git a/src/CoreBundle/Hook/HookObserver.php b/src/CoreBundle/Hook/HookObserver.php index b5374bbbb1..196b60e862 100644 --- a/src/CoreBundle/Hook/HookObserver.php +++ b/src/CoreBundle/Hook/HookObserver.php @@ -63,7 +63,7 @@ abstract class HookObserver implements HookObserverInterface $class = get_called_class(); return new $class(); - } catch (Exception $e) { + } catch (\Exception $e) { return null; } } diff --git a/src/CoreBundle/Repository/ResourceRepository.php b/src/CoreBundle/Repository/ResourceRepository.php index 6e7d2020d1..2ea7be623d 100644 --- a/src/CoreBundle/Repository/ResourceRepository.php +++ b/src/CoreBundle/Repository/ResourceRepository.php @@ -356,7 +356,7 @@ class ResourceRepository extends BaseEntityRepository $resourceLink = new ResourceLink(); $resourceLink ->setResourceNode($resourceNode) - ->setPrivate(true); + ; $this->getEntityManager()->persist($resourceLink); $this->getEntityManager()->flush(); @@ -726,14 +726,15 @@ class ResourceRepository extends BaseEntityRepository $resourceNode = $resource->getResourceNode(); if ($resourceNode->hasResourceFile()) { $resourceFile = $resourceNode->getResourceFile(); - $fileName = $resourceFile->getFile()->getPathname(); - - $this->fs->update($fileName, $content); - $size = $this->fs->getSize($fileName); - $resource->setSize($size); - $this->entityManager->persist($resource); - - return true; + if ($resourceFile) { + $fileName = $resourceFile->getFile()->getPathname(); + $this->fs->update($fileName, $content); + $size = $this->fs->getSize($fileName); + $resource->setSize($size); + $this->entityManager->persist($resource); + + return true; + } } return false; diff --git a/src/CoreBundle/Security/Authorization/Voter/GroupVoter.php b/src/CoreBundle/Security/Authorization/Voter/GroupVoter.php index 8b64d02fbd..56eadd94e3 100644 --- a/src/CoreBundle/Security/Authorization/Voter/GroupVoter.php +++ b/src/CoreBundle/Security/Authorization/Voter/GroupVoter.php @@ -55,22 +55,6 @@ class GroupVoter extends Voter return $this->entityManager; } - /** - * @return CourseManager - */ - public function getCourseManager() - { - return $this->courseManager; - } - - /** - * @return GroupManager - */ - public function getGroupManager() - { - return $this->groupManager; - } - /** * {@inheritdoc} */ diff --git a/src/CoreBundle/Settings/CourseSettingsSchema.php b/src/CoreBundle/Settings/CourseSettingsSchema.php index 4bc2bc8c44..04393fb154 100644 --- a/src/CoreBundle/Settings/CourseSettingsSchema.php +++ b/src/CoreBundle/Settings/CourseSettingsSchema.php @@ -28,26 +28,8 @@ class CourseSettingsSchema extends AbstractSettingsSchema */ protected $toolChain; - /** - * @var CourseManager - */ - protected $courseManager; - protected $repository; - public function setToolChain(ToolChain $tools): void - { - $this->toolChain = $tools; - } - - /** - * @param CourseManager $manager - */ - public function setCourseManager($manager): void - { - $this->courseManager = $manager; - } - public function getProcessedToolChain(): array { $tools = []; diff --git a/src/CoreBundle/ToolChain.php b/src/CoreBundle/ToolChain.php index 779682f7ef..bb57d0c885 100644 --- a/src/CoreBundle/ToolChain.php +++ b/src/CoreBundle/ToolChain.php @@ -115,41 +115,6 @@ class ToolChain } } - public function updateTools(): void - { - $manager = $this->entityManager; - $tools = $this->getTools(); - - /** @var AbstractTool $tool */ - foreach ($tools as $tool) { - $toolEntity = new Tool(); - $toolEntity - ->setName($tool->getName()) - ; - - if (1 === $tool->getAdmin()) { - // Only check ROLE_ADMIN - } else { - $this->setToolPermissions($toolEntity); - } - - $manager->persist($toolEntity); - - $types = $tool->getResourceTypes(); - if (!empty($types)) { - foreach ($types as $name => $data) { - $resourceType = new ResourceType(); - $resourceType->setName($name); - //$resourceType->setService($data['entity']); - $resourceType->setTool($toolEntity); - $manager->persist($resourceType); - } - } - - $manager->flush(); - } - } - public function setToolPermissions(Tool $tool): void { $toolResourceRight = new ToolResourceRight(); diff --git a/src/CourseBundle/Admin/CourseAdmin.php b/src/CourseBundle/Admin/CourseAdmin.php index f9240449c3..20cc64b68c 100644 --- a/src/CourseBundle/Admin/CourseAdmin.php +++ b/src/CourseBundle/Admin/CourseAdmin.php @@ -86,22 +86,19 @@ class CourseAdmin extends AbstractAdmin } } - foreach ($tools as $tool) { + /*foreach ($tools as $tool) { $toolName = $tool->getName(); if (!in_array($toolName, $addedTools)) { $toolEntity = new CTool(); $toolEntity - ->setCId($course->getId()) - ->setImage($tool->getImage()) + ->setCourse($course) ->setName($tool->getName()) - ->setLink($tool->getLink()) - ->setTarget($tool->getTarget()) ->setCategory($tool->getCategory()) ; $course->addTools($toolEntity); } - } + }*/ } public function setToolChain(ToolChain $chainTool) diff --git a/src/UserBundle/Entity/User.php b/src/UserBundle/Entity/User.php index bf79b56a67..d8cf24d951 100644 --- a/src/UserBundle/Entity/User.php +++ b/src/UserBundle/Entity/User.php @@ -1431,7 +1431,7 @@ class User extends BaseUser implements ThemeUser, EquatableInterface //implement } /** - * @param $slug + * @param string $slug * * @return User */ diff --git a/src/UserBundle/Form/EventListener/BuildAttributeFormChoicesListener.php b/src/UserBundle/Form/EventListener/BuildAttributeFormChoicesListener.php deleted file mode 100644 index b8ab9075d1..0000000000 --- a/src/UserBundle/Form/EventListener/BuildAttributeFormChoicesListener.php +++ /dev/null @@ -1,116 +0,0 @@ - - * @author Liverbool - */ -class BuildAttributeFormChoicesListener extends BaseBuildAttributeFormChoicesListener -{ - /** - * Form factory. - * - * @var FormFactoryInterface - */ - private $factory; - - /** - * Constructor. - */ - public function __construct(FormFactoryInterface $factory) - { - $this->factory = $factory; - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() - { - return [ - FormEvents::PRE_SET_DATA => 'buildChoices', - FormEvents::PRE_SUBMIT => 'buildConfiguration', - ]; - } - - /** - * Build configuration field for attribute form. - */ - public function buildConfiguration(FormEvent $event) - { - $data = $event->getData(); - $choices = []; - - if (AttributeTypes::CHOICE === $data['type'] && !empty($data['choices'])) { - $choices = $data['choices']; - } - - $data['configuration'] = $choices; - - if (!$event->getForm()->has('configuration')) { - $event->getForm()->add( - $this->factory->createNamed( - 'configuration', - 'collection', - null, - [ - 'allow_add' => true, - 'allow_delete' => true, - 'by_reference' => false, - 'auto_initialize' => false, - ] - ) - ); - } - - $event->setData($data); - } - - /** - * Builds choices for attribute form. - */ - public function buildChoices(FormEvent $event) - { - $attribute = $event->getData(); - if (null === $attribute) { - return; - } - - $type = $attribute->getType(); - - if (null === $type || AttributeTypes::CHOICE === $type) { - $data = null; - $config = $attribute->getConfiguration(); - - if (!empty($config['choices'])) { - $data = $config['choices']; - } - - $event->getForm()->add( - $this->factory->createNamed( - 'choices', - 'collection', - null, - [ - 'type' => 'text', - 'allow_add' => true, - 'allow_delete' => true, - 'by_reference' => false, - 'auto_initialize' => false, - 'mapped' => false, - 'data' => $data, - ] - ) - ); - } - } -} diff --git a/src/UserBundle/Form/EventListener/BuildAttributeValueFormListener.php b/src/UserBundle/Form/EventListener/BuildAttributeValueFormListener.php deleted file mode 100644 index 389ea21575..0000000000 --- a/src/UserBundle/Form/EventListener/BuildAttributeValueFormListener.php +++ /dev/null @@ -1,100 +0,0 @@ - 'onPreSetData', - FormEvents::PRE_SUBMIT => 'onPreSubmit', - ]; - } - - /** - * Builds proper product form after setting the product. - */ - public function buildForm(FormEvent $event) - { - /** @var \Chamilo\CoreBundle\Entity\ExtraFieldValues $attributeValue */ - $attributeValue = $event->getData(); - - $form = $event->getForm(); - - if (null === $attributeValue) { - $form->add( - $this->factory->createNamed( - 'value', - 'text', - null, - ['auto_initialize' => false] - ) - ); - - return; - } - - $type = $attributeValue->getType(); - $attributeValue->setAttribute($attributeValue->getField()); - - $options = [ - 'label' => $attributeValue->getName(), - 'auto_initialize' => false, - ]; - - if (is_array($attributeValue->getConfiguration())) { - $options = array_merge( - $options, - $attributeValue->getConfiguration() - ); - } - - $this->verifyValue($attributeValue); - - // If we're editing the attribute value, let's just render the value field, not full selection. - $form - ->remove('extraField') - ->add($this->factory->createNamed('value', $type, null, $options)); - } - - /** - * Verify value before set to form. - */ - protected function verifyValue(AttributeValueInterface $attributeValue) - { - switch ($attributeValue->getType()) { - case AttributeTypes::CHECKBOX: - if (!is_bool($attributeValue->getValue())) { - $attributeValue->setValue(false); - } - - break; - - case AttributeTypes::CHOICE: - if (!is_array($attributeValue->getValue())) { - $attributeValue->setValue(null); - } - - break; - - case AttributeTypes::MONEY: - case AttributeTypes::NUMBER: - case AttributeTypes::PERCENTAGE: - if (!is_numeric($attributeValue->getValue())) { - $attributeValue->setValue(null); - } - - break; - } - } -} diff --git a/src/UserBundle/Form/EventSubscriber/BuildAttributeFormSubscriber.php b/src/UserBundle/Form/EventSubscriber/BuildAttributeFormSubscriber.php deleted file mode 100644 index e1d54014c8..0000000000 --- a/src/UserBundle/Form/EventSubscriber/BuildAttributeFormSubscriber.php +++ /dev/null @@ -1,65 +0,0 @@ - - */ -class BuildAttributeFormSubscriber implements EventSubscriberInterface -{ - /** - * @var FormFactoryInterface - */ - protected $factory; - - public function __construct(FormFactoryInterface $formFactory) - { - $this->factory = $formFactory; - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() - { - return [ - FormEvents::PRE_SET_DATA => 'addConfigurationFields', - ]; - } - - public function addConfigurationFields(FormEvent $event) - { - $attribute = $event->getData(); - $form = $event->getForm(); - - try { - $requiredFields = $this->factory->createNamed( - 'configuration', - 'sylius_attribute_type_configuration_'.$attribute->getType(), - null, - [ - 'auto_initialize' => false, - 'label' => 'sylius.attribute_type.configuration', - ] - ); - - $form->add($requiredFields); - } catch (InvalidArgumentException $exception) { - } - } -} diff --git a/src/UserBundle/Form/EventSubscriber/BuildAttributeValueFormSubscriber.php b/src/UserBundle/Form/EventSubscriber/BuildAttributeValueFormSubscriber.php deleted file mode 100644 index 8a4f12a5cd..0000000000 --- a/src/UserBundle/Form/EventSubscriber/BuildAttributeValueFormSubscriber.php +++ /dev/null @@ -1,83 +0,0 @@ - - */ -class BuildAttributeValueFormSubscriber implements EventSubscriberInterface -{ - /** - * @var RepositoryInterface - */ - protected $attributeRepository; - - public function __construct(RepositoryInterface $attributeRepository) - { - $this->attributeRepository = $attributeRepository; - } - - /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() - { - return [ - FormEvents::PRE_SET_DATA => 'preSetData', - FormEvents::PRE_SUBMIT => 'preSubmit', - ]; - } - - public function preSetData(FormEvent $event) - { - $attributeValue = $event->getData(); - - if (null === $attributeValue || null === $attributeValue->getAttribute()) { - return; - } - $this->addValueField($event->getForm(), $attributeValue->getAttribute()); - } - - public function preSubmit(FormEvent $event) - { - $attributeValue = $event->getData(); - - if (!isset($attributeValue['value']) || !isset($attributeValue['attribute'])) { - throw new \InvalidArgumentException('Cannot create an attribute value form on pre submit event without "attribute" and "value" keys in data.'); - } - $form = $event->getForm(); - - $attribute = $this->attributeRepository->find($attributeValue['attribute']); - - $attribute = $attribute->getAttribute(); - - $this->addValueField($form, $attribute); - } - - private function addValueField(FormInterface $form, AttributeInterface $attribute) - { - $options = [ - 'auto_initialize' => false, - 'label' => $attribute->getName(), - ]; - - $form->add('attribute'); - $form->add('value', 'sylius_attribute_type_'.$attribute->getType(), $options); - } -} diff --git a/src/UserBundle/Form/Type/AttributeType.php b/src/UserBundle/Form/Type/AttributeType.php deleted file mode 100644 index 552018fc58..0000000000 --- a/src/UserBundle/Form/Type/AttributeType.php +++ /dev/null @@ -1,65 +0,0 @@ - - * @author Leszek Prabucki - * @author Mateusz Zalewski - */ -class AttributeType extends AbstractResourceType -{ - /** - * @var string - */ - protected $subjectName; - - /** - * @param string $dataClass - * @param string $subjectName - */ - public function __construct($dataClass, array $validationGroups, $subjectName) - { - parent::__construct($dataClass, $validationGroups); - - $this->subjectName = $subjectName; - } - - /** - * {@inheritdoc} - */ - public function buildForm(FormBuilderInterface $builder, array $options) - { - $builder - ->addEventSubscriber(new BuildAttributeFormSubscriber($builder->getFormFactory())) - ->addEventSubscriber(new AddCodeFormSubscriber()) - /*->add('translations', 'a2lix_translationsForms', array( - 'form_type' => sprintf('sylius_%s_attribute_translation', $this->subjectName), - 'label' => 'sylius.form.attribute.translations', - ))*/ - ->add('type', 'sylius_attribute_type_choice', [ - 'label' => 'sylius.form.attribute.type', - 'disabled' => true, - ]) - ; - } - - /** - * {@inheritdoc} - */ - public function getName() - { //chamilo_user_extra_field_choice - return 'chamilo_user_attribute_type'; - - return sprintf('%s_extra_field', $this->subjectName); - } -} diff --git a/src/UserBundle/Form/Type/AttributeTypeChoiceType.php b/src/UserBundle/Form/Type/AttributeTypeChoiceType.php deleted file mode 100644 index 3055af962b..0000000000 --- a/src/UserBundle/Form/Type/AttributeTypeChoiceType.php +++ /dev/null @@ -1,58 +0,0 @@ - - */ -class AttributeTypeChoiceType extends AbstractType -{ - /** - * @var array - */ - private $attributeTypes; - - /** - * @param array $attributeTypes - */ - public function __construct($attributeTypes) - { - $this->attributeTypes = $attributeTypes; - } - - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver) - { - $resolver - ->setDefaults( - ['choices' => $this->attributeTypes] - ) - ; - } - - /** - * {@inheritdoc} - */ - public function getParent() - { - return 'choice'; - } - - /** - * {@inheritdoc} - */ - public function getName() - { - //return sprintf('chamilo_%s_extra_field_choice', $this->subjectName); - return 'chamilo_user_attribute_choice'; - } -} diff --git a/src/UserBundle/Form/Type/AttributeValueType.php b/src/UserBundle/Form/Type/AttributeValueType.php deleted file mode 100644 index 51d4c171ea..0000000000 --- a/src/UserBundle/Form/Type/AttributeValueType.php +++ /dev/null @@ -1,114 +0,0 @@ - - */ -class AttributeValueType extends AbstractResourceType -{ - /** - * Attributes subject name. - * - * @var string - */ - protected $subjectName; - - /** - * @var EntityRepository - */ - protected $attributeRepository; - - /** - * @param string $dataClass - * @param string $subjectName - */ - public function __construct($dataClass, array $validationGroups, $subjectName, EntityRepository $attributeRepository) - { - parent::__construct($dataClass, $validationGroups); - - $this->subjectName = $subjectName; - $this->attributeRepository = $attributeRepository; - } - - /** - * {@inheritdoc} - */ - public function buildForm(FormBuilderInterface $builder, array $options) - { - $builder - /*->add( - 'attribute', - sprintf('chamilo_%s_attribute_choice', $this->subjectName), - ['label' => sprintf('chamilo.form.attribute.%s_attribute_value.attribute', $this->subjectName)] - )*/ - ->addEventSubscriber( - new BuildAttributeValueFormSubscriber($this->attributeRepository) - ) - ; - -// $prototypes = array(); -// $attributes = $this->getAttributes($builder); -// -// if ($attributes) { -// /** @var \Chamilo\CoreBundle\Entity\ExtraField $attribute */ -// foreach ($attributes as $attribute) { -// if (!empty($attribute)) { -// $configuration = $attribute->getConfiguration(); -// $type = $attribute->getTypeToString(); -// -// if (!is_array($configuration)) { -// $configuration = array(); -// } -// -// if (empty($type)) { -// continue; -// } -// } -// -// $prototypes[] = $builder->create( -// 'value', -// $type, -// $configuration -// )->getForm(); -// } -// } -// -// $builder->setAttribute('prototypes', $prototypes); - } - - /** - * {@inheritdoc} - */ - /*public function buildView( - FormView $view, - FormInterface $form, - array $options - ) { - $view->vars['prototypes'] = array(); - - foreach ($form->getConfig()->getAttribute('prototypes', array()) as $name => $prototype) { - $view->vars['prototypes'][$name] = $prototype->createView($view); - } - }*/ - - /** - * {@inheritdoc} - */ - public function getName() - { - return sprintf('chamilo_%s_extra_field_value', $this->subjectName); - } -} diff --git a/src/UserBundle/Form/Type/RegistrationFormType.php b/src/UserBundle/Form/Type/RegistrationFormType.php deleted file mode 100644 index dc5f144de1..0000000000 --- a/src/UserBundle/Form/Type/RegistrationFormType.php +++ /dev/null @@ -1,134 +0,0 @@ -add( - 'username', - null, - [ - 'label' => 'form.username', - 'translation_domain' => 'FOSUserBundle', - ] - ) - ->add('firstname', 'text') - ->add('lastname', 'text') - ->add( - 'email', - 'email', - [ - 'label' => 'form.email', - 'translation_domain' => 'FOSUserBundle', - ] - ) - ->add('captcha', 'Gregwar\CaptchaBundle\Type\CaptchaType'); - - //$builder - /*->add('official_code', 'text') - ->add('email', 'email') - ->add('username', 'text') - ->add('phone', 'text') - ->add('password', 'password') - ->add('groups') - ->add('timezone', 'timezone') - ->add( - 'locale', - 'locale', - array('preferred_choices' => array('en', 'fr', 'es')) - ) - ->add( - 'picture_uri', - 'sonata_media_type', - array( - 'provider' => 'sonata.media.provider.image', - 'context' => 'user_image', - 'required' => false, - ) - ) - ->add( - 'extraFields', - 'collection', - array( - 'required' => false, - 'type' => 'chamilo_user.form.type.attribute_value_type', - 'allow_add' => true, - 'allow_delete' => true, - 'by_reference' => false, - ) - ) - ->add('save', 'submit', array('label' => 'Update'))*/ - // ; - - // Update Author id - /*$builder->addEventListener( - FormEvents::POST_SUBMIT, - function (FormEvent $event) use ($currentUser) { - // @var User $user - $user = $event->getData(); - $extraFields = $user->getExtrafields(); - foreach ($extraFields as $extraField) { - $extraField->setAuthor($currentUser); - } - } - );*/ - } - - /** - * {@inheritdoc} - * - * @deprecated Remove it when bumping requirements to Symfony 2.7+ - */ - public function setDefaultOptions(OptionsResolverInterface $resolver) - { - $this->configureOptions($resolver); - } - - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver) - { - $resolver->setDefaults( - [ - 'class' => 'Chamilo\UserBundle\Entity\User', - ] - ); - } - - /** - * @return string - */ - public function getParent() - { - return 'fos_user_registration'; - } - - /** - * @return string - */ - public function getName() - { - return 'chamilo_sonata_user_registration'; - } -} diff --git a/src/UserBundle/Form/UserType.php b/src/UserBundle/Form/UserType.php deleted file mode 100644 index 336df7c192..0000000000 --- a/src/UserBundle/Form/UserType.php +++ /dev/null @@ -1,103 +0,0 @@ -securityContext = $securityContext; - } - - /** - * {@inheritdoc} - */ - public function buildForm(FormBuilderInterface $builder, array $options) - { - $currentUser = $this->securityContext->getToken()->getUser(); - - $builder - ->add('firstname', 'text') - ->add('lastname', 'text') - ->add('official_code', 'text') - ->add('email', 'email') - ->add('username', 'text') - ->add('phone', 'text') - ->add('password', 'password') - ->add('groups') - ->add('timezone', 'timezone') - ->add( - 'locale', - 'locale', - ['preferred_choices' => ['en', 'fr', 'es']] - ) - ->add( - 'picture_uri', - 'sonata_media_type', - [ - 'provider' => 'sonata.media.provider.image', - 'context' => 'user_image', - 'required' => false, - ] - ) - /*->add( - 'extraFields', - 'collection', - array( - 'required' => false, - //'type' => 'chamilo_user.form.type.attribute_value_type', - 'allow_add' => true, - 'allow_delete' => true, - 'by_reference' => false, - ) - )*/ - ->add('save', 'submit', ['label' => 'Update']); - - // Update Author id - $builder->addEventListener( - FormEvents::POST_SUBMIT, - function (FormEvent $event) use ($currentUser) { - /** @var User $user */ - $user = $event->getData(); - $extraFields = $user->getExtrafields(); - foreach ($extraFields as $extraField) { - $extraField->setAuthor($currentUser); - } - } - ); - } - - public function setDefaultOptions(OptionsResolverInterface $resolver) - { - $resolver->setDefaults( - [ - 'data_class' => 'Chamilo\UserBundle\Entity\User', - ] - ); - } - - /** - * @return string - */ - public function getName() - { - return 'user'; - } -} diff --git a/src/UserBundle/Repository/UserRepository.php b/src/UserBundle/Repository/UserRepository.php index 47d0d357a2..1da5d90bc7 100644 --- a/src/UserBundle/Repository/UserRepository.php +++ b/src/UserBundle/Repository/UserRepository.php @@ -26,7 +26,6 @@ use Chamilo\CoreBundle\Entity\TrackELastaccess; use Chamilo\CoreBundle\Entity\TrackELogin; use Chamilo\CoreBundle\Entity\TrackEOnline; use Chamilo\CoreBundle\Entity\TrackEUploads; -use Chamilo\CoreBundle\Entity\UserApiKey; use Chamilo\CoreBundle\Entity\UserCourseCategory; use Chamilo\CoreBundle\Entity\UsergroupRelUser; use Chamilo\CoreBundle\Entity\UserRelCourseVote; @@ -1262,29 +1261,6 @@ class UserRepository extends ResourceRepository $userRelCourseVote[] = implode(', ', $list); } - // UserApiKey - $criteria = [ - 'userId' => $userId, - ]; - $result = $em->getRepository('ChamiloCoreBundle:UserApiKey')->findBy($criteria); - $userApiKey = []; - /** @var UserApiKey $item */ - foreach ($result as $item) { - $validityStart = $item->getValidityStartDate() ? $item->getValidityStartDate()->format($dateFormat) : ''; - $validityEnd = $item->getValidityEndDate() ? $item->getValidityEndDate()->format($dateFormat) : ''; - $created = $item->getCreatedDate() ? $item->getCreatedDate()->format($dateFormat) : ''; - - $list = [ - 'ApiKey #'.$item->getApiKey(), - 'Service: '.$item->getApiService(), - 'EndPoint: '.$item->getApiEndPoint(), - 'Validity start date: '.$validityStart, - 'Validity enddate: '.$validityEnd, - 'Created at: '.$created, - ]; - $userApiKey[] = implode(', ', $list); - } - $user->setDropBoxSentFiles( [ 'Friends' => $friendList, @@ -1303,7 +1279,6 @@ class UserRepository extends ResourceRepository 'UserCourseCategory' => $userCourseCategory, 'SkillRelUserComment' => $skillRelUserComment, 'UserRelCourseVote' => $userRelCourseVote, - 'UserApiKey' => $userApiKey, // courses 'AttendanceResult' => $cAttendanceResult, diff --git a/src/UserBundle/Security/FOSUBUserProvider.php b/src/UserBundle/Security/FOSUBUserProvider.php deleted file mode 100644 index bd84739927..0000000000 --- a/src/UserBundle/Security/FOSUBUserProvider.php +++ /dev/null @@ -1,76 +0,0 @@ -getProperty($response); - $username = $response->getUsername(); - //on connect - get the access token and the user ID - $service = $response->getResourceOwner()->getName(); - $setter = 'set'.ucfirst($service); - $setterId = $setter.'Id'; - $setter_token = $setter.'AccessToken'; - //we "disconnect" previously connected users - if (null !== $previousUser = $this->userManager->findUserBy([$property => $username])) { - $previousUser->$setterId(null); - $previousUser->$setter_token(null); - $this->userManager->updateUser($previousUser); - } - // We connect current user - $user->$setterId($username); - $user->$setter_token($response->getAccessToken()); - $this->userManager->updateUser($user); - } - - /** - * {@inheritdoc} - */ - public function loadUserByOAuthUserResponse(UserResponseInterface $response) - { - $username = $response->getUsername(); - $user = $this->userManager->findUserBy([$this->getProperty($response) => $username]); - // User creation - if (null === $user) { - $service = $response->getResourceOwner()->getName(); - $setter = 'set'.ucfirst($service); - $setterId = $setter.'Id'; - $setterToken = $setter.'AccessToken'; - // create new user here - $user = $this->userManager->createUser(); - $user->$setterId($username); - $user->$setterToken($response->getAccessToken()); - //I have set all requested data with the user's username - //modify here with relevant data - $user->setUsername($username); - $user->setEmail($username); - $user->setPassword($username); - $user->setEnabled(true); - $this->userManager->updateUser($user); - - return $user; - } - //if user exists - go with the HWIOAuth way - $user = parent::loadUserByOAuthUserResponse($response); - $serviceName = $response->getResourceOwner()->getName(); - $setter = 'set'.ucfirst($serviceName).'AccessToken'; - //update access token - $user->$setter($response->getAccessToken()); - - return $user; - } -}