Attendance/Thematic use resources, doctrine entities.

pull/3844/head
Julio Montoya 5 years ago
parent 7dbaa59e6c
commit 624452fbd4
  1. 181
      public/main/course_progress/index.php
  2. 78
      public/main/inc/ajax/thematic.ajax.php
  3. 2
      public/main/inc/lib/attendance.lib.php
  4. 299
      public/main/inc/lib/thematic.lib.php

@ -59,9 +59,14 @@ $requestMethod = strtoupper($_SERVER['REQUEST_METHOD']);
$displayHeader = !empty($_REQUEST['display']) && 'no_header' === $_REQUEST['display'] ? false : true; $displayHeader = !empty($_REQUEST['display']) && 'no_header' === $_REQUEST['display'] ? false : true;
$thematicId = isset($_REQUEST['thematic_id']) ? (int) $_REQUEST['thematic_id'] : null; $thematicId = isset($_REQUEST['thematic_id']) ? (int) $_REQUEST['thematic_id'] : null;
$thematicAdvanceId = isset($_REQUEST['thematic_advance_id']) ? (int) $_REQUEST['thematic_advance_id'] : null; $thematicAdvanceId = isset($_REQUEST['thematic_advance_id']) ? (int) $_REQUEST['thematic_advance_id'] : null;
$url = api_get_path(WEB_AJAX_PATH).'thematic.ajax.php?a=get_datetime_by_attendance&'.api_get_cidreq();
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
$(function() { $(function() {
if ($("#div_result").html() !== undefined && $("#div_result").html().length == 0) {
$("#div_result").html("0");
}
$(".thematic_advance_actions, .thematic_tools ").hide(); $(".thematic_advance_actions, .thematic_tools ").hide();
$(".thematic_content").mouseover(function() { $(".thematic_content").mouseover(function() {
var id = parseInt(this.id.split("_")[3]); var id = parseInt(this.id.split("_")[3]);
@ -83,9 +88,7 @@ $(function() {
$("#thematic_advance_tools_"+id ).hide(); $("#thematic_advance_tools_"+id ).hide();
}); });
}); });
</script>';
$htmlHeadXtra[] = '<script>
function check_per_attendance(obj) { function check_per_attendance(obj) {
if (obj.checked) { if (obj.checked) {
$("#div_datetime_by_attendance").show(); $("#div_datetime_by_attendance").show();
@ -105,6 +108,51 @@ function check_per_custom_date(obj) {
$("#div_datetime_by_attendance").show(); $("#div_datetime_by_attendance").show();
} }
} }
function datetime_by_attendance(attendance_id, thematic_advance_id) {
$.ajax({
contentType: "application/x-www-form-urlencoded",
type: "GET",
url: "'.$url.'",
data: "attendance_id="+attendance_id+"&thematic_advance_id="+thematic_advance_id,
success: function(data) {
$("#div_datetime_attendance").html(data);
if (thematic_advance_id == 0) {
$("#from_attendance option:first").attr("checked", true);
$("#div_datetime_by_attendance").show();
$("#div_custom_datetime").hide();
}
}
});
}
function update_done_thematic_advance(selected_value) {
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(myObject) {},
type: "GET",
url: "'.api_get_path(WEB_AJAX_PATH).'thematic.ajax.php?a=update_done_thematic_advance",
data: "thematic_advance_id="+selected_value,
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 == selected_value) {
break;
}
}
}
</script>'; </script>';
$attendance = new Attendance(); $attendance = new Attendance();
@ -164,9 +212,7 @@ switch ($action) {
) { ) {
$title = trim($_POST['title']); $title = trim($_POST['title']);
$content = trim($_POST['content']); $content = trim($_POST['content']);
$session_id = api_get_session_id(); $thematicManager->thematicSave($thematicId, $title, $content, $course, $session);
$thematicManager->set_thematic_attributes($thematicId, $title, $content, $session_id);
$thematicManager->thematic_save();
Display::addFlash(Display::return_message(get_lang('Update successful'))); Display::addFlash(Display::return_message(get_lang('Update successful')));
header('Location: '.$currentUrl); header('Location: '.$currentUrl);
@ -258,7 +304,7 @@ switch ($action) {
} }
// Import the progress. // Import the progress.
$current_thematic = null; $currentThematic = null;
foreach ($csv_import_array as $key => $item) { foreach ($csv_import_array as $key => $item) {
if (!$key) { if (!$key) {
continue; continue;
@ -266,35 +312,22 @@ switch ($action) {
switch ($item[0]) { switch ($item[0]) {
case 'title': case 'title':
$thematicManager->set_thematic_attributes( $currentThematic = $thematicManager->thematicSave(null, $item[1], $item[2], $course, $session);
null,
$item[1],
$item[2],
api_get_session_id()
);
$current_thematic = $thematicManager->thematic_save();
$description_type = 1; $description_type = 1;
break; break;
case 'plan': case 'plan':
$thematicManager->set_thematic_plan_attributes( $thematicManager->thematicPlanSave($currentThematic, $item[1], $item[2], $description_type);
$current_thematic,
$item[1],
$item[2],
$description_type
);
$thematicManager->thematic_plan_save();
$description_type++; $description_type++;
break; break;
case 'progress': case 'progress':
$thematicManager->set_thematic_advance_attributes( $thematicManager->thematicAdvanceSave(
$currentThematic,
null,
null, null,
$current_thematic,
0,
$item[3], $item[3],
$item[1], $item[1],
$item[2] $item[2]
); );
$thematicManager->thematic_advance_save();
break; break;
} }
} }
@ -694,26 +727,24 @@ switch ($action) {
$description_type = $_REQUEST['description_type']; $description_type = $_REQUEST['description_type'];
for ($i = 1; $i < count($title_list) + 1; $i++) { for ($i = 1; $i < count($title_list) + 1; $i++) {
$thematicManager->set_thematic_plan_attributes( $thematicManager->thematicPlanSave(
$_REQUEST['thematic_id'], $thematicEntity,
$title_list[$i], $title_list[$i],
$description_list[$i], $description_list[$i],
$description_type[$i] $description_type[$i]
); );
$thematicManager->thematic_plan_save();
} }
$saveRedirect = api_get_path(WEB_PATH).'main/course_progress/index.php?'; $saveRedirect = api_get_path(WEB_PATH).'main/course_progress/index.php?';
$saveRedirect .= api_get_cidreq().'&'; $saveRedirect .= api_get_cidreq().'&';
if (isset($_REQUEST['add_item'])) { if (isset($_REQUEST['add_item'])) {
$thematicManager->set_thematic_plan_attributes( $thematicManager->thematicPlanSave(
$_REQUEST['thematic_id'], $thematicEntity,
'', '',
'', '',
$i $i
); );
$thematicManager->thematic_plan_save();
Display::addFlash( Display::addFlash(
Display::return_message(get_lang('Thematic section has been created successfully')) Display::return_message(get_lang('Thematic section has been created successfully'))
); );
@ -1012,22 +1043,20 @@ switch ($action) {
); );
$form->addGroup($radios, null, get_lang('Start date options')); $form->addGroup($radios, null, get_lang('Start date options'));
/*if (isset($thematic_advance_data['attendance_id']) && // Custom date.
0 == $thematic_advance_data['attendance_id']) { if ($advance && $advance->getAttendance()) {
$form->addElement('html', '<div id="div_custom_datetime" style="display:block">'); $form->addHtml('<div id="div_custom_datetime" style="display:none">');
} else { } else {
$form->addElement('html', '<div id="div_custom_datetime" style="display:none">'); $form->addHtml('<div id="div_custom_datetime" style="display:block">');
}*/ }
$form->addElement('DateTimePicker', 'custom_start_date', get_lang('Start Date')); $form->addElement('DateTimePicker', 'custom_start_date', get_lang('Start Date'));
$form->addElement('html', '</div>'); $form->addHtml('</div>');
if (isset($thematic_advance_data['attendance_id']) && // Date by attendance.
0 == $thematic_advance_data['attendance_id'] if ($advance && $advance->getAttendance()) {
) { $form->addHtml('<div id="div_datetime_by_attendance" style="display:block">');
$form->addElement('html', '<div id="div_datetime_by_attendance" style="display:none">');
} else { } else {
$form->addElement('html', '<div id="div_datetime_by_attendance" style="display:block">'); $form->addHtml('<div id="div_datetime_by_attendance" style="display:none">');
} }
if (count($attendance_select) > 1) { if (count($attendance_select) > 1) {
@ -1046,10 +1075,20 @@ switch ($action) {
); );
} }
$calendar_select = [];
if ($advance) {
$calendars = $advance->getAttendance()->getCalendars();
if (!empty($calendars)) {
foreach ($calendars as $calendar) {
$dateTime = $calendar->getDateTime()->format('Y-m-d H:i:s');
$calendar_select[$dateTime] = $dateTime;
}
}
}
$form->addHtml('<div id="div_datetime_attendance">'); $form->addHtml('<div id="div_datetime_attendance">');
if (!empty($calendar_select)) { if (!empty($calendar_select)) {
$form->addElement( $form->addSelect(
'select',
'start_date_by_attendance', 'start_date_by_attendance',
get_lang('Start Date'), get_lang('Start Date'),
$calendar_select, $calendar_select,
@ -1087,7 +1126,7 @@ switch ($action) {
} else { } else {
$form->addButtonUpdate(get_lang('Save')); $form->addButtonUpdate(get_lang('Save'));
} }
$js = '';
$attendance_select_item_id = null; $attendance_select_item_id = null;
if (count($attendance_select) > 1) { if (count($attendance_select) > 1) {
$i = 1; $i = 1;
@ -1101,9 +1140,9 @@ switch ($action) {
if (!empty($attendance_select_item_id)) { if (!empty($attendance_select_item_id)) {
$default['attendance_select'] = $attendance_select_item_id; $default['attendance_select'] = $attendance_select_item_id;
if ($thematicAdvanceId) { if ($thematicAdvanceId) {
echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", "'.$thematicAdvanceId.'"); </script>'; $js .= '<script>datetime_by_attendance("'.$attendance_select_item_id.'", "'.$thematicAdvanceId.'"); </script>';
} else { } else {
echo '<script> datetime_by_attendance("'.$attendance_select_item_id.'", 0); </script>'; $js .= '<script>datetime_by_attendance("'.$attendance_select_item_id.'", 0); </script>';
} }
} }
} }
@ -1117,48 +1156,56 @@ switch ($action) {
$default['content'] = $advance->getContent(); $default['content'] = $advance->getContent();
$default['duration_in_hours'] = $advance->getDuration(); $default['duration_in_hours'] = $advance->getDuration();
if ($advance->getThematic()) { if ($advance->getAttendance()) {
$default['start_date_type'] = 2; $default['start_date_type'] = 1;
//$default['custom_start_date'] = null; //$default['custom_start_date'] = null;
//if ($advance->getStartDate()) { //if ($advance->getStartDate()) {
if (!empty($thematic_advance_data['start_date'])) {
$default['start_date_by_attendance'] = api_get_local_time($advance->getStartDate());
}
$default['attendance_select'] = $advance->getAttendance()->getIid();
//}
} else {
$default['custom_start_date'] = date( $default['custom_start_date'] = date(
'Y-m-d H:i:s', 'Y-m-d H:i:s',
api_strtotime(api_get_local_time($advance->getStartDate())) api_strtotime(api_get_local_time($advance->getStartDate()))
); );
//}
} else {
$default['start_date_type'] = 1;
if (!empty($thematic_advance_data['start_date'])) {
$default['start_date_by_attendance'] = api_get_local_time($advance->getStartDate());
}
$default['attendance_select'] = $thematic_advance_data['attendance_id'];
} }
} }
$form->setDefaults($default); $form->setDefaults($default);
if ($form->validate()) { if ($form->validate()) {
$values = $form->exportValues(); $values = $form->getSubmitValues();
if (isset($_POST['start_date_by_attendance'])) { if (isset($_POST['start_date_by_attendance'])) {
$values['start_date_by_attendance'] = $_POST['start_date_by_attendance']; $values['start_date_by_attendance'] = $_POST['start_date_by_attendance'];
} }
$attendanceId = 1 == $values['start_date_type'] && isset($values['attendance_select']) ? $values['attendance_select'] : 0;
$attendance = Container::getAttendanceRepository()->find($attendanceId);
$startDate = $values['custom_start_date']; $startDate = $values['custom_start_date'];
if (2 == $values['start_date_type'] && isset($values['start_date_by_attendance'])) { if (1 == $values['start_date_type'] && isset($values['attendance_select']) &&
isset($values['start_date_by_attendance'])
) {
$startDate = $values['start_date_by_attendance']; $startDate = $values['start_date_by_attendance'];
} }
$thematicManager->set_thematic_advance_attributes(
isset($values['thematic_advance_id']) ? $values['thematic_advance_id'] : null, $advanceId = isset($values['thematic_advance_id']) ? $values['thematic_advance_id'] : null;
$values['thematic_id'], $advance = null;
1 == $values['start_date_type'] && isset($values['attendance_select']) ? $values['attendance_select'] : 0, if (!empty($advanceId)) {
$advance = Container::getThematicAdvanceRepository()->find($advanceId);
}
$newAdvance = $thematicManager->thematicAdvanceSave(
$thematicEntity,
$attendance,
$advance,
$values['content'], $values['content'],
$startDate, $startDate,
$values['duration_in_hours'] $values['duration_in_hours']
); );
$affected_rows = $thematicManager->thematic_advance_save(); if ($newAdvance) {
if ($affected_rows) {
// get last done thematic advance before move thematic list // get last done thematic advance before move thematic list
$last_done_thematic_advance = $thematicManager->get_last_done_thematic_advance($course, $session); $last_done_thematic_advance = $thematicManager->get_last_done_thematic_advance($course, $session);
// update done advances with de current thematic list // update done advances with de current thematic list
@ -1180,7 +1227,7 @@ switch ($action) {
exit; exit;
} }
$content = $form->returnForm(); $content = $form->returnForm().$js;
break; break;
case 'thematic_advance_delete': case 'thematic_advance_delete':

@ -2,9 +2,10 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** use Chamilo\CoreBundle\Framework\Container;
* Responses to AJAX calls for thematic. use Chamilo\CourseBundle\Entity\CAttendance;
*/ use Chamilo\CourseBundle\Entity\CThematicAdvance;
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
api_protect_course_script(true); api_protect_course_script(true);
@ -86,47 +87,51 @@ switch ($action) {
case 'get_datetime_by_attendance': case 'get_datetime_by_attendance':
$attendance_id = (int) $_REQUEST['attendance_id']; $attendance_id = (int) $_REQUEST['attendance_id'];
$thematic_advance_id = (int) $_REQUEST['thematic_advance_id']; $thematic_advance_id = (int) $_REQUEST['thematic_advance_id'];
$label = ''; $label = '';
$input_select = ''; $inputSelect = '';
if (!empty($attendance_id)) {
$attendance = new Attendance();
$thematic = new Thematic();
$thematic_list = $thematic->getThematicList($course, $session);
$repo = Container::getAttendanceRepository();
/** @var CAttendance $attendance */
$attendance = $repo->find($attendance_id);
$repo = Container::getThematicAdvanceRepository();
/** @var CThematicAdvance $thematicAdvance */
$thematicAdvance = $repo->find($thematic_advance_id);
if (!empty($attendance)) {
$thematicList = $thematic->getThematicList($course, $session);
$my_list = $thematic_list_temp = []; $my_list = $thematic_list_temp = [];
foreach ($thematic_list as $item) { foreach ($thematicList as $item) {
$thematic_list_temp[] = $item->getAdvances(); $thematic_list_temp[] = $item->getAdvances();
} }
$new_thematic_list = []; $new_thematic_list = [];
foreach ($thematic_list_temp as $advanceList) { foreach ($thematic_list_temp as $advanceList) {
foreach ($advanceList as $advance) { foreach ($advanceList as $advanceItem) {
$new_thematic_list[$advance->getIid()] = [ if (!empty($advanceItem->getAttendance())) {
'attendance_id' => $advance->getAttendance()->getIid(), $new_thematic_list[$advanceItem->getIid()] = [
'start_date' => $advance->getStartDate()->format('Y-m-d H:i:s'), 'attendance_id' => $advanceItem->getAttendance()->getIid(),
'start_date' => $advanceItem->getStartDate()->format('Y-m-d H:i:s'),
]; ];
} }
/*if (!empty($item['attendance_id'])) { }
$new_thematic_list[$item['id']] = [
'attendance_id' => $item['attendance_id'],
'start_date' => $item['start_date'],
];
}*/
} }
$attendance_calendar = $attendance->get_attendance_calendar($attendance_id); $attendance_calendar = $attendance->getCalendars();
$label = get_lang('Start Date'); $label = get_lang('Start Date');
if (!empty($attendance_calendar)) { if (!empty($attendance_calendar)) {
$input_select .= '<select $inputSelect .= '<select
id="start_date_select_calendar" id="start_date_select_calendar"
name="start_date_by_attendance" size="7" class="form-control">'; name="start_date_by_attendance" size="7" class="form-control">';
foreach ($attendance_calendar as $calendar) { foreach ($attendance_calendar as $calendar) {
$selected = null; $selected = null;
$insert = true; $insert = true;
//checking if was already taken $utcDateTime = $calendar->getDateTime()->format('Y-m-d H:i:s');
$dateTime = api_get_local_time($calendar->getDateTime()->format('Y-m-d H:i:s'));
// Checking if it was already taken.
foreach ($new_thematic_list as $key => $thematic_item) { foreach ($new_thematic_list as $key => $thematic_item) {
if ($calendar['db_date_time'] == $thematic_item['start_date']) { if ($utcDateTime === $thematic_item['start_date']) {
$insert = false; $insert = false;
if ($thematic_advance_id == $key) { if ($thematic_advance_id == $key) {
$insert = true; $insert = true;
@ -135,21 +140,24 @@ switch ($action) {
break; break;
} }
} }
if (true == $insert) {
$input_select .= '<option '.$selected.' value="'.$calendar['date_time'].'">'.$calendar['date_time'].'</option>'; if ($insert) {
$inputSelect .= '<option
'.$selected.'
value="'.$dateTime.'">'.
$dateTime.'</option>';
} }
} }
$input_select .= '</select>'; $inputSelect .= '</select>';
} else { } else {
$input_select .= '<em>'.get_lang('There is no date/time registered yet').'</em>'; $inputSelect .= '<em>'.get_lang('There is no date/time registered yet').'</em>';
} }
} }
?> echo '<div class="row form-group">';
<div class="form-group"> echo '<label class="col-sm-2 control-label">'.$label.'</label>';
<label class="col-sm-2 control-label"><?php echo $label; ?></label> echo '<div class="col-sm-8">'.$inputSelect.'</div>';
<div class="col-sm-8"><?php echo $input_select; ?></div> echo '</div>';
</div>
<?php
break; break;
case 'update_done_thematic_advance': case 'update_done_thematic_advance':
$id = (int) $_GET['thematic_advance_id']; $id = (int) $_GET['thematic_advance_id'];

@ -991,7 +991,7 @@ class Attendance
return 0; return 0;
} }
return $attendance->getCalendars()->matching($criteria); return $attendance->getCalendars()->matching($criteria)->count();
/*$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); /*$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$attendanceId = (int) $attendanceId; $attendanceId = (int) $attendanceId;

@ -5,6 +5,7 @@
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CAttendance;
use Chamilo\CourseBundle\Entity\CThematic; use Chamilo\CourseBundle\Entity\CThematic;
use Chamilo\CourseBundle\Entity\CThematicAdvance; use Chamilo\CourseBundle\Entity\CThematicAdvance;
use Chamilo\CourseBundle\Entity\CThematicPlan; use Chamilo\CourseBundle\Entity\CThematicPlan;
@ -287,6 +288,7 @@ class Thematic
$repo = Container::getThematicRepository(); $repo = Container::getThematicRepository();
$qb = $repo->getResourcesByCourse($course, $session); $qb = $repo->getResourcesByCourse($course, $session);
$qb->andWhere('resource.active = 1');
return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
@ -310,27 +312,23 @@ class Thematic
* *
* @return CThematic * @return CThematic
*/ */
public function thematic_save() public function thematicSave($id, $title, $content, Course $course, Session $session = null)
{ {
// protect data $id = (int) $id;
$id = (int) $this->thematic_id;
$title = $this->thematic_title;
$content = $this->thematic_content;
// get the maximum display order of all the glossary items // get the maximum display order of all the glossary items
//$max_thematic_item = $this->get_max_thematic_item(false); //$max_thematic_item = $this->get_max_thematic_item(false);
$repo = Container::getThematicRepository(); $repo = Container::getThematicRepository();
if (empty($id)) { if (empty($id)) {
$thematic = new CThematic(); $thematic = new CThematic();
$courseEntity = api_get_course_entity();
$thematic $thematic
->setTitle($title) ->setTitle($title)
->setContent($content) ->setContent($content)
->setActive(1) ->setActive(1)
//->setDisplayOrder($max_thematic_item + 1) //->setDisplayOrder($max_thematic_item + 1)
->setDisplayOrder(0) ->setDisplayOrder(0)
->setParent($courseEntity) ->setParent($course)
->addCourseLink($courseEntity, api_get_session_entity()) ->addCourseLink($course, $session)
; ;
$repo->create($thematic); $repo->create($thematic);
@ -453,41 +451,40 @@ class Thematic
} }
$thematicManager = new Thematic(); $thematicManager = new Thematic();
$thematicManager->set_thematic_attributes(
'', $newThematic = $thematicManager->thematicSave(
null,
$thematic->getTitle().' - '.get_lang('Copy'), $thematic->getTitle().' - '.get_lang('Copy'),
$thematic->getContent(), $thematic->getContent(),
api_get_session_id() api_get_course_entity(),
api_get_session_entity()
); );
$new_thematic_id = $thematicManager->thematic_save();
if (!empty($new_thematic_id)) { if (!empty($newThematic->getIid())) {
$thematic_advanced = $thematic->getAdvances(); $thematic_advanced = $thematic->getAdvances();
if (!empty($thematic_advanced)) { if (!empty($thematic_advanced)) {
foreach ($thematic_advanced as $item) { foreach ($thematic_advanced as $item) {
$thematic = new Thematic(); $thematic = new Thematic();
$thematic->set_thematic_advance_attributes( $thematic->thematicAdvanceSave(
0, $newThematic,
$new_thematic_id, $item->getAttendance(),
0, null,
$item->getContent(), $item->getContent(),
$item->getStartDate()->format('Y-m-d H:i:s'), $item->getStartDate()->format('Y-m-d H:i:s'),
$item->getDuration() $item->getDuration()
); );
$thematic->thematic_advance_save();
} }
} }
$thematic_plan = $thematic->getPlans(); $thematic_plan = $thematic->getPlans();
if (!empty($thematic_plan)) { if (!empty($thematic_plan)) {
foreach ($thematic_plan as $item) { foreach ($thematic_plan as $item) {
$thematic = new Thematic(); $thematic->thematicPlanSave(
$thematic->set_thematic_plan_attributes( $newThematic,
$new_thematic_id,
$item->getTitle(), $item->getTitle(),
$item->getDescription(), $item->getDescription(),
$item->getDescriptionType() $item->getDescriptionType()
); );
$thematic->thematic_plan_save();
} }
} }
} }
@ -583,68 +580,21 @@ class Thematic
return $repo->find($id); return $repo->find($id);
} }
/**
* Get thematic advance list.
*
* @param string $course_code Course code (optional)
* @param bool $force_session_id Force to have a session id
* @param bool $withLocalTime Force start_date to local time
*
* @return CThematicAdvance[]
*/
public function get_thematic_advance_list($course_code = null, $force_session_id = false, $withLocalTime = false)
{
$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 = null;
if ($force_session_id) {
$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);
$qb->orderBy('resource.startDate', 'DESC');
return $qb->getQuery()->getResult();
}
/** /**
* insert or update a thematic advance. * insert or update a thematic advance.
* *
* @todo problem * @return CThematicAdvance
*
* @return int last thematic advance id
*/ */
public function thematic_advance_save() public function thematicAdvanceSave(
{ CThematic $thematic,
$id = (int) $this->thematic_advance_id; CAttendance $attendance,
$thematic_id = intval($this->thematic_id); CThematicAdvance $advance = null,
$attendance_id = intval($this->attendance_id); $content,
$content = $this->thematic_advance_content; $start_date,
$start_date = $this->start_date; $duration
$duration = intval($this->duration); ) {
$repo = Container::getThematicAdvanceRepository();
$em = Database::getManager(); $em = Database::getManager();
/** @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) { if (null === $advance) {
$advance = new CThematicAdvance(); $advance = new CThematicAdvance();
$advance $advance
@ -655,23 +605,13 @@ class Thematic
->setDuration($duration) ->setDuration($duration)
; ;
if ($thematic) { //$courseEntity = api_get_course_entity();
$advance->setThematic($thematic);
}
if ($attendance) {
$advance->setAttendance($attendance);
}
$courseEntity = api_get_course_entity();
/*$advance /*$advance
->setParent($courseEntity) ->setParent($courseEntity)
->addCourseLink($courseEntity, api_get_session_entity()) ->addCourseLink($courseEntity, api_get_session_entity())
;*/ ;*/
$em->persist($advance); $em->persist($advance);
$em->flush(); $em->flush();
$last_id = $advance->getIid();
} else { } else {
$advance $advance
->setContent($content) ->setContent($content)
@ -686,118 +626,11 @@ class Thematic
if ($attendance) { if ($attendance) {
$advance->setAttendance($attendance); $advance->setAttendance($attendance);
} }
//$repo->update($advance);
$em->persist($advance); $em->persist($advance);
$em->flush(); $em->flush();
} }
return $last_id; return $advance;
}
/**
* get thematic plan data.
*
* @param int Thematic id (optional), get data by thematic id
* @param int Thematic plan description type (optional), get data by description type
*
* @return array Thematic plan data
*/
public function get_thematic_plan_data($thematic_id = null, $description_type = null)
{
// definition database table
$tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
$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 = '';
//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 (!empty($description_type)) {
$qb->andWhere($qb->expr()->eq('resource.descriptionType', $description_type));
//$condition .= " AND description_type = $description_type ";
}
return $qb->getQuery()->getResult();
/*$items_from_course = api_get_item_property_by_tool(
'thematic_plan',
api_get_course_id(),
0
);
$items_from_session = api_get_item_property_by_tool(
'thematic_plan',
api_get_course_id(),
api_get_session_id()
);*/
$thematic_plan_complete_list = [];
$thematic_plan_id_list = [];
/*if (!empty($items_from_course)) {
foreach ($items_from_course as $item) {
$thematic_plan_id_list[] = $item['ref'];
$thematic_plan_complete_list[$item['ref']] = $item;
}
}
if (!empty($items_from_session)) {
foreach ($items_from_session as $item) {
$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
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).') ';
$rs = Database::query($sql);
if (Database::num_rows($rs)) {
if (!isset($thematic_id) && !isset($description_type)) {
// group all data group by thematic id
$tmp = [];
while ($row = Database::fetch_array($rs, 'ASSOC')) {
$tmp[] = $row['thematic_id'];
if (in_array($row['thematic_id'], $tmp)) {
$row['session_id'] = $thematic_plan_complete_list[$row['id']];
$data[$row['thematic_id']][$row['description_type']] = $row;
}
}
} else {
while ($row = Database::fetch_array($rs, 'ASSOC')) {
$row['session_id'] = $thematic_plan_complete_list[$row['id']];
$data[] = $row;
}
}
}
}
return $data;
} }
/** /**
@ -805,19 +638,11 @@ class Thematic
* *
* @return int affected rows * @return int affected rows
*/ */
public function thematic_plan_save() public function thematicPlanSave(CThematic $thematic, $title, $description, $description_type, $course = null, $session = null)
{ {
$_course = api_get_course_info();
// definition database table
$tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
// protect data // protect data
$thematic_id = intval($this->thematic_id); $thematic_id = $thematic->getIid();
$title = $this->thematic_plan_title; $description_type = (int) $description_type;
$description = $this->thematic_plan_description;
$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', 'thematic_plan',
@ -930,7 +755,7 @@ class Thematic
return false; return false;
$_course = api_get_course_info(); /*$_course = api_get_course_info();
// definition database table // definition database table
$tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN); $tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
@ -952,7 +777,8 @@ class Thematic
thematic_id = $thematic_id AND thematic_id = $thematic_id AND
description_type = $description_type "; description_type = $description_type ";
$result = Database::query($sql); $result = Database::query($sql);
$affected_rows = Database::affected_rows($result); $affected_rows = Database::affected_rows($result);*/
/*
if ($affected_rows) { if ($affected_rows) {
/*api_item_property_update( /*api_item_property_update(
$_course, $_course,
@ -960,8 +786,8 @@ class Thematic
$thematic_plan_id, $thematic_plan_id,
'ThematicPlanDeleted', 'ThematicPlanDeleted',
$user_id $user_id
);*/ );
} }*/
return $affected_rows; return $affected_rows;
} }
@ -1154,7 +980,6 @@ class Thematic
public function get_last_done_thematic_advance($course, $session = null) public function get_last_done_thematic_advance($course, $session = null)
{ {
$thematic_data = self::getThematicList($course, $session); $thematic_data = self::getThematicList($course, $session);
$a_thematic_advance_ids = []; $a_thematic_advance_ids = [];
$last_done_advance_id = 0; $last_done_advance_id = 0;
if (!empty($thematic_data)) { if (!empty($thematic_data)) {
@ -1188,21 +1013,19 @@ class Thematic
public function get_next_thematic_advance_not_done($offset = 1, $course, $session = null) public function get_next_thematic_advance_not_done($offset = 1, $course, $session = null)
{ {
$thematic_data = self::getThematicList($course, $session); $thematic_data = self::getThematicList($course, $session);
$thematic_advance_data = $this->get_thematic_advance_list();
$a_thematic_advance_ids = []; $a_thematic_advance_ids = [];
$next_advance_not_done = 0;
if (!empty($thematic_data)) { if (!empty($thematic_data)) {
foreach ($thematic_data as $thematic) { foreach ($thematic_data as $thematic) {
if (!empty($thematic_advance_data[$thematic['id']])) { $advanceList = $thematic->getAdvances();
foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) { foreach ($advanceList as $advance) {
if (0 == $thematic_advance['done_advance']) { if (0 == $advance->getDoneAdvance()) {
$a_thematic_advance_ids[] = $thematic_advance['id']; $a_thematic_advance_ids[] = $advance->getIid();
}
} }
} }
} }
} }
$next_advance_not_done = 0;
if (!empty($a_thematic_advance_ids)) { 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 = array_shift($a_thematic_advance_ids);
@ -1272,42 +1095,6 @@ class Thematic
return $average; return $average;
} }
/**
* set attributes for fields of thematic table.
*
* @param int Thematic id
* @param string Thematic title
* @param string Thematic content
* @param int Session id
*/
public function set_thematic_attributes($id = null, $title = '', $content = '', $session_id = 0)
{
$this->thematic_id = $id;
$this->thematic_title = $title;
$this->thematic_content = $content;
$this->session_id = $session_id;
}
/**
* set attributes for fields of thematic_plan table.
*
* @param int Thematic id
* @param string Thematic plan title
* @param string Thematic plan description
* @param int Thematic plan description type
*/
public function set_thematic_plan_attributes(
$thematic_id = 0,
$title = '',
$description = '',
$description_type = 0
) {
$this->thematic_id = $thematic_id;
$this->thematic_plan_title = $title;
$this->thematic_plan_description = $description;
$this->thematic_plan_description_type = $description_type;
}
/** /**
* set attributes for fields of thematic_advance table. * set attributes for fields of thematic_advance table.
* *

Loading…
Cancel
Save