LP: Fix move form #3653

pull/3680/head
Julio Montoya 5 years ago
parent de955e8d29
commit cdf2f7934c
  1. 60
      main/lp/learnpath.class.php

@ -9389,7 +9389,7 @@ class learnpath
* *
* @return string HTML form * @return string HTML form
*/ */
public function display_link_form($action = 'add', $id = 0, $extra_info = '') public function display_link_form($action = 'add', $id = 0, $extra_info = '', $item = null)
{ {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$tbl_link = Database::get_course_table(TABLE_LINK); $tbl_link = Database::get_course_table(TABLE_LINK);
@ -9398,10 +9398,12 @@ class learnpath
$item_description = ''; $item_description = '';
$item_url = ''; $item_url = '';
$previousId = 0;
if ($id != 0 && is_array($extra_info)) { if ($id != 0 && is_array($extra_info)) {
$item_title = stripslashes($extra_info['title']); $item_title = stripslashes($extra_info['title']);
$item_description = stripslashes($extra_info['description']); $item_description = stripslashes($extra_info['description']);
$item_url = stripslashes($extra_info['url']); $item_url = stripslashes($extra_info['url']);
$previousId = $extra_info['previous_item_id'];
} elseif (is_numeric($extra_info)) { } elseif (is_numeric($extra_info)) {
$extra_info = (int) $extra_info; $extra_info = (int) $extra_info;
$sql = "SELECT title, description, url $sql = "SELECT title, description, url
@ -9414,6 +9416,10 @@ class learnpath
$item_url = $row['url']; $item_url = $row['url'];
} }
if ($item instanceof learnpathItem) {
$previousId = $extra_info->previous;
}
$form = new FormValidator( $form = new FormValidator(
'edit_link', 'edit_link',
'POST', 'POST',
@ -9431,9 +9437,9 @@ class learnpath
$arrLP = isset($this->arrMenu) ? $this->arrMenu : []; $arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
unset($this->arrMenu); unset($this->arrMenu);
if ($action == 'add') { if ($action === 'add') {
$legend = get_lang('CreateTheLink'); $legend = get_lang('CreateTheLink');
} elseif ($action == 'move') { } elseif ($action === 'move') {
$legend = get_lang('MoveCurrentLink'); $legend = get_lang('MoveCurrentLink');
} else { } else {
$legend = get_lang('EditCurrentLink'); $legend = get_lang('EditCurrentLink');
@ -9441,7 +9447,7 @@ class learnpath
$form->addHeader($legend); $form->addHeader($legend);
if ($action != 'move') { if ($action !== 'move') {
$this->setItemTitle($form); $this->setItemTitle($form);
$defaults['title'] = $item_title; $defaults['title'] = $item_title;
} }
@ -9512,15 +9518,15 @@ class learnpath
$arrLP[$i]['id'] $arrLP[$i]['id']
); );
if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) { if ($previousId == $arrLP[$i]['id']) {
$selectPrevious->setSelected($arrLP[$i]['id']); $selectPrevious->setSelected($arrLP[$i]['id']);
} elseif ($action == 'add') { } elseif ($action === 'add') {
$selectPrevious->setSelected($arrLP[$i]['id']); $selectPrevious->setSelected($arrLP[$i]['id']);
} }
} }
} }
if ($action != 'move') { if ($action !== 'move') {
$urlAttributes = ['class' => 'learnpath_item_form']; $urlAttributes = ['class' => 'learnpath_item_form'];
if (is_numeric($extra_info)) { if (is_numeric($extra_info)) {
@ -9542,13 +9548,13 @@ class learnpath
$extraField->addElements($form, $id); $extraField->addElements($form, $id);
} }
if ($action == 'add') { if ($action === 'add') {
$form->addButtonSave(get_lang('AddLinkToCourse'), 'submit_button'); $form->addButtonSave(get_lang('AddLinkToCourse'), 'submit_button');
} else { } else {
$form->addButtonSave(get_lang('EditCurrentLink'), 'submit_button'); $form->addButtonSave(get_lang('EditCurrentLink'), 'submit_button');
} }
if ($action == 'move') { if ($action === 'move') {
$form->addHidden('title', $item_title); $form->addHidden('title', $item_title);
$form->addHidden('description', $item_description); $form->addHidden('description', $item_description);
} }
@ -9579,15 +9585,18 @@ class learnpath
public function display_student_publication_form( public function display_student_publication_form(
$action = 'add', $action = 'add',
$id = 0, $id = 0,
$extra_info = '' $extra_info = '',
$item = null
) { ) {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$item_title = get_lang('Student_publication'); $item_title = get_lang('Student_publication');
$previousId = 0;
if ($id != 0 && is_array($extra_info)) { if ($id != 0 && is_array($extra_info)) {
$item_title = stripslashes($extra_info['title']); $item_title = stripslashes($extra_info['title']);
$item_description = stripslashes($extra_info['description']); $item_description = stripslashes($extra_info['description']);
$previousId = $extra_info['previous_item_id'];
} elseif (is_numeric($extra_info)) { } elseif (is_numeric($extra_info)) {
$extra_info = (int) $extra_info; $extra_info = (int) $extra_info;
$sql = "SELECT title, description $sql = "SELECT title, description
@ -9601,6 +9610,12 @@ class learnpath
} }
} }
if ($item instanceof learnpathItem) {
$item_title = $item->get_title();
$item_description = $item->get_description();
$previousId = $item->previous;
}
$parent = 0; $parent = 0;
if ($id != 0 && is_array($extra_info)) { if ($id != 0 && is_array($extra_info)) {
$parent = $extra_info['parent_item_id']; $parent = $extra_info['parent_item_id'];
@ -9614,15 +9629,15 @@ class learnpath
$form = new FormValidator('frm_student_publication', 'post', '#'); $form = new FormValidator('frm_student_publication', 'post', '#');
if ($action == 'add') { if ($action === 'add') {
$form->addHeader(get_lang('Student_publication')); $form->addHeader(get_lang('Student_publication'));
} elseif ($action == 'move') { } elseif ($action === 'move') {
$form->addHeader(get_lang('MoveCurrentStudentPublication')); $form->addHeader(get_lang('MoveCurrentStudentPublication'));
} else { } else {
$form->addHeader(get_lang('EditCurrentStudentPublication')); $form->addHeader(get_lang('EditCurrentStudentPublication'));
} }
if ($action != 'move') { if ($action !== 'move') {
$this->setItemTitle($form); $this->setItemTitle($form);
} }
@ -9658,7 +9673,7 @@ class learnpath
$arrHide[] = $arrLP[$i]['id']; $arrHide[] = $arrLP[$i]['id'];
} }
} else { } else {
if ($arrLP[$i]['item_type'] == 'dir') { if ($arrLP[$i]['item_type'] === 'dir') {
$parentSelect->addOption( $parentSelect->addOption(
$arrLP[$i]['title'], $arrLP[$i]['title'],
$arrLP[$i]['id'], $arrLP[$i]['id'],
@ -9690,9 +9705,9 @@ class learnpath
$arrLP[$i]['id'] $arrLP[$i]['id']
); );
if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) { if ($previousId == $arrLP[$i]['id']) {
$previousSelect->setSelected($arrLP[$i]['id']); $previousSelect->setSelected($arrLP[$i]['id']);
} elseif ($action == 'add') { } elseif ($action === 'add') {
$previousSelect->setSelected($arrLP[$i]['id']); $previousSelect->setSelected($arrLP[$i]['id']);
} }
} }
@ -9703,13 +9718,13 @@ class learnpath
$extraField->addElements($form, $id); $extraField->addElements($form, $id);
} }
if ($action == 'add') { if ($action === 'add') {
$form->addButtonCreate(get_lang('AddAssignmentToCourse'), 'submit_button'); $form->addButtonCreate(get_lang('AddAssignmentToCourse'), 'submit_button');
} else { } else {
$form->addButtonCreate(get_lang('EditCurrentStudentPublication'), 'submit_button'); $form->addButtonCreate(get_lang('EditCurrentStudentPublication'), 'submit_button');
} }
if ($action == 'move') { if ($action === 'move') {
$form->addHidden('title', $item_title); $form->addHidden('title', $item_title);
$form->addHidden('description', $item_description); $form->addHidden('description', $item_description);
} }
@ -9931,6 +9946,7 @@ class learnpath
if ($item) { if ($item) {
$item_id = $item->getIid(); $item_id = $item->getIid();
$type = $item->get_type(); $type = $item->get_type();
$path = (int) $item->get_path();
switch ($type) { switch ($type) {
case 'dir': case 'dir':
@ -9950,7 +9966,7 @@ class learnpath
break; break;
case TOOL_LINK: case TOOL_LINK:
$return .= $this->display_manipulate($item_id, $type); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_link_form('move', $item_id, $item); $return .= $this->display_link_form('move', $item_id, $path, $item);
break; break;
case TOOL_HOTPOTATOES: case TOOL_HOTPOTATOES:
$return .= $this->display_manipulate($item_id, $type); $return .= $this->display_manipulate($item_id, $type);
@ -9962,15 +9978,15 @@ class learnpath
break; break;
case TOOL_STUDENTPUBLICATION: case TOOL_STUDENTPUBLICATION:
$return .= $this->display_manipulate($item_id, $type); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_student_publication_form('move', $item_id, $item); $return .= $this->display_student_publication_form('move', $item_id, $path, $item);
break; break;
case TOOL_FORUM: case TOOL_FORUM:
$return .= $this->display_manipulate($item_id, $type); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_forum_form('move', $item_id, $item); $return .= $this->display_forum_form('move', $item_id, $path);
break; break;
case TOOL_THREAD: case TOOL_THREAD:
$return .= $this->display_manipulate($item_id, $type); $return .= $this->display_manipulate($item_id, $type);
$return .= $this->display_forum_form('move', $item_id, $item); $return .= $this->display_forum_form('move', $item_id, $path);
break; break;
} }
} }

Loading…
Cancel
Save