diff --git a/public/main/lp/learnpath.class.php b/public/main/lp/learnpath.class.php index 51eda1a248..2d36b5d7f9 100644 --- a/public/main/lp/learnpath.class.php +++ b/public/main/lp/learnpath.class.php @@ -121,6 +121,7 @@ class learnpath $debug = $this->debug; $this->encoding = api_get_system_encoding(); $lp_id = (int) $entity->getIid(); + $course_info = empty($course_info) ? api_get_course_info() : $course_info; $course_id = (int) $course_info['real_id']; $this->set_course_int_id($course_id); if (empty($lp_id) || empty($course_id)) { @@ -372,7 +373,6 @@ class learnpath error_log('End of learnpath constructor for learnpath '.$this->get_id()); } } - } /** @@ -946,7 +946,6 @@ class learnpath return false; } - $lp = Database::get_course_table(TABLE_LP_MAIN); $lp_item = Database::get_course_table(TABLE_LP_ITEM); $lp_view = Database::get_course_table(TABLE_LP_VIEW); $lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); @@ -967,7 +966,7 @@ class learnpath WHERE c_id = $course_id AND lp_id = ".$this->lp_id; Database::query($sql); - self::toggleVisibility($this->lp_id, 0); + //self::toggleVisibility($this->lp_id, 0); /*if (2 == $this->type || 3 == $this->type) { // This is a scorm learning path, delete the files as well. @@ -1008,14 +1007,13 @@ class learnpath } }*/ - if (api_get_configuration_value('allow_lp_subscription_to_usergroups')) { - $table = Database::get_course_table(TABLE_LP_REL_USERGROUP); - $sql = "DELETE FROM $table - WHERE - lp_id = {$this->lp_id} AND - c_id = $course_id "; - Database::query($sql); - } + $table = Database::get_course_table(TABLE_LP_REL_USERGROUP); + $sql = "DELETE FROM $table + WHERE + lp_id = {$this->lp_id} AND + c_id = $course_id "; + Database::query($sql); + /*$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $link = 'lp/lp_controller.php?action=view&lp_id='.$this->lp_id; @@ -1024,9 +1022,6 @@ class learnpath WHERE c_id = $course_id AND (link LIKE '$link%' AND image='scormbuilder.gif')"; Database::query($sql);*/ - /*$sql = "DELETE FROM $lp - WHERE iid = ".$this->lp_id; - Database::query($sql);*/ $repo = Container::getLpRepository(); $lp = $repo->find($this->lp_id); Database::getManager()->remove($lp); @@ -1035,14 +1030,6 @@ class learnpath // Updates the display order of all lps. $this->update_display_order(); - /*api_item_property_update( - api_get_course_info(), - TOOL_LEARNPATH, - $this->lp_id, - 'delete', - api_get_user_id() - );*/ - $link_info = GradebookUtils::isResourceInCourseGradebook( api_get_course_id(), 4, @@ -1054,7 +1041,7 @@ class learnpath GradebookUtils::remove_resource_from_course_gradebook($link_info['id']); } - if ('true' == api_get_setting('search_enabled')) { + if ('true' === api_get_setting('search_enabled')) { require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php'; delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id); } diff --git a/public/main/lp/lp_upload.php b/public/main/lp/lp_upload.php index 2de4b03c7b..d9adf7f50d 100644 --- a/public/main/lp/lp_upload.php +++ b/public/main/lp/lp_upload.php @@ -4,6 +4,7 @@ use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver; use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer; +use Chamilo\CourseBundle\Entity\CLp; /** * Script managing the learnpath upload. To best treat the uploaded file, make sure we can identify it. @@ -79,7 +80,7 @@ if (isset($_POST) && $is_error) { } break; case 'scorm': - $scorm = new scorm(); + $scorm = new scorm(new CLp()); $scorm->import_package( $_FILES['user_file'], $current_dir, diff --git a/public/main/lp/scorm.class.php b/public/main/lp/scorm.class.php index 3f916394b8..35dbe7aeb8 100644 --- a/public/main/lp/scorm.class.php +++ b/public/main/lp/scorm.class.php @@ -47,12 +47,12 @@ class scorm extends learnpath * @param int Learnpath ID in DB * @param int User ID */ - public function __construct($courseCode = null, $resource_id = null, $user_id = null) + public function __construct($entity, $course_info = null, $user_id = null) { $this->items = []; $this->subdir = ''; $this->manifestToString = ''; - parent::__construct($courseCode, $resource_id, $user_id); + parent::__construct($entity, $course_info, $user_id); } /** diff --git a/src/CoreBundle/Entity/Asset.php b/src/CoreBundle/Entity/Asset.php index 995dba2b20..4b6811d990 100644 --- a/src/CoreBundle/Entity/Asset.php +++ b/src/CoreBundle/Entity/Asset.php @@ -45,7 +45,13 @@ class Asset /** * @var string * - * @Assert\Choice({Asset::SCORM, Asset::WATERMARK, Asset::CSS}, message="Choose a valid category.") + * @Assert\Choice({ + * Asset::SCORM, + * Asset::WATERMARK, + * Asset::CSS + * }, + * message="Choose a valid category." + * ) * * @ORM\Column(type="string", length=255) */ @@ -339,12 +345,12 @@ class Asset return $this; } - public function getTitle(): string + public function getTitle() { return $this->title; } - public function setTitle(string $title): Asset + public function setTitle($title): Asset { $this->title = $title; diff --git a/src/CoreBundle/EventListener/AssetListener.php b/src/CoreBundle/EventListener/AssetListener.php new file mode 100644 index 0000000000..7b777db066 --- /dev/null +++ b/src/CoreBundle/EventListener/AssetListener.php @@ -0,0 +1,39 @@ +assetRepository = $assetRepository; + } + + public function onVichUploaderPostRemove(Event $event) + { + /** @var Asset $asset */ + $asset = $event->getObject(); + $mapping = $event->getMapping(); + $folder = $mapping->getFile($asset)->getFilename(); + + // Deletes scorm folder: example: assets/scorm/myABC . + if (Asset::SCORM === $asset->getCategory() && !empty($folder)) { + $folder = Asset::SCORM.'/'.$folder; + $this->assetRepository->getFileSystem()->deleteDir($folder); + } + } +} diff --git a/src/CoreBundle/Resources/config/services.yml b/src/CoreBundle/Resources/config/services.yml index 7d07f5b9b0..70ccdaced9 100644 --- a/src/CoreBundle/Resources/config/services.yml +++ b/src/CoreBundle/Resources/config/services.yml @@ -90,6 +90,14 @@ services: # tags: # - {name: kernel.event_listener, event: kernel.controller, method: onCoreController} + Chamilo\CoreBundle\Repository\AssetRepository: + + Chamilo\CoreBundle\EventListener\AssetListener: + arguments: + - '@Chamilo\CoreBundle\Repository\AssetRepository' + tags: + - {name: kernel.event_listener, event: vich_uploader.post_remove} + Chamilo\CoreBundle\Entity\Listener\ResourceListener: tags: - {name: doctrine.orm.entity_listener, entity_manager: default, lazy: true} diff --git a/src/CourseBundle/Entity/CLp.php b/src/CourseBundle/Entity/CLp.php index 94f407576b..47c7361012 100644 --- a/src/CourseBundle/Entity/CLp.php +++ b/src/CourseBundle/Entity/CLp.php @@ -287,7 +287,7 @@ class CLp extends AbstractResource implements ResourceInterface /** * @var Asset|null * - * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Asset") + * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Asset", cascade={"persist", "remove"}) * @ORM\JoinColumn(name="asset_id", referencedColumnName="id") */ protected $asset;