Refactor course-progress/thematic, use resources

pull/3124/head
Julio Montoya 6 years ago
parent 1c782fa66b
commit 784f70862b
  1. 1100
      public/main/course_progress/index.php
  2. 27
      public/main/course_progress/layout.php
  3. 14
      public/main/course_progress/layout_no_header.php
  4. 303
      public/main/course_progress/thematic.php
  5. 267
      public/main/course_progress/thematic_advance.php
  6. 497
      public/main/course_progress/thematic_controller.php
  7. 74
      public/main/course_progress/thematic_plan.php
  8. 1
      public/main/inc/ajax/thematic.ajax.php
  9. 445
      public/main/inc/lib/thematic.lib.php
  10. 126
      public/main/template/default/course_progress/progress.html.twig

File diff suppressed because it is too large Load Diff

@ -1,27 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Layout (principal view) used for structuring other views.
*
* @author Christian Fasanando <christian1827@gmail.com>
*/
// protect a course script
api_protect_course_script(true);
// Header
$tool = TOOL_COURSE_PROGRESS;
//Display::display_header('');
// Introduction section
Display::display_introduction_section($tool);
// Tracking
Event::event_access_tool($tool);
// Display
echo $content;
// Footer
//Display::display_footer();

@ -1,14 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
// protect a course script
api_protect_course_script(true);
Display::display_reduced_header();
$tool = isset($tool) ? $tool : null;
// Tracking
Event::event_access_tool($tool);
// Display
echo $content;

@ -1,303 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* View (MVC patter) for thematic control.
*
* @author Christian Fasanando <christian1827@gmail.com>
* @author Julio Montoya <gugli100@gmail.com> Bug fixing
*/
// protect a course script
api_protect_course_script(true);
$token = Security::get_token();
$url_token = "&sec_token=".$token;
$user_info = api_get_user_info();
$params = '&'.api_get_cidreq();
$tpl = new Template(get_lang('Thematic control'));
$isTeacher = api_is_allowed_to_edit(null, true);
$tpl->assign('token', $url_token);
$tpl->assign('is_allowed_to_edit', $isTeacher);
$toolbar = null;
if ($isTeacher) {
switch ($action) {
case 'thematic_add':
case 'thematic_import_select':
$actionLeft = '<a href="index.php?'.api_get_cidreq().'">';
$actionLeft .= Display::return_icon(
'back.png',
get_lang('Back to').' '.get_lang('Thematic view with details'),
'',
ICON_SIZE_MEDIUM
);
$actionLeft .= '</a>';
break;
case 'thematic_list':
$actionLeft = '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
Display::return_icon('new_course_progress.png', get_lang('New thematic section'), '', ICON_SIZE_MEDIUM).'</a>';
break;
case 'thematic_details':
$actionLeft = '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
Display::return_icon('new_course_progress.png', get_lang('New thematic section'), '', ICON_SIZE_MEDIUM).'</a>';
$actionLeft .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_import_select'.$url_token.'">'.
Display::return_icon('import_csv.png', get_lang('Import course progress'), '', ICON_SIZE_MEDIUM).'</a>';
$actionLeft .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_export'.$url_token.'">'.
Display::return_icon('export_csv.png', get_lang('Export course progress'), '', ICON_SIZE_MEDIUM).'</a>';
$actionLeft .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_export_pdf'.$url_token.'">'.
Display::return_icon('pdf.png', get_lang('Export to PDF'), '', ICON_SIZE_MEDIUM).'</a>';
$actionLeft .= Display::url(
Display::return_icon('export_to_documents.png', get_lang('Export latest version of this page to Documents'), [], ICON_SIZE_MEDIUM),
api_get_self().'?'.api_get_cidreq().'&'.http_build_query(['action' => 'export_documents']).$url_token
);
break;
default:
$actionLeft = '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.
Display::return_icon(
'new_course_progress.png',
get_lang('New thematic section'),
'',
ICON_SIZE_MEDIUM
).'</a>';
}
$toolbar = Display::toolbarAction('thematic-bar', [$actionLeft]);
}
if ('thematic_list' == $action) {
$table = new SortableTable(
'thematic_list',
['Thematic', 'get_number_of_thematics'],
['Thematic', 'get_thematic_data']
);
$parameters['action'] = $action;
$table->set_additional_parameters($parameters);
$table->set_header(0, '', false, ['style' => 'width:20px;']);
$table->set_header(1, get_lang('Title'), false);
if (api_is_allowed_to_edit(null, true)) {
$table->set_header(
2,
get_lang('Detail'),
false,
['style' => 'text-align:center;width:40%;']
);
$table->set_form_actions(['thematic_delete_select' => get_lang('Delete all thematics')]);
}
$table->display();
} elseif ('thematic_details' == $action) {
if (isset($_GET['thematic_plan_save_message']) &&
'ok' == $_GET['thematic_plan_save_message']
) {
Display::addFlash(
Display::return_message(
get_lang('Thematic section has been created successfully'),
'confirmation',
false
)
);
}
if (isset($last_id) && $last_id) {
$link_to_thematic_plan = '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$last_id.'">'.
Display::return_icon('lesson_plan.png', get_lang('Thematic plan'), ['style' => 'vertical-align:middle;float:none;'], ICON_SIZE_SMALL).'</a>';
$link_to_thematic_advance = '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$last_id.'">'.
Display::return_icon('lesson_plan_calendar.png', get_lang('Thematic advance'), ['style' => 'vertical-align:middle;float:none;'], ICON_SIZE_SMALL).'</a>';
Display::addFlash(Display::return_message(
get_lang('Thematic section has been created successfully').'<br />'.sprintf(get_lang('NowYouShouldAddThematic planXAndThematic advanceX'), $link_to_thematic_plan, $link_to_thematic_advance),
'confirmation',
false
));
}
if (empty($thematic_id)) {
// display information
$text = '<strong>'.get_lang('Information').': </strong>';
$text .= get_lang('Thematic view with detailsDescription');
$message = Display::return_message($text, 'info', false);
}
$list = [];
// Display thematic data
if (!empty($thematic_data)) {
// display progress
foreach ($thematic_data as $thematic) {
$list['id'] = $thematic['id'];
$list['id_course'] = $thematic['c_id'];
$list['id_session'] = $thematic['session_id'];
$list['title'] = Security::remove_XSS($thematic['title'], STUDENT);
$list['content'] = Security::remove_XSS($thematic['content'], STUDENT);
$list['display_orden'] = $thematic['display_order'];
$list['active'] = $thematic['active'];
$my_thematic_id = $thematic['id'];
$session_star = '';
if (api_is_allowed_to_edit(null, true)) {
if (api_get_session_id() == $thematic['session_id']) {
$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
}
}
$tpl->assign('session_star', $session_star);
//@todo add a validation in order to load or not course thematics in the session thematic
$toolbarThematic = '';
if (api_is_allowed_to_edit(null, true)) {
// Thematic title
$toolbarThematic = Display::url(
Display::return_icon(
'cd.png',
get_lang('Copy'),
null,
ICON_SIZE_TINY
),
'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$my_thematic_id.$params.$url_token,
['class' => 'btn btn-default']
);
if (0 == api_get_session_id()) {
if ($thematic['display_order'] > 1) {
$toolbarThematic .= ' <a class="btn btn-default" href="'.api_get_self().'?action=moveup&'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$params.$url_token.'">'.
Display::return_icon('up.png', get_lang('Up'), '', ICON_SIZE_TINY).'</a>';
} else {
$toolbarThematic .= '<div class="btn btn-default">'.
Display::return_icon('up_na.png', '&nbsp;', '', ICON_SIZE_TINY).'</div>';
}
if (isset($thematic['max_thematic_item']) && $thematic['display_order'] < $thematic['max_thematic_item']) {
$toolbarThematic .= ' <a class="btn btn-default" href="'.api_get_self().'?action=movedown&a'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$params.$url_token.'">'.
Display::return_icon('down.png', get_lang('down'), '', ICON_SIZE_TINY).'</a>';
} else {
$toolbarThematic .= '<div class="btn btn-default">'.
Display::return_icon('down_na.png', '&nbsp;', '', ICON_SIZE_TINY).'</div>';
}
}
if (api_get_session_id() == $thematic['session_id']) {
$toolbarThematic .= Display::url(
Display::return_icon('pdf.png', get_lang('Export to PDF'), null, ICON_SIZE_TINY),
api_get_self().'?'.api_get_cidreq()."$url_token&".http_build_query([
'action' => 'export_single_thematic',
'thematic_id' => $my_thematic_id,
]),
['class' => 'btn btn-default']
);
$toolbarThematic .= Display::url(
Display::return_icon(
'export_to_documents.png',
get_lang('Export latest version of this page to Documents'),
[],
ICON_SIZE_TINY
),
api_get_self().'?'.api_get_cidreq().$url_token.'&'.http_build_query(
['action' => 'export_single_documents', 'thematic_id' => $my_thematic_id]
),
['class' => 'btn btn-default']
);
$toolbarThematic .= '<a class="btn btn-default" href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='
.$my_thematic_id.$params.$url_token.'">'
.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_TINY).'</a>';
$toolbarThematic .= '<a class="btn btn-default" onclick="javascript:if(!confirm(\''
.get_lang('Are you sure you want to delete')
.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='
.$my_thematic_id.$params.$url_token.'">'
.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_TINY).'</a>';
}
}
if (empty($thematic_plan_div[$thematic['id']])) {
$list['thematic_plan'] = null;
} else {
$list['thematic_plan'] = $thematic_plan_div[$thematic['id']];
}
$list['thematic_advance'] = isset($thematic_advance_data[$thematic['id']])
? $thematic_advance_data[$thematic['id']]
: null;
$list['last_done'] = $last_done_thematic_advance;
$list['toolbar'] = $toolbarThematic;
$listThematic[] = $list;
$tpl->assign('data', $listThematic);
} //End for
}
$thematicLayout = $tpl->get_template('course_progress/progress.html.twig');
$content = $tpl->fetch($thematicLayout);
$tpl->assign('content', $content);
} elseif ('thematic_add' == $action || 'thematic_edit' == $action) {
// Display form
$form = new FormValidator('thematic_add', 'POST', 'index.php?action=thematic_add&'.api_get_cidreq());
if ('thematic_edit' == $action) {
$form->addElement('header', '', get_lang('Edit thematic section'));
}
$form->addElement('hidden', 'sec_token', $token);
$form->addElement('hidden', 'action', $action);
if (!empty($thematic_id)) {
$form->addElement('hidden', 'thematic_id', $thematic_id);
}
if (api_get_configuration_value('save_titles_as_html')) {
$form->addHtmlEditor(
'title',
get_lang('Title'),
true,
false,
['ToolbarSet' => 'TitleAsHtml']
);
} else {
$form->addText('title', get_lang('Title'), true, ['size' => '50']);
}
$form->addHtmlEditor(
'content',
get_lang('Content'),
false,
false,
['ToolbarSet' => 'Basic', 'Height' => '150']
);
$form->addButtonSave(get_lang('Save'));
$show_form = true;
if (!empty($thematic_data)) {
if (api_get_session_id()) {
if ($thematic_data['session_id'] != api_get_session_id()) {
$show_form = false;
echo Display::return_message(get_lang('Sorry, you are not allowed to access this page, or maybe your connection has expired. Please click your browser\'s "Back" button or follow the link below to return to the previous page.'), 'error', false);
}
}
// set default values
$default['title'] = $thematic_data['title'];
$default['content'] = $thematic_data['content'];
$form->setDefaults($default);
}
// error messages
if (isset($error)) {
echo Display::return_message(get_lang('The form contains incorrect or incomplete data. Please check your input.'), 'error', false);
}
if ($show_form) {
$html = $form->returnForm();
}
} elseif ('thematic_import_select' == $action) {
// Create form to upload csv file.
$form = new FormValidator(
'thematic_import',
'POST',
'index.php?action=thematic_import&'.api_get_cidreq().$url_token
);
$form->addElement('header', get_lang('Import course progress'));
$form->addElement('file', 'file');
$form->addElement('checkbox', 'replace', null, get_lang('Delete all course progress'));
$form->addButtonImport(get_lang('Import'), 'SubmitImport');
$html = $form->returnForm();
}
$tpl->assign('actions', $toolbar);
if (!empty($html)) {
$tpl->assign('content', $html);
$thematicLayout = $tpl->get_template('course_progress/layout.tpl');
}
if (!empty($message) && !empty($total_average_of_advances)) {
$tpl->assign('message', $message);
$tpl->assign('score_progress', $total_average_of_advances);
}
$tpl->display_one_col_template();

@ -1,267 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/**
* View (MVC patter) for thematic advance.
*
* @author Christian Fasanando <christian1827@gmail.com>
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2011 Bug fixing
*/
// protect a course script
api_protect_course_script(true);
$tpl = new Template(get_lang('Thematic control'));
$toolbar = null;
$formLayout = null;
if ('thematic_advance_add' === $action || 'thematic_advance_edit' === $action) {
$header_form = get_lang('New thematic advance');
if ('thematic_advance_edit' === $action) {
$header_form = get_lang('Edit thematic advance');
}
// display form
$form = new FormValidator(
'thematic_advance',
'POST',
api_get_self().'?'.api_get_cidreq()
);
$form->addElement('header', $header_form);
//$form->addElement('hidden', 'thematic_advance_token',$token);
$form->addElement('hidden', 'action', $action);
if (!empty($thematic_advance_id)) {
$form->addElement('hidden', 'thematic_advance_id', $thematic_advance_id);
}
if (!empty($thematic_id)) {
$form->addElement('hidden', 'thematic_id', $thematic_id);
}
$radios = [];
$radios[] = $form->createElement(
'radio',
'start_date_type',
null,
get_lang('Start date taken from an attendance date'),
'1',
[
'onclick' => 'check_per_attendance(this)',
'id' => 'from_attendance',
]
);
$radios[] = $form->createElement(
'radio',
'start_date_type',
null,
get_lang('Custom start date'),
'2',
[
'onclick' => 'check_per_custom_date(this)',
'id' => 'custom_date',
]
);
$form->addGroup($radios, null, get_lang('Start date options'));
if (isset($thematic_advance_data['attendance_id']) &&
0 == $thematic_advance_data['attendance_id']) {
$form->addElement('html', '<div id="div_custom_datetime" style="display:block">');
} else {
$form->addElement('html', '<div id="div_custom_datetime" style="display:none">');
}
$form->addElement('DateTimePicker', 'custom_start_date', get_lang('Start Date'));
$form->addElement('html', '</div>');
if (isset($thematic_advance_data['attendance_id']) &&
0 == $thematic_advance_data['attendance_id']
) {
$form->addElement('html', '<div id="div_datetime_by_attendance" style="display:none">');
} else {
$form->addElement('html', '<div id="div_datetime_by_attendance" style="display:block">');
}
if (count($attendance_select) > 1) {
$form->addElement(
'select',
'attendance_select',
get_lang('Attendances'),
$attendance_select,
['id' => 'id_attendance_select', 'onchange' => 'datetime_by_attendance(this.value)']
);
} else {
$form->addElement(
'label',
get_lang('Attendances'),
'<strong><em>'.get_lang('There is no attendance sheet in this course').'</em></strong>'
);
}
$form->addElement('html', '<div id="div_datetime_attendance">');
if (!empty($calendar_select)) {
$form->addElement(
'select',
'start_date_by_attendance',
get_lang('Start Date'),
$calendar_select,
['id' => 'start_date_select_calendar']
);
}
$form->addElement('html', '</div>');
$form->addElement('html', '</div>');
$form->addText(
'duration_in_hours',
get_lang('Duration in hours'),
false,
[
'size' => '3',
'id' => 'duration_in_hours_element',
'autofocus' => 'autofocus',
]
);
$form->addHtmlEditor(
'content',
get_lang('Content'),
false,
false,
[
'ToolbarStartExpanded' => 'false',
'ToolbarSet' => 'Basic',
'Height' => '150',
]
);
if ('thematic_advance_add' == $action) {
$form->addButtonSave(get_lang('Save'));
} else {
$form->addButtonUpdate(get_lang('Save'));
}
$attendance_select_item_id = null;
if (count($attendance_select) > 1) {
$i = 1;
foreach ($attendance_select as $key => $attendance_select_item) {
if (2 == $i) {
$attendance_select_item_id = $key;
break;
}
$i++;
}
if (!empty($attendance_select_item_id)) {
$default['attendance_select'] = $attendance_select_item_id;
if ($thematic_advance_id) {
echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", "'.$thematic_advance_id.'"); </script>';
} else {
echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", 0); </script>';
}
}
}
$default['start_date_type'] = 1;
$default['custom_start_date'] = date('Y-m-d H:i:s', api_strtotime(api_get_local_time()));
$default['duration_in_hours'] = 1;
if (!empty($thematic_advance_data)) {
// set default values
$default['content'] = isset($thematic_advance_data['content']) ? $thematic_advance_data['content'] : null;
$default['duration_in_hours'] = isset($thematic_advance_data['duration']) ? $thematic_advance_data['duration'] : 1;
if (empty($thematic_advance_data['attendance_id'])) {
$default['start_date_type'] = 1;
$default['custom_start_date'] = null;
if (isset($thematic_advance_data['start_date'])) {
$default['custom_start_date'] = date(
'Y-m-d H:i:s',
api_strtotime(api_get_local_time($thematic_advance_data['start_date']))
);
}
} else {
$default['start_date_type'] = 1;
if (!empty($thematic_advance_data['start_date'])) {
$default['start_date_by_attendance'] = api_get_local_time($thematic_advance_data['start_date']);
}
$default['attendance_select'] = $thematic_advance_data['attendance_id'];
}
}
$form->setDefaults($default);
if ($form->validate()) {
$values = $form->exportValues();
if (isset($_POST['start_date_by_attendance'])) {
$values['start_date_by_attendance'] = $_POST['start_date_by_attendance'];
}
$thematic = new Thematic();
$thematic->set_thematic_advance_attributes(
isset($values['thematic_advance_id']) ? $values['thematic_advance_id'] : null,
$values['thematic_id'],
1 == $values['start_date_type'] && isset($values['attendance_select']) ? $values['attendance_select'] : 0,
$values['content'],
2 == $values['start_date_type'] ? $values['custom_start_date'] : $values['start_date_by_attendance'],
$values['duration_in_hours']
);
$affected_rows = $thematic->thematic_advance_save();
if ($affected_rows) {
// get last done thematic advance before move thematic list
$last_done_thematic_advance = $thematic->get_last_done_thematic_advance();
// update done advances with de current thematic list
if (!empty($last_done_thematic_advance)) {
$thematic->update_done_thematic_advances($last_done_thematic_advance);
}
}
$redirectUrlParams = 'course_progress/index.php?'.api_get_cidreq().'&'.
http_build_query([
'action' => 'thematic_advance_list',
'thematic_id' => $values['thematic_id'],
]);
Display::addFlash(Display::return_message(get_lang('Update successful')));
header('Location: '.api_get_path(WEB_CODE_PATH).$redirectUrlParams);
exit;
}
$formLayout = $form->returnForm();
} elseif ('thematic_advance_list' == $action) {
// thematic advance list
echo '<div class="actions">';
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=thematic_details">'.
Display::return_icon('back.png', get_lang("Back to"), '', ICON_SIZE_MEDIUM).'</a>';
if (api_is_allowed_to_edit(false, true)) {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=thematic_advance_add&thematic_id='.$thematic_id.'"> '.
Display::return_icon('add.png', get_lang('New thematic advance'), '', ICON_SIZE_MEDIUM).'</a>';
}
echo '</div>';
$table = new SortableTable(
'thematic_advance_list',
['Thematic', 'get_number_of_thematic_advances'],
['Thematic', 'get_thematic_advance_data']
);
//$table->set_additional_parameters($parameters);
$table->set_header(0, '', false, ['style' => 'width:20px;']);
$table->set_header(1, get_lang('Start Date'), false);
$table->set_header(2, get_lang('Duration in hours'), false, ['style' => 'width:80px;']);
$table->set_header(3, get_lang('Content'), false);
if (api_is_allowed_to_edit(null, true)) {
$table->set_header(
4,
get_lang('Detail'),
false,
['style' => 'text-align:center']
);
}
$table->display();
}
$tpl->assign('form_thematic', $formLayout);
$thematicLayout = $tpl->get_template('course_progress/thematic_advance.html.twig');
$content = $tpl->fetch($thematicLayout);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -28,487 +28,6 @@ class ThematicController
$this->view = new View($this->toolname);
}
/**
* This method is used for thematic control (update, insert or listing).
*
* @param string $action
* render to thematic.php
*/
public function thematic($action)
{
$thematic = new Thematic();
$data = [];
$check = Security::check_token('request');
$thematic_id = isset($_REQUEST['thematic_id']) ? intval($_REQUEST['thematic_id']) : null;
$displayHeader = !empty($_REQUEST['display']) && 'no_header' === $_REQUEST['display'] ? false : true;
$courseId = api_get_course_int_id();
if ($check) {
switch ($action) {
case 'thematic_add':
case 'thematic_edit':
// insert or update a thematic
if ("POST" == strtoupper($_SERVER['REQUEST_METHOD'])) {
if ('' !== trim($_POST['title'])) {
if (api_is_allowed_to_edit(null, true)) {
$id = isset($_POST['thematic_id']) ? $_POST['thematic_id'] : null;
$title = trim($_POST['title']);
$content = trim($_POST['content']);
$session_id = api_get_session_id();
$thematic->set_thematic_attributes($id, $title, $content, $session_id);
$last_id = $thematic->thematic_save();
if ('thematic_add' == $_POST['action']) {
$action = 'thematic_details';
$thematic_id = null;
if ($last_id) {
$data['last_id'] = $last_id;
}
} else {
$action = 'thematic_details';
$thematic_id = null;
}
Display::addFlash(Display::return_message(get_lang('Update successful')));
}
} else {
$error = true;
$data['error'] = $error;
$data['action'] = $_POST['action'];
$data['thematic_id'] = $_POST['thematic_id'];
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic');
$this->view->render();
}
}
break;
case 'thematic_copy':
// Copy a thematic to a session
$thematic->copy($thematic_id);
$thematic_id = null;
$action = 'thematic_details';
break;
case 'thematic_delete_select':
// Delete many thematics
if ("POST" == strtoupper($_SERVER['REQUEST_METHOD'])) {
if (api_is_allowed_to_edit(null, true)) {
$thematic_ids = $_POST['id'];
$thematic->delete($thematic_ids);
Display::addFlash(Display::return_message(get_lang('Deleted')));
}
$action = 'thematic_details';
}
break;
case 'thematic_delete':
// Delete a thematic
if (isset($thematic_id)) {
if (api_is_allowed_to_edit(null, true)) {
$thematic->delete($thematic_id);
Display::addFlash(Display::return_message(get_lang('Deleted')));
}
$thematic_id = null;
$action = 'thematic_details';
}
break;
case 'thematic_import_select':
break;
case 'thematic_import':
$csv_import_array = Import::csv_reader($_FILES['file']['tmp_name'], false);
if (isset($_POST['replace']) && $_POST['replace']) {
// Remove current thematic.
$list = $thematic->get_thematic_list();
foreach ($list as $i) {
$thematic->delete($i);
}
}
// Import the progress.
$current_thematic = null;
foreach ($csv_import_array as $key => $item) {
if (!$key) {
continue;
}
switch ($item[0]) {
case 'title':
$thematic->set_thematic_attributes(
null,
$item[1],
$item[2],
api_get_session_id()
);
$current_thematic = $thematic->thematic_save();
$description_type = 1;
break;
case 'plan':
$thematic->set_thematic_plan_attributes(
$current_thematic,
$item[1],
$item[2],
$description_type
);
$thematic->thematic_plan_save();
$description_type++;
break;
case 'progress':
$thematic->set_thematic_advance_attributes(
null,
$current_thematic,
0,
$item[3],
$item[1],
$item[2]
);
$thematic->thematic_advance_save();
break;
}
}
$action = 'thematic_details';
break;
case 'thematic_export':
$list = $thematic->get_thematic_list();
$csv = [];
$csv[] = ['type', 'data1', 'data2', 'data3'];
foreach ($list as $theme) {
$csv[] = ['title', strip_tags($theme['title']), strip_tags($theme['content'])];
$data = $thematic->get_thematic_plan_data($theme['id']);
if (!empty($data)) {
foreach ($data as $plan) {
if (empty($plan['description'])) {
continue;
}
$csv[] = [
'plan',
strip_tags($plan['title']),
strip_tags($plan['description']),
];
}
}
$data = $thematic->get_thematic_advance_by_thematic_id($theme['id']);
if (!empty($data)) {
foreach ($data as $advance) {
$csv[] = [
'progress',
strip_tags($advance['start_date']),
strip_tags($advance['duration']),
strip_tags($advance['content']),
];
}
}
}
Export::arrayToCsv($csv);
exit;
// Don't continue building a normal page.
return;
case 'export_documents':
case 'thematic_export_pdf':
$pdfOrientation = api_get_configuration_value('thematic_pdf_orientation');
$list = $thematic->get_thematic_list();
$item = [];
$listFinish = [];
foreach ($list as $theme) {
$dataPlan = $thematic->get_thematic_plan_data($theme['id']);
if (!empty($dataPlan)) {
foreach ($dataPlan as $plan) {
if (empty($plan['description'])) {
continue;
}
$item[] = [
'title' => $plan['title'],
'description' => $plan['description'],
];
}
$theme['thematic_plan'] = $item;
}
$dataAdvance = $thematic->get_thematic_advance_by_thematic_id($theme['id']);
if (!empty($dataAdvance)) {
$theme['thematic_advance'] = $dataAdvance;
}
$listFinish[] = $theme;
}
$view = new Template('', false, false, false, true, false, false);
$view->assign('data', $listFinish);
$template = $view->get_template('course_progress/pdf_general_thematic.tpl');
$format = 'portrait' !== $pdfOrientation ? 'A4-L' : 'A4-P';
$orientation = 'portrait' !== $pdfOrientation ? 'L' : 'P';
$fileName = get_lang('Thematic').'-'.api_get_local_time();
$title = get_lang('Thematic');
$signatures = ['Drh', 'Teacher', 'Date'];
if ('export_documents' === $action) {
$pdf = new PDF(
$format,
$orientation,
[
'filename' => $fileName,
'pdf_title' => $fileName,
'add_signatures' => $signatures,
]
);
$pdf->exportFromHtmlToDocumentsArea($view->fetch($template), $fileName, $courseId);
header('Location: '.api_get_self().'?'.api_get_cidreq());
exit;
}
Export::export_html_to_pdf(
$view->fetch($template),
[
'filename' => $fileName,
'pdf_title' => $title,
'add_signatures' => $signatures,
'format' => $format,
'orientation' => $orientation,
]
);
break;
case 'export_single_documents':
case 'export_single_thematic':
$theme = $thematic->get_thematic_list($thematic_id);
$plans = $thematic->get_thematic_plan_data($theme['id']);
$plans = array_filter(
$plans,
function ($plan) {
return !empty($plan['description']);
}
);
$advances = $thematic->get_thematic_advance_by_thematic_id($theme['id']);
$view = new Template('', false, false, false, true, false, false);
$view->assign('theme', $theme);
$view->assign('plans', $plans);
$view->assign('advances', $advances);
$template = $view->get_template('course_progress/pdf_single_thematic.tpl');
$pdfOrientation = api_get_configuration_value('thematic_pdf_orientation');
$format = 'portrait' !== $pdfOrientation ? 'A4-L' : 'A4-P';
$orientation = 'portrait' !== $pdfOrientation ? 'L' : 'P';
$title = get_lang('Thematic').'-'.$theme['title'];
$fileName = $title.'-'.api_get_local_time();
$signatures = ['Drh', 'Teacher', 'Date'];
if ('export_single_documents' === $action) {
$pdf = new PDF(
$format,
$orientation,
[
'filename' => $fileName,
'pdf_title' => $fileName,
'add_signatures' => $signatures,
]
);
$pdf->exportFromHtmlToDocumentsArea(
$view->fetch($template),
$fileName,
$courseId
);
header('Location: '.api_get_self().'?'.api_get_cidreq());
exit;
}
Export::export_html_to_pdf(
$view->fetch($template),
[
'filename' => $fileName,
'pdf_title' => $title,
'add_signatures' => $signatures,
'format' => $format,
'orientation' => $orientation,
]
);
break;
case 'moveup':
$thematic->move_thematic('up', $thematic_id);
$action = 'thematic_details';
$thematic_id = null;
break;
case 'movedown':
$thematic->move_thematic('down', $thematic_id);
$action = 'thematic_details';
$thematic_id = null;
break;
}
Security::clear_token();
} else {
$action = 'thematic_details';
$thematic_id = null;
}
if (isset($thematic_id)) {
$data['thematic_data'] = $thematic->get_thematic_list($thematic_id);
$data['thematic_id'] = $thematic_id;
}
if ('thematic_details' == $action) {
if (isset($thematic_id)) {
$thematic_data_result = $thematic->get_thematic_list($thematic_id);
if (!empty($thematic_data_result)) {
$thematic_data[$thematic_id] = $thematic_data_result;
}
$data['total_average_of_advances'] = $thematic->get_average_of_advances_by_thematic($thematic_id);
} else {
$thematic_data = $thematic->get_thematic_list(null, api_get_course_id(), api_get_session_id());
$data['max_thematic_item'] = $thematic->get_max_thematic_item();
$data['last_done_thematic_advance'] = $thematic->get_last_done_thematic_advance();
$data['total_average_of_advances'] = $thematic->get_total_average_of_thematic_advances();
}
// Second column
$thematic_plan_data = $thematic->get_thematic_plan_data();
// Third column
$thematic_advance_data = $thematic->get_thematic_advance_list(null, null, true);
$data['thematic_plan_div'] = $thematic->get_thematic_plan_array($thematic_plan_data);
$data['thematic_advance_div'] = $thematic->get_thematic_advance_div($thematic_advance_data);
$data['thematic_plan_data'] = $thematic_plan_data;
$data['thematic_advance_data'] = $thematic_advance_data;
$data['thematic_data'] = $thematic_data;
}
$data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title();
$data['action'] = $action;
$layoutName = $displayHeader ? 'layout' : 'layout_no_header';
// render to the view
$this->view->set_data($data);
$this->view->set_layout($layoutName);
$this->view->set_template('thematic');
$this->view->render();
}
/**
* This method is used for thematic plan control (update, insert or listing).
*
* @param string $action
* render to thematic_plan.php
*/
public function thematic_plan($action)
{
$thematic = new Thematic();
$data = [];
if ("POST" == strtoupper($_SERVER['REQUEST_METHOD'])) {
if (isset($_POST['action']) &&
('thematic_plan_add' == $_POST['action'] || 'thematic_plan_edit' == $_POST['action'])
) {
if (isset($_POST['title'])) {
$token = Session::read('thematic_plan_token');
if ($_POST['thematic_plan_token'] == $token) {
if (api_is_allowed_to_edit(null, true)) {
$title_list = $_REQUEST['title'];
$description_list = $_REQUEST['description'];
$description_type = $_REQUEST['description_type'];
for ($i = 1; $i < count($title_list) + 1; $i++) {
$thematic->set_thematic_plan_attributes(
$_REQUEST['thematic_id'],
$title_list[$i],
$description_list[$i],
$description_type[$i]
);
$thematic->thematic_plan_save();
}
$saveRedirect = api_get_path(WEB_PATH).'main/course_progress/index.php?';
$saveRedirect .= api_get_cidreq().'&';
if (isset($_REQUEST['add_item'])) {
$thematic->set_thematic_plan_attributes(
$_REQUEST['thematic_id'],
'',
'',
$i
);
$thematic->thematic_plan_save();
$saveRedirect .= http_build_query([
'action' => 'thematic_plan_list',
'thematic_id' => $_REQUEST['thematic_id'],
]);
} else {
$saveRedirect .= 'thematic_plan_save_message=ok';
Session::erase('thematic_plan_token');
$data['message'] = 'ok';
}
header("Location: $saveRedirect");
exit;
}
$data['action'] = 'thematic_plan_list';
}
} else {
$error = true;
$action = $_POST['action'];
$data['error'] = $error;
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data(
$_POST['thematic_id'],
$_POST['description_type']
);
$data['thematic_id'] = $_POST['thematic_id'];
$data['description_type'] = $_POST['description_type'];
$data['action'] = $action;
$data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title();
$data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon();
$data['default_thematic_plan_question'] = $thematic->get_default_question();
$data['next_description_type'] = $thematic->get_next_description_type($_POST['thematic_id']);
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic_plan');
$this->view->render();
}
}
}
$thematic_id = intval($_GET['thematic_id']);
if ('thematic_plan_list' == $action) {
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id);
}
$description_type = isset($_GET['description_type']) ? intval($_GET['description_type']) : null;
if (!empty($thematic_id) && !empty($description_type)) {
if ('thematic_plan_delete' === $action) {
if (api_is_allowed_to_edit(null, true)) {
$thematic->thematic_plan_destroy(
$thematic_id,
$description_type
);
}
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id);
$action = 'thematic_plan_list';
} else {
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id, $description_type);
}
$data['thematic_id'] = $thematic_id;
$data['description_type'] = $description_type;
} elseif (!empty($thematic_id) && 'thematic_plan_list' === $action) {
$data['thematic_plan_data'] = $thematic->get_thematic_plan_data($thematic_id);
$data['thematic_id'] = $thematic_id;
}
$data['thematic_id'] = $thematic_id;
$data['action'] = $action;
$data['default_thematic_plan_title'] = $thematic->get_default_thematic_plan_title();
$data['default_thematic_plan_icon'] = $thematic->get_default_thematic_plan_icon();
$data['next_description_type'] = $thematic->get_next_description_type($thematic_id);
$data['default_thematic_plan_question'] = $thematic->get_default_question();
$data['thematic_data'] = $thematic->get_thematic_list($thematic_id);
// render to the view
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('thematic_plan');
$this->view->render();
exit;
}
/**
* This method is used for thematic advance control (update, insert or listing)
* render to thematic_advance.php.
@ -522,27 +41,13 @@ class ThematicController
$data = [];
$displayHeader = !empty($_REQUEST['display']) && 'no_header' === $_REQUEST['display'] ? false : true;
// get data for attendance input select
$attendance_list = $attendance->get_attendances_list();
$attendance_select = [];
$attendance_select[0] = get_lang('Select an attendance');
foreach ($attendance_list as $attendance_id => $attendance_data) {
$attendance_select[$attendance_id] = $attendance_data['name'];
}
$thematic_id = intval($_REQUEST['thematic_id']);
$thematic_advance_id = isset($_REQUEST['thematic_advance_id']) ? (int) $_REQUEST['thematic_advance_id'] : null;
$thematic_advance_data = [];
switch ($action) {
case 'thematic_advance_delete':
if (!empty($thematic_advance_id)) {
if (api_is_allowed_to_edit(null, true)) {
$thematic->thematic_advance_destroy($thematic_advance_id);
}
Display::addFlash(Display::return_message(get_lang('Deleted')));
header('Location: index.php');
exit;
}
break;
case 'thematic_advance_list':
if (!api_is_allowed_to_edit(null, true)) {

@ -37,9 +37,7 @@ if (isset($message) && 'ok' == $message) {
if ('thematic_plan_list' === $action) {
$token = Security::get_token();
Session::write('thematic_plan_token', $token);
$form = new FormValidator(
'thematic_plan_add',
'POST',
@ -100,81 +98,11 @@ if ('thematic_plan_list' === $action) {
]);
$formLayout = $form->returnForm();
} elseif ('thematic_plan_add' == $action || 'thematic_plan_edit' == $action) {
if ($description_type >= ADD_THEMATIC_PLAN) {
$header_form = get_lang('Other');
} else {
$header_form = $default_thematic_plan_title[$description_type];
}
if (!$error) {
$token = md5(uniqid(rand(), true));
Session::write('thematic_plan_token', $token);
}
// display form
$form = new FormValidator(
'thematic_plan_add',
'POST',
'index.php?action=thematic_plan_edit&thematic_id='.$thematic_id.'&'.api_get_cidreq(),
'',
'style="width: 100%;"'
);
$form->addElement('hidden', 'action', $action);
$form->addElement('hidden', 'thematic_plan_token', $token);
if (!empty($thematic_id)) {
$form->addElement('hidden', 'thematic_id', $thematic_id);
}
if (!empty($description_type)) {
$form->addElement('hidden', 'description_type', $description_type);
}
$form->addText('title', get_lang('Title'), true, ['size' => '50']);
$form->addHtmlEditor(
'description',
get_lang('Description'),
false,
false,
[
'ToolbarStartExpanded' => 'false',
'ToolbarSet' => 'Basic',
'Width' => '80%',
'Height' => '150',
]
);
$form->addButtonSave(get_lang('Save'));
}
if ($description_type < ADD_THEMATIC_PLAN) {
$default['title'] = $default_thematic_plan_title[$description_type];
}
if (!empty($thematic_plan_data)) {
// set default values
$default['title'] = $thematic_plan_data[0]['title'];
$default['description'] = $thematic_plan_data[0]['description'];
}
$form->setDefaults($default);
if (isset($default_thematic_plan_question[$description_type])) {
$message = '<strong>'.get_lang('Help').'</strong><br />';
$message .= $default_thematic_plan_question[$description_type];
Display::addFlash(Display::return_message($message, 'normal', false));
}
// error messages
if ($error) {
Display::addFlash(
Display::return_message(
get_lang('The form contains incorrect or incomplete data. Please check your input.'),
'error',
false
)
);
}
$formLayout = $form->returnForm();
}
$tpl->assign('title_thematic', $thematic_data['title']);
$tpl->assign('content_thematic', $thematic_data['content']);
$tpl->assign('form_thematic', $formLayout);
$thematicLayout = $tpl->get_template('course_progress/thematic_plan.tpl');
$content = $tpl->fetch($thematicLayout);
$tpl->assign('content', $content);

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**

@ -1,6 +1,13 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Resource\ResourceLink;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CThematic;
use Chamilo\CourseBundle\Entity\CThematicAdvance;
use Chamilo\CourseBundle\Entity\CThematicPlan;
/**
* Provides functions for thematic option inside attendance tool.
* It's also used like model to thematic_controller (MVC pattern)
@ -297,7 +304,7 @@ class Thematic
}
$condition = " WHERE active = 1 $condition_session ";
}
$sql = "SELECT *
$sql = "SELECT *
FROM $tbl_thematic $condition AND c_id = $course_id
ORDER BY display_order ";
@ -322,7 +329,6 @@ class Thematic
*/
public function thematic_save()
{
$_course = api_get_course_info();
// definition database table
$tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
@ -331,36 +337,70 @@ class Thematic
$title = $this->thematic_title;
$content = $this->thematic_content;
$session_id = intval($this->session_id);
$user_id = api_get_user_id();
// get the maximum display order of all the glossary items
$max_thematic_item = $this->get_max_thematic_item(false);
$repo = Container::getThematicRepository();
$em = $repo->getEntityManager();
if (empty($id)) {
$thematic = new CThematic();
$thematic
->setTitle($title)
->setContent($content)
->setActive(1)
->setCId($this->course_int_id)
->setDisplayOrder($max_thematic_item + 1)
->setSessionId($session_id)
;
$em->persist($thematic);
$repo->addResourceToCourse(
$thematic,
ResourceLink::VISIBILITY_PUBLISHED,
api_get_user_entity(api_get_user_id()),
api_get_course_entity(),
api_get_session_entity(),
api_get_group_entity()
);
$em->flush();
// insert
$params = [
/*$params = [
'c_id' => $this->course_int_id,
'title' => $title,
'content' => $content,
'active' => 1,
'display_order' => intval($max_thematic_item) + 1,
'session_id' => $session_id,
];
$last_id = Database::insert($tbl_thematic, $params);
];*/
$last_id = $thematic->getIid();
if ($last_id) {
$sql = "UPDATE $tbl_thematic SET id = iid WHERE iid = $last_id";
Database::query($sql);
api_item_property_update(
/*api_item_property_update(
$_course,
'thematic',
$last_id,
"ThematicAdded",
'ThematicAdded',
$user_id
);
);*/
}
} else {
$thematic = $repo->find($id);
if ($thematic) {
$thematic
->setTitle($title)
->setContent($content)
;
$em->persist($thematic);
$em->flush();
}
// Update
$params = [
/*$params = [
'title' => $title,
'content' => $content,
'session_id' => $session_id,
@ -379,12 +419,12 @@ class Thematic
$_course,
'thematic',
$last_id,
"ThematicUpdated",
'ThematicUpdated',
$user_id
);
);*/
}
return $last_id;
return $thematic;
}
/**
@ -411,13 +451,13 @@ class Thematic
$affected_rows += Database::affected_rows($result);
if (!empty($affected_rows)) {
// update row item property table
api_item_property_update(
/*api_item_property_update(
$_course,
'thematic',
$id,
"ThematicDeleted",
'ThematicDeleted',
$user_id
);
);*/
}
}
} else {
@ -428,13 +468,13 @@ class Thematic
$affected_rows = Database::affected_rows($result);
if (!empty($affected_rows)) {
// update row item property table
api_item_property_update(
/*api_item_property_update(
$_course,
'thematic',
$thematic_id,
"ThematicDeleted",
'ThematicDeleted',
$user_id
);
);*/
}
}
@ -500,7 +540,7 @@ class Thematic
$course_id = api_get_course_int_id();
$thematic_id = (int) $thematic_id;
$sql = "SELECT COUNT(id) AS total_number_of_items
$sql = "SELECT COUNT(id) AS total_number_of_items
FROM $table
WHERE c_id = $course_id AND thematic_id = $thematic_id ";
$res = Database::query($sql);
@ -564,7 +604,7 @@ class Thematic
$actions .= '<a onclick="javascript:if(!confirm(\''.get_lang('Are you sure you want to delete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_advance_delete&thematic_id='.$thematic_id.'&thematic_advance_id='.$thematic_advance[0].'">'.
Display::return_icon('delete.png', get_lang('Delete'), '', 22).'</a></center>';
$data[] = [$i, $thematic_advance[1], $thematic_advance[2], $thematic_advance[3], $actions];
$i++;
++$i;
}
}
}
@ -585,6 +625,17 @@ class Thematic
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$repo = Container::getThematicAdvanceRepository();
$courseEntity = api_get_course_entity($course_id);
$sessionEntity = api_get_session_entity(api_get_session_id());
$qb = $repo->getResourcesByCourse($courseEntity, $sessionEntity);
$qb->andWhere($qb->expr()->eq('resource.thematic', $thematic_id));
return $qb->getQuery()->getResult();
// set current course
$table = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
$thematic_id = (int) $thematic_id;
@ -614,86 +665,26 @@ class Thematic
return $data;
}
/**
* @param array $data
*
* @return array
*/
public function get_thematic_advance_div($data)
{
$return_array = [];
$uinfo = api_get_user_info();
foreach ($data as $thematic_id => $thematic_advance_data) {
foreach ($thematic_advance_data as $key => $thematic_advance) {
$session_star = '';
if (api_is_allowed_to_edit(null, true)) {
if (0 != $thematic_advance['session_id']) {
$session_star = api_get_session_image(api_get_session_id(), $uinfo['status']);
}
}
// DATE_TIME_FORMAT_LONG
$thematic_advance_item = '<div><strong>'.
api_convert_and_format_date($thematic_advance['start_date'], DATE_TIME_FORMAT_LONG).
$session_star.'</strong></div>';
$thematic_advance_item .= '<div>'.$thematic_advance['duration'].' '.get_lang('h').'</div>';
$thematic_advance_item .= '<div>'.Security::remove_XSS($thematic_advance['content'], STUDENT).'</div>';
$return_array[$thematic_id][$thematic_advance['id']] = $thematic_advance_item;
}
}
return $return_array;
}
/**
* @param array $data
*
* @return array
*/
public function get_thematic_plan_array($data)
{
$final_return = [];
$uinfo = api_get_user_info();
foreach ($data as $thematic_id => $thematic_plan_data) {
$new_thematic_plan_data = [];
foreach ($thematic_plan_data as $thematic_item) {
$thematic_simple_list[] = $thematic_item['description_type'];
$new_thematic_plan_data[$thematic_item['description_type']] = $thematic_item;
}
if (!empty($thematic_simple_list)) {
foreach ($thematic_simple_list as $item) {
$default_thematic_plan_title[$item] = $new_thematic_plan_data[$item]['title'];
}
}
$session_star = '';
$return = [];
if (!empty($default_thematic_plan_title)) {
foreach ($default_thematic_plan_title as $id => $title) {
//avoid others
if ('Others' == $title && empty($data[$thematic_id][$id]['description'])) {
continue;
}
if (!empty($data[$thematic_id][$id]['title']) &&
!empty($data[$thematic_id][$id]['description'])
) {
if (api_is_allowed_to_edit(null, true)) {
if (0 != $data[$thematic_id][$id]['session_id']) {
$session_star = api_get_session_image(api_get_session_id(), $uinfo['status']);
}
}
public function getThematicAdvance(
$id
) {
$repo = Container::getThematicAdvanceRepository();
$return[$id]['title'] = Security::remove_XSS($data[$thematic_id][$id]['title'], STUDENT).$session_star;
$return[$id]['description'] = Security::remove_XSS($data[$thematic_id][$id]['description'], STUDENT);
}
}
}
$final_return[$thematic_id] = $return;
$courseEntity = api_get_course_entity($courseId);
$sessionEntity = null;
if ($sessionId) {
$sessionEntity = api_get_session_entity($sessionId);
/*$list = api_get_item_property_by_tool(
'thematic_advance',
$course_info['code'],
api_get_session_id()
);
foreach ($list as $value) {
$elements[$value['ref']] = $value;
}*/
}
return $final_return;
return $repo->find($id);
}
/**
@ -726,18 +717,27 @@ class Thematic
WHERE c_id = $course_id $condition
ORDER BY start_date ";
$repo = Container::getThematicAdvanceRepository();
$courseEntity = api_get_course_entity($course_id);
$sessionEntity = null;
$elements = [];
if ($force_session_id) {
$list = api_get_item_property_by_tool(
$sessionEntity = api_get_session_entity(api_get_session_id());
/*$list = api_get_item_property_by_tool(
'thematic_advance',
$course_info['code'],
api_get_session_id()
);
foreach ($list as $value) {
$elements[$value['ref']] = $value;
}
}*/
}
$qb = $repo->getResourcesByCourse($courseEntity, $sessionEntity);
return $qb->getQuery()->getResult();
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
if (!empty($thematic_advance_id)) {
@ -786,31 +786,53 @@ class Thematic
$duration = intval($this->duration);
$user_id = api_get_user_id();
$repo = Container::getThematicAdvanceRepository();
$em = $repo->getEntityManager();
$advance = $repo->find($id);
$last_id = null;
if (empty($id)) {
// Insert
$params = [
'c_id' => $this->course_int_id,
'thematic_id' => $thematic_id,
'attendance_id' => $attendance_id,
'content' => $content,
'start_date' => api_get_utc_datetime($start_date),
'duration' => $duration,
'done_advance' => 0,
];
$last_id = Database::insert($table, $params);
if (null === $advance) {
$repoThematic = Container::getThematicRepository();
$thematic = $repoThematic->find($thematic_id);
$attendanceRepo = Container::getAttendanceRepository();
$attendance = $attendanceRepo->find($attendance_id);
$advance = new CThematicAdvance();
$advance
->setCId($this->course_int_id)
->setContent($content)
->setThematic($thematic)
->setAttendance($attendance)
->setStartDate(api_get_utc_datetime($start_date, true, true))
->setDuration($duration)
;
$em->persist($advance);
$repo->addResourceToCourse(
$advance,
ResourceLink::VISIBILITY_PUBLISHED,
api_get_user_entity(api_get_user_id()),
api_get_course_entity(),
api_get_session_entity(),
api_get_group_entity()
);
$em->flush();
$last_id = $advance->getIid();
if ($last_id) {
$sql = "UPDATE $table SET id = iid WHERE iid = $last_id";
Database::query($sql);
api_item_property_update(
/*api_item_property_update(
$_course,
'thematic_advance',
$last_id,
'ThematicAdvanceAdded',
$user_id
);
);*/
}
} else {
$params = [
@ -890,18 +912,33 @@ class Thematic
$tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
$course_id = api_get_course_int_id();
$repo = Container::getThematicPlanRepository();
$courseEntity = api_get_course_entity();
$sessionEntity = api_get_session_entity(api_get_session_id());
$qb = $repo->getResourcesByCourse($courseEntity, $sessionEntity);
$result = $qb->getQuery()->getResult();
//var_dump(count($result));
$data = [];
$condition = '';
if (isset($thematic_id)) {
$thematic_id = intval($thematic_id);
$condition .= " AND thematic_id = $thematic_id ";
//var_dump($thematic_id, $description_type);
if (!empty($thematic_id)) {
$qb->andWhere($qb->expr()->eq('resource.thematic', $thematic_id));
//$thematic_id = intval($thematic_id);
//$condition .= " AND thematic_id = $thematic_id ";
}
if (isset($description_type)) {
$description_type = intval($description_type);
$condition .= " AND description_type = $description_type ";
if (!empty($description_type)) {
$qb->andWhere($qb->expr()->eq('resource.descriptionType', $description_type));
//$condition .= " AND description_type = $description_type ";
}
$items_from_course = api_get_item_property_by_tool(
return $qb->getQuery()->getResult();
/*$items_from_course = api_get_item_property_by_tool(
'thematic_plan',
api_get_course_id(),
0
@ -910,12 +947,12 @@ class Thematic
'thematic_plan',
api_get_course_id(),
api_get_session_id()
);
);*/
$thematic_plan_complete_list = [];
$thematic_plan_id_list = [];
if (!empty($items_from_course)) {
/*if (!empty($items_from_course)) {
foreach ($items_from_course as $item) {
$thematic_plan_id_list[] = $item['ref'];
$thematic_plan_complete_list[$item['ref']] = $item;
@ -927,18 +964,19 @@ class Thematic
$thematic_plan_id_list[] = $item['ref'];
$thematic_plan_complete_list[$item['ref']] = $item;
}
}
}*/
if (!empty($thematic_plan_id_list)) {
$sql = "SELECT
tp.id, thematic_id, tp.title, description, description_type, t.session_id
FROM $tbl_thematic_plan tp
INNER JOIN $tbl_thematic t
INNER JOIN $tbl_thematic t
ON (t.id = tp.thematic_id AND t.c_id = tp.c_id)
WHERE
t.c_id = $course_id AND
tp.c_id = $course_id
$condition AND
tp.id IN (".implode(', ', $thematic_plan_id_list).") ";
tp.id IN (".implode(', ', $thematic_plan_id_list).') ';
$rs = Database::query($sql);
@ -983,7 +1021,8 @@ class Thematic
$description_type = intval($this->thematic_plan_description_type);
$user_id = api_get_user_id();
$course_id = api_get_course_int_id();
$list = api_get_item_property_by_tool(
/*$list = api_get_item_property_by_tool(
'thematic_plan',
api_get_course_id(),
api_get_session_id()
@ -995,91 +1034,93 @@ class Thematic
}
$condition = '';
if (!empty($elements_to_show)) {
$condition = "AND id IN (".implode(',', $elements_to_show).") ";
}
$condition = 'AND id IN ('.implode(',', $elements_to_show).') ';
}*/
$repo = Container::getThematicPlanRepository();
$criteria = [
'cId' => $course_id,
'thematic' => $thematic_id,
'descriptionType' => $description_type,
];
$em = $repo->getEntityManager();
/** @var CThematicPlan $plan */
$plan = $repo->findOneBy($criteria);
// check thematic plan type already exists
$sql = "SELECT id FROM $tbl_thematic_plan
/*$sql = "SELECT id FROM $tbl_thematic_plan
WHERE
c_id = $course_id AND
thematic_id = $thematic_id AND
description_type = '$description_type'";
$rs = Database::query($sql);
$affected_rows = 0;
if (Database::num_rows($rs) > 0) {
$row_thematic_plan = Database::fetch_array($rs);
$thematic_plan_id = $row_thematic_plan['id'];
$update = false;
if (in_array($thematic_plan_id, $elements_to_show)) {
$update = true;
}
if ($update) {
// update
$params = [
'title' => $title,
'description' => $description,
];
Database::update(
$tbl_thematic_plan,
$params,
['c_id = ? AND id = ?' => [$course_id, $thematic_plan_id]]
);
api_item_property_update(
$_course,
'thematic_plan',
$thematic_plan_id,
'ThematicPlanUpdated',
$user_id
);
} else {
// insert
$params = [
'c_id' => $this->course_int_id,
'thematic_id' => $thematic_id,
'title' => $title,
'description' => $description,
'description_type' => $description_type,
];
$last_id = Database::insert($tbl_thematic_plan, $params);
if ($last_id) {
$sql = "UPDATE $tbl_thematic_plan SET id = iid WHERE iid = $last_id";
Database::query($sql);
api_item_property_update(
$_course,
'thematic_plan',
$last_id,
'ThematicPlanAdded',
$user_id
);
}
}
} else {
// insert
$params = [
'c_id' => $this->course_int_id,
'thematic_id' => $thematic_id,
$rs = Database::query($sql);*/
if ($plan) {
$plan
->setTitle($title)
->setDescription($description)
;
$em->persist($plan);
$em->flush();
// update
/*$params = [
'title' => $title,
'description' => $description,
'description_type' => $description_type,
];
$last_id = Database::insert($tbl_thematic_plan, $params);
Database::update(
$tbl_thematic_plan,
$params,
['c_id = ? AND id = ?' => [$course_id, $thematic_plan_id]]
);
if ($last_id) {
$sql = "UPDATE $tbl_thematic_plan SET id = iid WHERE iid = $last_id";
api_item_property_update(
$_course,
'thematic_plan',
$thematic_plan_id,
'ThematicPlanUpdated',
$user_id
);*/
} else {
$thematic = Container::getThematicRepository()->find($thematic_id);
$plan = new CThematicPlan();
$plan
->setTitle($title)
->setDescription($description)
->setCId($this->course_int_id)
->setThematic($thematic)
->setDescriptionType($description_type)
;
$em->persist($plan);
$repo->addResourceToCourse(
$plan,
ResourceLink::VISIBILITY_PUBLISHED,
api_get_user_entity(api_get_user_id()),
api_get_course_entity(),
api_get_session_entity(),
api_get_group_entity()
);
$em->flush();
if ($plan && $plan->getIid()) {
$id = $plan->getIid();
$sql = "UPDATE $tbl_thematic_plan SET id = iid WHERE iid = $id";
Database::query($sql);
/*
api_item_property_update(
$_course,
'thematic_plan',
$last_id,
'ThematicPlanAdded',
$user_id
);
);*/
}
}
return $affected_rows;
return true;
}
/**
@ -1218,7 +1259,7 @@ class Thematic
// update done thematic for previous advances ((done_advance = 1))
$upd = "UPDATE $table SET
done_advance = 1
WHERE c_id = $course_id AND id = ".$thematic_advance['id']." ";
WHERE c_id = $course_id AND id = ".$thematic_advance['id'].' ';
$result = Database::query($upd);
$my_affected_rows = Database::affected_rows($result);
$affected_rows += $my_affected_rows;
@ -1227,7 +1268,7 @@ class Thematic
$_course,
'thematic_advance',
$thematic_advance['id'],
"ThematicAdvanceDone",
'ThematicAdvanceDone',
$user_id
);
//}
@ -1245,7 +1286,7 @@ class Thematic
$diff = array_diff($all, $a_thematic_advance_ids);
if (!empty($diff)) {
$upd = "UPDATE $table SET done_advance = 0
WHERE c_id = $course_id AND id IN(".implode(',', $diff).") ";
WHERE c_id = $course_id AND id IN(".implode(',', $diff).') ';
Database::query($upd);
}
@ -1344,7 +1385,7 @@ class Thematic
}
if (!empty($a_thematic_advance_ids)) {
for ($i = 0; $i < $offset; $i++) {
for ($i = 0; $i < $offset; ++$i) {
$next_advance_not_done = array_shift($a_thematic_advance_ids);
}
$next_advance_not_done = intval($next_advance_not_done);
@ -1417,11 +1458,13 @@ class Thematic
// get all done advances by thematic
$advances = [];
$count_done_advances = 0;
/** @var CThematicAdvance $thematic_advance */
foreach ($thematic_advance_data as $thematic_advance) {
if (1 == $thematic_advance['done_advance']) {
if (1 == $thematic_advance->getDoneAdvance()) {
$count_done_advances++;
}
$advances[] = $thematic_advance['done_advance'];
$advances[] = $thematic_advance->getDoneAdvance();
}
// calculate average by thematic
$count_total_advances = count($advances);

@ -36,19 +36,20 @@
</div>
</td>
<td>
{% if tutor %}
<div class="float-right">
<a title="{{ 'EditThematicPlan' | get_lang }}" href="index.php?{{ _p.web_cid_query }}&origin=thematic_details&action=thematic_plan_list&thematic_id={{ item.id }}&width=700&height=500'" class="btn btn-outline-secondary btn-sm">
<i class="fas fa-pencil-alt"></i>
</a>
</div>
{% endif %}
<div class="thematic_plan_{{ item.id }}">
{% if tutor %}
<div class="btn-group">
<a title="{{ 'Edit thematic section' | trans }}"
href="index.php?{{ course_url_params }}&origin=thematic_details&action=thematic_plan_list&thematic_id={{ item.id }}&width=700&height=500"
class="btn btn-outline-secondary btn-sm">
<i class="fas fa-pencil-alt"></i>
</a>
</div>
{% endif %}
{% if item.thematic_plan is empty %}
<div class="alert-thematic">
<div class="alert alert-info" role="alert">{{ 'StillDoNotHaveAThematicPlan' | get_lang }}</div>
<div class="alert alert-info" role="alert">{{ 'StillDoNotHaveAThematicPlan' | trans }}</div>
</div>
{% else %}
{% for subitem in item.thematic_plan %}
@ -59,58 +60,67 @@
</div>
</td>
<td>
<div class="thematic-advance">
{% if tutor %}
<div class="float-right">
<a title="{{ 'NewThematicAdvance' | get_lang }}" href="index.php?{{ _p.web_cid_query }}&action=thematic_advance_add&thematic_id={{ item.id }}" class="btn btn-outline-secondary btn-sm">
<i class="fa fa-plus-circle" aria-hidden="true"></i>
</a>
</div>
<div class="btn-group">
<a title="{{ 'New thematic advance' | trans }}"
href="index.php?{{ course_url_params }}&action=thematic_advance_add&thematic_id={{ item.id }}"
class="btn btn-outline-secondary btn-sm">
<i class="fa fa-plus-circle" aria-hidden="true"></i>
</a>
</div>
{% endif %}
<div class="thematic-advance">
<table width="100%" class="table">
{% if item.thematic_advance is not empty %}
{% for advance in item.thematic_advance %}
<tr>
<td style="width: 90%" class="thematic_advance_content" id="thematic_advance_content_id_{{ advance.id }}">
<div id="thematic_advance_{{ advance.id }}">
<strong>{{ advance.start_date | format_date }}</strong>
{{ advance.content }}
</div>
{% if tutor %}
<div class="toolbar-actions">
<div id="thematic_advance_tools_{{ advance.id }}" class="thematic_advance_actions">
<div class="btn-group btn-group-sm">
<a class="btn btn-default btn-sm" href="index.php?{{ _p.web_cid_query }}&action=thematic_advance_edit&thematic_id={{ item.id }}&thematic_advance_id={{ advance.id }}" title="{{ 'Edit' |get_lang }}">
<i class="fa fa-pencil" aria-hidden="true"></i>
</a>
<a class="btn btn-default btn-sm" onclick="javascript:if(!confirm('{{ 'AreYouSureToDelete' | get_lang }}')) return false;" href="index.php?{{ _p.web_cid_query }}&action=thematic_advance_delete&thematic_id={{ item.id }}&thematic_advance_id={{ advance.id }}" title="{{ 'Delete' |get_lang }}">
<i class="fa fa-trash" aria-hidden="true"></i>
</a>
{% for advance in item.thematic_advance %}
<tr>
<td style="width: 90%" class="thematic_advance_content" id="thematic_advance_content_id_{{ advance.id }}">
<div id="thematic_advance_{{ advance.id }}">
<strong>{{ advance.start_date }}</strong>
{{ advance.content }}
</div>
{% if tutor %}
<div class="toolbar-actions">
<div id="thematic_advance_tools_{{ advance.id }}" class="thematic_advance_actions">
<div class="btn-group btn-group-sm">
<a class="btn btn-default btn-sm"
href="index.php?{{ course_url_params }}&action=thematic_advance_edit&thematic_id={{ item.id }}&thematic_advance_id={{ advance.id }}" title="{{ 'Edit' |trans }}">
<i class="fa fa-pencil" aria-hidden="true"></i>
</a>
<a class="btn btn-default btn-sm"
onclick="javascript:if(!confirm('{{ 'Are you sure to delete' | trans }}')) return false;"
href="index.php?{{ course_url_params }}&action=thematic_advance_delete&thematic_id={{ item.id }}&thematic_advance_id={{ advance.id }}" title="{{ 'Delete' |trans }}">
<i class="fa fa-trash" aria-hidden="true"></i>
</a>
</div>
</div>
</div>
{% endif %}
</div>
</div>
{% endif %}
</div>
</td>
{% if advance.done_advance == 1 %}
{% set color = "background-color:#E5EDF9;" %}
{% else %}
{% set color = "background-color:#FFFFFF;" %}
{% endif %}
{% if tutor %}
<td style="width: 10%; {{ color }}" id="td_done_thematic_{{ advance.id }}">
{% set check = "" %}
{% if item.last_done == advance.id %}
{% set check = "checked" %}
{% endif %}
<input type="radio" class="done_thematic" id="done_thematic_{{ advance.id }}" name="done_thematic" value="{{ advance.id }}" {{ check }} onclick="update_done_thematic_advance(this.value)">
{% else %}
</td>
{% endif %}
</tr>
{% endfor %}
</td>
{% if advance.done_advance == 1 %}
{% set color = "background-color:#E5EDF9;" %}
{% else %}
{% set color = "background-color:#FFFFFF;" %}
{% endif %}
{% if tutor %}
<td style="width: 10%; {{ color }}" id="td_done_thematic_{{ advance.id }}">
{% set check = "" %}
{% if item.last_done == advance.id %}
{% set check = "checked" %}
{% endif %}
<input type="radio" class="done_thematic"
id="done_thematic_{{ advance.id }}"
name="done_thematic"
value="{{ advance.id }}" {{ check }} onclick="update_done_thematic_advance(this.value)">
{% else %}
</td>
{% endif %}
</tr>
{% endfor %}
{% else %}
<div class="alert alert-info" role="alert">{{ 'ThereIsNoAThematicAdvance' | get_lang }}</div>
<div class="alert alert-info" role="alert">{{ 'There is no thematic advance' | trans }}</div>
{% endif %}
</table>
</div>
@ -124,13 +134,15 @@
</div>
</div>
{% else %}
<div class="alert alert-info" role="alert">{{ 'There is no thematic section' | get_lang }}</div>
<div class="alert alert-info" role="alert">{{ 'There is no thematic section' | trans }}</div>
{% if is_allowed_to_edit %}
<div id="no-data-view" class="tool-view">
<h2>{{ "Educational programming"|trans }}</h2>
<img src="{{ "course_progress.png"|icon(64) }}" width="64" height="64">
<div class="controls">
<a href="{{ url('legacy_main', {name : 'course_progress/index.php'}) }}?{{ course_url_params ~ "&action=thematic_add" ~ token }}" class="btn btn-outline-primary">
<a
href="{{ url('legacy_main', {name : 'course_progress/index.php'}) }}?{{ course_url_params ~ "&action=thematic_add" ~ token }}"
class="btn btn-outline-primary">
{{ "Add thematic"|trans }}
</a>
</div>

Loading…
Cancel
Save