Skip to content

Commit

Permalink
LP: Fix move form #3653
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Nov 27, 2020
1 parent de955e8 commit cdf2f79
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions main/lp/learnpath.class.php
Expand Up @@ -9389,7 +9389,7 @@ public function createReadOutText($courseInfo, $content = '', $title = '', $pare
*
* @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();
$tbl_link = Database::get_course_table(TABLE_LINK);
Expand All @@ -9398,10 +9398,12 @@ public function display_link_form($action = 'add', $id = 0, $extra_info = '')
$item_description = '';
$item_url = '';

$previousId = 0;
if ($id != 0 && is_array($extra_info)) {
$item_title = stripslashes($extra_info['title']);
$item_description = stripslashes($extra_info['description']);
$item_url = stripslashes($extra_info['url']);
$previousId = $extra_info['previous_item_id'];
} elseif (is_numeric($extra_info)) {
$extra_info = (int) $extra_info;
$sql = "SELECT title, description, url
Expand All @@ -9414,6 +9416,10 @@ public function display_link_form($action = 'add', $id = 0, $extra_info = '')
$item_url = $row['url'];
}

if ($item instanceof learnpathItem) {
$previousId = $extra_info->previous;
}

$form = new FormValidator(
'edit_link',
'POST',
Expand All @@ -9431,17 +9437,17 @@ public function display_link_form($action = 'add', $id = 0, $extra_info = '')
$arrLP = isset($this->arrMenu) ? $this->arrMenu : [];
unset($this->arrMenu);

if ($action == 'add') {
if ($action === 'add') {
$legend = get_lang('CreateTheLink');
} elseif ($action == 'move') {
} elseif ($action === 'move') {
$legend = get_lang('MoveCurrentLink');
} else {
$legend = get_lang('EditCurrentLink');
}

$form->addHeader($legend);

if ($action != 'move') {
if ($action !== 'move') {
$this->setItemTitle($form);
$defaults['title'] = $item_title;
}
Expand Down Expand Up @@ -9512,15 +9518,15 @@ public function display_link_form($action = 'add', $id = 0, $extra_info = '')
$arrLP[$i]['id']
);

if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
if ($previousId == $arrLP[$i]['id']) {
$selectPrevious->setSelected($arrLP[$i]['id']);
} elseif ($action == 'add') {
} elseif ($action === 'add') {
$selectPrevious->setSelected($arrLP[$i]['id']);
}
}
}

if ($action != 'move') {
if ($action !== 'move') {
$urlAttributes = ['class' => 'learnpath_item_form'];

if (is_numeric($extra_info)) {
Expand All @@ -9542,13 +9548,13 @@ public function display_link_form($action = 'add', $id = 0, $extra_info = '')
$extraField->addElements($form, $id);
}

if ($action == 'add') {
if ($action === 'add') {
$form->addButtonSave(get_lang('AddLinkToCourse'), 'submit_button');
} else {
$form->addButtonSave(get_lang('EditCurrentLink'), 'submit_button');
}

if ($action == 'move') {
if ($action === 'move') {
$form->addHidden('title', $item_title);
$form->addHidden('description', $item_description);
}
Expand Down Expand Up @@ -9579,15 +9585,18 @@ public function display_link_form($action = 'add', $id = 0, $extra_info = '')
public function display_student_publication_form(
$action = 'add',
$id = 0,
$extra_info = ''
$extra_info = '',
$item = null
) {
$course_id = api_get_course_int_id();
$tbl_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);

$item_title = get_lang('Student_publication');
$previousId = 0;
if ($id != 0 && is_array($extra_info)) {
$item_title = stripslashes($extra_info['title']);
$item_description = stripslashes($extra_info['description']);
$previousId = $extra_info['previous_item_id'];
} elseif (is_numeric($extra_info)) {
$extra_info = (int) $extra_info;
$sql = "SELECT title, description
Expand All @@ -9601,6 +9610,12 @@ public function display_student_publication_form(
}
}

if ($item instanceof learnpathItem) {
$item_title = $item->get_title();
$item_description = $item->get_description();
$previousId = $item->previous;
}

$parent = 0;
if ($id != 0 && is_array($extra_info)) {
$parent = $extra_info['parent_item_id'];
Expand All @@ -9614,15 +9629,15 @@ public function display_student_publication_form(

$form = new FormValidator('frm_student_publication', 'post', '#');

if ($action == 'add') {
if ($action === 'add') {
$form->addHeader(get_lang('Student_publication'));
} elseif ($action == 'move') {
} elseif ($action === 'move') {
$form->addHeader(get_lang('MoveCurrentStudentPublication'));
} else {
$form->addHeader(get_lang('EditCurrentStudentPublication'));
}

if ($action != 'move') {
if ($action !== 'move') {
$this->setItemTitle($form);
}

Expand Down Expand Up @@ -9658,7 +9673,7 @@ public function display_student_publication_form(
$arrHide[] = $arrLP[$i]['id'];
}
} else {
if ($arrLP[$i]['item_type'] == 'dir') {
if ($arrLP[$i]['item_type'] === 'dir') {
$parentSelect->addOption(
$arrLP[$i]['title'],
$arrLP[$i]['id'],
Expand Down Expand Up @@ -9690,9 +9705,9 @@ public function display_student_publication_form(
$arrLP[$i]['id']
);

if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
if ($previousId == $arrLP[$i]['id']) {
$previousSelect->setSelected($arrLP[$i]['id']);
} elseif ($action == 'add') {
} elseif ($action === 'add') {
$previousSelect->setSelected($arrLP[$i]['id']);
}
}
Expand All @@ -9703,13 +9718,13 @@ public function display_student_publication_form(
$extraField->addElements($form, $id);
}

if ($action == 'add') {
if ($action === 'add') {
$form->addButtonCreate(get_lang('AddAssignmentToCourse'), 'submit_button');
} else {
$form->addButtonCreate(get_lang('EditCurrentStudentPublication'), 'submit_button');
}

if ($action == 'move') {
if ($action === 'move') {
$form->addHidden('title', $item_title);
$form->addHidden('description', $item_description);
}
Expand Down Expand Up @@ -9931,6 +9946,7 @@ public function display_move_item($item)
if ($item) {
$item_id = $item->getIid();
$type = $item->get_type();
$path = (int) $item->get_path();

switch ($type) {
case 'dir':
Expand All @@ -9950,7 +9966,7 @@ public function display_move_item($item)
break;
case TOOL_LINK:
$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;
case TOOL_HOTPOTATOES:
$return .= $this->display_manipulate($item_id, $type);
Expand All @@ -9962,15 +9978,15 @@ public function display_move_item($item)
break;
case TOOL_STUDENTPUBLICATION:
$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;
case TOOL_FORUM:
$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;
case TOOL_THREAD:
$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;
}
}
Expand Down

0 comments on commit cdf2f79

Please sign in to comment.