Merge with 1.11.x

pull/2528/head
jmontoyaa 7 years ago
parent bd22e50e3b
commit ae56217718
  1. 9
      main/admin/add_drh_to_user.php
  2. 9
      main/admin/settings.lib.php
  3. 143
      main/admin/statistics/index.php
  4. 2
      main/admin/user_import.php
  5. 2
      main/admin/user_update_import.php
  6. 187
      main/auth/inscription.php
  7. 4
      main/auth/profile.php
  8. 2
      main/inc/lib/api.lib.php
  9. 2
      src/CoreBundle/Component/Editor/CkEditor/CkEditor.php
  10. 4
      src/CoreBundle/Component/Editor/CkEditor/Toolbar/LearningPathAuthor.php
  11. 2
      src/CoreBundle/Component/Editor/CkEditor/Toolbar/Minimal.php
  12. 2
      src/CoreBundle/Entity/Repository/ExtraFieldRelTagRepository.php
  13. 2
      src/CoreBundle/Entity/Repository/ExtraFieldValuesRepository.php
  14. 42
      src/CoreBundle/Entity/Repository/ItemPropertyRepository.php
  15. 3
      src/CoreBundle/Entity/Repository/SequenceRepository.php
  16. 1
      src/CoreBundle/Entity/SkillRelUser.php
  17. 5
      src/CoreBundle/Settings/AdminSettingsSchema.php
  18. 2
      src/CourseBundle/Component/CourseCopy/Course.php
  19. 18
      src/CourseBundle/Component/CourseCopy/CourseArchiver.php
  20. 423
      src/CourseBundle/Component/CourseCopy/CourseBuilder.php
  21. 379
      src/CourseBundle/Component/CourseCopy/CourseRestorer.php
  22. 24
      src/CourseBundle/Component/CourseCopy/CourseSelectForm.php
  23. 6
      src/CourseBundle/Component/CourseCopy/Resources/Asset.php
  24. 1
      src/CourseBundle/Component/CourseCopy/Resources/CalendarEvent.php
  25. 1
      src/CourseBundle/Component/CourseCopy/Resources/CourseCopyTestCategory.php
  26. 5
      src/CourseBundle/Component/CourseCopy/Resources/CourseDescription.php
  27. 7
      src/CourseBundle/Component/CourseCopy/Resources/Quiz.php
  28. 53
      src/CourseBundle/Component/CourseCopy/Resources/QuizQuestion.php
  29. 13
      src/CourseBundle/Component/CourseCopy/Resources/Resource.php
  30. 2
      src/CourseBundle/Component/CourseCopy/Resources/SurveyQuestion.php
  31. 7
      src/CourseBundle/Entity/CDocument.php

@ -15,7 +15,7 @@ if (!isset($_REQUEST['u'])) {
}
$em = Database::getManager();
$relationsRepo = $em->getRepository('ChamiloCoreBundle:UserRelUser');
$userRepository = $em->getRepository('ChamiloUserBundle:User');
/** @var UserEntity $user */
$user = UserManager::getManager()->find($_REQUEST['u']);
@ -23,10 +23,12 @@ if (!$user) {
api_not_allowed(true);
}
$subscribedUsers = $user->getHrm();
$subscribedUsers = $userRepository->getAssignedHrmUserList(
$user->getId(),
api_get_current_access_url_id()
);
$hrmOptions = [];
/** @var UserRelUser $subscribedUser */
foreach ($subscribedUsers as $subscribedUser) {
/** @var UserEntity $hrm */
@ -58,7 +60,6 @@ if ($form->validate()) {
foreach ($subscribedUsers as $subscribedUser) {
$em->remove($subscribedUser);
}
$em->flush();
$values = $form->exportValues();

@ -521,6 +521,10 @@ function uploadStylesheet($values, $picture)
$result = false;
// Valid name for the stylesheet folder.
$style_name = api_preg_replace('/[^A-Za-z0-9]/', '', $values['name_stylesheet']);
if (empty($style_name) || is_array($style_name)) {
// The name of the uploaded stylesheet doesn't have the expected format
return $result;
}
$cssToUpload = CSS_UPLOAD_PATH;
// Check if a virtual instance vchamilo is used
@ -1006,7 +1010,7 @@ function getNumberOfTemplates()
* @param int $from the start of the limit statement
* @param int $number_of_items the number of elements that have to be retrieved from the database
* @param int $column the column that is
* @param string $direction the sorting direction (ASC or DESC<EFBFBD>
* @param string $direction the sorting direction (ASC or DESC)
*
* @return array
*
@ -1120,8 +1124,7 @@ function addEditTemplate()
get_lang('Text'),
true,
true,
['ToolbarSet' => 'Documents', 'Width' => '100%', 'Height' => '400'],
true
['ToolbarSet' => 'Documents', 'Width' => '100%', 'Height' => '400']
);
// Setting the form elements: the form to upload an image to be used with the template.

@ -14,22 +14,27 @@ api_protect_admin_script();
$interbreadcrumb[] = ['url' => '../index.php', 'name' => get_lang('PlatformAdmin')];
$report = isset($_REQUEST['report']) ? $_REQUEST['report'] : '';
$sessionDuration = isset($_GET['session_duration']) ? (int) $_GET['session_duration'] : '';
if ($report) {
if ($report == 'recentlogins') {
$htmlHeadXtra[] = api_get_js('chartjs/Chart.min.js');
$htmlHeadXtra[] = '
<script>
$(document).ready(function() {
$.ajax({
url: "'.api_get_path(WEB_CODE_PATH).'inc/ajax/statistics.ajax.php?a=recentlogins",
type: "POST",
success: function(data) {
Chart.defaults.global.responsive = true;
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(data);
}
});
<script>
$(document).ready(function() {
$.ajax({
url: "'.api_get_path(WEB_CODE_PATH).'inc/ajax/statistics.ajax.php?a=recentlogins&session_duration='.$sessionDuration.'",
type: "POST",
success: function(data) {
Chart.defaults.global.responsive = true;
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(data);
}
});
</script>';
});
</script>';
}
if ($report == 'user_session') {
$htmlHeadXtra[] = api_get_jqgrid_js();
}
$tool_name = get_lang('Statistics');
@ -61,6 +66,10 @@ $tools[$strUsers]['report=zombies'] = get_lang('Zombies');
// system ...
$tools[$strSystem]['report=activities'] = get_lang('ImportantActivities');
if (api_is_global_platform_admin() && api_is_multiple_url_enabled()) {
$tools[$strSystem]['report=user_session'] = get_lang('PortalUserSessionStats');
}
// social ...
$tools[$strSocial]['report=messagesent'] = get_lang('MessagesSent');
$tools[$strSocial]['report=messagereceived'] = get_lang('MessagesReceived');
@ -80,9 +89,106 @@ foreach ($tools as $section => $items) {
echo '</tr></table>';
$course_categories = Statistics::getCourseCategories();
echo '<br/><br/>'; //@todo: spaces between elements should be handled in the css, br should be removed if only there for presentation
//@todo: spaces between elements should be handled in the css, br should be removed if only there for presentation
echo '<br/><br/>';
switch ($report) {
case 'user_session':
$form = new FormValidator('user_session', 'get');
$form->addDateRangePicker('range', get_lang('DateRange'), true);
$form->addHidden('report', 'user_session');
$form->addButtonSearch(get_lang('Search'));
$date = new DateTime($now);
$startDate = $date->format('Y-m-d').' 00:00:00';
$endDate = $date->format('Y-m-d').' 23:59:59';
$start = $startDate;
$end = $endDate;
if ($form->validate()) {
$values = $form->getSubmitValues();
$start = $values['range_start'];
$end = $values['range_end'];
}
echo $form->returnForm();
$url = api_get_path(WEB_AJAX_PATH).'statistics.ajax.php?a=get_user_session&start='.$start.'&end='.$end;
$columns = [
'URL',
get_lang('Session'),
get_lang('Course'),
get_lang('CountUsers'),
];
$columnModel = [
[
'name' => 'url',
'index' => 'url',
'width' => '120',
'align' => 'left',
],
[
'name' => 'session',
'index' => 'session',
'width' => '180',
'align' => 'left',
'sortable' => 'false',
],
[
'name' => 'course',
'index' => 'course',
'width' => '100',
'align' => 'left',
'sortable' => 'false',
],
[
'name' => 'count',
'index' => 'count',
'width' => '50',
'align' => 'left',
'sortable' => 'false',
],
];
$extraParams['autowidth'] = 'true'; //use the width of the parent
$extraParams['height'] = 'auto'; //use the width of the parent
$actionLinks = '';
?>
<script>
$(function() {
<?php
echo Display::grid_js(
'user_session_grid',
$url,
$columns,
$columnModel,
$extraParams,
[],
$actionLinks,
true
);
?>
jQuery("#user_session_grid").jqGrid("navGrid","#user_session_grid_pager",{
view:false,
edit:false,
add:false,
del:false,
search:false,
excel:true
});
jQuery("#user_session_grid").jqGrid("navButtonAdd","#user_session_grid_pager", {
caption:"",
onClickButton : function () {
jQuery("#user_session_grid").jqGrid("excelExport",{"url":"<?php echo $url; ?>&export_format=xls"});
}
});
});
</script>
<?php
echo Display::grid_html('user_session_grid');
break;
case 'courses':
// total amount of courses
foreach ($course_categories as $code => $name) {
@ -123,9 +229,16 @@ switch ($report) {
break;
case 'recentlogins':
echo '<h2>'.sprintf(get_lang('LastXDays'), '15').'</h2>';
$form = new FormValidator('session_time', 'get', api_get_self().'?report=recentlogins&session_duration='.$sessionDuration);
$sessionTimeList = ['', 5 => 5, 15 => 15, 30 => 30, 60 => 60];
$form->addSelect('session_duration', [get_lang('SessionMinDuration'), get_lang('Minutes')], $sessionTimeList);
$form->addButtonSend(get_lang('Filter'));
$form->addHidden('report', 'recentlogins');
$form->display();
echo '<canvas class="col-md-12" id="canvas" height="100px" style="margin-bottom: 20px"></canvas>';
Statistics::printRecentLoginStats();
Statistics::printRecentLoginStats(true);
Statistics::printRecentLoginStats(false, $sessionDuration);
Statistics::printRecentLoginStats(true, $sessionDuration);
break;
case 'logins':
Statistics::printLoginStats($_GET['type']);

@ -387,7 +387,7 @@ function parse_xml_data($file)
}
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true, null, 'login');
api_protect_admin_script(true, null);
api_protect_limit_for_session_admin();
$defined_auth_sources[] = PLATFORM_AUTH_SOURCE;

@ -337,7 +337,7 @@ function parse_xml_data($file)
}
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true, null, 'login');
api_protect_admin_script(true, null);
$defined_auth_sources[] = PLATFORM_AUTH_SOURCE;

@ -4,9 +4,9 @@
use ChamiloSession as Session;
/**
* This script displays a form for registering new users.
* This script displays a form for registering new users.
*
* @package chamilo.auth
* @package chamilo.auth
*/
//quick hack to adapt the registration form result to the selected registration language
@ -41,7 +41,9 @@ if ($geolocalization) {
$htmlHeadXtra[] = api_get_password_checker_js('#username', '#pass1');
// User is not allowed if Terms and Conditions are disabled and
// registration is disabled too.
$isNotAllowedHere = api_get_setting('allow_terms_conditions') === 'false' && api_get_setting('allow_registration') === 'false';
$isNotAllowedHere = api_get_setting('allow_terms_conditions') === 'false' && api_get_setting(
'allow_registration'
) === 'false';
if ($isNotAllowedHere) {
api_not_allowed(true, get_lang('RegistrationDisabled'));
@ -89,6 +91,22 @@ if (!empty($course_code_redirect)) {
}
if ($user_already_registered_show_terms === false) {
// STUDENT/TEACHER
if (api_get_setting('allow_registration_as_teacher') != 'false') {
if (in_array('status', $allowedFields)) {
$form->addRadio(
'status',
get_lang('RegistrationRoleWhatDoYouWantToDo'),
[
STUDENT => '<p class="caption">'.get_lang('RegistrationRoleFollowCourses').'</p>',
COURSEMANAGER => '<p class="caption">'.get_lang('RegistrationRoleTeachCourses').'</p>',
],
['class' => 'register-profile']
);
$form->addRule('status', get_lang('ThisFieldIsRequired'), 'required');
}
}
if (api_is_western_name_order()) {
// FIRST NAME and LAST NAME
$form->addElement('text', 'firstname', get_lang('FirstName'), ['size' => 40]);
@ -130,25 +148,6 @@ if ($user_already_registered_show_terms === false) {
$form->addElement('text', 'openid', get_lang('OpenIDURL'), ['size' => 40]);
}
// OFFICIAL CODE
if (CONFVAL_ASK_FOR_OFFICIAL_CODE) {
if (in_array('official_code', $allowedFields)) {
$form->addElement(
'text',
'official_code',
get_lang('OfficialCode'),
['size' => 40]
);
if (api_get_setting('registration', 'officialcode') == 'true') {
$form->addRule(
'official_code',
get_lang('ThisFieldIsRequired'),
'required'
);
}
}
}
// USERNAME
if (api_get_setting('login_is_email') != 'true') {
$form->addText(
@ -184,11 +183,6 @@ if ($user_already_registered_show_terms === false) {
['id' => 'pass1', 'size' => 20, 'autocomplete' => 'off']
);
$checkPass = api_get_setting('allow_strength_pass_checker');
if ($checkPass === 'true') {
$form->addElement('label', null, '<div id="password_progress"></div>');
}
$form->addElement(
'password',
'pass2',
@ -227,73 +221,25 @@ if ($user_already_registered_show_terms === false) {
}
}
// STUDENT/TEACHER
if (api_get_setting('allow_registration_as_teacher') != 'false') {
if (in_array('status', $allowedFields)) {
$form->addElement(
'radio',
'status',
get_lang('Profile'),
get_lang('RegStudent'),
STUDENT
);
// OFFICIAL CODE
if (CONFVAL_ASK_FOR_OFFICIAL_CODE) {
if (in_array('official_code', $allowedFields)) {
$form->addElement(
'radio',
'status',
null,
get_lang('RegAdmin'),
COURSEMANAGER
'text',
'official_code',
get_lang('OfficialCode'),
['size' => 40]
);
if (api_get_setting('registration', 'officialcode') == 'true') {
$form->addRule(
'official_code',
get_lang('ThisFieldIsRequired'),
'required'
);
}
}
}
$captcha = api_get_setting('allow_captcha');
$allowCaptcha = $captcha === 'true';
if ($allowCaptcha) {
$ajax = api_get_path(WEB_AJAX_PATH).'form.ajax.php?a=get_captcha';
$options = [
'width' => 220,
'height' => 90,
'callback' => $ajax.'&var='.basename(__FILE__, '.php'),
'sessionVar' => basename(__FILE__, '.php'),
'imageOptions' => [
'font_size' => 20,
'font_path' => api_get_path(SYS_FONTS_PATH).'opensans/',
'font_file' => 'OpenSans-Regular.ttf',
//'output' => 'gif'
],
];
$captcha_question = $form->addElement(
'CAPTCHA_Image',
'captcha_question',
'',
$options
);
$form->addElement('static', null, null, get_lang('ClickOnTheImageForANewOne'));
$form->addElement(
'text',
'captcha',
get_lang('EnterTheLettersYouSee'),
['size' => 40]
);
$form->addRule(
'captcha',
get_lang('EnterTheCharactersYouReadInTheImage'),
'required',
null,
'client'
);
$form->addRule(
'captcha',
get_lang('TheTextYouEnteredDoesNotMatchThePicture'),
'CAPTCHA',
$captcha_question
);
}
// EXTENDED FIELDS
if (api_get_setting('extended_profile') == 'true' &&
api_get_setting('extendedprofile_registration', 'mycomptetences') == 'true'
@ -306,6 +252,7 @@ if ($user_already_registered_show_terms === false) {
['ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130']
);
}
if (api_get_setting('extended_profile') == 'true' &&
api_get_setting('extendedprofile_registration', 'mydiplomas') == 'true'
) {
@ -317,6 +264,7 @@ if ($user_already_registered_show_terms === false) {
['ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130']
);
}
if (api_get_setting('extended_profile') == 'true' &&
api_get_setting('extendedprofile_registration', 'myteach') == 'true'
) {
@ -328,6 +276,7 @@ if ($user_already_registered_show_terms === false) {
['ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130']
);
}
if (api_get_setting('extended_profile') == 'true' &&
api_get_setting('extendedprofile_registration', 'mypersonalopenarea') == 'true'
) {
@ -339,6 +288,7 @@ if ($user_already_registered_show_terms === false) {
['ToolbarSet' => 'register', 'Width' => '100%', 'Height' => '130']
);
}
if (api_get_setting('extended_profile') === 'true') {
if (api_get_setting('extendedprofile_registration', 'mycomptetences') === 'true' &&
api_get_setting('extendedprofile_registrationrequired', 'mycomptetences') === 'true'
@ -367,7 +317,9 @@ if ($user_already_registered_show_terms === false) {
in_array('extra_fields', $allowedFields)
) {
$extraField = new ExtraField('user');
$extraFieldList = isset($allowedFields['extra_fields']) && is_array($allowedFields['extra_fields']) ? $allowedFields['extra_fields'] : [];
$extraFieldList = isset($allowedFields['extra_fields']) && is_array(
$allowedFields['extra_fields']
) ? $allowedFields['extra_fields'] : [];
$returnParams = $extraField->addElements(
$form,
0,
@ -377,7 +329,56 @@ if ($user_already_registered_show_terms === false) {
$extraFieldList
);
}
// CAPTCHA
$captcha = api_get_setting('allow_captcha');
$allowCaptcha = $captcha === 'true';
if ($allowCaptcha) {
$ajax = api_get_path(WEB_AJAX_PATH).'form.ajax.php?a=get_captcha';
$options = [
'width' => 220,
'height' => 90,
'callback' => $ajax.'&var='.basename(__FILE__, '.php'),
'sessionVar' => basename(__FILE__, '.php'),
'imageOptions' => [
'font_size' => 20,
'font_path' => api_get_path(SYS_FONTS_PATH).'opensans/',
'font_file' => 'OpenSans-Regular.ttf',
//'output' => 'gif'
],
];
$captcha_question = $form->addElement(
'CAPTCHA_Image',
'captcha_question',
'',
$options
);
$form->addElement('static', null, null, get_lang('ClickOnTheImageForANewOne'));
$form->addElement(
'text',
'captcha',
get_lang('EnterTheLettersYouSee'),
['size' => 40]
);
$form->addRule(
'captcha',
get_lang('EnterTheCharactersYouReadInTheImage'),
'required',
null,
'client'
);
$form->addRule(
'captcha',
get_lang('TheTextYouEnteredDoesNotMatchThePicture'),
'CAPTCHA',
$captcha_question
);
}
}
if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {
$defaults['language'] = $_SESSION['user_language_choice'];
} else {
@ -461,7 +462,7 @@ if (file_exists($home.'register_top_'.$user_selected_language.'.html')) {
$open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
if (!empty($open)) {
$content = '<div class="well well-lg">'.$open.'</div>';
$content = '<div class="well well-sm help-registration">'.$open.'</div>';
}
}
@ -520,7 +521,9 @@ if (api_get_setting('allow_terms_conditions') == 'true') {
'checkbox',
'legal_accept',
null,
get_lang('IHaveReadAndAgree').'&nbsp;<a href="inscription.php?legal" target="_blank">'.get_lang('TermsAndConditions').'</a>'
get_lang('IHaveReadAndAgree').'&nbsp;<a href="inscription.php?legal" target="_blank">'.get_lang(
'TermsAndConditions'
).'</a>'
);
$form->addRule('legal_accept', get_lang('ThisFieldIsRequired'), 'required');
} else {

@ -316,10 +316,6 @@ if (is_platform_authentication() &&
$form->addElement('password', 'password0', [get_lang('Pass'), get_lang('Enter2passToChange')], ['size' => 40]);
$form->addElement('password', 'password1', get_lang('NewPass'), ['id' => 'password1', 'size' => 40]);
$checkPass = api_get_setting('allow_strength_pass_checker');
if ($checkPass == 'true') {
$form->addElement('label', null, '<div id="password_progress"></div>');
}
$form->addElement('password', 'password2', get_lang('Confirmation'), ['size' => 40]);
// user must enter identical password twice so we can prevent some user errors
$form->addRule(['password1', 'password2'], get_lang('PassTwo'), 'compare');

@ -2683,6 +2683,7 @@ function api_get_setting($variable)
return '';
}
$variable = trim($variable);
switch ($variable) {
case 'header_extra_content':
$filename = api_get_path(SYS_PATH).api_get_home_path().'header_extra_content.txt';
@ -2743,6 +2744,7 @@ function api_get_setting($variable)
break;
default:
return $settingsManager->getSetting($variable);
break;
}
// Old code

@ -97,6 +97,8 @@ class CkEditor extends Editor
/**
* @param array $templates
*
* @return string
*/
public function formatTemplates($templates)
{

@ -24,7 +24,7 @@ class LearningPathAuthor extends Basic
$config['toolbar_maxToolbar'] = $this->getMaximizedToolbar();
}
$config['fullPage'] = true;
$config['fullPage'] = false;
return $config;
}
@ -38,7 +38,6 @@ class LearningPathAuthor extends Basic
{
return [
['PageBreak', 'ShowBlocks', 'Source'],
['Toolbarswitch'],
];
}
@ -63,7 +62,6 @@ class LearningPathAuthor extends Basic
{
return [
['Link', 'Unlink', 'Bold', 'Italic', 'TextColor', 'BGColor', 'Source'],
['Toolbarswitch'],
];
}
}

@ -33,7 +33,7 @@ class Minimal extends Basic
],
[
'name' => 'links',
'items' => ['Link', 'Unlink', 'Anchor'],
'items' => ['Link', 'Unlink', 'Anchor', 'Source'],
],
];

@ -22,7 +22,7 @@ class ExtraFieldRelTagRepository extends EntityRepository
* @param ExtraField $extraField The extrafield
* @param int $itemId The item ID
*
* @return \Doctrine\ORM\QueryBuilder
* @return array
*/
public function getTags(ExtraField $extraField, $itemId)
{

@ -21,7 +21,7 @@ class ExtraFieldValuesRepository extends EntityRepository
* @param int $extraFieldType The type of extra field
* @param int $itemId The item ID
*
* @return \Doctrine\ORM\QueryBuilder
* @return array
*/
public function getVisibleValues($extraFieldType, $itemId)
{

@ -4,9 +4,10 @@
namespace Chamilo\CoreBundle\Entity\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Group;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CourseBundle\Entity\CItemProperty;
use Chamilo\UserBundle\Entity\Group;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\EntityRepository;
/**
@ -17,13 +18,13 @@ class ItemPropertyRepository extends EntityRepository
/**
* Get users subscribed to a item LP, Document, etc (item_property).
*
* @param $tool learnpath | document | etc
* @param $itemId
* @param string $tool learnpath | document | etc
* @param int $itemId
* @param Course $course
* @param Session $session
* @param Group $group
*
* @return \Doctrine\ORM\QueryBuilder
* @return array
*/
public function getUsersSubscribedToItem(
$tool,
@ -47,8 +48,8 @@ class ItemPropertyRepository extends EntityRepository
/**
* Get Groups subscribed to a item: LP, Doc, etc.
*
* @param $tool learnpath | document | etc
* @param $itemId
* @param string $tool learnpath | document | etc
* @param int $itemId
* @param Course $course
* @param Session $session
*
@ -75,12 +76,12 @@ class ItemPropertyRepository extends EntityRepository
/**
* Subscribe groups to a LP, doc (itemproperty).
*
* @param User $currentUser
* @param $tool learnpath | document | etc
* @param User $currentUser
* @param string $tool learnpath | document | etc
* @param Course $course
* @param Session $session
* @param $itemId
* @param array $newList
* @param int $itemId
* @param array $newList
*/
public function subscribeGroupsToItem(
$currentUser,
@ -147,11 +148,12 @@ class ItemPropertyRepository extends EntityRepository
/**
* Unsubscribe groups to item.
*
* @param $tool
* @param string $tool
* @param Course $course
* @param Session $session
* @param $itemId
* @param $groups
* @param int $itemId
* @param array $groups
* @param bool $unsubscribeUserToo
*/
public function unsubscribeGroupsToItem(
$tool,
@ -200,12 +202,12 @@ class ItemPropertyRepository extends EntityRepository
/**
* Subscribe users to a LP, doc (itemproperty).
*
* @param User $currentUser
* @param $tool
* @param User $currentUser
* @param string $tool
* @param Course $course
* @param Session $session
* @param $itemId
* @param array $newUserList
* @param int $itemId
* @param array $newUserList
*/
public function subscribeUsersToItem(
$currentUser,
@ -275,11 +277,11 @@ class ItemPropertyRepository extends EntityRepository
/**
* Unsubscribe users to item.
*
* @param $tool
* @param string $tool
* @param Course $course
* @param Session $session
* @param $itemId
* @param $usersToDelete
* @param int $itemId
* @param array $usersToDelete
*/
public function unsubcribeUsersToItem(
$tool,

@ -116,7 +116,7 @@ class SequenceRepository extends EntityRepository
]);
$result = [];
/** @var SequenceResource $sequenceResource */
foreach ($sequencesResource as $sequenceResource) {
if (!$sequenceResource->hasGraph()) {
continue;
@ -174,6 +174,7 @@ class SequenceRepository extends EntityRepository
$result = [];
/** @var SequenceResource $sequenceResource */
foreach ($sequencesResource as $sequenceResource) {
if (!$sequenceResource->hasGraph()) {
continue;

@ -38,6 +38,7 @@ class SkillRelUser
* @ORM\Column(name="validation_status", type="integer")
*/
protected $validationStatus;
/**
* @var int
*

@ -5,6 +5,7 @@ namespace Chamilo\CoreBundle\Settings;
use Chamilo\CoreBundle\Form\Type\YesNoType;
use Sylius\Bundle\SettingsBundle\Schema\SettingsBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
/**
@ -44,7 +45,9 @@ class AdminSettingsSchema extends AbstractSettingsSchema
public function buildForm(FormBuilderInterface $builder)
{
$builder
->add('administrator_name')
->add('administrator_name',
TextType::class,
['label' => 'emailAdministratorTitle', 'help_block' => 'emailAdministratorComment'])
->add('administrator_surname')
->add('administrator_email', 'email')
->add('administrator_phone')

@ -59,6 +59,8 @@ class Course
/**
* Add a resource from a given type to this course.
*
* @param $resource
*/
public function add_resource(&$resource)
{

@ -4,6 +4,7 @@
namespace Chamilo\CourseBundle\Component\CourseCopy;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Asset;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Document;
use Symfony\Component\Filesystem\Filesystem;
/**
@ -108,12 +109,28 @@ class CourseArchiver
// Copy all documents to the temp-dir
if (isset($course->resources[RESOURCE_DOCUMENT]) && is_array($course->resources[RESOURCE_DOCUMENT])) {
$webEditorCss = api_get_path(WEB_CSS_PATH).'editor.css';
/** @var Document $document */
foreach ($course->resources[RESOURCE_DOCUMENT] as $document) {
if ($document->file_type == DOCUMENT) {
$doc_dir = $backup_dir.$document->path;
@mkdir(dirname($doc_dir), $perm_dirs, true);
if (file_exists($course->path.$document->path)) {
copy($course->path.$document->path, $doc_dir);
// Check if is html or htm
$extension = pathinfo(basename($document->path), PATHINFO_EXTENSION);
switch ($extension) {
case 'html':
case 'htm':
$contents = file_get_contents($doc_dir);
$contents = str_replace(
$webEditorCss,
'{{css_editor}}',
$contents
);
file_put_contents($doc_dir, $contents);
break;
}
}
} else {
@mkdir($backup_dir.$document->path, $perm_dirs, true);
@ -171,7 +188,6 @@ class CourseArchiver
copyDirTo($course->path.$asset->path, $doc_dir, false);
continue;
}
copy($course->path.$asset->path, $doc_dir);
}
}

@ -131,15 +131,15 @@ class CourseBuilder
*
* @param int $session_id
* @param string $courseCode
* @param bool true if you want to get the elements that exists in the course and
* in the session, (session_id = 0 or session_id = X)
* @param bool $withBaseContent true if you want to get the elements that exists in the course and
* in the session, (session_id = 0 or session_id = X)
*
* @return Course The course object structure
*/
public function build(
$session_id = 0,
$courseCode = '',
$with_base_content = false
$withBaseContent = false
) {
$table_properties = Database::get_course_table(TABLE_ITEM_PROPERTY);
$course = api_get_course_info($courseCode);
@ -152,7 +152,7 @@ class CourseBuilder
$this->$function_build(
$session_id,
$courseId,
$with_base_content,
$withBaseContent,
$specificIdList
);
}
@ -204,14 +204,14 @@ class CourseBuilder
*
* @param int $session_id
* @param int $courseId
* @param bool $with_base_content
* @param array $id_list
* @param bool $withBaseContent
* @param array $idList
*/
public function build_documents(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$id_list = []
$withBaseContent = false,
$idList = []
) {
$table_doc = Database::get_course_table(TABLE_DOCUMENT);
$table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -220,9 +220,16 @@ class CourseBuilder
$avoid_paths = " path NOT LIKE '/shared_folder%' AND
path NOT LIKE '/chat_files%' ";
$documentCondition = '';
if (!empty($idList)) {
$idList = array_unique($idList);
$idList = array_map('intval', $idList);
$documentCondition = ' d.iid IN ("'.implode('","', $idList).'") AND ';
}
if (!empty($courseId) && !empty($session_id)) {
$session_id = intval($session_id);
if ($with_base_content) {
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -247,6 +254,7 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
p.visibility != 2 AND
path NOT LIKE '/images/gallery%' AND
$avoid_paths
@ -261,6 +269,7 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
$avoid_paths AND
p.visibility != 2 $session_condition
ORDER BY path";
@ -288,6 +297,7 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
p.visibility != 2 AND
path NOT LIKE '/images/gallery%' AND
$avoid_paths AND
@ -302,14 +312,15 @@ class CourseBuilder
d.c_id = $courseId AND
p.c_id = $courseId AND
tool = '".TOOL_DOCUMENT."' AND
$documentCondition
p.visibility != 2 AND
$avoid_paths AND
(d.session_id = 0 OR d.session_id IS NULL)
ORDER BY path";
}
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
$result = Database::query($sql);
while ($obj = Database::fetch_object($result)) {
$doc = new Document(
$obj->id,
$obj->path,
@ -326,26 +337,32 @@ class CourseBuilder
/**
* Build the forums.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_forums(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$id_list = []
$withBaseContent = false,
$idList = []
) {
$table = Database::get_course_table(TABLE_FORUM);
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_content
$withBaseContent
);
$sql = "SELECT * FROM $table WHERE c_id = $courseId $sessionCondition";
$idCondition = '';
if (!empty($idList)) {
$idList = array_unique($idList);
$idList = array_map('intval', $idList);
$idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
}
$sql = "SELECT * FROM $table WHERE c_id = $courseId $sessionCondition $idCondition";
$sql .= " ORDER BY forum_title, forum_category";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
@ -357,27 +374,34 @@ class CourseBuilder
/**
* Build a forum-category.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_forum_category(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$id_list = []
$withBaseContent = false,
$idList = []
) {
$table = Database::get_course_table(TABLE_FORUM_CATEGORY);
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_content
$withBaseContent
);
$idCondition = '';
if (!empty($idList)) {
$idList = array_unique($idList);
$idList = array_map('intval', $idList);
$idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
}
$sql = "SELECT * FROM $table
WHERE c_id = $courseId $sessionCondition
WHERE c_id = $courseId $sessionCondition $idCondition
ORDER BY cat_title";
$result = Database::query($sql);
@ -390,34 +414,41 @@ class CourseBuilder
/**
* Build the forum-topics.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_forum_topics(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$id_list = []
$withBaseContent = false,
$idList = []
) {
$table = Database::get_course_table(TABLE_FORUM_THREAD);
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_content
$withBaseContent
);
$idCondition = '';
if (!empty($idList)) {
$idList = array_map('intval', $idList);
$idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
}
$sql = "SELECT * FROM $table WHERE c_id = $courseId
$sessionCondition
$idCondition
ORDER BY thread_title ";
$result = Database::query($sql);
while ($obj = Database::fetch_object($result)) {
$forum_topic = new ForumTopic($obj);
$this->course->add_resource($forum_topic);
$this->build_forum_posts($courseId, $obj->thread_id, $obj->forum_id, true);
$forumTopic = new ForumTopic($obj);
$this->course->add_resource($forumTopic);
$this->build_forum_posts($courseId, $obj->thread_id, $obj->forum_id);
}
}
@ -425,24 +456,31 @@ class CourseBuilder
* Build the forum-posts
* TODO: All tree structure of posts should be built, attachments for example.
*
* @param int $courseId Internal course ID
* @param int $thread_id Internal thread ID
* @param int $forum_id Internal forum ID
* @param bool $only_first_post Whether to only copy the first post or not
* @param int $courseId Internal course ID
* @param int $thread_id Internal thread ID
* @param int $forum_id Internal forum ID
* @param array $idList
*/
public function build_forum_posts(
$courseId = 0,
$thread_id = null,
$forum_id = null,
$only_first_post = false
$idList = []
) {
$table = Database::get_course_table(TABLE_FORUM_POST);
$courseId = (int) $courseId;
$sql = "SELECT * FROM $table WHERE c_id = $courseId ";
if (!empty($thread_id) && !empty($forum_id)) {
$forum_id = intval($forum_id);
$thread_id = intval($thread_id);
$sql .= " AND thread_id = $thread_id AND forum_id = $forum_id ";
}
if (!empty($idList)) {
$idList = array_map('intval', $idList);
$sql .= ' AND iid IN ("'.implode('","', $idList).'") ';
}
$sql .= " ORDER BY post_id ASC LIMIT 1";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
@ -454,21 +492,21 @@ class CourseBuilder
/**
* Build the links.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_links(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$id_list = []
$withBaseContent = false,
$idList = []
) {
$categories = LinkManager::getLinkCategories(
$courseId,
$session_id,
$with_base_content
$withBaseContent
);
// Adding empty category
@ -481,10 +519,16 @@ class CourseBuilder
$category['id'],
$courseId,
$session_id,
$with_base_content
$withBaseContent
);
foreach ($links as $item) {
if (!empty($idList)) {
if (!in_array($item['id'], $idList)) {
continue;
}
}
$link = new Link(
$item['id'],
$item['title'],
@ -506,25 +550,27 @@ class CourseBuilder
/**
* Build tool intro.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_tool_intro(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$id_list = []
$withBaseContent = false,
$idList = []
) {
$table = Database::get_course_table(TABLE_TOOL_INTRO);
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_content
$withBaseContent
);
$courseId = (int) $courseId;
$sql = "SELECT * FROM $table
WHERE c_id = $courseId $sessionCondition";
@ -563,24 +609,31 @@ class CourseBuilder
/**
* Build the Quizzes.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_quizzes(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$withBaseContent = false,
$idList = []
) {
$table_qui = Database::get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_doc = Database::get_course_table(TABLE_DOCUMENT);
$courseId = (int) $courseId;
$idCondition = '';
if (!empty($idList)) {
$idList = array_map('intval', $idList);
$idCondition = ' iid IN ("'.implode('","', $idList).'") AND ';
}
if (!empty($courseId) && !empty($session_id)) {
$session_id = intval($session_id);
if ($with_base_content) {
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -592,13 +645,22 @@ class CourseBuilder
true
);
}
//select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
// Select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
$sql = "SELECT * FROM $table_qui
WHERE c_id = $courseId AND active >=0 $session_condition";
WHERE
c_id = $courseId AND
$idCondition
active >=0
$session_condition ";
} else {
//select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
// Select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
$sql = "SELECT * FROM $table_qui
WHERE c_id = $courseId AND active >=0 AND (session_id = 0 OR session_id IS NULL)";
WHERE
c_id = $courseId AND
$idCondition
active >=0 AND
(session_id = 0 OR session_id IS NULL)";
}
$sql .= 'ORDER BY title';
@ -613,7 +675,6 @@ class CourseBuilder
$obj->sound = $doc->id;
}
$quiz = new Quiz($obj);
$sql = 'SELECT * FROM '.$table_rel.'
WHERE c_id = '.$courseId.' AND exercice_id = '.$obj->id;
$db_result2 = Database::query($sql);
@ -642,6 +703,8 @@ class CourseBuilder
$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
$courseId = (int) $courseId;
// Building normal tests.
$sql = "SELECT * FROM $table_que
WHERE c_id = $courseId ";
@ -668,6 +731,7 @@ class CourseBuilder
$obj->extra,
$question_category_id
);
$question->addPicture($this);
$sql = 'SELECT * FROM '.$table_ans.'
WHERE c_id = '.$courseId.' AND question_id = '.$obj->id;
@ -685,9 +749,7 @@ class CourseBuilder
$obj2->hotspot_type
);
if ($obj->type == MULTIPLE_ANSWER_TRUE_FALSE) {
$table_options = Database::get_course_table(
TABLE_QUIZ_QUESTION_OPTION
);
$table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$sql = 'SELECT * FROM '.$table_options.'
WHERE c_id = '.$courseId.' AND question_id = '.$obj->id;
$db_result3 = Database::query($sql);
@ -706,7 +768,6 @@ class CourseBuilder
// 1st union gets the orphan questions from deleted exercises
// 2nd union gets the orphan questions from question that were deleted in a exercise.
$sql = " (
SELECT question_id, q.* FROM $table_que q
INNER JOIN $table_rel r
@ -745,10 +806,7 @@ class CourseBuilder
if (!isset($this->course->resources[$obj->id])) {
// find the question category
// @todo : need to be adapted for multi category questions in 1.10
$question_category_id = TestCategory::getCategoryForQuestion(
$obj->id,
$courseId
);
$question_category_id = TestCategory::getCategoryForQuestion($obj->id, $courseId);
$question = new QuizQuestion(
$obj->id,
$obj->question,
@ -761,6 +819,7 @@ class CourseBuilder
$obj->extra,
$question_category_id
);
$question->addPicture($this);
$sql = "SELECT * FROM $table_ans
WHERE c_id = $courseId AND question_id = ".$obj->id;
$db_result2 = Database::query($sql);
@ -853,6 +912,8 @@ class CourseBuilder
$obj->level,
$obj->extra
);
$question->addPicture($this);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
@ -904,24 +965,26 @@ class CourseBuilder
/**
* Build the Surveys.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_surveys(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$withBaseContent = false,
$id_list = []
) {
$table_survey = Database::get_course_table(TABLE_SURVEY);
$table_question = Database::get_course_table(TABLE_SURVEY_QUESTION);
$courseId = (int) $courseId;
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_content
$withBaseContent
);
$sql = 'SELECT * FROM '.$table_survey.'
@ -971,6 +1034,8 @@ class CourseBuilder
$table_que = Database::get_course_table(TABLE_SURVEY_QUESTION);
$table_opt = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$courseId = (int) $courseId;
$sql = 'SELECT * FROM '.$table_que.' WHERE c_id = '.$courseId.' ';
$db_result = Database::query($sql);
$is_required = 0;
@ -1005,15 +1070,15 @@ class CourseBuilder
/**
* Build the announcements.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_announcements(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$withBaseContent = false,
$id_list = []
) {
$table = Database::get_course_table(TABLE_ANNOUNCEMENT);
@ -1021,9 +1086,11 @@ class CourseBuilder
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_content
$withBaseContent
);
$courseId = (int) $courseId;
$sql = 'SELECT * FROM '.$table.'
WHERE c_id = '.$courseId.' '.$sessionCondition;
$db_result = Database::query($sql);
@ -1067,15 +1134,15 @@ class CourseBuilder
/**
* Build the events.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_events(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$withBaseContent = false,
$id_list = []
) {
$table = Database::get_course_table(TABLE_AGENDA);
@ -1083,9 +1150,11 @@ class CourseBuilder
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_content
$withBaseContent
);
$courseId = (int) $courseId;
$sql = 'SELECT * FROM '.$table.'
WHERE c_id = '.$courseId.' '.$sessionCondition;
$db_result = Database::query($sql);
@ -1125,22 +1194,23 @@ class CourseBuilder
/**
* Build the course-descriptions.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_course_descriptions(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$withBaseContent = false,
$id_list = []
) {
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$courseId = (int) $courseId;
if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id);
if ($with_base_content) {
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -1175,24 +1245,28 @@ class CourseBuilder
/**
* Build the learnpaths.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param bool $addScormFolder
*/
public function build_learnpaths(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$id_list = []
$withBaseContent = false,
$id_list = [],
$addScormFolder = true
) {
$table_main = Database::get_course_table(TABLE_LP_MAIN);
$table_item = Database::get_course_table(TABLE_LP_ITEM);
$table_tool = Database::get_course_table(TABLE_TOOL_LIST);
$courseId = (int) $courseId;
if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id);
if ($with_base_content) {
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -1216,9 +1290,9 @@ class CourseBuilder
$sql .= " AND id IN (".implode(', ', $id_list).") ";
}
$db_result = Database::query($sql);
if ($db_result) {
while ($obj = Database::fetch_object($db_result)) {
$result = Database::query($sql);
if ($result) {
while ($obj = Database::fetch_object($result)) {
$items = [];
$sql = "SELECT * FROM ".$table_item."
WHERE c_id = '$courseId' AND lp_id = ".$obj->id;
@ -1250,11 +1324,9 @@ class CourseBuilder
(link LIKE '%lp_controller.php%lp_id=".$obj->id."%' AND image='scormbuilder.gif') AND
visibility = '1' ";
$db_tool = Database::query($sql);
$visibility = '0';
if (Database::num_rows($db_tool)) {
$visibility = '1';
} else {
$visibility = '0';
}
$lp = new CourseCopyLearnpath(
@ -1286,44 +1358,59 @@ class CourseBuilder
$obj->session_id,
$items
);
$this->course->add_resource($lp);
if (!empty($obj->preview_image)) {
// Add LP teacher image
$asset = new Asset(
$obj->preview_image,
'/upload/learning_path/images/'.$obj->preview_image,
'/upload/learning_path/images/'.$obj->preview_image
);
$this->course->add_resource($asset);
}
}
}
// Save scorm directory (previously build_scorm_documents())
$i = 1;
if ($dir = @opendir($this->course->backup_path.'/scorm')) {
while ($file = readdir($dir)) {
if (is_dir($this->course->backup_path.'/scorm/'.$file) &&
!in_array($file, ['.', '..'])
) {
$doc = new ScormDocument($i++, '/'.$file, $file);
$this->course->add_resource($doc);
if ($addScormFolder) {
$i = 1;
if ($dir = @opendir($this->course->backup_path.'/scorm')) {
while ($file = readdir($dir)) {
if (is_dir($this->course->backup_path.'/scorm/'.$file) &&
!in_array($file, ['.', '..'])
) {
$doc = new ScormDocument($i++, '/'.$file, $file);
$this->course->add_resource($doc);
}
}
closedir($dir);
}
closedir($dir);
}
}
/**
* Build the glossaries.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_glossary(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$withBaseContent = false,
$id_list = []
) {
$table_glossary = Database::get_course_table(TABLE_GLOSSARY);
$courseId = (int) $courseId;
if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id);
if ($with_base_content) {
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -1335,6 +1422,7 @@ class CourseBuilder
true
);
}
//@todo check this queries are the same ...
if (!empty($this->course->type) && $this->course->type == 'partial') {
$sql = 'SELECT * FROM '.$table_glossary.' g
@ -1403,22 +1491,23 @@ class CourseBuilder
}
/**
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_wiki(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$withBaseContent = false,
$id_list = []
) {
$tbl_wiki = Database::get_course_table(TABLE_WIKI);
$courseId = (int) $courseId;
if (!empty($session_id) && !empty($courseId)) {
$session_id = intval($session_id);
if ($with_base_content) {
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -1458,24 +1547,25 @@ class CourseBuilder
/**
* Build the Surveys.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_thematic(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$withBaseContent = false,
$id_list = []
) {
$table_thematic = Database::get_course_table(TABLE_THEMATIC);
$table_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
$table_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
$courseId = (int) $courseId;
$courseInfo = api_get_course_info_by_id($courseId);
$session_id = intval($session_id);
if ($with_base_content) {
if ($withBaseContent) {
$session_condition = api_get_session_condition(
$session_id,
true,
@ -1532,21 +1622,21 @@ class CourseBuilder
/**
* Build the attendances.
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
*/
public function build_attendance(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$withBaseContent = false,
$id_list = []
) {
$table_attendance = Database::get_course_table(TABLE_ATTENDANCE);
$table_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
$sessionCondition = api_get_session_condition($session_id, true, $withBaseContent);
$courseId = (int) $courseId;
$sql = 'SELECT * FROM '.$table_attendance.'
WHERE c_id = '.$courseId.' '.$sessionCondition;
@ -1567,33 +1657,42 @@ class CourseBuilder
/**
* Build the works (or "student publications", or "assignments").
*
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $with_base_content Whether to include content from the course without session or not
* @param array $id_list If you want to restrict the structure to only the given IDs
* @param int $session_id Internal session ID
* @param int $courseId Internal course ID
* @param bool $withBaseContent Whether to include content from the course without session or not
* @param array $idList If you want to restrict the structure to only the given IDs
*/
public function build_works(
$session_id = 0,
$courseId = 0,
$with_base_content = false,
$id_list = []
$withBaseContent = false,
$idList = []
) {
$table_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sessionCondition = api_get_session_condition(
$session_id,
true,
$with_base_content
$withBaseContent
);
$courseId = (int) $courseId;
$idCondition = '';
if (!empty($idList)) {
$idList = array_map('intval', $idList);
$idCondition = ' AND iid IN ("'.implode('","', $idList).'") ';
}
$sql = "SELECT * FROM $table_work
WHERE
c_id = $courseId
$sessionCondition AND
c_id = $courseId
$sessionCondition AND
filetype = 'folder' AND
parent_id = 0 AND
active = 1";
$db_result = Database::query($sql);
while ($row = Database::fetch_array($db_result, 'ASSOC')) {
active = 1
$idCondition
";
$result = Database::query($sql);
while ($row = Database::fetch_array($result, 'ASSOC')) {
$obj = new Work($row);
$this->course->add_resource($obj);
}
@ -1602,12 +1701,12 @@ class CourseBuilder
/**
* @param int $session_id
* @param int $courseId
* @param bool $with_base_content
* @param bool $withBaseContent
*/
public function build_gradebook(
$session_id = 0,
$courseId = 0,
$with_base_content = false
$withBaseContent = false
) {
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo['code'];

@ -52,13 +52,13 @@ class CourseRestorer
'quizzes',
'test_category',
'links',
'learnpaths',
'works',
'surveys',
'learnpaths',
//'scorm_documents', ??
'tool_intro',
'thematic',
'wiki',
'works',
'gradebook',
'assets',
];
@ -81,10 +81,9 @@ class CourseRestorer
{
$this->course = $course;
$courseInfo = api_get_course_info($this->course->code);
$this->course_origin_id = null;
if (!empty($courseInfo)) {
$this->course_origin_id = $courseInfo['real_id'];
} else {
$this->course_origin_id = null;
}
$this->file_option = FILE_RENAME;
$this->set_tools_invisible_by_default = false;
@ -289,6 +288,7 @@ class CourseRestorer
return;
}
$webEditorCss = api_get_path(WEB_CSS_PATH).'editor.css';
$table = Database::get_course_table(TABLE_DOCUMENT);
$resources = $this->course->resources;
$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
@ -297,7 +297,7 @@ class CourseRestorer
$my_session_id = empty($document->item_properties[0]['id_session']) ? 0 : $session_id;
if ($document->file_type == FOLDER) {
$visibility = $document->item_properties[0]['visibility'];
$visibility = isset($document->item_properties[0]['visibility']) ? $document->item_properties[0]['visibility'] : '';
$new = substr($document->path, 8);
$folderList = explode('/', $new);
@ -332,7 +332,6 @@ class CourseRestorer
$title,
$visibility
);
continue;
}
@ -356,7 +355,9 @@ class CourseRestorer
null,
false,
null,
$my_session_id
$my_session_id,
0,
false
);
} else {
$insertUserId = isset($document->item_properties[0]['insert_user_id']) ? $document->item_properties[0]['insert_user_id'] : api_get_user_id();
@ -385,9 +386,8 @@ class CourseRestorer
}
}
} elseif ($document->file_type == DOCUMENT) {
//Checking if folder exists in the database otherwise we created it
// Checking if folder exists in the database otherwise we created it
$dir_to_create = dirname($document->path);
if (!empty($dir_to_create) && $dir_to_create != 'document' && $dir_to_create != '/') {
if (is_dir($path.dirname($document->path))) {
$sql = "SELECT id FROM $table
@ -395,6 +395,7 @@ class CourseRestorer
c_id = ".$this->destination_course_id." AND
path = '/".self::DBUTF8escapestring(substr(dirname($document->path), 9))."'";
$res = Database::query($sql);
if (Database::num_rows($res) == 0) {
//continue;
$visibility = $document->item_properties[0]['visibility'];
@ -413,6 +414,10 @@ class CourseRestorer
$title,
null,
null,
false,
0,
0,
0,
false
);
@ -444,9 +449,9 @@ class CourseRestorer
switch ($this->file_option) {
case FILE_OVERWRITE:
$origin_path = $this->course->backup_path.'/'.$document->path;
if (file_exists($origin_path)) {
copy($origin_path, $path.$document->path);
$this->fixEditorHtmlContent($path.$document->path, $webEditorCss);
$sql = "SELECT id FROM $table
WHERE
c_id = ".$this->destination_course_id." AND
@ -681,6 +686,7 @@ class CourseRestorer
$this->course->info['path']
);
file_put_contents($dest_document_path, $content);
$this->fixEditorHtmlContent($dest_document_path, $webEditorCss);
}
}
@ -699,36 +705,36 @@ class CourseRestorer
if ($document_id) {
$sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
Database::query($sql);
}
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
$itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
$insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
$toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0;
$toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null;
$itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
$insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
$toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0;
$toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null;
$insertUserId = $this->checkUserId($insertUserId);
$toUserId = $this->checkUserId($toUserId, true);
$groupInfo = $this->checkGroupId($toGroupId);
$insertUserId = $this->checkUserId($insertUserId);
$toUserId = $this->checkUserId($toUserId, true);
$groupInfo = $this->checkGroupId($toGroupId);
api_item_property_update(
$course_info,
TOOL_DOCUMENT,
$document_id,
'DocumentAdded',
$insertUserId,
$groupInfo,
$toUserId,
null,
null,
$my_session_id
);
api_item_property_update(
$course_info,
TOOL_DOCUMENT,
$document_id,
'DocumentAdded',
$insertUserId,
$groupInfo,
$toUserId,
null,
null,
$my_session_id
);
}
} else {
if (file_exists($path.$document->path)) {
copy($path.$document->path, $path.$new_file_name);
}
//Replace old course code with the new destination code see BT#1985
// Replace old course code with the new destination code see BT#1985
if (file_exists($path.$new_file_name)) {
$file_info = pathinfo($path.$new_file_name);
if (in_array($file_info['extension'], ['html', 'htm'])) {
@ -744,6 +750,7 @@ class CourseRestorer
$this->course->info['path']
);
file_put_contents($path.$new_file_name, $content);
$this->fixEditorHtmlContent($path.$new_file_name, $webEditorCss);
}
}
@ -810,6 +817,7 @@ class CourseRestorer
$this->course->info['path']
);
file_put_contents($path.$new_file_name, $content);
$this->fixEditorHtmlContent($path.$new_file_name, $webEditorCss);
}
}
@ -828,31 +836,30 @@ class CourseRestorer
if ($document_id) {
$sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
Database::query($sql);
}
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
$itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
$insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
$toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0;
$toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null;
$insertUserId = $this->checkUserId($insertUserId);
$toUserId = $this->checkUserId($toUserId, true);
$groupInfo = $this->checkGroupId($toGroupId);
api_item_property_update(
$course_info,
TOOL_DOCUMENT,
$document_id,
'DocumentAdded',
$insertUserId,
$groupInfo,
$toUserId,
null,
null,
$my_session_id
);
$itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
$insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
$toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0;
$toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null;
$insertUserId = $this->checkUserId($insertUserId);
$toUserId = $this->checkUserId($toUserId, true);
$groupInfo = $this->checkGroupId($toGroupId);
api_item_property_update(
$course_info,
TOOL_DOCUMENT,
$document_id,
'DocumentAdded',
$insertUserId,
$groupInfo,
$toUserId,
null,
null,
$my_session_id
);
}
}
break;
} // end switch
@ -885,6 +892,7 @@ class CourseRestorer
$this->course->info['path']
);
file_put_contents($path.$document->path, $content);
$this->fixEditorHtmlContent($path.$document->path, $webEditorCss);
}
}
@ -904,47 +912,61 @@ class CourseRestorer
if ($document_id) {
$sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
Database::query($sql);
}
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
$itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
$insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
$toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0;
$toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null;
$itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
$insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
$toGroupId = isset($itemProperty['to_group_id']) ? $itemProperty['to_group_id'] : 0;
$toUserId = isset($itemProperty['to_user_id']) ? $itemProperty['to_user_id'] : null;
$insertUserId = $this->checkUserId($insertUserId);
$toUserId = $this->checkUserId($toUserId, true);
$groupInfo = $this->checkGroupId($toGroupId);
$insertUserId = $this->checkUserId($insertUserId);
$toUserId = $this->checkUserId($toUserId, true);
$groupInfo = $this->checkGroupId($toGroupId);
api_item_property_update(
$course_info,
TOOL_DOCUMENT,
$document_id,
'DocumentAdded',
$insertUserId,
$groupInfo,
$toUserId,
null,
null,
$my_session_id
);
api_item_property_update(
$course_info,
TOOL_DOCUMENT,
$document_id,
'DocumentAdded',
$insertUserId,
$groupInfo,
$toUserId,
null,
null,
$my_session_id
);
}
} else {
// There was an error in checking existence and
// permissions for files to copy. Try to determine
// the exact issue
// Issue with origin document?
if (!is_file($this->course->backup_path.'/'.$document->path)) {
error_log('Course copy generated an ignorable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': origin file not found');
error_log(
'Course copy generated an ignorable error while trying to copy '.
$this->course->backup_path.'/'.$document->path.': origin file not found'
);
} elseif (!is_readable($this->course->backup_path.'/'.$document->path)) {
error_log('Course copy generated an ignorable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': origin file not readable');
error_log(
'Course copy generated an ignorable error while trying to copy '.
$this->course->backup_path.'/'.$document->path.': origin file not readable'
);
}
// Issue with destination directories?
if (!is_dir(dirname($path.$document->path))) {
error_log('Course copy generated an ignorable error while trying to copy '.$this->course->backup_path.'/'.$document->path.' to '.dirname($path.$document->path).': destination directory not found');
error_log(
'Course copy generated an ignorable error while trying to copy '.
$this->course->backup_path.'/'.$document->path.' to '.
dirname($path.$document->path).': destination directory not found'
);
}
if (!is_writeable(dirname($path.$document->path))) {
error_log('Course copy generated an ignorable error while trying to copy '.$this->course->backup_path.'/'.$document->path.' to '.dirname($path.$document->path).': destination directory not writable');
error_log(
'Course copy generated an ignorable error while trying to copy '.
$this->course->backup_path.'/'.$document->path.' to '.
dirname($path.$document->path).': destination directory not writable'
);
}
}
} // end file doesn't exist
@ -1030,7 +1052,6 @@ class CourseRestorer
$this->course->backup_path.'/'.$new_file_name,
$this->course->backup_path.'/'.$document->path
);
break;
} // end switch
} else {
@ -1091,7 +1112,8 @@ class CourseRestorer
if (!empty($params['forum_image'])) {
$original_forum_image = $this->course->path.'upload/forum/images/'.$params['forum_image'];
if (file_exists($original_forum_image)) {
$new_forum_image = api_get_path(SYS_COURSE_PATH).$this->destination_course_info['path'].'/upload/forum/images/'.$params['forum_image'];
$new_forum_image = api_get_path(SYS_COURSE_PATH).
$this->destination_course_info['path'].'/upload/forum/images/'.$params['forum_image'];
@copy($original_forum_image, $new_forum_image);
}
}
@ -1101,6 +1123,15 @@ class CourseRestorer
if ($new_id) {
$sql = "UPDATE $table_forum SET forum_id = iid WHERE iid = $new_id";
Database::query($sql);
api_item_property_update(
$this->destination_course_info,
TOOL_FORUM,
$new_id,
'ForumUpdated',
api_get_user_id()
);
$this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
$forum_topics = 0;
@ -1158,9 +1189,17 @@ class CourseRestorer
if ($new_id) {
$sql = "UPDATE $forum_cat_table SET cat_id = iid WHERE iid = $new_id";
Database::query($sql);
api_item_property_update(
$this->destination_course_info,
TOOL_FORUM_CATEGORY,
$new_id,
'ForumCategoryUpdated',
api_get_user_id()
);
$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id;
}
$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id;
if (!empty($my_id)) {
return $new_id;
}
@ -1201,28 +1240,28 @@ class CourseRestorer
if ($new_id) {
$sql = "UPDATE $table SET thread_id = iid WHERE iid = $new_id";
Database::query($sql);
}
api_item_property_update(
$this->destination_course_info,
TOOL_FORUM_THREAD,
$new_id,
'ThreadAdded',
api_get_user_id(),
0,
0,
null,
null,
$sessionId
);
api_item_property_update(
$this->destination_course_info,
TOOL_FORUM_THREAD,
$new_id,
'ThreadAdded',
api_get_user_id(),
0,
0,
null,
null,
$sessionId
);
$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
$topic_replies = -1;
$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
$topic_replies = -1;
foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
if ($post->obj->thread_id == $thread_id) {
$topic_replies++;
$this->restore_post($post_id, $new_id, $forum_id, $sessionId);
foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
if ($post->obj->thread_id == $thread_id) {
$topic_replies++;
$this->restore_post($post_id, $new_id, $forum_id, $sessionId);
}
}
}
@ -1263,21 +1302,21 @@ class CourseRestorer
if ($new_id) {
$sql = "UPDATE $table_post SET post_id = iid WHERE iid = $new_id";
Database::query($sql);
}
api_item_property_update(
$this->destination_course_info,
TOOL_FORUM_POST,
$new_id,
'PostAdded',
api_get_user_id(),
0,
0,
null,
null,
$sessionId
);
$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
api_item_property_update(
$this->destination_course_info,
TOOL_FORUM_POST,
$new_id,
'PostAdded',
api_get_user_id(),
0,
0,
null,
null,
$sessionId
);
$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
}
return $new_id;
}
@ -1346,6 +1385,8 @@ class CourseRestorer
*
* @param int
* @param int
*
* @return bool
*/
public function restore_link_category($id, $session_id = 0)
{
@ -1591,7 +1632,6 @@ class CourseRestorer
);
$params = [];
$session_id = intval($session_id);
$params['session_id'] = $session_id;
$params['c_id'] = $this->destination_course_id;
@ -1817,7 +1857,7 @@ class CourseRestorer
'end_time' => $quiz->end_time,
'save_correct_answers' => 0,
'display_category_name' => 0,
'save_correct_answers' => $quiz->save_correct_answers,
'save_correct_answers' => isset($quiz->save_correct_answers) ? $quiz->save_correct_answers : 0,
'hide_question_title' => isset($quiz->hide_question_title) ? $quiz->hide_question_title : 0,
];
@ -2322,7 +2362,7 @@ class CourseRestorer
'session_id' => $sessionId,
];
//An existing survey exists with the same code and the same language
// An existing survey exists with the same code and the same language
if (Database::num_rows($result_check) == 1) {
switch ($this->file_option) {
case FILE_SKIP:
@ -2544,8 +2584,7 @@ class CourseRestorer
*/
public function restore_learnpaths($session_id = 0, $respect_base_content = false)
{
$session_id = intval($session_id);
$session_id = (int) $session_id;
if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
$table_main = Database::get_course_table(TABLE_LP_MAIN);
$table_item = Database::get_course_table(TABLE_LP_ITEM);
@ -2720,8 +2759,7 @@ class CourseRestorer
if ($item['item_type'] == 'sco') {
$path = $item['path'];
} else {
$path = $item['path'];
$path = $this->get_new_id($item['item_type'], $path);
$path = $this->get_new_id($item['item_type'], $item['path']);
}
$item['item_type'] = $item['item_type'] == 'dokeos_chapter' ? 'dir' : $item['item_type'];
@ -2748,38 +2786,38 @@ class CourseRestorer
];
$new_item_id = Database::insert($table_item, $params);
if ($new_item_id) {
$sql = "UPDATE $table_item SET id = iid WHERE iid = $new_item_id";
Database::query($sql);
$sql = "UPDATE $table_item SET id = iid WHERE iid = $new_item_id";
Database::query($sql);
//save a link between old and new item IDs
$new_item_ids[$item['id']] = $new_item_id;
//save a reference of items that need a parent_item_id refresh
$parent_item_ids[$new_item_id] = $item['parent_item_id'];
//save a reference of items that need a previous_item_id refresh
$previous_item_ids[$new_item_id] = $item['previous_item_id'];
//save a reference of items that need a next_item_id refresh
$next_item_ids[$new_item_id] = $item['next_item_id'];
if (!empty($item['prerequisite'])) {
if ($lp->lp_type == '2') {
// if is an sco
$old_prerequisite[$new_item_id] = $item['prerequisite'];
} else {
$old_prerequisite[$new_item_id] = $new_item_ids[$item['prerequisite']];
//save a link between old and new item IDs
$new_item_ids[$item['id']] = $new_item_id;
//save a reference of items that need a parent_item_id refresh
$parent_item_ids[$new_item_id] = $item['parent_item_id'];
//save a reference of items that need a previous_item_id refresh
$previous_item_ids[$new_item_id] = $item['previous_item_id'];
//save a reference of items that need a next_item_id refresh
$next_item_ids[$new_item_id] = $item['next_item_id'];
if (!empty($item['prerequisite'])) {
if ($lp->lp_type == '2') {
// if is an sco
$old_prerequisite[$new_item_id] = $item['prerequisite'];
} else {
$old_prerequisite[$new_item_id] = isset($new_item_ids[$item['prerequisite']]) ? $new_item_ids[$item['prerequisite']] : '';
}
}
}
if (!empty($ref)) {
if ($lp->lp_type == '2') {
// if is an sco
$old_refs[$new_item_id] = $ref;
} elseif (isset($new_item_ids[$ref])) {
$old_refs[$new_item_id] = $new_item_ids[$ref];
if (!empty($ref)) {
if ($lp->lp_type == '2') {
// if is an sco
$old_refs[$new_item_id] = $ref;
} elseif (isset($new_item_ids[$ref])) {
$old_refs[$new_item_id] = $new_item_ids[$ref];
}
}
$prerequisite_ids[$new_item_id] = $item['prerequisite'];
}
$prerequisite_ids[$new_item_id] = $item['prerequisite'];
}
// Updating prerequisites
@ -2809,6 +2847,7 @@ class CourseRestorer
WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
Database::query($sql);
}
foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
$previous_new_id = 0;
if ($previous_item_old_id != 0) {
@ -2896,6 +2935,10 @@ class CourseRestorer
$tool = 'document';
}
if ($tool === 'student_publication') {
$tool = RESOURCE_WORK;
}
if (isset($this->course->resources[$tool][$ref]) &&
isset($this->course->resources[$tool][$ref]->destination_id) &&
!empty($this->course->resources[$tool][$ref]->destination_id)
@ -3208,7 +3251,7 @@ class CourseRestorer
{
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
if ($this->course->has_resources(RESOURCE_WORK)) {
$table_work_assignment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_WORK] as $obj) {
@ -3231,6 +3274,7 @@ class CourseRestorer
$path = '/'.str_replace('/', '', substr($path, 1));
$workData = [];
switch ($this->file_option) {
case FILE_SKIP:
$workData = get_work_data_by_path(
@ -3243,11 +3287,10 @@ class CourseRestorer
break;
case FILE_OVERWRITE:
if (!empty($this->course_origin_id)) {
$sql = 'SELECT * FROM '.$table_work_assignment.'
$sql = 'SELECT * FROM '.$table.'
WHERE
c_id = '.$this->course_origin_id.' AND
publication_id = '.$id_work;
$result = Database::query($sql);
$cant = Database::num_rows($result);
if ($cant > 0) {
@ -3274,13 +3317,14 @@ class CourseRestorer
$obj->params['new_dir'] = $obj->params['title'];
if (empty($workData)) {
addDir(
$workId = addDir(
$obj->params,
api_get_user_id(),
$this->destination_course_info,
0,
$sessionId
);
$this->course->resources[RESOURCE_WORK][$id_work]->destination_id = $workId;
} else {
$workId = $workData['iid'];
updateWork(
@ -3295,6 +3339,7 @@ class CourseRestorer
$this->destination_course_info,
0
);
$this->course->resources[RESOURCE_WORK][$id_work]->destination_id = $workId;
}
}
}
@ -3425,7 +3470,7 @@ class CourseRestorer
$resources = $this->course->resources;
$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
foreach ($resources[RESOURCE_ASSET] as $id => $asset) {
foreach ($resources[RESOURCE_ASSET] as $asset) {
if (is_file($this->course->backup_path.'/'.$asset->path) &&
is_readable($this->course->backup_path.'/'.$asset->path) &&
is_dir(dirname($path.$asset->path)) &&
@ -3502,6 +3547,28 @@ class CourseRestorer
return \GroupManager::get_group_properties($groupId);
}
/**
* @param string $documentPath
* @param string $webEditorCss
*/
public function fixEditorHtmlContent($documentPath, $webEditorCss = '')
{
$extension = pathinfo(basename($documentPath), PATHINFO_EXTENSION);
switch ($extension) {
case 'html':
case 'htm':
$contents = file_get_contents($documentPath);
$contents = str_replace(
'{{css_editor}}',
$webEditorCss,
$contents
);
file_put_contents($documentPath, $contents);
break;
}
}
/**
* Check if user exist otherwise use current user.
*

@ -242,8 +242,12 @@ class CourseSelectForm
echo '<div class="well">';
echo '<div class="btn-group">';
echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
echo "<a class=\"btn btn-default\"
href=\"javascript: void(0);\"
onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
echo "<a class=\"btn btn-default\"
href=\"javascript: void(0);\"
onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
echo '</div>';
echo '<ul class="list-backups-options">';
foreach ($resources as $id => $resource) {
@ -252,7 +256,9 @@ class CourseSelectForm
// Event obj in 1.9.x in 1.10.x the class is CalendarEvent
Resource::setClassType($resource);
echo '<label class="checkbox">';
echo '<input type="checkbox" name="resource['.$type.']['.$id.']" id="resource['.$type.']['.$id.']" />';
echo '<input
type="checkbox"
name="resource['.$type.']['.$id.']" id="resource['.$type.']['.$id.']" />';
$resource->show();
echo '</label>';
echo '</li>';
@ -339,14 +345,22 @@ class CourseSelectForm
echo Display::return_message(get_lang('NoDataAvailable'), 'warning');
} else {
if (!empty($hidden_fields['destination_session'])) {
echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."'".')) return false;" >'.
echo '<br />
<button
class="save"
type="submit"
onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."'".')) return false;" >'.
get_lang('Ok').'</button>';
} else {
if ($recycleOption) {
echo '<br /><button class="save" type="submit">'.
get_lang('Ok').'</button>';
} else {
echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
echo '<br />
<button
class="save"
type="submit"
onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
get_lang('Ok').'</button>';
}
}

@ -17,9 +17,9 @@ class Asset extends Resource
/**
* Asset constructor.
*
* @param int $id
* @param int $path
* @param $title
* @param int $id
* @param int $path
* @param string $title
*/
public function __construct($id, $path, $title)
{

@ -73,7 +73,6 @@ class CalendarEvent extends Resource
$this->start_date = $start_date;
$this->end_date = $end_date;
$this->all_day = $all_day;
$this->attachment_path = $attachment_path;
$this->attachment_filename = $attachment_filename;
$this->attachment_size = $attachment_size;

@ -25,6 +25,7 @@ class CourseCopyTestCategory extends Resource
/**
* Create a new TestCategory.
*
* @param int $id
* @param string $title
* @param string $description
*/

@ -33,13 +33,14 @@ class CourseDescription extends Resource
* @param int $id
* @param string $title
* @param string $content
* @param string $descriptionType
*/
public function __construct($id, $title, $content, $description_type)
public function __construct($id, $title, $content, $descriptionType)
{
parent::__construct($id, RESOURCE_COURSEDESCRIPTION);
$this->title = $title;
$this->content = $content;
$this->description_type = $description_type;
$this->description_type = $descriptionType;
}
/**

@ -38,11 +38,14 @@ class Quiz extends Resource
/**
* Add a question to this Quiz.
*
* @param int $id
* @param int $questionOrder
*/
public function add_question($id, $question_order)
public function add_question($id, $questionOrder)
{
$this->obj->question_ids[] = $id;
$this->obj->question_orders[] = $question_order;
$this->obj->question_orders[] = $questionOrder;
}
/**

@ -3,6 +3,8 @@
namespace Chamilo\CourseBundle\Component\CourseCopy\Resources;
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
/**
* Exercises questions backup script
* Class QuizQuestion.
@ -66,12 +68,12 @@ class QuizQuestion extends Resource
* @param string $question
* @param string $description
* @param int $ponderation
* @param $type
* @param $position
* @param $picture
* @param $level
* @param $extra
* @param int $question_category
* @param $type
* @param $position
* @param string $picture
* @param $level
* @param $extra
* @param int $question_category
*/
public function __construct(
$id,
@ -91,11 +93,42 @@ class QuizQuestion extends Resource
$this->ponderation = $ponderation;
$this->quiz_type = $type;
$this->position = $position;
$this->picture = $picture;
$this->level = $level;
$this->answers = [];
$this->extra = $extra;
$this->question_category = $question_category;
$this->picture = $picture;
}
/**
* @param CourseBuilder $courseBuilder
*/
public function addPicture(CourseBuilder $courseBuilder)
{
if (!empty($this->picture)) {
$courseInfo = $courseBuilder->course->info;
$courseId = $courseInfo['real_id'];
$courseCode = $courseInfo['code'];
$questionId = $this->source_id;
$question = \Question::read($questionId, $courseId);
$pictureId = $question->getPictureId();
// Add the picture document in the builder
if (!empty($pictureId)) {
$itemsToAdd[] = $pictureId;
// Add the "images" folder needed for correct restore
$documentData = \DocumentManager::get_document_data_by_id($pictureId, $courseCode, true);
if ($documentData) {
if (isset($documentData['parents'])) {
foreach ($documentData['parents'] as $parent) {
$itemsToAdd[] = $parent['id'];
}
}
}
// Add the picture
$courseBuilder->build_documents(api_get_session_id(), $courseId, false, $itemsToAdd);
}
}
}
/**
@ -133,11 +166,11 @@ class QuizQuestion extends Resource
}
/**
* @param QuizQuestionOption $option_obj
* @param QuizQuestionOption $option
*/
public function add_option($option_obj)
public function add_option($option)
{
$this->question_options[$option_obj->obj->id] = $option_obj;
$this->question_options[$option->obj->id] = $option;
}
/**

@ -119,7 +119,7 @@ class Resource
* Get the constant which defines the tool of this resource. This is
* used in the item_properties table.
*
* @param bool $for_item_property_table (optional) Added by Ivan,
* @param bool $for_item_property_table (optional) Added by Ivan,
* 29-AUG-2009: A parameter for resolving differencies between defined TOOL_*
* constants and hardcoded strings that are stored in the database.
* Example: The constant TOOL_THREAD is defined in the main_api.lib.php
@ -145,12 +145,15 @@ class Resource
case RESOURCE_ANNOUNCEMENT:
return TOOL_ANNOUNCEMENT;
case RESOURCE_FORUMCATEGORY:
return 'forum_category'; // Ivan, 29-AUG-2009: A constant like TOOL_FORUM_CATEGORY is missing in main_api.lib.php. Such a constant has been defined in the forum tool for local needs.
// Ivan, 29-AUG-2009: A constant like TOOL_FORUM_CATEGORY is missing in main_api.lib.php.
// Such a constant has been defined in the forum tool for local needs.
return 'forum_category';
case RESOURCE_FORUM:
return TOOL_FORUM;
case RESOURCE_FORUMTOPIC:
if ($for_item_property_table) {
return 'forum_thread'; // Ivan, 29-AUG-2009: A hardcoded value that the "Forums" tool stores in the item property table.
// Ivan, 29-AUG-2009: A hardcoded value that the "Forums" tool stores in the item property table.
return 'forum_thread';
}
return TOOL_THREAD;
@ -200,9 +203,9 @@ class Resource
}
/**
* Check if this resource is allready restored in the destination course.
* Check if this resource is already restored in the destination course.
*
* @return bool true if allready restored (i.e. destination_id is set).
* @return bool true if already restored (i.e. destination_id is set).
*/
public function is_restored()
{

@ -64,7 +64,7 @@ class SurveyQuestion extends Resource
* @param int $sort
* @param int $shared_question_id
* @param int $max_value
* @param int $is_required
* @param bool $is_required
*/
public function __construct(
$id,

@ -90,6 +90,13 @@ class CDocument
*/
private $sessionId;
/**
* CDocument constructor.
*/
public function __construct()
{
}
/**
* Set path.
*

Loading…
Cancel
Save