added function for updating item_property table for course progress tool - partial BT#578

skala
Cristian Fasanando 15 years ago
parent 544efbd98d
commit ac4a0b1b86
  1. 47
      main/inc/lib/thematic.lib.php

@ -35,7 +35,7 @@ class Thematic
* Get the total number of thematic inside current course and current session * Get the total number of thematic inside current course and current session
* @see SortableTable#get_total_number_of_items() * @see SortableTable#get_total_number_of_items()
*/ */
public function get_number_of_thematics() { public function get_number_of_thematics() {
$tbl_thematic = Database :: get_course_table(TABLE_THEMATIC); $tbl_thematic = Database :: get_course_table(TABLE_THEMATIC);
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id); $condition_session = api_get_session_condition($session_id);
@ -223,33 +223,42 @@ class Thematic
* @return int last thematic id * @return int last thematic id
*/ */
public function thematic_save() { public function thematic_save() {
global $_course;
// definition database table // definition database table
$tbl_thematic = Database::get_course_table(TABLE_THEMATIC); $tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
// protect data // protect data
$id = intval($this->thematic_id); $id = intval($this->thematic_id);
$title = Database::escape_string($this->thematic_title); $title = Database::escape_string($this->thematic_title);
$content = Database::escape_string($this->thematic_content); $content = Database::escape_string($this->thematic_content);
$session_id = intval($this->session_id); $session_id = intval($this->session_id);
$user_id = api_get_user_id();
// 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(); $max_thematic_item = $this->get_max_thematic_item();
if (empty($id)) { if (empty($id)) {
// insert // insert
$sql = "INSERT INTO $tbl_thematic(title, content, active, display_order, session_id) VALUES ('$title', '$content', 1, ".(intval($max_thematic_item)+1).", $session_id) "; $sql = "INSERT INTO $tbl_thematic(title, content, active, display_order, session_id) VALUES ('$title', '$content', 1, ".(intval($max_thematic_item)+1).", $session_id) ";
Database::query($sql); Database::query($sql);
$last_id = Database::insert_id(); $last_id = Database::insert_id();
if (Database::affected_rows()) {
// save inside item property table
$last_id = Database::insert_id();
api_item_property_update($_course, TOOL_COURSE_PROGRESS, $last_id,"CourseProgressAdded", $user_id);
}
} else { } else {
// update // update
$sql = "UPDATE $tbl_thematic SET title = '$title', content = '$content', session_id = $session_id WHERE id = $id "; $sql = "UPDATE $tbl_thematic SET title = '$title', content = '$content', session_id = $session_id WHERE id = $id ";
Database::query($sql); Database::query($sql);
$last_id = $id; $last_id = $id;
} if (Database::affected_rows()) {
// save inside item property table
return $last_id; $last_id = Database::insert_id();
api_item_property_update($_course, TOOL_COURSE_PROGRESS, $last_id,"CourseProgressUpdated", $user_id);
}
}
return $last_id;
} }
/** /**
@ -258,21 +267,30 @@ class Thematic
* @return int Affected rows * @return int Affected rows
*/ */
public function thematic_destroy($thematic_id) { public function thematic_destroy($thematic_id) {
global $_course;
$tbl_thematic = Database::get_course_table(TABLE_THEMATIC); $tbl_thematic = Database::get_course_table(TABLE_THEMATIC);
$affected_rows = 0; $affected_rows = 0;
$user_id = api_get_user_id();
if (is_array($thematic_id)) { if (is_array($thematic_id)) {
foreach ($thematic_id as $id) { foreach ($thematic_id as $id) {
$id = intval($id); $id = intval($id);
$sql = "UPDATE $tbl_thematic SET active = 0 WHERE id = $id"; $sql = "UPDATE $tbl_thematic SET active = 0 WHERE id = $id";
Database::query($sql); Database::query($sql);
$affected_rows += Database::affected_rows(); $affected_rows += Database::affected_rows();
if (!empty($affected_rows)) {
// update row item property table
api_item_property_update($_course, TOOL_COURSE_PROGRESS, $id,"delete", $user_id);
}
} }
} else { } else {
$thematic_id = intval($thematic_id); $thematic_id = intval($thematic_id);
$sql = "UPDATE $tbl_thematic SET active = 0 WHERE id = $thematic_id"; $sql = "UPDATE $tbl_thematic SET active = 0 WHERE id = $thematic_id";
Database::query($sql); Database::query($sql);
$affected_rows = Database::affected_rows(); $affected_rows = Database::affected_rows();
if (!empty($affected_rows)) {
// update row item property table
api_item_property_update($_course, TOOL_COURSE_PROGRESS, $thematic_id,"delete", $user_id);
}
} }
return $affected_rows; return $affected_rows;
@ -328,8 +346,9 @@ class Thematic
} }
$i = 1; $i = 1;
while ($thematic_advance = Database::fetch_row($res)) { while ($thematic_advance = Database::fetch_row($res)) {
$thematic_advance[1] = api_get_local_time($thematic_advance[1]);
$thematic_advance[1] = api_convert_and_format_date($thematic_advance[1], DATE_TIME_FORMAT_LONG, date_default_timezone_get());
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
$actions = ''; $actions = '';
$actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_edit&thematic_id='.$thematic_id.'&thematic_advance_id='.$thematic_advance[0].$param_gradebook.'">'.Display::return_icon('edit.gif',get_lang('Edit')).'</a>&nbsp;'; $actions .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_edit&thematic_id='.$thematic_id.'&thematic_advance_id='.$thematic_advance[0].$param_gradebook.'">'.Display::return_icon('edit.gif',get_lang('Edit')).'</a>&nbsp;';

Loading…
Cancel
Save