/** * Build the Surveys * @param int $session_id Internal session ID * @param int $courseId Internal course ID * @param bool $with_base_content Whether to include content from the course without session or not * @param array $id_list If you want to restrict the structure to only the given IDs */ public function build_thematic($session_id = 0, $courseId = 0, $with_base_content = false, $id_list = array()) { $table_thematic = Database::get_course_table(TABLE_THEMATIC); $table_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE); $table_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN); $session_id = intval($session_id); if ($with_base_content) { $session_condition = api_get_session_condition($session_id, true, true); } else { $session_condition = api_get_session_condition($session_id, true); } $sql = "SELECT * FROM {$table_thematic}\n WHERE c_id = {$courseId} {$session_condition} "; $db_result = Database::query($sql); while ($row = Database::fetch_array($db_result, 'ASSOC')) { $thematic = new Thematic($row); $sql = 'SELECT * FROM ' . $table_thematic_advance . ' WHERE c_id = ' . $courseId . ' AND thematic_id = ' . $row['id']; $result = Database::query($sql); while ($sub_row = Database::fetch_array($result, 'ASSOC')) { $thematic->add_thematic_advance($sub_row); } $items = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), $session_id); $thematic_plan_id_list = array(); if (!empty($items)) { foreach ($items as $item) { $thematic_plan_id_list[] = $item['ref']; //$thematic_plan_complete_list[$item['ref']] = $item; } } if (count($thematic_plan_id_list) > 0) { $sql = "SELECT tp.*\n FROM {$table_thematic_plan} tp\n INNER JOIN {$table_thematic} t ON (t.id=tp.thematic_id)\n WHERE\n t.c_id = {$courseId} AND\n tp.c_id = {$courseId} AND\n thematic_id = {$row['id']} AND\n tp.id IN (" . implode(', ', $thematic_plan_id_list) . ") "; $result = Database::query($sql); while ($sub_row = Database::fetch_array($result, 'ASSOC')) { $thematic->add_thematic_plan($sub_row); } } $this->course->add_resource($thematic); } }
/** * insert or update a thematic plan * @return int affected rows */ public function thematic_plan_save() { // definition database table $tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN); // protect data $thematic_id = intval($this->thematic_id); $title = Database::escape_string($this->thematic_plan_title); $description = Database::escape_string($this->thematic_plan_description); $description_type = intval($this->thematic_plan_description_type); $thematic_plan_id = intval($this->thematic_plan_id); $user_id = api_get_user_id(); $course_id = $this->get_course_int_id(); $session_id = $this->get_session_id(); $course_info = $this->course; $list = api_get_item_property_by_tool('thematic_plan', $course_info['code'], $session_id); $elements_to_show = array(); foreach ($list as $value) { $elements_to_show[] = $value['ref']; } $condition = ''; if (!empty($elements_to_show)) { $condition = "AND id IN (" . implode(',', $elements_to_show) . ") "; } if ($thematic_plan_id) { // update $upd = "UPDATE {$tbl_thematic_plan} SET\n title = '{$title}',\n description = '{$description}'\n WHERE c_id = {$course_id} AND id = {$thematic_plan_id}"; $result = Database::query($upd); $affected_rows = Database::affected_rows($result); if ($affected_rows) { api_item_property_update($course_info, 'thematic_plan', $thematic_plan_id, "ThematicPlanUpdated", $user_id); } } else { // insert $ins = "INSERT INTO {$tbl_thematic_plan} (c_id, thematic_id, title, description, description_type)\n VALUES ({$course_id}, {$thematic_id}, '{$title}', '{$description}', {$description_type}) "; $result = Database::query($ins); $last_id = Database::insert_id(); $affected_rows = Database::affected_rows($result); if ($affected_rows) { api_item_property_update($course_info, 'thematic_plan', $last_id, "ThematicPlanAdded", $user_id); } } return $affected_rows; }
/** * insert or update a thematic plan * @return int affected rows */ public function thematic_plan_save() { $_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(); $list = api_get_item_property_by_tool('thematic_plan', api_get_course_id(), api_get_session_id()); $elements_to_show = array(); foreach ($list as $value) { $elements_to_show[] = $value['ref']; } $condition = ''; if (!empty($elements_to_show)) { $condition = "AND id IN (" . implode(',', $elements_to_show) . ") "; } // check thematic plan type already exists $sql = "SELECT id FROM {$tbl_thematic_plan}\n WHERE\n c_id = {$course_id} AND\n thematic_id = {$thematic_id} AND\n description_type = '{$description_type}'"; $rs = Database::query($sql); $affected_rows = 0; if (Database::num_rows($rs) > 0) { $row_thematic_plan = Database::fetch_array($rs); $thematic_plan_id = $row_thematic_plan['id']; $update = false; if (in_array($thematic_plan_id, $elements_to_show)) { $update = true; } if ($update) { // update $params = ['title' => $title, 'description' => $description]; Database::update($tbl_thematic_plan, $params, ['c_id = ? AND id = ?' => [$course_id, $thematic_plan_id]]); api_item_property_update($_course, 'thematic_plan', $thematic_plan_id, "ThematicPlanUpdated", $user_id); } else { // insert $params = ['c_id' => $this->course_int_id, 'thematic_id' => $thematic_id, 'title' => $title, 'description' => $description, 'description_type' => $description_type]; $last_id = Database::insert($tbl_thematic_plan, $params); if ($last_id) { $sql = "UPDATE {$tbl_thematic_plan} SET id = iid WHERE iid = {$last_id}"; Database::query($sql); api_item_property_update($_course, 'thematic_plan', $last_id, "ThematicPlanAdded", $user_id); } } } else { // insert $params = ['c_id' => $this->course_int_id, 'thematic_id' => $thematic_id, 'title' => $title, 'description' => $description, 'description_type' => $description_type]; $last_id = Database::insert($tbl_thematic_plan, $params); if ($last_id) { $sql = "UPDATE {$tbl_thematic_plan} SET id = iid WHERE iid = {$last_id}"; Database::query($sql); api_item_property_update($_course, 'thematic_plan', $last_id, "ThematicPlanAdded", $user_id); } } return $affected_rows; }
/** * insert or update a thematic plan * @return int affected rows */ public function thematic_plan_save() { global $_course; // definition database table $tbl_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN); // protect data $thematic_id = intval($this->thematic_id); $title = Database::escape_string($this->thematic_plan_title); $description = Database::escape_string($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( 'thematic_plan', api_get_course_id(), api_get_session_id() ); $elements_to_show = array(); foreach($list as $value) { $elements_to_show[]= $value['ref']; } $condition = ''; if (!empty($elements_to_show)) { $condition = "AND id IN (".implode(',', $elements_to_show).") "; } // check thematic plan type already exists $sql = "SELECT id FROM $tbl_thematic_plan WHERE c_id = $course_id AND thematic_id = $thematic_id AND description_type = '$description_type'"; $rs = Database::query($sql); $affected_rows = 0; if (Database::num_rows($rs) > 0) { $row_thematic_plan = Database::fetch_array($rs); $thematic_plan_id = $row_thematic_plan['id']; //Checking the session $thematic_plan_data = api_get_item_property_info(api_get_course_int_id(), 'thematic_plan', $thematic_plan_id); $update = false; if (in_array($thematic_plan_id, $elements_to_show)) { $update = true; } if ($update) { // update $upd = "UPDATE $tbl_thematic_plan SET title = '$title', description = '$description' WHERE c_id = $course_id AND id = $thematic_plan_id"; Database::query($upd); $affected_rows = Database::affected_rows(); if ($affected_rows) { api_item_property_update($_course, 'thematic_plan', $thematic_plan_id, "ThematicPlanUpdated", $user_id); } } else { // insert $ins = "INSERT INTO $tbl_thematic_plan (c_id, thematic_id, title, description, description_type) VALUES ($this->course_int_id, $thematic_id, '$title', '$description', $description_type) "; Database::query($ins); $last_id = Database::insert_id(); $affected_rows = Database::affected_rows(); if ($affected_rows) { api_item_property_update($_course, 'thematic_plan', $last_id,"ThematicPlanAdded", $user_id); } } } else { // insert $ins = "INSERT INTO $tbl_thematic_plan (c_id, thematic_id, title, description, description_type) VALUES($this->course_int_id, $thematic_id, '$title', '$description', $description_type) "; Database::query($ins); $last_id = Database::insert_id(); $affected_rows = Database::affected_rows(); if ($affected_rows) { api_item_property_update($_course, 'thematic_plan', $last_id,"ThematicPlanAdded", $user_id); } } return $affected_rows; }