Attendance/Thematic use resources, doctrine entities.

pull/3844/head
Julio Montoya 4 years ago
parent 7dbaa59e6c
commit 624452fbd4
  1. 183
      public/main/course_progress/index.php
  2. 80
      public/main/inc/ajax/thematic.ajax.php
  3. 4
      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;
$thematicId = isset($_REQUEST['thematic_id']) ? (int) $_REQUEST['thematic_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>
$(function() {
if ($("#div_result").html() !== undefined && $("#div_result").html().length == 0) {
$("#div_result").html("0");
}
$(".thematic_advance_actions, .thematic_tools ").hide();
$(".thematic_content").mouseover(function() {
var id = parseInt(this.id.split("_")[3]);
@ -83,9 +88,7 @@ $(function() {
$("#thematic_advance_tools_"+id ).hide();
});
});
</script>';
$htmlHeadXtra[] = '<script>
function check_per_attendance(obj) {
if (obj.checked) {
$("#div_datetime_by_attendance").show();
@ -105,6 +108,51 @@ function check_per_custom_date(obj) {
$("#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>';
$attendance = new Attendance();
@ -164,9 +212,7 @@ switch ($action) {
) {
$title = trim($_POST['title']);
$content = trim($_POST['content']);
$session_id = api_get_session_id();
$thematicManager->set_thematic_attributes($thematicId, $title, $content, $session_id);
$thematicManager->thematic_save();
$thematicManager->thematicSave($thematicId, $title, $content, $course, $session);
Display::addFlash(Display::return_message(get_lang('Update successful')));
header('Location: '.$currentUrl);
@ -258,7 +304,7 @@ switch ($action) {
}
// Import the progress.
$current_thematic = null;
$currentThematic = null;
foreach ($csv_import_array as $key => $item) {
if (!$key) {
continue;
@ -266,35 +312,22 @@ switch ($action) {
switch ($item[0]) {
case 'title':
$thematicManager->set_thematic_attributes(
null,
$item[1],
$item[2],
api_get_session_id()
);
$current_thematic = $thematicManager->thematic_save();
$currentThematic = $thematicManager->thematicSave(null, $item[1], $item[2], $course, $session);
$description_type = 1;
break;
case 'plan':
$thematicManager->set_thematic_plan_attributes(
$current_thematic,
$item[1],
$item[2],
$description_type
);
$thematicManager->thematic_plan_save();
$thematicManager->thematicPlanSave($currentThematic, $item[1], $item[2], $description_type);
$description_type++;
break;
case 'progress':
$thematicManager->set_thematic_advance_attributes(
$thematicManager->thematicAdvanceSave(
$currentThematic,
null,
null,
$current_thematic,
0,
$item[3],
$item[1],
$item[2]
);
$thematicManager->thematic_advance_save();
break;
}
}
@ -694,26 +727,24 @@ switch ($action) {
$description_type = $_REQUEST['description_type'];
for ($i = 1; $i < count($title_list) + 1; $i++) {
$thematicManager->set_thematic_plan_attributes(
$_REQUEST['thematic_id'],
$thematicManager->thematicPlanSave(
$thematicEntity,
$title_list[$i],
$description_list[$i],
$description_type[$i]
);
$thematicManager->thematic_plan_save();
}
$saveRedirect = api_get_path(WEB_PATH).'main/course_progress/index.php?';
$saveRedirect .= api_get_cidreq().'&';
if (isset($_REQUEST['add_item'])) {
$thematicManager->set_thematic_plan_attributes(
$_REQUEST['thematic_id'],
$thematicManager->thematicPlanSave(
$thematicEntity,
'',
'',
$i
);
$thematicManager->thematic_plan_save();
Display::addFlash(
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'));
/*if (isset($thematic_advance_data['attendance_id']) &&
0 == $thematic_advance_data['attendance_id']) {
$form->addElement('html', '<div id="div_custom_datetime" style="display:block">');
// Custom date.
if ($advance && $advance->getAttendance()) {
$form->addHtml('<div id="div_custom_datetime" style="display:none">');
} 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('html', '</div>');
$form->addHtml('</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">');
// Date by attendance.
if ($advance && $advance->getAttendance()) {
$form->addHtml('<div id="div_datetime_by_attendance" style="display:block">');
} 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) {
@ -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">');
if (!empty($calendar_select)) {
$form->addElement(
'select',
$form->addSelect(
'start_date_by_attendance',
get_lang('Start Date'),
$calendar_select,
@ -1087,7 +1126,7 @@ switch ($action) {
} else {
$form->addButtonUpdate(get_lang('Save'));
}
$js = '';
$attendance_select_item_id = null;
if (count($attendance_select) > 1) {
$i = 1;
@ -1101,9 +1140,9 @@ switch ($action) {
if (!empty($attendance_select_item_id)) {
$default['attendance_select'] = $attendance_select_item_id;
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 {
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['duration_in_hours'] = $advance->getDuration();
if ($advance->getThematic()) {
$default['start_date_type'] = 2;
if ($advance->getAttendance()) {
$default['start_date_type'] = 1;
//$default['custom_start_date'] = null;
//if ($advance->getStartDate()) {
$default['custom_start_date'] = date(
'Y-m-d H:i:s',
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'];
$default['attendance_select'] = $advance->getAttendance()->getIid();
//}
} else {
$default['custom_start_date'] = date(
'Y-m-d H:i:s',
api_strtotime(api_get_local_time($advance->getStartDate()))
);
}
}
$form->setDefaults($default);
if ($form->validate()) {
$values = $form->exportValues();
$values = $form->getSubmitValues();
if (isset($_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'];
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'];
}
$thematicManager->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,
$advanceId = isset($values['thematic_advance_id']) ? $values['thematic_advance_id'] : null;
$advance = null;
if (!empty($advanceId)) {
$advance = Container::getThematicAdvanceRepository()->find($advanceId);
}
$newAdvance = $thematicManager->thematicAdvanceSave(
$thematicEntity,
$attendance,
$advance,
$values['content'],
$startDate,
$values['duration_in_hours']
);
$affected_rows = $thematicManager->thematic_advance_save();
if ($affected_rows) {
if ($newAdvance) {
// get last done thematic advance before move thematic list
$last_done_thematic_advance = $thematicManager->get_last_done_thematic_advance($course, $session);
// update done advances with de current thematic list
@ -1180,7 +1227,7 @@ switch ($action) {
exit;
}
$content = $form->returnForm();
$content = $form->returnForm().$js;
break;
case 'thematic_advance_delete':

@ -2,9 +2,10 @@
/* For licensing terms, see /license.txt */
/**
* Responses to AJAX calls for thematic.
*/
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CAttendance;
use Chamilo\CourseBundle\Entity\CThematicAdvance;
require_once __DIR__.'/../global.inc.php';
api_protect_course_script(true);
@ -86,47 +87,51 @@ switch ($action) {
case 'get_datetime_by_attendance':
$attendance_id = (int) $_REQUEST['attendance_id'];
$thematic_advance_id = (int) $_REQUEST['thematic_advance_id'];
$label = '';
$input_select = '';
if (!empty($attendance_id)) {
$attendance = new Attendance();
$thematic = new Thematic();
$thematic_list = $thematic->getThematicList($course, $session);
$inputSelect = '';
$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 = [];
foreach ($thematic_list as $item) {
foreach ($thematicList as $item) {
$thematic_list_temp[] = $item->getAdvances();
}
$new_thematic_list = [];
foreach ($thematic_list_temp as $advanceList) {
foreach ($advanceList as $advance) {
$new_thematic_list[$advance->getIid()] = [
'attendance_id' => $advance->getAttendance()->getIid(),
'start_date' => $advance->getStartDate()->format('Y-m-d H:i:s'),
];
foreach ($advanceList as $advanceItem) {
if (!empty($advanceItem->getAttendance())) {
$new_thematic_list[$advanceItem->getIid()] = [
'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');
if (!empty($attendance_calendar)) {
$input_select .= '<select
$inputSelect .= '<select
id="start_date_select_calendar"
name="start_date_by_attendance" size="7" class="form-control">';
foreach ($attendance_calendar as $calendar) {
$selected = null;
$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) {
if ($calendar['db_date_time'] == $thematic_item['start_date']) {
if ($utcDateTime === $thematic_item['start_date']) {
$insert = false;
if ($thematic_advance_id == $key) {
$insert = true;
@ -135,21 +140,24 @@ switch ($action) {
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 {
$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>';
}
}
?>
<div class="form-group">
<label class="col-sm-2 control-label"><?php echo $label; ?></label>
<div class="col-sm-8"><?php echo $input_select; ?></div>
</div>
<?php
echo '<div class="row form-group">';
echo '<label class="col-sm-2 control-label">'.$label.'</label>';
echo '<div class="col-sm-8">'.$inputSelect.'</div>';
echo '</div>';
break;
case 'update_done_thematic_advance':
$id = (int) $_GET['thematic_advance_id'];

@ -856,7 +856,7 @@ class Attendance
/**
* update users' attendance results.
*
* @param array $user_ids registered users inside current course
* @param array $user_ids registered users inside current course
*/
public function updateUsersResults($user_ids, CAttendance $attendance)
{
@ -991,7 +991,7 @@ class Attendance
return 0;
}
return $attendance->getCalendars()->matching($criteria);
return $attendance->getCalendars()->matching($criteria)->count();
/*$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
$attendanceId = (int) $attendanceId;

@ -5,6 +5,7 @@
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CAttendance;
use Chamilo\CourseBundle\Entity\CThematic;
use Chamilo\CourseBundle\Entity\CThematicAdvance;
use Chamilo\CourseBundle\Entity\CThematicPlan;
@ -287,6 +288,7 @@ class Thematic
$repo = Container::getThematicRepository();
$qb = $repo->getResourcesByCourse($course, $session);
$qb->andWhere('resource.active = 1');
return $qb->getQuery()->getResult();
@ -310,27 +312,23 @@ class Thematic
*
* @return CThematic
*/
public function thematic_save()
public function thematicSave($id, $title, $content, Course $course, Session $session = null)
{
// protect data
$id = (int) $this->thematic_id;
$title = $this->thematic_title;
$content = $this->thematic_content;
$id = (int) $id;
// get the maximum display order of all the glossary items
//$max_thematic_item = $this->get_max_thematic_item(false);
$repo = Container::getThematicRepository();
if (empty($id)) {
$thematic = new CThematic();
$courseEntity = api_get_course_entity();
$thematic
->setTitle($title)
->setContent($content)
->setActive(1)
//->setDisplayOrder($max_thematic_item + 1)
->setDisplayOrder(0)
->setParent($courseEntity)
->addCourseLink($courseEntity, api_get_session_entity())
->setParent($course)
->addCourseLink($course, $session)
;
$repo->create($thematic);
@ -453,41 +451,40 @@ class Thematic
}
$thematicManager = new Thematic();
$thematicManager->set_thematic_attributes(
'',
$newThematic = $thematicManager->thematicSave(
null,
$thematic->getTitle().' - '.get_lang('Copy'),
$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();
if (!empty($thematic_advanced)) {
foreach ($thematic_advanced as $item) {
$thematic = new Thematic();
$thematic->set_thematic_advance_attributes(
0,
$new_thematic_id,
0,
$thematic->thematicAdvanceSave(
$newThematic,
$item->getAttendance(),
null,
$item->getContent(),
$item->getStartDate()->format('Y-m-d H:i:s'),
$item->getDuration()
);
$thematic->thematic_advance_save();
}
}
$thematic_plan = $thematic->getPlans();
if (!empty($thematic_plan)) {
foreach ($thematic_plan as $item) {
$thematic = new Thematic();
$thematic->set_thematic_plan_attributes(
$new_thematic_id,
$thematic->thematicPlanSave(
$newThematic,
$item->getTitle(),
$item->getDescription(),
$item->getDescriptionType()
);
$thematic->thematic_plan_save();
}
}
}
@ -583,68 +580,21 @@ class Thematic
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.
*
* @todo problem
*
* @return int last thematic advance id
* @return CThematicAdvance
*/
public function thematic_advance_save()
{
$id = (int) $this->thematic_advance_id;
$thematic_id = intval($this->thematic_id);
$attendance_id = intval($this->attendance_id);
$content = $this->thematic_advance_content;
$start_date = $this->start_date;
$duration = intval($this->duration);
$repo = Container::getThematicAdvanceRepository();
public function thematicAdvanceSave(
CThematic $thematic,
CAttendance $attendance,
CThematicAdvance $advance = null,
$content,
$start_date,
$duration
) {
$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) {
$advance = new CThematicAdvance();
$advance
@ -655,23 +605,13 @@ class Thematic
->setDuration($duration)
;
if ($thematic) {
$advance->setThematic($thematic);
}
if ($attendance) {
$advance->setAttendance($attendance);
}
$courseEntity = api_get_course_entity();
//$courseEntity = api_get_course_entity();
/*$advance
->setParent($courseEntity)
->addCourseLink($courseEntity, api_get_session_entity())
;*/
$em->persist($advance);
$em->flush();
$last_id = $advance->getIid();
} else {
$advance
->setContent($content)
@ -686,118 +626,11 @@ class Thematic
if ($attendance) {
$advance->setAttendance($attendance);
}
//$repo->update($advance);
$em->persist($advance);
$em->flush();
}
return $last_id;
}
/**
* 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;
return $advance;
}
/**
@ -805,19 +638,11 @@ class Thematic
*
* @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
$thematic_id = intval($this->thematic_id);
$title = $this->thematic_plan_title;
$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();
$thematic_id = $thematic->getIid();
$description_type = (int) $description_type;
/*$list = api_get_item_property_by_tool(
'thematic_plan',
@ -930,7 +755,7 @@ class Thematic
return false;
$_course = api_get_course_info();
/*$_course = api_get_course_info();
// definition database table
$tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
@ -952,7 +777,8 @@ class Thematic
thematic_id = $thematic_id AND
description_type = $description_type ";
$result = Database::query($sql);
$affected_rows = Database::affected_rows($result);
$affected_rows = Database::affected_rows($result);*/
/*
if ($affected_rows) {
/*api_item_property_update(
$_course,
@ -960,8 +786,8 @@ class Thematic
$thematic_plan_id,
'ThematicPlanDeleted',
$user_id
);*/
}
);
}*/
return $affected_rows;
}
@ -1154,7 +980,6 @@ class Thematic
public function get_last_done_thematic_advance($course, $session = null)
{
$thematic_data = self::getThematicList($course, $session);
$a_thematic_advance_ids = [];
$last_done_advance_id = 0;
if (!empty($thematic_data)) {
@ -1188,21 +1013,19 @@ class Thematic
public function get_next_thematic_advance_not_done($offset = 1, $course, $session = null)
{
$thematic_data = self::getThematicList($course, $session);
$thematic_advance_data = $this->get_thematic_advance_list();
$a_thematic_advance_ids = [];
$next_advance_not_done = 0;
if (!empty($thematic_data)) {
foreach ($thematic_data as $thematic) {
if (!empty($thematic_advance_data[$thematic['id']])) {
foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
if (0 == $thematic_advance['done_advance']) {
$a_thematic_advance_ids[] = $thematic_advance['id'];
}
$advanceList = $thematic->getAdvances();
foreach ($advanceList as $advance) {
if (0 == $advance->getDoneAdvance()) {
$a_thematic_advance_ids[] = $advance->getIid();
}
}
}
}
$next_advance_not_done = 0;
if (!empty($a_thematic_advance_ids)) {
for ($i = 0; $i < $offset; $i++) {
$next_advance_not_done = array_shift($a_thematic_advance_ids);
@ -1272,42 +1095,6 @@ class Thematic
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.
*

Loading…
Cancel
Save