Refactor - Course progress / Thematic code, use resources.

pull/3124/head
Julio Montoya 5 years ago
parent 784f70862b
commit 96b7ea0677
  1. 787
      public/main/course_progress/index.php
  2. 99
      public/main/course_progress/thematic_controller.php
  3. 109
      public/main/course_progress/thematic_plan.php
  4. 16
      public/main/inc/ajax/thematic.ajax.php
  5. 24
      public/main/inc/introductionSection.inc.php
  6. 300
      public/main/inc/lib/thematic.lib.php
  7. 24
      public/main/template/default/course_progress/pdf_general_thematic.html.twig
  8. 21
      public/main/template/default/course_progress/pdf_single_thematic.html.twig
  9. 91
      public/main/template/default/course_progress/progress.html.twig
  10. 9
      public/main/template/default/course_progress/thematic_advance.html.twig
  11. 11
      public/main/template/default/course_progress/thematic_plan.html.twig
  12. 4
      public/main/template/default/export/alt_pdf_footer.html.twig
  13. 4
      public/main/template/default/export/pdf_footer.html.twig
  14. 3
      public/main/template/default/export/pdf_header.html.twig
  15. 2
      public/main/template/default/export/table_pdf.html.twig
  16. 35
      src/CourseBundle/Entity/CThematic.php
  17. 3
      src/CourseBundle/Entity/CThematicAdvance.php

File diff suppressed because it is too large Load Diff

@ -1,99 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* Thematic Controller script.
* Prepares the common background variables to give to the scripts corresponding to
* the requested action.
*
* This file contains class used like controller for thematic,
* it should be included inside a dispatcher file (e.g: index.php)
*
* !!! WARNING !!! : ALL DATES IN THIS MODULE ARE STORED IN UTC !
* DO NOT CONVERT DURING THE TRANSITION FROM CHAMILO 1.8.x TO 2.0
*
* @author Christian Fasanando <christian1827@gmail.com>
* @author Julio Montoya <gugli100@gmail.com> token support improving UI
*/
class ThematicController
{
/**
* Constructor.
*/
public function __construct()
{
$this->toolname = 'course_progress';
$this->view = new View($this->toolname);
}
/**
* This method is used for thematic advance control (update, insert or listing)
* render to thematic_advance.php.
*
* @param string $action
*/
public function thematic_advance($action)
{
$thematic = new Thematic();
$attendance = new Attendance();
$data = [];
$displayHeader = !empty($_REQUEST['display']) && 'no_header' === $_REQUEST['display'] ? false : true;
$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':
break;
case 'thematic_advance_list':
if (!api_is_allowed_to_edit(null, true)) {
echo '';
exit;
}
$data['action'] = $_REQUEST['action'];
$data['thematic_id'] = $_REQUEST['thematic_id'];
$data['attendance_select'] = $attendance_select;
if (isset($_REQUEST['thematic_advance_id'])) {
$data['thematic_advance_id'] = $_REQUEST['thematic_advance_id'];
$thematic_advance_data = $thematic->get_thematic_advance_list($_REQUEST['thematic_advance_id']);
$data['thematic_advance_data'] = $thematic_advance_data;
}
break;
default:
$thematic_advance_data = $thematic->get_thematic_advance_list($thematic_advance_id);
break;
}
// get calendar select by attendance id
$calendar_select = [];
if (!empty($thematic_advance_data)) {
if (!empty($thematic_advance_data['attendance_id'])) {
$attendance_calendar = $attendance->get_attendance_calendar($thematic_advance_data['attendance_id']);
if (!empty($attendance_calendar)) {
foreach ($attendance_calendar as $calendar) {
$calendar_select[$calendar['date_time']] = $calendar['date_time'];
}
}
}
}
$data['action'] = $action;
$data['thematic_id'] = $thematic_id;
$data['thematic_advance_id'] = $thematic_advance_id;
$data['attendance_select'] = $attendance_select;
$data['thematic_advance_data'] = $thematic_advance_data;
$data['calendar_select'] = $calendar_select;
$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_advance');
$this->view->render();
}
}

@ -1,109 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* View (MVC patter) for thematic plan.
*
* @author Christian Fasanando <christian1827@gmail.com>
*/
$tpl = new Template(get_lang('Thematic control'));
$toolbar = null;
$formLayout = null;
// actions menu
$new_thematic_plan_data = [];
if (!empty($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;
}
}
$new_id = ADD_THEMATIC_PLAN;
if (!empty($thematic_simple_list)) {
foreach ($thematic_simple_list as $item) {
if ($item >= ADD_THEMATIC_PLAN) {
$new_id = $item + 1;
$default_thematic_plan_title[$item] = $new_thematic_plan_data[$item]['title'];
}
}
}
if (isset($message) && 'ok' == $message) {
echo Display::return_message(get_lang('Thematic section has been created successfully'), 'normal');
}
if ('thematic_plan_list' === $action) {
$token = Security::get_token();
Session::write('thematic_plan_token', $token);
$form = new FormValidator(
'thematic_plan_add',
'POST',
'index.php?action=thematic_plan_list&thematic_id='.$thematic_id.'&'.api_get_cidreq()
);
$form->addElement('hidden', 'action', 'thematic_plan_add');
$form->addElement('hidden', 'thematic_plan_token', $token);
$form->addElement('hidden', 'thematic_id', $thematic_id);
foreach ($default_thematic_plan_title as $id => $title) {
$btnDelete = Display::toolbarButton(
get_lang('Delete'),
'#',
'times',
'danger',
['role' => 'button', 'data-id' => $id, 'class' => 'btn-delete']
);
$form->addElement('hidden', 'description_type['.$id.']', $id);
$form->addText("title[$id]", [get_lang('Title'), null, $btnDelete], false);
$form->addHtmlEditor(
'description['.$id.']',
get_lang('Description'),
false,
false,
[
'ToolbarStartExpanded' => 'false',
'ToolbarSet' => 'Basic',
'Height' => '150',
]
);
if (!empty($thematic_simple_list) && in_array($id, $thematic_simple_list)) {
$thematic_plan = $new_thematic_plan_data[$id];
// set default values
$default['title['.$id.']'] = $thematic_plan['title'];
$default['description['.$id.']'] = $thematic_plan['description'];
$thematic_plan = null;
} else {
$thematic_plan = null;
$default['title['.$id.']'] = $title;
$default['description['.$id.']'] = '';
}
$form->setDefaults($default);
}
$form->addGroup([
$form->addButton(
'add_item',
get_lang('Save and add new item'),
'plus',
'info',
'default',
null,
[],
true
),
$form->addButtonSave(get_lang('Save'), 'submit', true),
]);
$formLayout = $form->returnForm();
} elseif ('thematic_plan_add' == $action || 'thematic_plan_edit' == $action) {
}
$content = $tpl->fetch($thematicLayout);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -82,8 +82,8 @@ switch ($action) {
echo $return[$_REQUEST['thematic_id']][$_REQUEST['thematic_advance_id']];*/
break;
case 'get_datetime_by_attendance':
$attendance_id = intval($_REQUEST['attendance_id']);
$thematic_advance_id = intval($_REQUEST['thematic_advance_id']);
$attendance_id = (int) $_REQUEST['attendance_id'];
$thematic_advance_id = (int) $_REQUEST['thematic_advance_id'];
$label = '';
$input_select = '';
@ -144,17 +144,17 @@ switch ($action) {
<?php
break;
case 'update_done_thematic_advance':
$thematic_advance_id = intval($_GET['thematic_advance_id']);
$total_average = 0;
if (!empty($thematic_advance_id)) {
$advanceId = (int) $_GET['thematic_advance_id'];
$average = 0;
if (!empty($advanceId)) {
$thematic = new Thematic();
$affected_rows = $thematic->update_done_thematic_advances($thematic_advance_id);
$total_average = $thematic->get_total_average_of_thematic_advances(
$thematic->update_done_thematic_advances($advanceId);
$average = $thematic->get_total_average_of_thematic_advances(
api_get_course_id(),
api_get_session_id()
);
}
echo $total_average;
echo $average;
break;
default:
echo '';

@ -178,20 +178,20 @@ if (TOOL_COURSE_HOMEPAGE == $tool && !isset($_GET['intro_cmdEdit'])) {
$thematic = new Thematic();
$displayMode = api_get_course_setting('display_info_advance_inside_homecourse');
$class1 = '';
if ('1' == $displayMode) {
if ('1' === $displayMode) {
// Show only the current course progress step
$last_done_advance = $thematic->get_last_done_thematic_advance();
$thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
$subTitle1 = get_lang('Current topic');
$class1 = ' current';
} elseif ('2' == $displayMode) {
} elseif ('2' === $displayMode) {
// Show only the two next course progress steps
$last_done_advance = $thematic->get_next_thematic_advance_not_done();
$next_advance_not_done = $thematic->get_next_thematic_advance_not_done(2);
$thematic_advance_info = $thematic->get_thematic_advance_list($last_done_advance);
$thematic_advance_info2 = $thematic->get_thematic_advance_list($next_advance_not_done);
$subTitle1 = $subTitle2 = get_lang('Next topic');
} elseif ('3' == $displayMode) {
} elseif ('3' === $displayMode) {
// Show the current and next course progress steps
$last_done_advance = $thematic->get_last_done_thematic_advance();
$next_advance_not_done = $thematic->get_next_thematic_advance_not_done();
@ -206,16 +206,16 @@ if (TOOL_COURSE_HOMEPAGE == $tool && !isset($_GET['intro_cmdEdit'])) {
$thematic_advance = get_lang('Course progress');
$thematicScore = $thematic->get_total_average_of_thematic_advances().'%';
$thematicUrl = api_get_path(WEB_CODE_PATH).'course_progress/index.php?action=thematic_details&'.api_get_cidreq();
$thematic_info = $thematic->get_thematic_list($thematic_advance_info['thematic_id']);
$thematic_advance_info['start_date'] = api_get_local_time(
$thematic_advance_info['start_date']
);
$repo = \Chamilo\CoreBundle\Framework\Container::getThematicRepository();
/** @var \Chamilo\CourseBundle\Entity\CThematic $thematic_info */
$thematic_info = $repo->find($thematic_advance_info['thematic_id']);
$thematic_advance_info['start_date'] = api_get_local_time($thematic_advance_info['start_date']);
$thematic_advance_info['start_date'] = api_format_date(
$thematic_advance_info['start_date'],
DATE_TIME_FORMAT_LONG
);
$userInfo = api_get_user_info();
); $userInfo = api_get_user_info();
$courseInfo = api_get_course_info();
$titleThematic = $thematic_advance.' : '.$courseInfo['name'].' <b>( '.$thematicScore.' )</b>';
@ -230,7 +230,7 @@ if (TOOL_COURSE_HOMEPAGE == $tool && !isset($_GET['intro_cmdEdit'])) {
<div class="col-md-6 items-progress">
<div class="thematic-cont '.$class1.'">
<div class="topics">'.$subTitle1.'</div>
<h4 class="title-topics">'.Display::returnFontAwesomeIcon('book').strip_tags($thematic_info['title']).'</h4>
<h4 class="title-topics">'.Display::returnFontAwesomeIcon('book').strip_tags($thematic_info->getTitle()).'</h4>
<p class="date">'.Display::returnFontAwesomeIcon('calendar-o').$thematic_advance_info['start_date'].'</p>
<div class="views">'.Display::returnFontAwesomeIcon('file-text-o').strip_tags($thematic_advance_info['content']).'</div>
<p class="time">'.Display::returnFontAwesomeIcon('clock-o').get_lang('Duration in hours').' : '.$thematic_advance_info['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('See detail').'</a></p>
@ -238,7 +238,7 @@ if (TOOL_COURSE_HOMEPAGE == $tool && !isset($_GET['intro_cmdEdit'])) {
</div>';
if (!empty($thematic_advance_info2)) {
$thematic_info2 = $thematic->get_thematic_list($thematic_advance_info2['thematic_id']);
$thematic_info2 = $repo->find($thematic_advance_info2['thematic_id']);
$thematic_advance_info2['start_date'] = api_get_local_time($thematic_advance_info2['start_date']);
$thematic_advance_info2['start_date'] = api_format_date($thematic_advance_info2['start_date'], DATE_TIME_FORMAT_LONG);
@ -246,7 +246,7 @@ if (TOOL_COURSE_HOMEPAGE == $tool && !isset($_GET['intro_cmdEdit'])) {
<div class="col-md-6 items-progress">
<div class="thematic-cont">
<div class="topics">'.$subTitle2.'</div>
<h4 class="title-topics">'.Display::returnFontAwesomeIcon('book').$thematic_info2['title'].'</h4>
<h4 class="title-topics">'.Display::returnFontAwesomeIcon('book').api_get_local_time($thematic_info2->getStartDate()).'</h4>
<p class="date">'.Display::returnFontAwesomeIcon('calendar-o').$thematic_advance_info2['start_date'].'</p>
<div class="views">'.Display::returnFontAwesomeIcon('file-text-o').strip_tags($thematic_advance_info2['content']).'</div>
<p class="time">'.Display::returnFontAwesomeIcon('clock-o').get_lang('Duration in hours').' : '.$thematic_advance_info2['duration'].' - <a href="'.$thematicUrl.'">'.get_lang('See detail').'</a></p>

@ -270,52 +270,42 @@ class Thematic
/**
* Get thematic list.
*
* @param int $thematic_id Thematic id (optional), get list by id
* @param string $course_code
* @param int $session_id
*
* @return array Thematic data
*/
public static function get_thematic_list(
$thematic_id = null,
$course_code = null,
$session_id = null
) {
public static function get_thematic_list($course_code = null, $session_id = null)
{
// set current course and session
$tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
if (isset($session_id)) {
$session_id = intval($session_id);
if (!empty($session_id)) {
$session_id = (int) $session_id;
} else {
$session_id = api_get_session_id();
}
$data = [];
if (isset($thematic_id)) {
$thematic_id = intval($thematic_id);
$condition = " WHERE id = $thematic_id AND active = 1 ";
if (empty($session_id)) {
$condition_session = api_get_session_condition(0);
} else {
if (empty($session_id)) {
$condition_session = api_get_session_condition(0);
} else {
$condition_session = api_get_session_condition($session_id, true, true);
}
$condition = " WHERE active = 1 $condition_session ";
$condition_session = api_get_session_condition($session_id, true, true);
}
$condition = " WHERE active = 1 $condition_session ";
$sql = "SELECT *
FROM $tbl_thematic $condition AND c_id = $course_id
ORDER BY display_order ";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
if (!empty($thematic_id)) {
$data = Database::fetch_array($res, 'ASSOC');
} else {
while ($row = Database::fetch_array($res, 'ASSOC')) {
$data[$row['id']] = $row;
}
$repo = Container::getThematicRepository();
while ($row = Database::fetch_array($res, 'ASSOC')) {
$entity = $repo->find($row['iid']);
$data[$row['iid']] = $entity;
}
}
@ -325,7 +315,7 @@ class Thematic
/**
* Insert or update a thematic.
*
* @return int last thematic id
* @return CThematic
*/
public function thematic_save()
{
@ -482,22 +472,28 @@ class Thematic
}
/**
* @param int $thematic_id
* @param int $thematicId
*/
public function copy($thematic_id)
public function copy($thematicId)
{
$thematic = self::get_thematic_list($thematic_id, api_get_course_id(), 0);
$thematic_copy = new Thematic();
$thematic_copy->set_thematic_attributes(
$repo = Container::getThematicRepository();
/** @var CThematic $thematic */
$thematic = $repo->find($thematicId);
if (null === $thematic) {
return false;
}
$thematicManager = new Thematic();
$thematicManager->set_thematic_attributes(
'',
$thematic['title'].' - '.get_lang('Copy'),
$thematic['content'],
$thematic->getTitle().' - '.get_lang('Copy'),
$thematic->getContent(),
api_get_session_id()
);
$new_thematic_id = $thematicManager->thematic_save();
$new_thematic_id = $thematic_copy->thematic_save();
if (!empty($new_thematic_id)) {
$thematic_advanced = self::get_thematic_advance_by_thematic_id($thematic_id);
$thematic_advanced = $thematic->getAdvances();
if (!empty($thematic_advanced)) {
foreach ($thematic_advanced as $item) {
$thematic = new Thematic();
@ -505,22 +501,22 @@ class Thematic
0,
$new_thematic_id,
0,
$item['content'],
$item['start_date'],
$item['duration']
$item->getContent(),
$item->getStartDate()->format('Y-m-d H:i:s'),
$item->getDuration()
);
$thematic->thematic_advance_save();
}
}
$thematic_plan = self::get_thematic_plan_data($thematic_id);
$thematic_plan = $thematic->getPlans();
if (!empty($thematic_plan)) {
foreach ($thematic_plan as $item) {
$thematic = new Thematic();
$thematic->set_thematic_plan_attributes(
$new_thematic_id,
$item['title'],
$item['description'],
$item['description_type']
$item->getTitle(),
$item->getDescription(),
$item->getDescriptionType()
);
$thematic->thematic_plan_save();
}
@ -561,19 +557,18 @@ class Thematic
*
* @see SortableTable#get_table_data($from)
*/
public static function get_thematic_advance_data($from, $number_of_items, $column, $direction)
public static function get_thematic_advance_data($from, $number_of_items, $column, $direction, $params = [])
{
global $thematic_id;
$table = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
$column = intval($column);
$from = intval($from);
$number_of_items = intval($number_of_items);
$column = (int) $column;
$from = (int) $from;
$number_of_items = (int) $number_of_items;
if (!in_array($direction, ['ASC', 'DESC'])) {
$direction = 'ASC';
}
$data = [];
$course_id = api_get_course_int_id();
$thematic_id = (int) $thematic_id;
$thematic_id = (int) $params['thematic_id'];
if (api_is_allowed_to_edit(null, true)) {
$sql = "SELECT id AS col0, start_date AS col1, duration AS col2, content AS col3
FROM $table
@ -581,21 +576,21 @@ class Thematic
ORDER BY col$column $direction
LIMIT $from,$number_of_items ";
$list = api_get_item_property_by_tool(
/*$list = api_get_item_property_by_tool(
'thematic_advance',
api_get_course_id(),
api_get_session_id()
);
);*/
$elements = [];
/*$elements = [];
foreach ($list as $value) {
$elements[] = $value['ref'];
}
}*/
$res = Database::query($sql);
$i = 1;
while ($thematic_advance = Database::fetch_row($res)) {
if (in_array($thematic_advance[0], $elements)) {
//if (in_array($thematic_advance[0], $elements)) {
$thematic_advance[1] = api_get_local_time($thematic_advance[1]);
$thematic_advance[1] = api_format_date($thematic_advance[1], DATE_TIME_FORMAT_LONG);
$actions = '';
@ -605,7 +600,7 @@ class Thematic
Display::return_icon('delete.png', get_lang('Delete'), '', 22).'</a></center>';
$data[] = [$i, $thematic_advance[1], $thematic_advance[2], $thematic_advance[3], $actions];
++$i;
}
// }
}
}
@ -665,9 +660,8 @@ class Thematic
return $data;
}
public function getThematicAdvance(
$id
) {
public function getThematicAdvance($id)
{
$repo = Container::getThematicAdvanceRepository();
$courseEntity = api_get_course_entity($courseId);
@ -735,6 +729,7 @@ class Thematic
}
$qb = $repo->getResourcesByCourse($courseEntity, $sessionEntity);
$qb->orderBy('resource.startDate', 'DESC');
return $qb->getQuery()->getResult();
@ -789,25 +784,36 @@ class Thematic
$repo = Container::getThematicAdvanceRepository();
$em = $repo->getEntityManager();
/** @var CThematicAdvance $advance */
$advance = $repo->find($id);
$repoThematic = Container::getThematicRepository();
$thematic = $repoThematic->find($thematic_id);
$attendanceRepo = Container::getAttendanceRepository();
$attendance = $attendanceRepo->find($attendance_id);
$last_id = null;
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)
//->setThematic($thematic)
//->setAttendance($attendance)
->setStartDate(api_get_utc_datetime($start_date, true, true))
->setDuration($duration)
;
if ($thematic) {
$advance ->setThematic($thematic);
}
if ($attendance) {
$advance ->setAttendance($attendance);
}
$em->persist($advance);
$repo->addResourceToCourse(
@ -835,14 +841,23 @@ class Thematic
);*/
}
} else {
$params = [
'thematic_id' => $thematic_id,
'attendance_id' => $attendance_id,
'content' => $content,
'start_date' => api_get_utc_datetime($start_date),
'duration' => $duration,
];
$advance
->setCId($this->course_int_id)
->setContent($content)
->setStartDate(api_get_utc_datetime($start_date, true, true))
->setDuration($duration)
;
if ($thematic) {
$advance ->setThematic($thematic);
}
if ($attendance) {
$advance ->setAttendance($attendance);
}
$em->persist($advance);
$em->flush();
/*
Database::update(
$table,
$params,
@ -855,7 +870,7 @@ class Thematic
$id,
'ThematicAdvanceUpdated',
$user_id
);
);*/
}
return $last_id;
@ -870,6 +885,17 @@ class Thematic
*/
public function thematic_advance_destroy($id)
{
$repo = Container::getThematicAdvanceRepository();
$advance = $repo->find($id);
if ($advance) {
$repo->getEntityManager()->remove($advance);
$repo->getEntityManager()->flush();
}
return true;
$_course = api_get_course_info();
$course_id = api_get_course_int_id();
@ -884,6 +910,7 @@ class Thematic
WHERE c_id = $course_id AND id = $id ";
$result = Database::query($sql);
$affected_rows = Database::affected_rows($result);
if ($affected_rows) {
api_item_property_update(
$_course,
@ -903,6 +930,8 @@ class Thematic
* @param int Thematic id (optional), get data by thematic id
* @param int Thematic plan description type (optional), get data by description type
*
* @deprecated
*
* @return array Thematic plan data
*/
public function get_thematic_plan_data($thematic_id = null, $description_type = null)
@ -1131,8 +1160,23 @@ class Thematic
*
* @return int Affected rows
*/
public function thematic_plan_destroy($thematic_id, $description_type)
public function thematic_plan_destroy($thematic_id, $descriptionType)
{
$repo = Container::getThematicRepository();
/** @var CThematic $thematic */
$thematic = $repo->find($thematic_id);
foreach ($thematic->getPlans() as $plan) {
if ($descriptionType == $plan->getDescriptionType()) {
$thematic->getPlans()->removeElement($plan);
}
}
$repo->getEntityManager()->persist($thematic);
$repo->getEntityManager()->flush();
return false;
$_course = api_get_course_info();
// definition database table
$tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
@ -1157,13 +1201,13 @@ class Thematic
$result = Database::query($sql);
$affected_rows = Database::affected_rows($result);
if ($affected_rows) {
api_item_property_update(
/*api_item_property_update(
$_course,
'thematic_plan',
$thematic_plan_id,
'ThematicPlanDeleted',
$user_id
);
);*/
}
return $affected_rows;
@ -1207,25 +1251,55 @@ class Thematic
/**
* update done thematic advances from thematic details interface.
*
* @param int $thematic_advance_id
*
* @return int Affected rows
*/
public function update_done_thematic_advances($thematic_advance_id)
public function update_done_thematic_advances($advanceId)
{
$repo = Container::getThematicRepository();
$em = $repo->getEntityManager();
$list = self::get_thematic_list( api_get_course_id());
$ordered = [];
foreach ($list as $thematic) {
$done = true;
foreach ($thematic->getAdvances() as $advance) {
$ordered[] = $advance;
/*if ($advanceId === $advance->getIid()) {
$done = false;
}*/
$advance->setDoneAdvance($done);
}
}
$done = true;
foreach ($ordered as $advance) {
if ($advanceId === $advance->getIid()) {
$done = false;
$advance->setDoneAdvance(true);
$em->persist($advance);
continue;
}
$advance->setDoneAdvance($done);
$em->persist($advance);
}
$em->flush();
return true;
$_course = api_get_course_info();
$thematic_data = self::get_thematic_list(null, api_get_course_id());
$thematic_advance_data = $this->get_thematic_advance_list(
null,
api_get_course_id(),
true
);
$thematic_data = self::get_thematic_list( api_get_course_id());
$table = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
$affected_rows = 0;
$user_id = api_get_user_id();
$all = [];
/*$all = [];
if (!empty($thematic_data)) {
foreach ($thematic_data as $thematic) {
$thematic_id = $thematic['id'];
@ -1235,13 +1309,13 @@ class Thematic
}
}
}
}
}*/
$error = null;
$a_thematic_advance_ids = [];
$course_id = api_get_course_int_id();
$sessionId = api_get_session_id();
if (!empty($thematic_data)) {
/*if (!empty($thematic_data)) {
foreach ($thematic_data as $thematic) {
$my_affected_rows = 0;
$thematic_id = $thematic['id'];
@ -1279,7 +1353,7 @@ class Thematic
}
}
}
}
}*/
// Update done thematic for others advances (done_advance = 0)
if (!empty($a_thematic_advance_ids) && count($a_thematic_advance_ids) > 0) {
@ -1332,20 +1406,17 @@ class Thematic
public function get_last_done_thematic_advance()
{
$thematic_data = self::get_thematic_list();
$thematic_advance_data = $this->get_thematic_advance_list(
null,
api_get_course_id(),
true
);
$a_thematic_advance_ids = [];
$last_done_advance_id = 0;
if (!empty($thematic_data)) {
/** @var CThematic $thematic */
foreach ($thematic_data as $thematic) {
if (!empty($thematic_advance_data[$thematic['id']])) {
foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
if (1 == $thematic_advance['done_advance']) {
$a_thematic_advance_ids[] = $thematic_advance['id'];
$id = $thematic->getIid();
if ($thematic->getAdvances()->count()) {
foreach ($thematic->getAdvances() as $thematic_advance) {
if (1 == $thematic_advance->getDoneAdvance()) {
$a_thematic_advance_ids[] = $thematic_advance->getIid();
}
}
}
@ -1408,25 +1479,19 @@ class Thematic
$course_code = api_get_course_id();
}
if (api_get_session_id()) {
$thematic_data = self::get_thematic_list(null, $course_code);
$thematic_data = self::get_thematic_list( $course_code);
} else {
$thematic_data = self::get_thematic_list(null, $course_code, 0);
}
$new_thematic_data = [];
if (!empty($thematic_data)) {
foreach ($thematic_data as $item) {
$new_thematic_data[] = $item;
}
$thematic_data = $new_thematic_data;
$thematic_data = self::get_thematic_list( $course_code, 0);
}
$a_average_of_advances_by_thematic = [];
$total_average = 0;
if (!empty($thematic_data)) {
/** @var CThematic $thematic */
foreach ($thematic_data as $thematic) {
$thematic_id = $thematic['id'];
$thematic_id = $thematic->getIid();
$a_average_of_advances_by_thematic[$thematic_id] = $this->get_average_of_advances_by_thematic(
$thematic_id,
$thematic,
$course_code
);
}
@ -1445,30 +1510,27 @@ class Thematic
/**
* Get average of advances by thematic.
*
* @param int Thematic id
* @param CThematic $thematic
* @param string $course_code
*
* @return float Average of thematic advances
*/
public function get_average_of_advances_by_thematic($thematic_id, $course_code = null)
public function get_average_of_advances_by_thematic($thematic, $course_code = null)
{
$thematic_advance_data = $this->get_thematic_advance_by_thematic_id($thematic_id, $course_code);
$advances = $thematic->getAdvances();
$average = 0;
if (!empty($thematic_advance_data)) {
if ($advances->count()) {
// get all done advances by thematic
$advances = [];
$count_done_advances = 0;
$count = 0;
/** @var CThematicAdvance $thematic_advance */
foreach ($thematic_advance_data as $thematic_advance) {
if (1 == $thematic_advance->getDoneAdvance()) {
$count_done_advances++;
foreach ($advances as $thematic_advance) {
if ($thematic_advance->getDoneAdvance()) {
$count++;
}
$advances[] = $thematic_advance->getDoneAdvance();
}
// calculate average by thematic
$count_total_advances = count($advances);
$average = round(($count_done_advances * 100) / $count_total_advances);
$average = round(($count * 100) / count($advances));
}
return $average;

@ -1,14 +1,16 @@
{% autoescape false %}
<table style="margin-top: 30px;" class="full-width border-thin">
<thead>
<tr>
<th width="30%" style="display:inline-block; padding: 10px; text-align: center; background-color: #E5E5E5;">
{{ "Thematic"|get_lang }}
{{ "Thematic"|trans }}
</th>
<th width="50%" style="display:inline-block; padding: 10px; text-align: center; background-color: #E5E5E5;">
{{ "ThematicPlan"|get_lang }}
{{ "Thematic plan"|trans }}
</th>
<th width="20%" style="display:inline-block; padding: 10px; text-align: center; background-color: #E5E5E5;">
{{ "ThematicAdvance"|get_lang }}
{{ "Thematic advance"|trans }}
</th>
</tr>
</thead>
@ -17,24 +19,20 @@
<tr>
<td>
<h4 style="margin-bottom: 10px;">{{ item.title }}</h4>
<br>
{{ item.content }}
</td>
<td>
{% for plan in item.thematic_plan %}
<br>
{% for plan in item.plans %}
<h4 style="margin-bottom: 10px;">{{ plan.title }}</h4>
<br>
{{ plan.description }}
{% endfor %}
</td>
<td>
{% for advance in item.thematic_advance %}
<br>
{% for advance in item.advances %}
<h4 style="margin-bottom: 10px;">
{{ advance.duration }} {{ "MinHours" | get_lang }}
{{ advance.duration }} {{ "hours" | trans }}
</h4>
{{ advance.start_date | api_convert_and_format_date(2) }}
{{ advance.startDate | api_convert_and_format_date(2) }}
<br>
{{ advance.content }}
{% endfor %}
@ -42,4 +40,6 @@
</tr>
{% endfor %}
</tbody>
</table>
</table>
{% endautoescape %}

@ -1,20 +1,21 @@
{% autoescape false %}
<table class="full-width border-thin">
<thead>
<tr>
<th width="30%" style="display:inline-block; padding: 10px; text-align: center; background-color: #E5E5E5;">{{ 'Thematic'|get_lang }}</th>
<th width="50%" style="display:inline-block; padding: 10px; text-align: center; background-color: #E5E5E5;">{{ 'ThematicPlan'|get_lang }}</th>
<th width="20%" style="display:inline-block; padding: 10px; text-align: center; background-color: #E5E5E5;">{{ 'ThematicAdvance'|get_lang }}</th>
<th width="30%" style="display:inline-block; padding: 10px; text-align: center; background-color: #E5E5E5;">{{ 'Thematic'|trans }}</th>
<th width="50%" style="display:inline-block; padding: 10px; text-align: center; background-color: #E5E5E5;">{{ 'Thematic plan'|trans }}</th>
<th width="20%" style="display:inline-block; padding: 10px; text-align: center; background-color: #E5E5E5;">{{ 'Thematic advance'|trans }}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<h4>{{ theme.title }}</h4>
<h4>{{ thematic.title }}</h4>
<br>
{{ theme.content }}
{{ thematic.content }}
</td>
<td>
{% for plan in plans %}
{% for plan in thematic.plans %}
<br>
<h4>{{ plan.title }}</h4>
<br>
@ -22,11 +23,11 @@
{% endfor %}
</td>
<td>
{% for advance in advances %}
{% for advance in thematic.advances %}
<h4 style="margin-bottom: 10px;">
{{ advance.duration }} {{ "MinHours" | get_lang }}
{{ advance.duration }} {{ "hours" | trans }}
</h4>
<p>{{ advance.start_date|api_convert_and_format_date(2) }}</p>
<p>{{ advance.startDate|api_convert_and_format_date(2) }}</p>
{{ advance.content }}
<br>
{% endfor %}
@ -34,3 +35,5 @@
</tr>
</tbody>
</table>
{% endautoescape %}

@ -1,14 +1,61 @@
{% autoescape false %}
<script>
function datetime_by_attendance(attendance_id, thematic_advance_id) {
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(myObject) {},
type: "GET",
url: "{{ url('legacy_main', {'name' : 'inc/ajax/thematic.ajax.php'}) ~ '?' ~ course_url_params ~ '&a=get_datetime_by_attendance' }}",
data: "attendance_id="+attendance_id+"&thematic_advance_id="+thematic_advance_id,
success: function(data) {
$("#div_datetime_attendance").html(data);
if (thematic_advance_id == 0) {
$("#start_date_select_calendar").val($("#start_date_select_calendar option:first").val());
}
}
});
}
function updateDoneThematicAdvance(advanceId) {
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(myObject) {},
type: "GET",
url: "{{ url('legacy_main', {'name' : 'inc/ajax/thematic.ajax.php'}) ~ '?' ~ course_url_params ~ '&a=update_done_thematic_advance' }}",
data: "thematic_advance_id="+advanceId,
success: function(data) {
$("#div_result").html(data);
}
});
// clean all radios
for (var i=0; i< $(".done_thematic").length;i++) {
var id_radio_thematic = $(".done_thematic").get(i).id;
$("#td_"+id_radio_thematic).css({"background-color":"#FFF"});
}
// set background to previous radios
for (var i=0; i < $(".done_thematic").length;i++) {
var id_radio_thematic = $(".done_thematic").get(i).id;
$("#td_"+id_radio_thematic).css({"background-color":"#E5EDF9"});
if ($(".done_thematic").get(i).value == advanceId) {
break;
}
}
}
</script>
{% if data is not empty %}
{% set tutor = is_granted('ROLE_TEACHER') %}
{% set tutor = is_granted('ROLE_TEACHER') %}
<div id="course-progress" class="thematic">
<div class="row">
<div class="col-md-12">
<div class="bar-progress">
<div class="float-right">
<div class="score-progress">
<h3>{{ 'Progress' | get_lang }}: <span id="div_result">{{ score_progress }}</span> %</h3>
<h3>{{ 'Progress' | trans }}: <span id="div_result">{{ score_progress }}</span> %</h3>
</div>
</div>
</div>
@ -16,9 +63,9 @@
<table width="100%" class="table">
<thead>
<tr>
<th scope="col" style="width: 35%">{{ 'Thematic' | get_lang }}</th>
<th scope="col" style="width: 40%">{{ 'ThematicPlan' | get_lang }}</th>
<th scope="col" style="width: 25%">{{ 'ThematicAdvance' | get_lang }}</th>
<th scope="col" style="width: 35%">{{ 'Thematic' | trans }}</th>
<th scope="col" style="width: 40%">{{ 'Thematic plan' | trans }}</th>
<th scope="col" style="width: 25%">{{ 'Thematic advance' | trans }}</th>
</tr>
</thead>
<tbody>
@ -47,14 +94,14 @@
</div>
{% endif %}
{% if item.thematic_plan is empty %}
<div class="alert-thematic">
<div class="alert alert-info" role="alert">{{ 'StillDoNotHaveAThematicPlan' | trans }}</div>
</div>
{% if item.plans is empty %}
<div class="alert-thematic">
<div class="alert alert-info" role="alert">{{ 'There is no thematic plan for now' | trans }}</div>
</div>
{% else %}
{% for subitem in item.thematic_plan %}
<h5>{{ subitem.title }}</h5>
{{ subitem.description }}
{% for plan in item.plans %}ssss
<h5>{{ plan.title }}</h5>
{{ plan.description }}
{% endfor %}
{% endif %}
</div>
@ -71,13 +118,12 @@
</div>
{% endif %}
<table width="100%" class="table">
{% if item.thematic_advance is not empty %}
{% for advance in item.thematic_advance %}
{% if item.advances is not empty %}
{% for advance in item.advances %}
<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>
<strong>{{ advance.startDate | format_date }}</strong>
{{ advance.content }}
</div>
{% if tutor %}
@ -86,7 +132,7 @@
<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>
<i class="fa fa-pen" aria-hidden="true"></i>
</a>
<a class="btn btn-default btn-sm"
onclick="javascript:if(!confirm('{{ 'Are you sure to delete' | trans }}')) return false;"
@ -111,16 +157,19 @@
{% 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)">
id="done_thematic_{{ advance.id }}"
name="done_thematic"
value="{{ advance.id }}" {{ check }}
onclick="updateDoneThematicAdvance(this.value); ">
{% else %}
</td>
{% endif %}
</tr>
{% endfor %}
{% else %}
<div class="alert alert-info" role="alert">{{ 'There is no thematic advance' | trans }}</div>
<div class="alert alert-info" role="alert">
{{ 'There is no thematic advance' | trans }}
</div>
{% endif %}
</table>
</div>

@ -1,9 +0,0 @@
{% autoescape false %}
<div class="row">
<div class="col-md-12">
<div class="thematic-plan">
{{ form_thematic }}
</div>
</div>
</div>
{% endautoescape %}

@ -1,11 +0,0 @@
{% autoescape false %}
<div class="row">
<div class="col-md-12">
<h3>{{ title_thematic }}</h3>
{{ content_thematic }}
<div class="thematic-plan">
{{ form_thematic }}
</div>
</div>
</div>
{% endautoescape %}

@ -1,3 +1,5 @@
{% autoescape false %}
<table border="0" class="full-width border-top page-footer">
<tr>
<td class="text-center">
@ -7,3 +9,5 @@
</td>
</tr>
</table>
{% endautoescape %}

@ -1,3 +1,5 @@
{% autoescape false %}
<table border="0" class="full-width border-top page-footer">
<tr>
<td class="text-left">
@ -8,3 +10,5 @@
</td>
</tr>
</table>
{% endautoescape %}

@ -1,3 +1,5 @@
{% autoescape false %}
<table border="0" width="100%" class="pdf-header">
<tr>
<td width="30%">
@ -9,3 +11,4 @@
</tr>
</table>
{% endautoescape %}

@ -1,7 +1,7 @@
{% autoescape false %}
{% if pdf_title %}
<h2 align="center"> {{ pdf_title }} </h2>
<h2 align="center"> {{ pdf_title }} </h2>
{% endif %}
{% if pdf_description %}

@ -6,6 +6,7 @@ namespace Chamilo\CourseBundle\Entity;
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
@ -80,9 +81,27 @@ class CThematic extends AbstractResource implements ResourceInterface
*/
protected $sessionId;
/**
* @var CThematicPlan[]
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CThematicPlan", mappedBy="thematic", cascade={"persist", "remove"}, orphanRemoval=true)
*/
protected $plans;
/**
* @var CThematicAdvance[]
*
* @ORM\OrderBy({"startDate" = "ASC"})
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CThematicAdvance", mappedBy="thematic", cascade={"persist", "remove"}, orphanRemoval=true)
*/
protected $advances;
public function __construct()
{
$this->id = 0;
$this->plans = new ArrayCollection();
$this->advances = new ArrayCollection();
}
/**
@ -258,6 +277,22 @@ class CThematic extends AbstractResource implements ResourceInterface
return $this->cId;
}
/**
* @return CThematicPlan[]|ArrayCollection
*/
public function getPlans()
{
return $this->plans;
}
/**
* @return CThematicAdvance[]|ArrayCollection
*/
public function getAdvances()
{
return $this->advances;
}
public function __toString(): string
{
return $this->getTitle();

@ -102,6 +102,7 @@ class CThematicAdvance extends AbstractResource implements ResourceInterface
{
$this->doneAdvance = 0;
$this->id = 0;
$this->duration = 1;
}
/**
@ -278,7 +279,7 @@ class CThematicAdvance extends AbstractResource implements ResourceInterface
return $this;
}
public function getAttendance(): CAttendance
public function getAttendance(): ?CAttendance
{
return $this->attendance;
}

Loading…
Cancel
Save