Lps: Remove preview image, move preview image to load as resource.

Use entity to save LP settings
pull/3741/head
Julio Montoya 5 years ago
parent 39ba658338
commit 5ca395fb31
  1. 4
      public/main/inc/lib/thematic.lib.php
  2. 100
      public/main/lp/aicc.class.php
  3. 319
      public/main/lp/learnpath.class.php
  4. 1
      public/main/lp/learnpathList.class.php
  5. 39
      public/main/lp/lp_controller.php
  6. 7
      public/main/lp/lp_edit.php
  7. 75
      public/main/lp/scorm.class.php
  8. 41
      src/CoreBundle/Migrations/Schema/V200/Version20190110182615.php
  9. 32
      src/CourseBundle/Entity/CLp.php

@ -802,8 +802,8 @@ class Thematic
$sessionEntity = api_get_session_entity(api_get_session_id());
$qb = $repo->getResourcesByCourse($courseEntity, $sessionEntity);
$result = $qb->getQuery()->getResult();
//var_dump(count($result));
$data = [];
@ -811,10 +811,10 @@ class Thematic
//var_dump($thematic_id, $description_type);
if (!empty($thematic_id)) {
$qb->andWhere($qb->expr()->eq('resource.thematic', $thematic_id));
//$thematic_id = intval($thematic_id);
//$condition .= " AND thematic_id = $thematic_id ";
}
if (!empty($description_type)) {
$qb->andWhere($qb->expr()->eq('resource.descriptionType', $description_type));
//$condition .= " AND description_type = $description_type ";

@ -598,106 +598,6 @@ class aicc extends learnpath
}
}
/**
* Sets the theme setting in the database.
*
* @param string Theme setting
*
* @return bool
*/
public function set_theme($theme = '')
{
$course_id = api_get_course_int_id();
if ($this->debug > 0) {
error_log('In aicc::set_theme('.$theme.') method', 0);
}
$lp = $this->get_id();
if (0 != $lp) {
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql = "UPDATE $tbl_lp SET theme = '$theme' WHERE c_id = ".$course_id." id = ".$lp;
$res = Database::query($sql);
return true;
} else {
return false;
}
}
/**
* Sets the image LP in the database.
*
* @param string $preview_image Theme setting
*
* @return bool
*/
public function set_preview_image($preview_image = '')
{
$course_id = api_get_course_int_id();
if ($this->debug > 0) {
error_log('In aicc::set_preview_image('.$preview_image.') method', 0);
}
$lp = $this->get_id();
if (0 != $lp) {
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql = "UPDATE $tbl_lp SET preview_image = '$preview_image'
WHERE c_id = ".$course_id." id = ".$lp;
Database::query($sql);
return true;
} else {
return false;
}
}
/**
* Sets the Author LP in the database.
*
* @param string $author
*
* @return true
*/
public function set_author($author = '')
{
$course_id = api_get_course_int_id();
$lp = $this->get_id();
if (0 != $lp) {
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql = "UPDATE $tbl_lp SET author = '$author'
WHERE c_id = ".$course_id." id = ".$lp;
Database::query($sql);
return true;
}
return false;
}
/**
* Sets the content maker setting in the database.
*
* @param string $maker
*
* @return bool
*/
public function set_maker($maker = '')
{
$course_id = api_get_course_int_id();
if ($this->debug > 0) {
error_log('In aicc::set_maker method('.$maker.')', 0);
}
$lp = $this->get_id();
if (0 != $lp) {
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql = "UPDATE $tbl_lp SET content_maker = '$maker'
WHERE c_id = ".$course_id." id = ".$lp;
Database::query($sql);
return true;
} else {
return false;
}
}
/**
* Exports the current AICC object's files as a zip. Excerpts taken from learnpath_functions.inc.php::exportpath().
*

@ -72,7 +72,6 @@ class learnpath
public $ordered_items = []; // List of the learnpath items in the order they are to be read.
public $path = ''; // Path inside the scorm directory (if scorm).
public $theme; // The current theme of the learning path.
public $preview_image; // The current image of the learning path.
public $accumulateScormTime; // Flag to decide whether to accumulate SCORM time or not
public $accumulateWorkTime; // The min time of learnpath
@ -160,7 +159,6 @@ class learnpath
$this->scorm_debug = $entity->getDebug();
$this->js_lib = $entity->getJsLib();
$this->path = $entity->getPath();
$this->preview_image = $entity->getPreviewImage();
$this->author = $entity->getAuthor();
$this->hide_toc_frame = $entity->getHideTocFrame();
$this->lp_session_id = $entity->getSessionId();
@ -2572,56 +2570,6 @@ class learnpath
return 0;
}
/**
* Gets the learnpath image.
*
* @return string Web URL of the LP image
*/
public function get_preview_image()
{
if (!empty($this->preview_image)) {
return $this->preview_image;
}
return '';
}
/**
* @param string $size
* @param string $path_type
*
* @return bool|string
*/
public function get_preview_image_path($size = null, $path_type = 'web')
{
$preview_image = $this->get_preview_image();
if (isset($preview_image) && !empty($preview_image)) {
$image_sys_path = api_get_path(SYS_COURSE_PATH).$this->course_info['path'].'/upload/learning_path/images/';
$image_path = api_get_path(WEB_COURSE_PATH).$this->course_info['path'].'/upload/learning_path/images/';
if (isset($size)) {
$info = pathinfo($preview_image);
$image_custom_size = $info['filename'].'.'.$size.'.'.$info['extension'];
if (file_exists($image_sys_path.$image_custom_size)) {
if ('web' == $path_type) {
return $image_path.$image_custom_size;
} else {
return $image_sys_path.$image_custom_size;
}
}
} else {
if ('web' == $path_type) {
return $image_path.$preview_image;
} else {
return $image_sys_path.$preview_image;
}
}
}
return false;
}
/**
* Gets the learnpath author.
*
@ -5046,75 +4994,6 @@ class learnpath
return false;
}
/**
* Sets the name of the LP maker (publisher) (and save).
*
* @param string $name Optional string giving the new content_maker of this learnpath
*
* @return bool True
*/
public function set_maker($name = '')
{
if (empty($name)) {
return false;
}
$this->maker = $name;
$table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $table SET
content_maker = '".Database::escape_string($this->maker)."'
WHERE iid = $lp_id";
Database::query($sql);
return true;
}
/**
* Sets the name of the current learnpath (and save).
*
* @param string $name Optional string giving the new name of this learnpath
*
* @return bool True/False
*/
public function set_name($name = null)
{
if (empty($name)) {
return false;
}
$this->name = $name;
$lp_id = $this->get_id();
$repo = Container::getLpRepository();
/** @var CLp $lp */
$lp = $repo->find($lp_id);
$lp->setName($name);
$repo->updateNodeForResource($lp);
/*
$course_id = $this->course_info['real_id'];
$sql = "UPDATE $lp_table SET
name = '$name'
WHERE iid = $lp_id";
$result = Database::query($sql);
// If the lp is visible on the homepage, change his name there.
if (Database::affected_rows($result)) {
$session_id = api_get_session_id();
$session_condition = api_get_session_condition($session_id);
$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
$link = 'lp/lp_controller.php?action=view&lp_id='.$lp_id.'&id_session='.$session_id;
$sql = "UPDATE $tbl_tool SET name = '$name'
WHERE
c_id = $course_id AND
(link='$link' AND image='scormbuilder.gif' $session_condition)";
Database::query($sql);*/
//return true;
//}
return false;
}
/**
* Set index specified prefix terms for all items in this path.
*
@ -5193,108 +5072,6 @@ class learnpath
return true;
}
/**
* Sets the theme of the LP (local/remote) (and save).
*
* @param string $name Optional string giving the new theme of this learnpath
*
* @return bool Returns true if theme name is not empty
*/
public function set_theme($name = '')
{
$this->theme = $name;
$table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $table
SET theme = '".Database::escape_string($this->theme)."'
WHERE iid = $lp_id";
Database::query($sql);
return true;
}
/**
* Sets the image of an LP (and save).
*
* @param string $name Optional string giving the new image of this learnpath
*
* @return bool Returns true if theme name is not empty
*/
public function set_preview_image($name = '')
{
$this->preview_image = $name;
$table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $table SET
preview_image = '".Database::escape_string($this->preview_image)."'
WHERE iid = $lp_id";
Database::query($sql);
return true;
}
/**
* Sets the author of a LP (and save).
*
* @param string $name Optional string giving the new author of this learnpath
*
* @return bool Returns true if author's name is not empty
*/
public function set_author($name = '')
{
$this->author = $name;
$table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $table SET author = '".Database::escape_string($name)."'
WHERE iid = $lp_id";
Database::query($sql);
return true;
}
/**
* Sets the hide_toc_frame parameter of a LP (and save).
*
* @param int $hide 1 if frame is hidden 0 then else
*
* @return bool Returns true if author's name is not empty
*/
public function set_hide_toc_frame($hide)
{
if (intval($hide) == $hide) {
$this->hide_toc_frame = $hide;
$table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $table SET
hide_toc_frame = '".(int) $this->hide_toc_frame."'
WHERE iid = $lp_id";
Database::query($sql);
return true;
}
return false;
}
/**
* Sets the prerequisite of a LP (and save).
*
* @param int $prerequisite integer giving the new prerequisite of this learnpath
*
* @return bool returns true if prerequisite is not empty
*/
public function set_prerequisite($prerequisite)
{
$this->prerequisite = (int) $prerequisite;
$table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $table SET prerequisite = '".$this->prerequisite."'
WHERE iid = $lp_id";
Database::query($sql);
return true;
}
/**
* Sets the location/proximity of the LP (local/remote) (and save).
*
@ -9878,79 +9655,6 @@ EOD;
}
}
/**
* Delete the image relative to this learning path. No parameter. Only works on instanciated object.
*
* @return bool The results of the unlink function, or false if there was no image to start with
*/
public function delete_lp_image()
{
$img = $this->get_preview_image();
if ('' != $img) {
$del_file = $this->get_preview_image_path(null, 'sys');
if (isset($del_file) && file_exists($del_file)) {
$del_file_2 = $this->get_preview_image_path(64, 'sys');
if (file_exists($del_file_2)) {
unlink($del_file_2);
}
$this->set_preview_image('');
return @unlink($del_file);
}
}
return false;
}
/**
* Uploads an author image to the upload/learning_path/images directory.
*
* @param array The image array, coming from the $_FILES superglobal
*
* @return bool True on success, false on error
*/
public function upload_image($image_array)
{
if (!empty($image_array['name'])) {
$upload_ok = process_uploaded_file($image_array);
$has_attachment = true;
}
if ($upload_ok && $has_attachment) {
$courseDir = api_get_course_path().'/upload/learning_path/images';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$updir = $sys_course_path.$courseDir;
// Try to add an extension to the file if it hasn't one.
$new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
if (filter_extension($new_file_name)) {
$file_extension = explode('.', $image_array['name']);
$file_extension = strtolower($file_extension[count($file_extension) - 1]);
$filename = uniqid('');
$new_file_name = $filename.'.'.$file_extension;
$new_path = $updir.'/'.$new_file_name;
// Resize the image.
$temp = new Image($image_array['tmp_name']);
$temp->resize(104);
$result = $temp->send_image($new_path);
// Storing the image filename.
if ($result) {
$this->set_preview_image($new_file_name);
//Resize to 64px to use on course homepage
$temp->resize(64);
$temp->send_image($updir.'/'.$filename.'.64.'.$file_extension);
return true;
}
}
}
return false;
}
/**
* @param int $lp_id
* @param string $status
@ -11581,29 +11285,6 @@ EOD;
return (int) $row['total'];
}
/**
* Set whether this is a learning path with the accumulated work time or not.
*
* @param int $value (0 = false, 1 = true)
*
* @return bool
*/
public function setAccumulateWorkTime($value)
{
if (!api_get_configuration_value('lp_minimum_time')) {
return false;
}
$this->accumulateWorkTime = (int) $value;
$table = Database::get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $table SET accumulate_work_time = ".$this->accumulateWorkTime."
WHERE c_id = ".$this->course_int_id." AND id = $lp_id";
Database::query($sql);
return true;
}
/**
* @param int $lpId
* @param int $courseId

@ -154,7 +154,6 @@ class LearnpathList
'seriousgame_mode' => $lp->getSeriousgameMode(),
'lp_scorm_debug' => $lp->getDebug(),
'lp_display_order' => $lp->getDisplayOrder(),
'lp_preview_image' => stripslashes($lp->getPreviewImage()),
'autolaunch' => $lp->getAutolaunch(),
'session_id' => $lp->getSessionId(),
'created_on' => $lp->getCreatedOn() ? $lp->getCreatedOn()->format('Y-m-d H:i:s') : null,

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CLpItem;
use ChamiloSession as Session;
@ -314,6 +315,7 @@ if (!empty($lpObject)) {
}
}
$lpRepo = Database::getManager()->getRepository(CLp::class);
$course_id = api_get_course_int_id();
$lpItemId = $_REQUEST['id'] ?? 0;
$lpItem = null;
@ -1151,27 +1153,33 @@ switch ($action) {
require 'lp_list.php';
} else {
Session::write('refresh', 1);
$_SESSION['oLP']->set_name($_REQUEST['lp_name']);
$author = $_REQUEST['lp_author'];
$_SESSION['oLP']->set_author($author);
$em = Database::getManager();
$lpId = $oLP->get_id();
/** @var Clp $lp */
$lp = $lpRepo->find($lpId);
$hide_toc_frame = null;
if (isset($_REQUEST['hide_toc_frame']) && 1 == $_REQUEST['hide_toc_frame']) {
$hide_toc_frame = $_REQUEST['hide_toc_frame'];
}
$lp
->setName($_REQUEST['lp_name'])
->setAuthor($_REQUEST['lp_author'])
->setTheme($_REQUEST['lp_theme'])
->setHideTocFrame($hide_toc_frame)
->setPrerequisite($_POST['prerequisites'] ?? 0)
->setAccumulateWorkTime($_REQUEST['accumulate_work_time'] ?? 0)
->setContentMaker($_REQUEST['lp_maker'] ?? '')
;
// TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
$_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
if (isset($_REQUEST['lp_maker'])) {
$_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
}
if (isset($_REQUEST['lp_proximity'])) {
$_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
}
$_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
$hide_toc_frame = null;
if (isset($_REQUEST['hide_toc_frame']) && 1 == $_REQUEST['hide_toc_frame']) {
$hide_toc_frame = $_REQUEST['hide_toc_frame'];
}
$_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
$_SESSION['oLP']->set_prerequisite(isset($_POST['prerequisites']) ? (int) $_POST['prerequisites'] : 0);
$_SESSION['oLP']->setAccumulateWorkTime(isset($_REQUEST['accumulate_work_time']) ? $_REQUEST['accumulate_work_time'] : 0);
$_SESSION['oLP']->set_use_max_score(isset($_POST['use_max_score']) ? 1 : 0);
$subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
@ -1207,6 +1215,9 @@ switch ($action) {
$_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
}
$em->persist($lp);
$em->flush();
$form = new FormValidator('form1');
$form->addSelect('skills', 'skills');
Skill::saveSkills($form, ITEM_TYPE_LEARNPATH, $_SESSION['oLP']->get_id());

@ -122,7 +122,12 @@ if (strlen($learnPath->get_preview_image()) > 0) {
}
$label = '' != $learnPath->get_preview_image() ? get_lang('Update Image') : get_lang('Add image');
$form->addElement('file', 'lp_preview_image', [$label, get_lang('Trainer picture will resize if needed')]);
$form->addRule('lp_preview_image', get_lang('Only PNG, JPG or GIF images allowed'), 'filetype', ['jpg', 'jpeg', 'png', 'gif']);
$form->addRule(
'lp_preview_image',
get_lang('Only PNG, JPG or GIF images allowed'),
'filetype',
['jpg', 'jpeg', 'png', 'gif']
);
// Search terms (only if search is activated).
if ('true' === api_get_setting('search_enabled')) {

@ -783,81 +783,6 @@ class scorm extends learnpath
}
}
/**
* Sets the theme setting in the database.
*
* @param string theme setting
*
* @return bool
*/
public function set_theme($theme = '')
{
if ($this->debug > 0) {
error_log('In scorm::set_theme('.$theme.') method');
}
$lp = $this->get_id();
if (0 != $lp) {
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql = "UPDATE $tbl_lp SET theme = '$theme'
WHERE iid = $lp";
$res = Database::query($sql);
return $res;
} else {
return false;
}
}
/**
* Sets the image setting in the database.
*
* @param string preview_image setting
*
* @return bool
*/
public function set_preview_image($preview_image = '')
{
if ($this->debug > 0) {
error_log('In scorm::set_theme('.$preview_image.') method', 0);
}
$lp = $this->get_id();
if (0 != $lp) {
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql = "UPDATE $tbl_lp SET preview_image = '$preview_image'
WHERE iid = $lp";
$res = Database::query($sql);
return $res;
} else {
return false;
}
}
/**
* Sets the author setting in the database.
*
* @param string $author
*
* @return bool
*/
public function set_author($author = '')
{
if ($this->debug > 0) {
error_log('In scorm::set_author('.$author.') method', 0);
}
$lp = $this->get_id();
if (0 != $lp) {
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql = "UPDATE $tbl_lp SET author = '$author'
WHERE iid = ".$lp;
$res = Database::query($sql);
return $res;
} else {
return false;
}
}
/**
* Sets the content maker setting in the database.
*

@ -4,7 +4,11 @@
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Chamilo\CourseBundle\Repository\CLpRepository;
use Chamilo\Kernel;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
class Version20190110182615 extends AbstractMigrationChamilo
@ -16,6 +20,12 @@ class Version20190110182615 extends AbstractMigrationChamilo
public function up(Schema $schema): void
{
$container = $this->getContainer();
/** @var Kernel $kernel */
$kernel = $container->get('kernel');
$rootPath = $kernel->getProjectDir();
$doctrine = $container->get('doctrine');
$this->addSql('ALTER TABLE c_lp CHANGE author author LONGTEXT NOT NULL');
$table = $schema->getTable('c_lp');
@ -51,6 +61,37 @@ class Version20190110182615 extends AbstractMigrationChamilo
);
}
$em = $doctrine->getManager();
/** @var Connection $connection */
$connection = $em->getConnection();
$lpRepo = $container->get(CLpRepository::class);
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');
/** @var Course $course */
foreach ($q->toIterable() as $course) {
$courseId = $course->getId();
$sql = "SELECT * FROM c_lp WHERE c_id = $courseId
ORDER BY iid";
$result = $connection->executeQuery($sql);
$items = $result->fetchAllAssociative();
foreach ($items as $itemData) {
$id = $itemData['iid'];
$lp = $lpRepo->find($id);
if ($lp && !empty($lp->getPreviewImage())) {
$path = $lp->getPreviewImage();
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/learning_path/images/'.$path;
if (file_exists($rootPath)) {
$this->addLegacyFileToResource($filePath, $lpRepo, $lp, $lp->getIid(), $path);
$em->persist($lp);
$em->flush();
}
}
}
$em->flush();
$em->clear();
}
$table = $schema->getTable('c_lp_category');
if (false === $table->hasColumn('session_id')) {
$this->addSql('ALTER TABLE c_lp_category ADD session_id INT DEFAULT NULL');

@ -149,13 +149,6 @@ class CLp extends AbstractResource implements ResourceInterface
*/
protected $theme;
/**
* @var string
*
* @ORM\Column(name="preview_image", type="string", length=255, nullable=false)
*/
protected $previewImage;
/**
* @var string
*
@ -309,7 +302,6 @@ class CLp extends AbstractResource implements ResourceInterface
$this->preventReinit = true;
$this->path = '';
$this->prerequisite = 0;
$this->previewImage = '';
$this->publicatedOn = new \DateTime();
$this->seriousgameMode = 0;
$this->subscribeUsers = 0;
@ -707,30 +699,6 @@ class CLp extends AbstractResource implements ResourceInterface
return $this->theme;
}
/**
* Set previewImage.
*
* @param string $previewImage
*
* @return CLp
*/
public function setPreviewImage($previewImage)
{
$this->previewImage = $previewImage;
return $this;
}
/**
* Get previewImage.
*
* @return string
*/
public function getPreviewImage()
{
return $this->previewImage;
}
/**
* Set author.
*

Loading…
Cancel
Save