Minor - flint fixes

pull/2744/head
Julio Montoya 7 years ago
parent 66ca989516
commit 76abd292f1
  1. 2
      main/course_info/infocours.php
  2. 2
      main/course_info/tools.php
  3. 14
      main/exercise/hotpotatoes.php
  4. 439
      main/inc/lib/document.lib.php
  5. 1
      main/inc/lib/fileUpload.lib.php
  6. 6
      main/inc/lib/formvalidator/FormValidator.class.php
  7. 34
      main/inc/lib/pdf.lib.php
  8. 19
      main/lp/learnpath.class.php
  9. 5
      src/CourseBundle/Repository/CDocumentRepository.php

@ -720,7 +720,6 @@ $form->addPanelOption(
// ********** EXERCISE ********************* //
if (api_get_configuration_value('allow_exercise_auto_launch')) {
$globalGroup = [];
// Auto launch exercise
@ -762,7 +761,6 @@ if (api_get_configuration_value('allow_exercise_auto_launch')) {
false,
'accordionSettings'
);
}
// *************** START THEMATIC *************/

@ -120,7 +120,7 @@ switch ($action) {
);
$list = [];
$tmp = [];
foreach ($toolList as $tool){
foreach ($toolList as $tool) {
$tmp['id'] = $tool['id'];
$tmp['name'] = Security::remove_XSS(stripslashes($tool['name']));

@ -132,13 +132,13 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
$fld = GenerateHpFolder($document_sys_path.$uploadPath.'/');
@mkdir($document_sys_path.$uploadPath.'/'.$fld, api_get_permissions_for_new_directories());
$doc_id = DocumentManager::addDocument($_course, '/HotPotatoes_files/'.$fld, 'folder', 0, $fld);
/*api_item_property_update(
$_course,
TOOL_DOCUMENT,
$doc_id,
'FolderCreated',
api_get_user_id()
);*/
/*api_item_property_update(
$_course,
TOOL_DOCUMENT,
$doc_id,
'FolderCreated',
api_get_user_id()
);*/
} else {
// It is not the first step... get the filename directly from the system params.
$filename = $_FILES['userFile']['name'];

@ -7,9 +7,9 @@ use Chamilo\CoreBundle\Entity\Resource\ResourceRight;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter;
use Chamilo\CourseBundle\Entity\CDocument;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Chamilo\UserBundle\Entity\User;
use ChamiloSession as Session;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Class DocumentManager
@ -6407,6 +6407,224 @@ class DocumentManager
return $list;
}
/**
* Adds a new document to the database.
*
* @param array $courseInfo
* @param string $path
* @param string $fileType
* @param int $fileSize
* @param string $title
* @param string $comment
* @param int $readonly
* @param int $visibility see ResourceLink constants
* @param int $group_id group.id
* @param int $sessionId Session ID, if any
* @param int $userId creator user id
* @param bool $sendNotification
* @param string $content
* @param int $parentId
*
* @return CDocument|false
*/
public static function addDocument(
$courseInfo,
$path,
$fileType,
$fileSize,
$title,
$comment = null,
$readonly = 0,
$visibility = null,
$group_id = 0,
$sessionId = 0,
$userId = 0,
$sendNotification = true,
$content = '',
$parentId = 0
) {
$userId = empty($userId) ? api_get_user_id() : $userId;
if (empty($userId)) {
return false;
}
$userEntity = api_get_user_entity($userId);
if (empty($userEntity)) {
return false;
}
$courseEntity = api_get_course_entity($courseInfo['real_id']);
if (empty($courseEntity)) {
return false;
}
$sessionId = empty($sessionId) ? api_get_session_id() : $sessionId;
$session = api_get_session_entity($sessionId);
$group = api_get_group_entity($group_id);
$readonly = (int) $readonly;
$em = Database::getManager();
$documentRepo = $em->getRepository('ChamiloCourseBundle:CDocument');
$parentNode = null;
if (!empty($parentId)) {
$parent = $documentRepo->find($parentId);
if ($parent) {
$parentNode = $parent->getResourceNode();
}
}
$document = new CDocument();
$document
->setCourse($courseEntity)
->setPath($path)
->setFiletype($fileType)
->setSize($fileSize)
->setTitle($title)
->setComment($comment)
->setReadonly($readonly)
->setSession($session)
;
$em->persist($document);
$em->flush();
$resourceNode = $documentRepo->addResourceNode($document, $userEntity);
$resourceNode->setParent($parentNode);
$document->setResourceNode($resourceNode);
// Only create a ResourseFile and Media if there's a file involved
if ($fileType === 'file') {
$mediaManager = Container::$container->get('sonata.media.manager.media');
/** @var \Chamilo\MediaBundle\Entity\Media $media */
$media = $mediaManager->create();
$media->setName($title);
$fileName = basename($path);
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
$media->setContext('default');
$provider = 'sonata.media.provider.image';
if (!in_array($extension, ['jpeg', 'jpg', 'gif', 'png'])) {
$provider = 'sonata.media.provider.file';
}
$media->setProviderName($provider);
$media->setEnabled(true);
if ($content instanceof UploadedFile) {
$file = $content;
$media->setSize($file->getSize());
} else {
$handle = tmpfile();
fwrite($handle, $content);
$file = new \Sonata\MediaBundle\Extra\ApiMediaFile($handle);
$file->setMimetype($media->getContentType());
}
$media->setBinaryContent($file);
$mediaManager->save($media, true);
$resourceFile = new ResourceFile();
$resourceFile->setMedia($media);
$resourceFile->setName($title);
$em->persist($resourceFile);
$resourceNode->setResourceFile($resourceFile);
$em->persist($resourceNode);
}
// By default visibility is published
// @todo change visibility
//$newVisibility = ResourceLink::VISIBILITY_PUBLISHED;
if (is_null($visibility)) {
$visibility = ResourceLink::VISIBILITY_PUBLISHED;
}
$link = new ResourceLink();
$link
->setCourse($courseEntity)
->setSession($session)
->setGroup($group)
//->setUser($toUser)
->setResourceNode($resourceNode)
->setVisibility($visibility)
;
$rights = [];
switch ($visibility) {
case ResourceLink::VISIBILITY_PENDING:
case ResourceLink::VISIBILITY_DRAFT:
$editorMask = ResourceNodeVoter::getEditorMask();
$resourceRight = new ResourceRight();
$resourceRight
->setMask($editorMask)
->setRole(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER)
;
$rights[] = $resourceRight;
break;
}
if (!empty($rights)) {
foreach ($rights as $right) {
$link->addResourceRight($right);
}
}
$em->persist($link);
$em->persist($document);
$em->flush();
$documentId = $document->getIid();
if ($documentId) {
$table = Database::get_course_table(TABLE_DOCUMENT);
$sql = "UPDATE $table SET id = iid WHERE iid = $documentId";
Database::query($sql);
/*if ($saveVisibility) {
api_set_default_visibility(
$documentId,
TOOL_DOCUMENT,
$group_id,
$courseInfo,
$sessionId,
$userId
);
}*/
$allowNotification = api_get_configuration_value('send_notification_when_document_added');
if ($sendNotification && $allowNotification) {
$courseTitle = $courseInfo['title'];
if (!empty($sessionId)) {
$sessionInfo = api_get_session_info($sessionId);
$courseTitle .= ' ( '.$sessionInfo['name'].') ';
}
$url = api_get_path(WEB_CODE_PATH).
'document/showinframes.php?cidReq='.$courseInfo['code'].'&id_session='.$sessionId.'&id='.$documentId;
$link = Display::url(basename($title), $url, ['target' => '_blank']);
$userInfo = api_get_user_info($userId);
$message = sprintf(
get_lang('DocumentXHasBeenAddedToDocumentInYourCourseXByUserX'),
$link,
$courseTitle,
$userInfo['complete_name']
);
$subject = sprintf(get_lang('NewDocumentAddedToCourseX'), $courseTitle);
MessageManager::sendMessageToAllUsersInCourse($subject, $message, $courseInfo, $sessionId);
}
return $document;
}
return false;
}
/**
* Parse file information into a link.
*
@ -6833,223 +7051,4 @@ class DocumentManager
return $btn;
}
/**
* Adds a new document to the database.
*
* @param array $courseInfo
* @param string $path
* @param string $fileType
* @param int $fileSize
* @param string $title
* @param string $comment
* @param int $readonly
* @param int $visibility see ResourceLink constants
* @param int $group_id group.id
* @param int $sessionId Session ID, if any
* @param int $userId creator user id
* @param bool $sendNotification
* @param string $content
* @param int $parentId
*
* @return CDocument|false
*/
public static function addDocument(
$courseInfo,
$path,
$fileType,
$fileSize,
$title,
$comment = null,
$readonly = 0,
$visibility = null,
$group_id = 0,
$sessionId = 0,
$userId = 0,
$sendNotification = true,
$content = '',
$parentId = 0
) {
$userId = empty($userId) ? api_get_user_id() : $userId;
if (empty($userId)) {
return false;
}
$userEntity = api_get_user_entity($userId);
if (empty($userEntity)) {
return false;
}
$courseEntity = api_get_course_entity($courseInfo['real_id']);
if (empty($courseEntity)) {
return false;
}
$sessionId = empty($sessionId) ? api_get_session_id() : $sessionId;
$session = api_get_session_entity($sessionId);
$group = api_get_group_entity($group_id);
$readonly = (int) $readonly;
$em = Database::getManager();
$documentRepo = $em->getRepository('ChamiloCourseBundle:CDocument');
$parentNode = null;
if (!empty($parentId)) {
$parent = $documentRepo->find($parentId);
if ($parent) {
$parentNode = $parent->getResourceNode();
}
}
$document = new CDocument();
$document
->setCourse($courseEntity)
->setPath($path)
->setFiletype($fileType)
->setSize($fileSize)
->setTitle($title)
->setComment($comment)
->setReadonly($readonly)
->setSession($session)
;
$em->persist($document);
$em->flush();
$resourceNode = $documentRepo->addResourceNode($document, $userEntity);
$resourceNode->setParent($parentNode);
$document->setResourceNode($resourceNode);
// Only create a ResourseFile and Media if there's a file involved
if ($fileType === 'file') {
$mediaManager = Container::$container->get('sonata.media.manager.media');
/** @var \Chamilo\MediaBundle\Entity\Media $media */
$media = $mediaManager->create();
$media->setName($title);
$fileName = basename($path);
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
$media->setContext('default');
$provider = 'sonata.media.provider.image';
if (!in_array($extension, ['jpeg', 'jpg', 'gif', 'png'])) {
$provider = 'sonata.media.provider.file';
}
$media->setProviderName($provider);
$media->setEnabled(true);
if ($content instanceof UploadedFile) {
$file = $content;
$media->setSize($file->getSize());
} else {
$handle = tmpfile();
fwrite($handle, $content);
$file = new \Sonata\MediaBundle\Extra\ApiMediaFile($handle);
$file->setMimetype($media->getContentType());
}
$media->setBinaryContent($file);
$mediaManager->save($media, true);
$resourceFile = new ResourceFile();
$resourceFile->setMedia($media);
$resourceFile->setName($title);
$em->persist($resourceFile);
$resourceNode->setResourceFile($resourceFile);
$em->persist($resourceNode);
}
// By default visibility is published
// @todo change visibility
//$newVisibility = ResourceLink::VISIBILITY_PUBLISHED;
if (is_null($visibility)) {
$visibility = ResourceLink::VISIBILITY_PUBLISHED;
}
$link = new ResourceLink();
$link
->setCourse($courseEntity)
->setSession($session)
->setGroup($group)
//->setUser($toUser)
->setResourceNode($resourceNode)
->setVisibility($visibility)
;
$rights = [];
switch ($visibility) {
case ResourceLink::VISIBILITY_PENDING:
case ResourceLink::VISIBILITY_DRAFT:
$editorMask = ResourceNodeVoter::getEditorMask();
$resourceRight = new ResourceRight();
$resourceRight
->setMask($editorMask)
->setRole(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER)
;
$rights[] = $resourceRight;
break;
}
if (!empty($rights)) {
foreach ($rights as $right) {
$link->addResourceRight($right);
}
}
$em->persist($link);
$em->persist($document);
$em->flush();
$documentId = $document->getIid();
if ($documentId) {
$table = Database::get_course_table(TABLE_DOCUMENT);
$sql = "UPDATE $table SET id = iid WHERE iid = $documentId";
Database::query($sql);
/*if ($saveVisibility) {
api_set_default_visibility(
$documentId,
TOOL_DOCUMENT,
$group_id,
$courseInfo,
$sessionId,
$userId
);
}*/
$allowNotification = api_get_configuration_value('send_notification_when_document_added');
if ($sendNotification && $allowNotification) {
$courseTitle = $courseInfo['title'];
if (!empty($sessionId)) {
$sessionInfo = api_get_session_info($sessionId);
$courseTitle .= ' ( '.$sessionInfo['name'].') ';
}
$url = api_get_path(WEB_CODE_PATH).
'document/showinframes.php?cidReq='.$courseInfo['code'].'&id_session='.$sessionId.'&id='.$documentId;
$link = Display::url(basename($title), $url, ['target' => '_blank']);
$userInfo = api_get_user_info($userId);
$message = sprintf(
get_lang('DocumentXHasBeenAddedToDocumentInYourCourseXByUserX'),
$link,
$courseTitle,
$userInfo['complete_name']
);
$subject = sprintf(get_lang('NewDocumentAddedToCourseX'), $courseTitle);
MessageManager::sendMessageToAllUsersInCourse($subject, $message, $courseInfo, $sessionId);
}
return $document;
}
return false;
}
}

@ -1502,7 +1502,6 @@ function search_img_from_html($html_file)
* @param bool $sendNotification depends in conf setting "send_notification_when_document_added"
*
* @return CDocument|false
*
*/
function create_unexisting_directory(
$_course,

@ -900,9 +900,9 @@ EOT;
/**
* @param string $name
* @param string $label
* @param array $attributes
* @param array $attributes
*
* @throws Exception if the file doesn't have an id
* @throws Exception if the file doesn't have an id
* @throws HTML_QuickForm_Error
*/
public function addFile($name, $label, $attributes = [])
@ -932,7 +932,7 @@ EOT;
$this->addHidden($id.'_crop_result', '');
$this->addHidden($id.'_crop_image_base_64', '');
}
} catch (HTML_Quick|Form_Error $e) {
} catch (HTML_Quick | Form_Error $e) {
var_dump($e->getMessage());
}
}

@ -2,9 +2,9 @@
/* See license terms in /license.txt */
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Mpdf\Output\Destination;
use Mpdf\Mpdf;
use Masterminds\HTML5;
use Mpdf\Mpdf;
use Mpdf\Output\Destination;
/**
* Class PDF.
@ -100,7 +100,7 @@ class PDF
* Export the given HTML to PDF, using a global template.
*
* @uses \export/table_pdf.tpl
*
*
* @param string $content
* @param bool|false $saveToFile
* @param bool|false $returnHtml
@ -188,20 +188,20 @@ class PDF
/**
* Converts HTML files to PDF.
*
* @param mixed $htmlFileArray could be an html file path or an array
* with paths example:
* /var/www/myfile.html or array('/myfile.html','myotherfile.html') or
* even an indexed array with both 'title' and 'path' indexes
* for each element like
* array(
* 0 => array('title'=>'Hello','path'=>'file.html'),
* 1 => array('title'=>'Bye','path'=>'file2.html')
* );
* @param mixed $htmlFileArray could be an html file path or an array
* with paths example:
* /var/www/myfile.html or array('/myfile.html','myotherfile.html') or
* even an indexed array with both 'title' and 'path' indexes
* for each element like
* array(
* 0 => array('title'=>'Hello','path'=>'file.html'),
* 1 => array('title'=>'Bye','path'=>'file2.html')
* );
* @param string $pdfName pdf name
* @param string $courseCode (if you are using html that are located
* in the document tool you must provide this)
* @param bool $print_title add title
* @param bool $complete_style show header and footer if true
* in the document tool you must provide this)
* @param bool $print_title add title
* @param bool $complete_style show header and footer if true
* @param bool $addStyle
*
* @return false|null
@ -356,7 +356,7 @@ class PDF
* @param string $document_html valid html
* @param string $css CSS content of a CSS file
* @param string $pdf_name pdf name
* @param string $courseCode course code
* @param string $courseCode course code
* (if you are using html that are located in the document tool you must provide this)
* @param string $outputMode the MPDF output mode can be:
* @param bool $saveInFile
@ -712,7 +712,7 @@ class PDF
* header, footer and watermark (if any).
*
* @param array $courseInfo General course information (to fill headers)
* @param bool $complete Whether we want headers, footers and watermark or not
* @param bool $complete Whether we want headers, footers and watermark or not
*/
public function format_pdf($courseInfo, $complete = true)
{

@ -6,7 +6,6 @@ use Chamilo\CoreBundle\Entity\Repository\ItemPropertyRepository;
use Chamilo\CourseBundle\Component\CourseCopy\CourseArchiver;
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
use Chamilo\CourseBundle\Entity\CDocument;
use Chamilo\CourseBundle\Entity\CItemProperty;
use Chamilo\CourseBundle\Entity\CLp;
use Chamilo\CourseBundle\Entity\CLpCategory;
@ -6876,7 +6875,7 @@ class learnpath
$folder = false;
//if (!is_dir($filepath.'/'.$dir)) {
$folderData = create_unexisting_directory(
$folderData = create_unexisting_directory(
$course,
$creatorId,
0,
@ -6887,9 +6886,9 @@ class learnpath
get_lang('LearningPaths'),
0
);
if (!empty($folderData)) {
$folder = true;
}
if (!empty($folderData)) {
$folder = true;
}
/*} else {
$folder = true;
}*/
@ -6925,7 +6924,7 @@ class learnpath
if ($folder) {
$filepath = api_get_path(SYS_COURSE_PATH).$course['path'].'/document';
//if (!is_dir($filepath.'/'.$dir)) {
$folderData = create_unexisting_directory(
$folderData = create_unexisting_directory(
$course,
$creatorId,
0,
@ -6935,11 +6934,11 @@ class learnpath
$dir,
$lp_name
);
if (!empty($folderData)) {
$folder = true;
}
if (!empty($folderData)) {
$folder = true;
}
$documentId = $folderData->getIid();
$documentId = $folderData->getIid();
/*} else {
$folder = true;
}*/

@ -9,11 +9,9 @@ use Doctrine\ORM\EntityRepository;
use Gaufrette\Exception\FileNotFound;
use Sonata\MediaBundle\Provider\MediaProviderInterface;
use Sonata\MediaBundle\Provider\Pool;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
/**
* Class CDocumentRepository.
*
*/
class CDocumentRepository
{
@ -61,7 +59,7 @@ class CDocumentRepository
*
* @return string
*/
public function getDocumentPath($id) :string
public function getDocumentPath($id): string
{
try {
$document = $this->find($id);
@ -79,7 +77,6 @@ class CDocumentRepository
$provider->generatePrivateUrl($media, $format)
);
return $filename;
} catch (\Throwable $exception) {
throw new FileNotFound($id);

Loading…
Cancel
Save