Fix exercise when using ckeditor + adding exercise css

pull/3016/head
Julio Montoya 5 years ago
parent c786b61e15
commit 38e61cfa2d
  1. 4
      assets/css/scss/_base.scss
  2. 11
      assets/css/scss/_exercise.scss
  3. 3
      assets/css/scss/index.scss
  4. 4
      main/exercise/admin.php
  5. 1
      main/exercise/exercise.class.php
  6. 4
      main/exercise/exercise_submit.php
  7. 5
      main/exercise/question.class.php
  8. 52
      main/inc/lib/api.lib.php
  9. 15
      main/inc/lib/document.lib.php
  10. 2
      main/inc/lib/formvalidator/Element/HtmlEditor.php
  11. 6
      main/inc/lib/pear/HTML/QuickForm/select.php
  12. 1
      main/inc/lib/pear/HTML/QuickForm/text.php
  13. 98
      main/inc/lib/pear/HTML/QuickForm/textarea.php
  14. 2
      src/CoreBundle/Component/Editor/CkEditor/CkEditor.php
  15. 14
      src/CoreBundle/Component/Editor/Editor.php
  16. 6
      src/CoreBundle/Controller/EditorController.php

@ -1,6 +1,4 @@
// ---------------------------------------------------------
// BASE CSS
// ---------------------------------------------------------
html, html a, body {
-webkit-font-smoothing: antialiased;
@ -4082,4 +4080,4 @@ table.certaintyTable {
.img-responsive {
@extend .img-fluid;
}
}

@ -0,0 +1,11 @@
// Exercise CSS
.question_menu {
list-style: none;
margin: 0;
padding: 0;
}
.question_menu li {
display: inline-block;
}

@ -1,3 +1,4 @@
@import 'variables';
@import "media";
@import 'inbox';
@ -7,6 +8,8 @@
@import "forms";
@import 'base';
@import 'announcement';
@import 'exercise';
@import "jqueryui";
/*
@import "spinner";*/

@ -307,13 +307,13 @@ if ($modifyIn === 'thisExercise') {
}
}
$htmlHeadXtra[] = api_get_js('jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
//$htmlHeadXtra[] = api_get_js('jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
$htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js');
$template = new Template();
$templateName = $template->get_template('exercise/submit.js.tpl');
$htmlHeadXtra[] = $template->fetch($templateName);
$htmlHeadXtra[] = api_get_js('d3/jquery.xcolor.js');
//$htmlHeadXtra[] = api_get_js('d3/jquery.xcolor.js');
$htmlHeadXtra[] = '<link rel="stylesheet" href="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/css/hotspot.css">';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/js/hotspot.js"></script>';

@ -8055,6 +8055,7 @@ class Exercise
])
) {
$hide = (int) $this->getPageConfigurationAttribute('hide_expected_answer');
if ($hide === 1) {
return false;
}

@ -54,9 +54,9 @@ if ($showGlossary) {
$js = '<script>'.api_get_language_translate_html().'</script>';
$htmlHeadXtra[] = $js;
$htmlHeadXtra[] = api_get_js('jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
//$htmlHeadXtra[] = api_get_js('jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
$htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js');
$htmlHeadXtra[] = api_get_js('d3/jquery.xcolor.js');
//$htmlHeadXtra[] = api_get_js('d3/jquery.xcolor.js');
//This library is necessary for the time control feature
//tmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');

@ -1847,14 +1847,15 @@ abstract class Question
break;
}
echo '<div class="panel panel-default">';
echo '<div class="panel-body">';
echo '<div class="card">';
echo '<div class="card-body">';
echo '<ul class="question_menu">';
foreach ($questionTypeList as $i => $type) {
/** @var Question $type */
$type = new $type[1]();
$img = $type->getTypePicture();
$explanation = get_lang($type->getExplanation());
echo '<li>';
echo '<div class="icon-image">';
$icon = '<a href="admin.php?'.api_get_cidreq().'&newQuestion=yes&answerType='.$i.'">'.

@ -6,8 +6,10 @@ use Chamilo\CoreBundle\Entity\Session as SessionEntity;
use Chamilo\CoreBundle\Entity\SettingsCurrent;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CItemProperty;
use Chamilo\ThemeBundle\Controller\ExceptionController;
use Chamilo\UserBundle\Entity\User;
use ChamiloSession as Session;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@ -687,11 +689,6 @@ define('TOOL_DRH', 'tool_drh');
define('TOOL_STUDENT_VIEW', 'toolstudentview');
define('TOOL_ADMIN_VISIBLE', 'tooladminvisible');
/**
* Inclusion of internationalization libraries.
*/
require_once __DIR__.'/internationalization.lib.php';
/**
* Returns a path to a certain resource within the Chamilo area, specifyed through a parameter.
* Also, this function provides conversion between path types, in this case the input path points inside the Chamilo area too.
@ -735,6 +732,7 @@ function api_get_path($path = '', $configuration = [])
}
$course_folder = 'courses/';
$code_folder = 'main/';
$root_sys = Container::getRootDir();
$root_web = '';
// If no $root_web has been set so far *and* no custom config has been passed to the function
@ -777,6 +775,7 @@ function api_get_path($path = '', $configuration = [])
[],
UrlGeneratorInterface::ABSOLUTE_URL
);
// Fix for php files inside main
if (strpos($root_web, 'main') !== false) {
$pos = (int) strpos($root_web, 'main');
@ -789,9 +788,12 @@ function api_get_path($path = '', $configuration = [])
$root_web = substr($root_web, 0, $pos);
}
$root_web = urldecode($root_web);
}
$root_web = str_replace('public/../', '', $root_web);
if (isset($configuration['multiple_access_urls']) &&
$configuration['multiple_access_urls']
) {
@ -864,20 +866,10 @@ function api_get_path($path = '', $configuration = [])
// Web server base and system server base.
if (!array_key_exists($root_web, $isInitialized)) {
// process absolute global roots
$code_folder = 'main';
// Support for the installation process.
// Developers might use the function api_get_path() directly or indirectly (this is difficult to be traced),
// at the moment when configuration has not been created yet. This is why this function should be
// upgraded to return correct results in this case.
// Dealing with trailing slashes.
$rootWebWithSlash = api_add_trailing_slash($root_web);
$root_sys = api_add_trailing_slash($root_sys);
$root_rel = api_add_trailing_slash($root_rel);
$code_folder = api_add_trailing_slash($code_folder);
$course_folder = api_add_trailing_slash($course_folder);
// Initialization of a table that contains common-purpose paths.
$paths[$root_web][REL_PATH] = $root_rel;
@ -962,30 +954,6 @@ function api_get_path($path = '', $configuration = [])
$path = substr($path, 0, $pos);
}
// Detection of the input path type. Conversion to semi-absolute type ( /chamilo/main/inc/.... ).
if (preg_match(VALID_WEB_PATH, $path)) {
// A special case: When a URL points to the document download script directly, without
// mod-rewrite translation, we have to translate it into an "ordinary" web path.
// For example:
// http://localhost/chamilo/main/document/download.php?doc_url=/image.png&cDir=/
// becomes
// http://localhost/chamilo/courses/TEST/document/image.png
// TEST is a course directory name, so called "system course code".
if (strpos($path, 'download.php') !== false) { // Fast detection first.
$path = urldecode($path);
if (preg_match('/(.*)main\/document\/download.php\?doc_url=\/(.*)&cDir=\/(.*)?/', $path, $matches)) {
$sys_course_code =
isset($_SESSION['_course']['sysCode']) // User is inside a course?
? $_SESSION['_course']['sysCode'] // Yes, then use course's directory name.
: '{SYS_COURSE_CODE}'; // No, then use a fake code, it may be processed later.
$path = $matches[1].'courses/'.$sys_course_code.'/document/'.str_replace('//', '/', $matches[3].'/'.$matches[2]);
}
}
// Replacement of the present web server base with a slash '/'.
$path = preg_replace(VALID_WEB_SERVER_BASE, '/', $path);
}
// Path now is semi-absolute. It is convenient at this moment repeated slashes to be removed.
$path = preg_replace(REPEATED_SLASHES_PURIFIER, '/', $path);
@ -3788,7 +3756,7 @@ function api_not_allowed(
$message = null,
$responseCode = 0
) {
$debug = api_get_setting('server_type') == 'test';
$debug = api_get_setting('server_type') === 'test';
// Default code is 403 forbidden
$responseCode = empty($responseCode) ? 403 : $responseCode;
@ -3801,8 +3769,8 @@ function api_not_allowed(
// src/ThemeBundle/Resources/views/Exception/error404.html.twig
$exception = new Exception($message);
$request = Container::getRequest();
$exception = \Symfony\Component\Debug\Exception\FlattenException::create($exception, $responseCode);
$controller = new \Chamilo\ThemeBundle\Controller\ExceptionController(Container::getTwig(), $debug);
$exception = FlattenException::create($exception, $responseCode);
$controller = new ExceptionController(Container::getTwig(), $debug);
$response = $controller->showAction($request, $exception);
$response->send();
exit;

@ -4913,6 +4913,8 @@ class DocumentManager
$title = basename($document_data['path']);
}
$isAdmin = api_is_platform_admin();
$filetype = $document_data['filetype'];
$path = $document_data['path'];
$url_path = urlencode($document_data['path']);
@ -5010,23 +5012,23 @@ class DocumentManager
$document_data['file_extension'] = $extension;
if (!$show_as_icon) {
if ($filetype == 'folder') {
if ($filetype === 'folder') {
if ($isAllowedToEdit ||
api_is_platform_admin() ||
$isAdmin ||
api_get_setting('students_download_folders') == 'true'
) {
// filter: when I am into a shared folder, I can only show "my shared folder" for donwload
if (self::is_shared_folder($curdirpath, $sessionId)) {
if (preg_match('/shared_folder\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link)) ||
preg_match('/shared_folder_session_'.$sessionId.'\/sf_user_'.api_get_user_id().'$/', urldecode($forcedownload_link)) ||
$isAllowedToEdit || api_is_platform_admin()
$isAllowedToEdit || $isAdmin
) {
$force_download_html = ($size == 0) ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.
Display::return_icon($forcedownload_icon, get_lang('Download'), [], ICON_SIZE_SMALL).'</a>';
}
} elseif (!preg_match('/shared_folder/', urldecode($forcedownload_link)) ||
$isAllowedToEdit ||
api_is_platform_admin()
$isAdmin
) {
$force_download_html = ($size == 0) ? '' : '<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.
Display::return_icon($forcedownload_icon, get_lang('Download'), [], ICON_SIZE_SMALL).'</a>';
@ -6229,7 +6231,7 @@ class DocumentManager
if ($result && Database::num_rows($result)) {
$row = Database::fetch_array($result);
return intval($row[0]);
return (int) $row[0];
}
}
@ -6379,13 +6381,14 @@ class DocumentManager
// $path points to a file in the directory
if (file_exists($realPath) && !is_dir($realPath)) {
error_log('file_exists');
$file = new UploadedFile($realPath, $title, null, null, true);
$resourceFile->setFile($file);
} else {
error_log('Content');
// We get the content and create a file
$handle = tmpfile();
fwrite($handle, $content);
$meta = stream_get_meta_data($handle);
//$file = new ApiMediaFile($handle);
error_log($meta['uri']);
$file = new UploadedFile($meta['uri'], $title, null, null, true);
$resourceFile->setFile($file);

@ -36,6 +36,7 @@ class HtmlEditor extends HTML_QuickForm_textarea
parent::__construct($name, $label, $attributes);
$id = $this->getAttribute('id');
//var_dump($id);
$this->_persistantFreeze = true;
$this->_type = 'html_editor';
@ -102,6 +103,7 @@ class HtmlEditor extends HTML_QuickForm_textarea
$value = $this->getCleanValue();
$this->editor->setName($this->getName());
$this->editor->setTextareaId($this->getAttribute('id'));
if ($style === true) {
$result = $this->editor->createHtmlStyle($value);
} else {

@ -88,6 +88,11 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
$attributes['data-live-search'] = '';
}
if (isset($attributes['extra_class']) && $attributes['extra_class']) {
$attributes['class'] .= ' '.$attributes['extra_class'];
unset($attributes['extra_class']);
}
if (isset($attributes['placeholder'])) {
$addBlank = $attributes['placeholder'];
}
@ -413,7 +418,6 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
$strValues = is_array($this->_values)? array_map('strval', $this->_values): array();
foreach ($this->_options as $option) {
if (!empty($strValues) && in_array($option['attr']['value'], $strValues, true)) {
$option['attr']['selected'] = 'selected';
}

@ -113,7 +113,6 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
switch ($layout) {
case FormValidator::LAYOUT_INLINE:
//<div class="input-group {error_class}">
return '
<label class="sr-only" {label-for} >
<!-- BEGIN required --><span class="form_required">*</span><!-- END required -->

@ -1,8 +1,7 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* HTML class for a textarea type field
* HTML class for a textarea type field.
*
* PHP versions 4 and 5
*
@ -14,36 +13,43 @@
*
* @category HTML
* @package HTML_QuickForm
*
* @author Adam Daniel <adaniel1@eesus.jnj.com>
* @author Bertrand Mansion <bmansion@mamasam.com>
* @copyright 2001-2009 The PHP Group
* @license http://www.php.net/license/3_01.txt PHP License 3.01
*
* @version CVS: $Id: textarea.php,v 1.13 2009/04/04 21:34:04 avb Exp $
* @link http://pear.php.net/package/HTML_QuickForm
*
* @see http://pear.php.net/package/HTML_QuickForm
*/
/**
* HTML class for a textarea type field
* HTML class for a textarea type field.
*
* @category HTML
* @package HTML_QuickForm
*
* @author Adam Daniel <adaniel1@eesus.jnj.com>
* @author Bertrand Mansion <bmansion@mamasam.com>
*
* @version Release: 3.2.11
*
* @since 1.0
*/
class HTML_QuickForm_textarea extends HTML_QuickForm_element
{
/**
* Field value
* @var string
* Field value.
*
* @var string
*
* @since 1.0
* @access private
*/
public $_value;
/**
* Class constructor
* Class constructor.
*
* @param string $elementName Input field name attribute
* @param string|array $label Label(s) for a field
@ -72,24 +78,23 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
}
/**
* Sets the input field name
* Sets the input field name.
*
* @param string $name Input field name attribute
*
* @param string $name Input field name attribute
* @since 1.0
* @access public
* @return void
*/
public function setName($name)
{
$this->updateAttributes(array('name' => $name));
$this->updateAttributes(['name' => $name]);
}
/**
* Returns the element name
* Returns the element name.
*
* @since 1.0
* @access public
* @return string
*
* @return string
*/
public function getName()
{
@ -97,12 +102,11 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
}
/**
* Sets value for textarea element
* Sets value for textarea element.
*
* @param string $value Value for textarea element
*
* @param string $value Value for textarea element
* @since 1.0
* @access public
* @return void
*/
public function setValue($value)
{
@ -110,11 +114,11 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
}
/**
* Returns the value of the form element
* Returns the value of the form element.
*
* @since 1.0
* @access public
* @return string
*
* @return string
*/
public function getValue()
{
@ -122,37 +126,35 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
}
/**
* Sets height in rows for textarea element
* Sets height in rows for textarea element.
*
* @param string $rows Height expressed in rows
*
* @param string $rows Height expressed in rows
* @since 1.0
* @access public
* @return void
*/
public function setRows($rows)
{
$this->updateAttributes(array('rows' => $rows));
$this->updateAttributes(['rows' => $rows]);
}
/**
* Sets width in cols for textarea element
* Sets width in cols for textarea element.
*
* @param string $cols Width expressed in cols
*
* @param string $cols Width expressed in cols
* @since 1.0
* @access public
* @return void
*/
public function setCols($cols)
{
$this->updateAttributes(array('cols' => $cols));
$this->updateAttributes(['cols' => $cols]);
}
/**
* Returns the textarea element in HTML
* Returns the textarea element in HTML.
*
* @since 1.0
* @access public
* @return string
*
* @return string
*/
public function toHtml()
{
@ -160,32 +162,33 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
return $this->getFrozenHtml();
} else {
return $this->_getTabs().
'<textarea' . $this->_getAttrString($this->_attributes) . '>' .
'<textarea'.$this->_getAttrString($this->_attributes).'>'.
// because we wrap the form later we don't want the text indented
// Modified by Ivan Tcholakov, 16-MAR-2010.
//preg_replace("/(\r\n|\n|\r)/", '&#010;', htmlspecialchars($this->_value)) .
preg_replace("/(\r\n|\n|\r)/", '&#010;', $this->getCleanValue()) .
//
preg_replace("/(\r\n|\n|\r)/", '&#010;', $this->getCleanValue()).
'</textarea>';
}
}
/**
* Returns the value of field without HTML tags (in this case, value is changed to a mask)
* Returns the value of field without HTML tags (in this case, value is changed to a mask).
*
* @since 1.0
* @access public
* @return string
*
* @return string
*/
public function getFrozenHtml()
{
$value = $this->getCleanValue();
if ($this->getAttribute('wrap') == 'off') {
$html = $this->_getTabs() . '<pre>' . $value."</pre>\n";
$html = $this->_getTabs().'<pre>'.$value."</pre>\n";
} else {
$html = nl2br($value)."\n";
}
return $html . $this->_getPersistantData();
return $html.$this->_getPersistantData();
}
/**
@ -215,7 +218,6 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
</div>';
break;
case FormValidator::LAYOUT_HORIZONTAL:
$template = '
<div class="form-group row {error_class}">
<label {label-for} class="col-sm-'.$size[0].' col-form-label" >
@ -240,14 +242,12 @@ class HTML_QuickForm_textarea extends HTML_QuickForm_element
<!-- END label_3 -->
</div>
</div>';
if(isset($custom['data-block']) && $custom['data-block'] == true){
if (isset($custom['data-block']) && $custom['data-block'] == true) {
$template = '
<label {label-for}>{label}</label>
<div class="card-textarea">
{element}
</div>
</div>
';
}

@ -72,6 +72,8 @@ class CkEditor extends Editor
$config = $toolbar->getConfig();
$javascript = $this->toJavascript($config);
//var_dump($this->getTextareaId());
$html = "<script>
CKEDITOR.replace('".$this->getTextareaId()."',
$javascript

@ -110,20 +110,6 @@ class Editor
return $this;
}
/**
* Return the HTML code required to run editor.
*
* @param string $value
*
* @return string
*/
public function createHtml($value)
{
$html = '<textarea id="'.$this->getTextareaId().'" name="'.$this->getName().'">'.$value.'</textarea>';
return $html;
}
/**
* @param string $key
* @param mixed $value

@ -70,7 +70,8 @@ class EditorController extends BaseController
/**
* @Route("/filemanager/{parentId}", methods={"GET"}, name="editor_filemanager")
*
* @param int $parentId
* @param int $parentId
* @param CDocumentRepository $documentRepository
*
* @return Response
*/
@ -116,6 +117,7 @@ class EditorController extends BaseController
);
$url = $this->generateUrl('editor_filemanager');
$data = DocumentManager::processDocumentAndFolders(
$documentAndFolders,
$courseInfo,
@ -152,7 +154,7 @@ class EditorController extends BaseController
$params = [
'table' => $table->return_table(),
'parent_id' => (int) $oldParentId,
'parent_id' => $oldParentId,
'allow_course' => true,
];
}

Loading…
Cancel
Save