Skip to content

Commit

Permalink
LPs: save extra field values when copying an LP to another course
Browse files Browse the repository at this point in the history
BT#18064
  • Loading branch information
jmontoyaa committed Dec 31, 2020
1 parent df1362f commit 89b8740
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php
Expand Up @@ -4,6 +4,7 @@
namespace Chamilo\CourseBundle\Component\CourseCopy;

use Category;
use Chamilo\CoreBundle\Entity\ExtraField;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Announcement;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Asset;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\Attendance;
Expand Down Expand Up @@ -1421,7 +1422,7 @@ public function build_learnpaths(
$id_list = [],
$addScormFolder = true
) {
$table_main = Database::get_course_table(TABLE_LP_MAIN);
$lpTable = Database::get_course_table(TABLE_LP_MAIN);
$table_item = Database::get_course_table(TABLE_LP_ITEM);
$table_tool = Database::get_course_table(TABLE_TOOL_LIST);

Expand All @@ -1441,10 +1442,10 @@ public function build_learnpaths(
true
);
}
$sql = 'SELECT * FROM '.$table_main.'
$sql = 'SELECT * FROM '.$lpTable.'
WHERE c_id = '.$courseId.' '.$sessionCondition;
} else {
$sql = 'SELECT * FROM '.$table_main.'
$sql = 'SELECT * FROM '.$lpTable.'
WHERE c_id = '.$courseId.' AND (session_id = 0 OR session_id IS NULL)';
}

Expand Down Expand Up @@ -1523,6 +1524,9 @@ public function build_learnpaths(
$items
);

$extraFieldValue = new \ExtraFieldValue('lp');
$lp->extraFields = $extraFieldValue->getAllValuesByItem($obj->id);

$this->course->add_resource($lp);

if (!empty($obj->preview_image)) {
Expand Down
17 changes: 15 additions & 2 deletions src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php
Expand Up @@ -4,6 +4,7 @@

namespace Chamilo\CourseBundle\Component\CourseCopy;

use Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseCopyLearnpath;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\GradeBookBackup;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\LearnPathCategory;
use Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestion;
Expand Down Expand Up @@ -1379,7 +1380,7 @@ public function restore_links($session_id = 0)
c_id = ".$this->destination_course_id." AND
category_id='".$cat_id."'";
$result = Database::query($sql);
list($max_order) = Database::fetch_array($result);
[$max_order] = Database::fetch_array($result);

$params = [];
if (!empty($session_id)) {
Expand Down Expand Up @@ -1449,7 +1450,7 @@ public function restore_link_category($id, $sessionId = 0)
$sql = "SELECT MAX(display_order) FROM $link_cat_table
WHERE c_id = ".$this->destination_course_id;
$result = Database::query($sql);
list($orderMax) = Database::fetch_array($result, 'NUM');
[$orderMax] = Database::fetch_array($result, 'NUM');
$display_order = $orderMax + 1;

$params['c_id'] = $this->destination_course_id;
Expand Down Expand Up @@ -2872,6 +2873,18 @@ public function restore_learnpaths($session_id = 0, $respect_base_content = fals
}
}

if (isset($lp->extraFields) && !empty($lp->extraFields)) {
$extraFieldValue = new \ExtraFieldValue('lp');
foreach ($lp->extraFields as $extraField) {
$params = [
'item_id' => $new_lp_id,
'value' => $extraField['value'],
'variable' => $extraField['variable']
];
$extraFieldValue->save($params);
}
}

api_item_property_update(
$this->destination_course_info,
TOOL_LEARNPATH,
Expand Down
@@ -1,4 +1,5 @@
<?php

/* For licensing terms, see /license.txt */

namespace Chamilo\CourseBundle\Component\CourseCopy\Resources;
Expand All @@ -7,8 +8,6 @@
* Class CourseCopyLearnpath.
*
* @author Bart Mollet <bart.mollet@hogent.be>
*
* @package chamilo.backup
*/
class CourseCopyLearnpath extends Resource
{
Expand Down
@@ -1,4 +1,5 @@
<?php

/* For licensing terms, see /license.txt */

namespace Chamilo\CourseBundle\Component\CourseCopy\Resources;
Expand All @@ -11,8 +12,6 @@
*
* @author Bart Mollet <bart.mollet@hogent.be>s
*
* @package chamilo.backup
*
* @todo Use the globally defined constants voor tools and remove the RESOURCE_*
* constants
*/
Expand Down Expand Up @@ -42,8 +41,8 @@ class Resource
* The properties of this resource.
*/
public $item_properties;

public $obj = null;
public $obj;
public $extraFields;

/**
* Create a new Resource.
Expand All @@ -58,6 +57,7 @@ public function __construct($id, $type)
$this->destination_id = -1;
$this->linked_resources = [];
$this->item_properties = [];
$this->extraFields = [];
}

/**
Expand Down

0 comments on commit 89b8740

Please sign in to comment.