Fix issue editing course description items from action bar - refs #7803 #TMI

1.10.x
Yannick Warnier 10 years ago
parent 79e9403ce4
commit 279dc299a4
  1. 20
      main/course_description/course_description_controller.php
  2. 13
      main/course_description/edit.php
  3. 21
      main/inc/lib/course_description.lib.php
  4. 4
      main/template/default/course_description/edit.tpl

@ -65,7 +65,8 @@ class CourseDescriptionController
/**
* It's used for editing a course description,
* render to listing or edit view
* @param int description type
* @param int $id description item id
* @param int $description_type description type id
*/
public function edit($id, $description_type)
{
@ -84,6 +85,14 @@ class CourseDescriptionController
$content = $_POST['contentDescription'];
$description_type = $_POST['description_type'];
$id = $_POST['id'];
if (empty($id)) {
// If the ID was not provided, find the first matching description item given the item type
$description = $course_description->get_data_by_description_type($description_type);
if (count($description) > 0) {
$id = $description['id'];
}
// If no corresponding description is found, edit a new one
}
$progress = isset($_POST['progress']) ? $_POST['progress'] : '';
$course_description->set_description_type($description_type);
$course_description->set_title($title);
@ -131,7 +140,14 @@ class CourseDescriptionController
$data['information'] = $course_description->get_default_information();
$data['description_type'] = $description_type;
if (empty($id)) {
// If the ID was not provided, find the first matching description item given the item type
$description = $course_description->get_data_by_description_type($description_type);
if (count($description) > 0) {
$id = $description['id'];
}
// If no corresponding description is found, edit a new one
}
if (!empty($id)) {
if (isset($_GET['id_session'])) {
$session_id = intval($_GET['id_session']);

@ -9,6 +9,19 @@
// protect a course script
api_protect_course_script(true);
if (empty($id)) {
$id = intval($_REQUEST['id']);
if (empty($id)) {
// If the ID was not provided, find the first matching description item given the item type
$course_description = new CourseDescription();
$description = $course_description->get_data_by_description_type($description_type);
if (count($description) > 0) {
$id = $description['id'];
}
unset ($course_description);
// If no corresponding description is found, edit a new one
}
}
$original_id = $id;
if (empty($error)) {

@ -93,36 +93,35 @@ class CourseDescription
/**
* Get all data by description and session id,
* first you must set session_id property with the object CourseDescription
* @param int description type
* @param string course code (optional)
* @param int session id (optional)
* @return array
* @param int $description_type Description type
* @param string $course_code Course code (optional)
* @param int $session_id Session id (optional)
* @return array List of fields from the descriptions found of the given type
*/
public function get_data_by_description_type(
$description_type,
$course_code = '',
$courseId = null,
$session_id = null
) {
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
if (empty($courseId)) {
$courseId = api_get_course_int_id();
}
if (!isset($session_id)) {
$session_id = $this->session_id;
}
$condition_session = api_get_session_condition($session_id);
if (!empty($course_code)) {
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
}
$description_type = intval($description_type);
$sql = "SELECT * FROM $tbl_course_description
WHERE c_id = $course_id AND description_type='$description_type' $condition_session ";
WHERE c_id = $courseId AND description_type='$description_type' $condition_session ";
$rs = Database::query($sql);
$data = array();
if ($description = Database::fetch_array($rs)) {
$data['description_title'] = $description['title'];
$data['description_content'] = $description['content'];
$data['progress'] = $description['progress'];
$data['id'] = $description['id'];
}
return $data;

@ -22,9 +22,9 @@
{% endif %}
{% if type.question %}
{% if type.question %}
<div class="normal-message">
<div>
<div>
<strong>{{'QuestionPlan'|get_lang}}</strong>
</div>
{{type.question}}

Loading…
Cancel
Save