, Ghent University * @author Roan Embrechts, refactoring * * @package chamilo.create_course * "Course validation" feature: * * @author Jose Manuel Abuin Mosquera , Centro de Supercomputacion de Galicia * "Course validation" feature, technical adaptation for Chamilo 1.8.8: * @author Ivan Tcholakov */ // Flag forcing the "current course" reset. $cidReset = true; require_once __DIR__.'/../inc/global.inc.php'; // Check access rights. if (!api_is_allowed_to_create_course()) { api_not_allowed(true); exit; } // Section for the tabs. $this_section = SECTION_COURSES; $em = Database::getManager(); /** @var CourseCategoryRepository $courseCategoriesRepo */ $courseCategoriesRepo = $em->getRepository('ChamiloCoreBundle:CourseCategory'); // Get all possible teachers. $accessUrlId = api_get_current_access_url_id(); // "Course validation" feature. This value affects the way of a new course creation: // true - the new course is requested only and it is created after approval; // false - the new course is created immediately, after filling this form. $course_validation_feature = false; if (api_get_setting('course_validation') === 'true' && !api_is_platform_admin() ) { $course_validation_feature = true; } $htmlHeadXtra[] = ''; $interbreadcrumb[] = [ 'url' => api_get_path(WEB_PATH).'user_portal.php', 'name' => get_lang('My courses'), ]; // Displaying the header. $tool_name = $course_validation_feature ? get_lang('Create a course request') : get_lang('Add a new course'); $tpl = new Template($tool_name); // Build the form. $form = new FormValidator('add_course'); // Form title $form->addElement('header', $tool_name); // Title $form->addText( 'title', [ get_lang('Course Name'), get_lang('Write a short and striking course name, For example: Innovation Management'), ], true); $form->applyFilter('title', 'html_filter'); $form->addButtonAdvancedSettings('advanced_params'); $form->addElement( 'html', ''); // Submit button. $form->addButtonCreate($course_validation_feature ? get_lang('Create this course request') : get_lang('Create this course')); // The progress bar of this form. $form->addProgress(); // Set default values. if (isset($_user['language']) && $_user['language'] != '') { $values['course_language'] = $_user['language']; } else { $values['course_language'] = api_get_setting('platformLanguage'); } $form->setDefaults($values); $message = null; $formContent = null; // Validate the form. if ($form->validate()) { $course_values = $form->exportValues(); $wanted_code = $course_values['wanted_code']; $category_code = isset($course_values['category_code']) ? $course_values['category_code'] : ''; $title = $course_values['title']; $course_language = $course_values['course_language']; $exemplary_content = !empty($course_values['exemplary_content']); if ($course_validation_feature) { $description = $course_values['description']; $objetives = $course_values['objetives']; $target_audience = $course_values['target_audience']; } if ($wanted_code == '') { $wanted_code = CourseManager::generate_course_code( api_substr($title, 0, CourseManager::MAX_COURSE_LENGTH_CODE) ); } // Check whether the requested course code has already been occupied. if (!$course_validation_feature) { $course_code_ok = !CourseManager::course_code_exists($wanted_code); } else { $course_code_ok = !CourseRequestManager::course_code_exists($wanted_code); } if ($course_code_ok) { if (!$course_validation_feature) { $params = []; $params['title'] = $title; $params['exemplary_content'] = $exemplary_content; $params['wanted_code'] = $wanted_code; $params['course_category'] = $category_code; $params['course_language'] = $course_language; $params['gradebook_model_id'] = isset($course_values['gradebook_model_id']) ? $course_values['gradebook_model_id'] : null; $params['course_template'] = isset($course_values['course_template']) ? $course_values['course_template'] : ''; /*include_once api_get_path(SYS_CODE_PATH).'lang/english/trad4all.inc.php'; $file_to_include = api_get_path(SYS_CODE_PATH).'lang/'.$course_language.'/trad4all.inc.php'; if (file_exists($file_to_include)) { include $file_to_include; }*/ $course_info = CourseManager::create_course($params); if (!empty($course_info)) { $request = Container::getRequest(); if ($request->files->has('picture')) { $uploadFile = $request->files->get('picture'); $repo = Container::getCourseRepository(); $em = $repo->getEntityManager(); // @todo add in repository $course = $repo->find($course_info['real_id']); $illustration = new \Chamilo\CoreBundle\Entity\Illustration(); $repo->addResourceNode($illustration, api_get_user_entity(api_get_user_id()), $course); $file = $repo->addFileToResource($illustration, $uploadFile); $file->setCrop($course_values['picture_crop_result']); $em->persist($file); $em->persist($illustration); $em->flush(); } $splash = api_get_setting('course_creation_splash_screen'); if ($splash === 'true') { $url = Container::getRouter()->generate('chamilo_core_course_welcome', ['course' =>$course_info['code']]); header('Location: '.$url); exit; } else { $url = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/'; header('Location: '.$url); exit; } } else { $message = Display::return_message( get_lang('The course has not been created due to an internal error.'), 'error', false ); // Display the form. $formContent = $form->returnForm(); } } else { // Create a request for a new course. $request_id = CourseRequestManager::create_course_request( $wanted_code, $title, $description, $category_code, $course_language, $objetives, $target_audience, api_get_user_id(), $exemplary_content ); if ($request_id) { $course_request_info = CourseRequestManager::get_course_request_info($request_id); $message = (is_array($course_request_info) ? ''.$course_request_info['code'].' : ' : '').get_lang('Your request for a new course has been sent successfully. You may receive a reply soon, within one or two days.'); $message = Display::return_message( $message, 'confirmation', false ); $message .= Display::tag( 'div', Display::url( get_lang('Back to courses list'), api_get_path(WEB_PATH).'user_portal.php', ['class' => 'btn btn-primary'] ), ['style' => 'float: left; margin:0px; padding: 0px;'] ); } else { $message = Display::return_message( get_lang('The course request has not been created due to an internal error.'), 'error', false ); // Display the form. $formContent = $form->returnForm(); } } } else { $message = Display::return_message( get_lang('CourseCourse codeAlreadyExists'), 'error', false ); // Display the form. $formContent = $form->returnForm(); } } else { if (!$course_validation_feature) { $message = Display::return_message(get_lang('Once you click on "Create a course", a course is created with a section for Tests, Project based learning, Assessments, Courses, Dropbox, Agenda and much more. Logging in as teacher provides you with editing privileges for this course.')); } // Display the form. $formContent = $form->returnForm(); } $tpl->assign('form', $formContent); $layout = $tpl->fetch($tpl->get_template('create_course/add_course.html.twig')); $tpl->assign('message', $message); $tpl->assign('content', $layout); $tpl->display_one_col_template();