Skip to content

Commit

Permalink
Learnpath: Fix position for Certificate item #2887
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Apr 29, 2019
1 parent 2b1d000 commit e0920d6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion main/inc/lib/fileUpload.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ function create_unexisting_directory(

if ($document_id) {
// Update document item_property
if (in_array($visibility, [0, 1, 2])) {
if (!empty($visibility) && in_array($visibility, [0, 1, 2])) {
$visibilities = [
0 => 'invisible',
1 => 'visible',
Expand Down
47 changes: 41 additions & 6 deletions main/lp/learnpath.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ public function add_item(
if (!empty($next)) {
$sql = "UPDATE $tbl_lp_item
SET previous_item_id = $new_item_id
WHERE c_id = $course_id AND id = $next";
WHERE c_id = $course_id AND id = $next AND item_type != '".TOOL_LP_FINAL_ITEM."'";
Database::query($sql);
}

Expand Down Expand Up @@ -656,6 +656,11 @@ public function add_item(
WHERE c_id = $course_id AND iid = $new_item_id";
Database::query($sql);

$sql = "UPDATE $tbl_lp_item
SET previous_item_id = ".$this->getLastInFirstLevel()."
WHERE c_id = $course_id AND lp_id = {$this->lp_id} AND item_type = '".TOOL_LP_FINAL_ITEM."'";
Database::query($sql);

// Upload audio.
if (!empty($_FILES['mp3']['name'])) {
// Create the audio folder if it does not exist yet.
Expand Down Expand Up @@ -1242,7 +1247,7 @@ public function delete_item($id)
WHERE iid = $previous";
Database::query($sql_upd);
$sql_upd = "UPDATE $lp_item SET previous_item_id = $previous
WHERE iid = $next";
WHERE iid = $next AND item_type != '".TOOL_LP_FINAL_ITEM."'";
Database::query($sql_upd);
// Now update all following items with new display order.
$sql_all = "UPDATE $lp_item SET display_order = display_order-1
Expand All @@ -1258,6 +1263,11 @@ public function delete_item($id)
WHERE c_id = $course_id AND prerequisite = $id";
Database::query($sql_all);

$sql = "UPDATE $lp_item
SET previous_item_id = ".$this->getLastInFirstLevel()."
WHERE c_id = $course_id AND lp_id = {$this->lp_id} AND item_type = '".TOOL_LP_FINAL_ITEM."'";
Database::query($sql);

// Remove from search engine if enabled.
if (api_get_setting('search_enabled') === 'true') {
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
Expand Down Expand Up @@ -1991,6 +2001,30 @@ public function get_last()
return false;
}

/**
* Get the last element in the first level.
* Unlike learnpath::get_last this delete_item doesn't consider the subsection' elements.
*
* @throws \Doctrine\ORM\Query\QueryException
*
* @return mixed
*/
public function getLastInFirstLevel()
{
try {
$lastId = Database::getManager()
->createQuery('SELECT i.iid FROM ChamiloCourseBundle:CLpItem i
WHERE i.lpId = :lp AND i.parentItemId = 0 AND i.itemType != :type ORDER BY i.displayOrder DESC')
->setMaxResults(1)
->setParameters(['lp' => $this->lp_id, 'type' => TOOL_LP_FINAL_ITEM])
->getSingleScalarResult();

return $lastId;
} catch (Exception $exception) {
return 0;
}
}

/**
* Gets the navigation bar for the learnpath display screen.
*
Expand Down Expand Up @@ -8701,7 +8735,8 @@ public function display_item_form(
$arrHide = [];
// POSITION
for ($i = 0; $i < count($arrLP); $i++) {
if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id &&
$arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM) {
//this is the same!
if (isset($extra_info['previous_item_id']) &&
$extra_info['previous_item_id'] == $arrLP[$i]['id']
Expand Down Expand Up @@ -9417,8 +9452,8 @@ public function displayFrmReadOutText($action = 'add', $id = 0, $extra_info = 'n
$lastPosition = null;

for ($i = 0; $i < count($arrLP); $i++) {
if (($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) ||
$arrLP[$i]['item_type'] == TOOL_LP_FINAL_ITEM
if (($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) &&
$arrLP[$i]['item_type'] !== TOOL_LP_FINAL_ITEM
) {
if ((isset($extra_info['previous_item_id']) &&
$extra_info['previous_item_id'] == $arrLP[$i]['id']) || $action == 'add'
Expand Down Expand Up @@ -13246,7 +13281,7 @@ public function getFinalItemForm()

if ($form->validate()) {
$values = $form->exportValues();
$lastItemId = $this->get_last();
$lastItemId = $this->getLastInFirstLevel();

if (!$finalItem) {
$documentId = $this->create_document(
Expand Down

0 comments on commit e0920d6

Please sign in to comment.