Fix php errors, fix queries, remove require_once already loaded.

pull/3844/head
Julio Montoya 5 years ago
parent 7b6b244b4f
commit a7beb2feaf
  1. 23
      public/main/exercise/answer.class.php
  2. 2
      public/main/exercise/fill_blanks.class.php
  3. 29
      public/main/exercise/question.class.php
  4. 2
      public/main/lp/learnpath.class.php
  5. 2
      public/main/lp/lp_upload.php
  6. 26
      public/main/lp/lp_view.php
  7. 2
      public/main/lp/openoffice_document.class.php
  8. 5
      public/main/lp/openoffice_presentation.class.php
  9. 2
      public/main/lp/openoffice_text.class.php
  10. 2
      public/main/lp/openoffice_text_document.class.php
  11. 22
      public/main/lp/readout_text.php
  12. 4
      public/main/lp/scorm.class.php
  13. 2
      public/main/lp/scorm_api.php
  14. 6
      public/main/survey/surveyUtil.class.php
  15. 2
      src/CoreBundle/Traits/Repository/ORM/TreeRepositoryTrait.php

@ -830,14 +830,11 @@ class Answer
$fixed_list = []; $fixed_list = [];
$tableAnswer = Database::get_course_table(TABLE_QUIZ_ANSWER); $tableAnswer = Database::get_course_table(TABLE_QUIZ_ANSWER);
if (MULTIPLE_ANSWER_TRUE_FALSE == self::getQuestionType() || if (MULTIPLE_ANSWER_TRUE_FALSE === self::getQuestionType() ||
MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY == self::getQuestionType() MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY === self::getQuestionType()
) { ) {
// Selecting origin options // Selecting origin options
$origin_options = Question::readQuestionOption( $origin_options = Question::readQuestionOption($this->selectQuestionId(), $this->course['real_id']);
$this->selectQuestionId(),
$this->course['real_id']
);
if (!empty($origin_options)) { if (!empty($origin_options)) {
foreach ($origin_options as $item) { foreach ($origin_options as $item) {
@ -845,10 +842,7 @@ class Answer
} }
} }
$destination_options = Question::readQuestionOption( $destination_options = Question::readQuestionOption($newQuestionId, $course_info['real_id']);
$newQuestionId,
$course_info['real_id']
);
$i = 0; $i = 0;
if (!empty($destination_options)) { if (!empty($destination_options)) {
foreach ($destination_options as $item) { foreach ($destination_options as $item) {
@ -858,6 +852,8 @@ class Answer
} }
} }
$repo = Container::getQuestionRepository();
// if at least one answer // if at least one answer
if ($this->nbrAnswers) { if ($this->nbrAnswers) {
// inserts new answers into data base // inserts new answers into data base
@ -903,9 +899,11 @@ class Answer
); );
} }
$question = $repo->find($newQuestionId);
$quizAnswer = new CQuizAnswer(); $quizAnswer = new CQuizAnswer();
$quizAnswer $quizAnswer
->setQuestionId($newQuestionId) ->setQuestion($question)
->setAnswer($answer['answer']) ->setAnswer($answer['answer'])
->setCorrect($answer['correct']) ->setCorrect($answer['correct'])
->setComment($answer['comment']) ->setComment($answer['comment'])
@ -950,9 +948,10 @@ class Answer
$correct = $fixed_list[(int) $correct]; $correct = $fixed_list[(int) $correct];
} }
$question = $repo->find($newQuestionId);
$quizAnswer = new CQuizAnswer(); $quizAnswer = new CQuizAnswer();
$quizAnswer $quizAnswer
->setQuestionId($newQuestionId) ->setQuestion($question)
->setAnswer($this->answer[$i]) ->setAnswer($this->answer[$i])
->setCorrect($correct) ->setCorrect($correct)
->setComment($this->comment[$i]) ->setComment($this->comment[$i])

@ -781,7 +781,7 @@ class FillBlanks extends Question
$blankCharEnd = self::getEndSeparator($blankSeparatorNumber); $blankCharEnd = self::getEndSeparator($blankSeparatorNumber);
$blankCharStartForRegexp = self::escapeForRegexp($blankCharStart); $blankCharStartForRegexp = self::escapeForRegexp($blankCharStart);
$blankCharEndForRegexp = self::escapeForRegexp($blankCharEnd); $blankCharEndForRegexp = self::escapeForRegexp($blankCharEnd);
$listWords = [];
// Get all blanks words // Get all blanks words
$listAnswerResults['words_count'] = api_preg_match_all( $listAnswerResults['words_count'] = api_preg_match_all(
'/'.$blankCharStartForRegexp.'[^'.$blankCharEndForRegexp.']*'.$blankCharEndForRegexp.'/', '/'.$blankCharStartForRegexp.'[^'.$blankCharEndForRegexp.']*'.$blankCharEndForRegexp.'/',

@ -163,7 +163,7 @@ abstract class Question
if ($object = Database::fetch_object($result)) { if ($object = Database::fetch_object($result)) {
$objQuestion = self::getInstance($object->type); $objQuestion = self::getInstance($object->type);
if (!empty($objQuestion)) { if (!empty($objQuestion)) {
$objQuestion->id = (int) $id; $objQuestion->id = $id;
$objQuestion->iid = (int) $object->iid; $objQuestion->iid = (int) $object->iid;
$objQuestion->question = $object->question; $objQuestion->question = $object->question;
$objQuestion->description = $object->description; $objQuestion->description = $object->description;
@ -426,7 +426,7 @@ abstract class Question
* delete any category entry for question id * delete any category entry for question id
* delete the category for question * delete the category for question
* *
* @deprecated * @todo Check if deprecated
* *
* @return bool * @return bool
*/ */
@ -1063,7 +1063,6 @@ abstract class Question
$question = new CQuizQuestion(); $question = new CQuizQuestion();
$question $question
->setCId($course_id)
->setQuestion($questionText) ->setQuestion($questionText)
->setDescription($description) ->setDescription($description)
->setPonderation($this->weighting) ->setPonderation($this->weighting)
@ -1073,9 +1072,7 @@ abstract class Question
->setLevel($this->level) ->setLevel($this->level)
->setFeedback($this->feedback) ->setFeedback($this->feedback)
->setParent($courseEntity) ->setParent($courseEntity)
->addCourseLink( ->addCourseLink($courseEntity)
$courseEntity
)
; ;
$em->persist($question); $em->persist($question);
@ -1288,7 +1285,7 @@ abstract class Question
); );
if (MEDIA_QUESTION != $this->type) { if (MEDIA_QUESTION != $this->type) {
// Advanced parameters // Advanced parameters.
$form->addElement( $form->addElement(
'select', 'select',
'questionLevel', 'questionLevel',
@ -1296,8 +1293,7 @@ abstract class Question
self::get_default_levels() self::get_default_levels()
); );
// Categories // Categories.
$form->addElement( $form->addElement(
'select', 'select',
'questionCategory', 'questionCategory',
@ -1313,8 +1309,8 @@ abstract class Question
); );
} }
global $text; //global $text;
$text = get_lang('Save the question');
switch ($this->type) { switch ($this->type) {
case UNIQUE_ANSWER: case UNIQUE_ANSWER:
$buttonGroup = []; $buttonGroup = [];
@ -1755,10 +1751,13 @@ abstract class Question
['class' => 'question_description'] ['class' => 'question_description']
); );
} else { } else {
if (true == $score['pass']) { /** @var ReadingComprehension $this */
if (true === $score['pass']) {
$message = Display::div( $message = Display::div(
sprintf( sprintf(
get_lang('Congratulations, you have reached and correctly understood, at a speed of %s words per minute, a text of a total %s words.'), get_lang(
'Congratulations, you have reached and correctly understood, at a speed of %s words per minute, a text of a total %s words.'
),
ReadingComprehension::$speeds[$this->level], ReadingComprehension::$speeds[$this->level],
$this->getWordsCount() $this->getWordsCount()
) )
@ -1766,7 +1765,9 @@ abstract class Question
} else { } else {
$message = Display::div( $message = Display::div(
sprintf( sprintf(
get_lang('Sorry, it seems like a speed of %s words/minute was too fast for this text of %s words.'), get_lang(
'Sorry, it seems like a speed of %s words/minute was too fast for this text of %s words.'
),
ReadingComprehension::$speeds[$this->level], ReadingComprehension::$speeds[$this->level],
$this->getWordsCount() $this->getWordsCount()
) )

@ -6609,7 +6609,7 @@ class learnpath
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$return = ''; $return = '';
if (empty($lpItem)) { if (null === $lpItem) {
return ''; return '';
} }
$item_id = $lpItem->getIid(); $item_id = $lpItem->getIid();

@ -121,14 +121,12 @@ if (isset($_POST) && $is_error) {
$em->flush(); $em->flush();
break; break;
case 'oogie': case 'oogie':
require_once 'openoffice_presentation.class.php';
$take_slide_name = empty($_POST['take_slide_name']) ? false : true; $take_slide_name = empty($_POST['take_slide_name']) ? false : true;
$o_ppt = new OpenofficePresentation($take_slide_name); $o_ppt = new OpenofficePresentation($take_slide_name);
$first_item_id = $o_ppt->convert_document($_FILES['user_file'], 'make_lp', $_POST['slide_size']); $first_item_id = $o_ppt->convert_document($_FILES['user_file'], 'make_lp', $_POST['slide_size']);
Display::addFlash(Display::return_message(get_lang('File upload succeeded!'))); Display::addFlash(Display::return_message(get_lang('File upload succeeded!')));
break; break;
case 'woogie': case 'woogie':
require_once 'openoffice_text.class.php';
$split_steps = empty($_POST['split_steps']) || 'per_page' === $_POST['split_steps'] ? 'per_page' : 'per_chapter'; $split_steps = empty($_POST['split_steps']) || 'per_page' === $_POST['split_steps'] ? 'per_page' : 'per_chapter';
$o_doc = new OpenofficeText($split_steps); $o_doc = new OpenofficeText($split_steps);
$first_item_id = $o_doc->convert_document($_FILES['user_file']); $first_item_id = $o_doc->convert_document($_FILES['user_file']);

@ -37,10 +37,8 @@ $session = api_get_session_entity($sessionId);
$lpRepo = Container::getLpRepository(); $lpRepo = Container::getLpRepository();
/** @var learnpath $lp */ /** @var learnpath $lp */
//$oLP = Session::read('oLP'); $oLP = Session::read('oLP');
/** @var CLp $lp */ /** @var CLp $lp */
$lp = $lp;
// Check if the learning path is visible for student - (LP requisites) // Check if the learning path is visible for student - (LP requisites)
if (!api_is_platform_admin()) { if (!api_is_platform_admin()) {
if (!api_is_allowed_to_edit(null, true, false, false) && if (!api_is_allowed_to_edit(null, true, false, false) &&
@ -76,11 +74,7 @@ if (!$is_allowed_to_edit) {
} }
} }
$isVisible = learnpath::categoryIsVisibleForStudent( $isVisible = learnpath::categoryIsVisibleForStudent($category, $user, $course, $session);
$category,
$user
);
if ($isVisible) { if ($isVisible) {
$block = false; $block = false;
} }
@ -101,7 +95,7 @@ var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
--> -->
</script>'; </script>';
$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>'; $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
$(function() { $(function() {
$("div#log_content_cleaner").bind("click", function() { $("div#log_content_cleaner").bind("click", function() {
@ -256,7 +250,7 @@ if (!isset($src)) {
case CLp::SCORM_TYPE: case CLp::SCORM_TYPE:
// save old if asset // save old if asset
$oLP->stop_previous_item(); // save status manually if asset $oLP->stop_previous_item(); // save status manually if asset
$htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>'; $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript"></script>';
$preReqCheck = $oLP->prerequisites_match($lp_item_id); $preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) { if (true === $preReqCheck) {
$src = $oLP->get_link('http', $lp_item_id, $get_toc_list); $src = $oLP->get_link('http', $lp_item_id, $get_toc_list);
@ -267,7 +261,7 @@ if (!isset($src)) {
break; break;
case CLp::AICC_TYPE: case CLp::AICC_TYPE:
$oLP->stop_previous_item(); // save status manually if asset $oLP->stop_previous_item(); // save status manually if asset
$htmlHeadXtra[] = '<script src="'.$oLP->get_js_lib().'" type="text/javascript" language="javascript"></script>'; $htmlHeadXtra[] = '<script src="'.$oLP->get_js_lib().'" type="text/javascript"></script>';
$preReqCheck = $oLP->prerequisites_match($lp_item_id); $preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) { if (true === $preReqCheck) {
$src = $oLP->get_link( $src = $oLP->get_link(
@ -290,9 +284,9 @@ $autostart = 'true';
if ($debug) { if ($debug) {
error_log('$type_quiz: '.$type_quiz); error_log('$type_quiz: '.$type_quiz);
error_log('$_REQUEST[exeId]: '.intval($_REQUEST['exeId'] ?? 0)); error_log('$_REQUEST[exeId]: '.(int) ($_REQUEST['exeId'] ?? 0));
error_log('$lp_id: '.$lp_id); error_log('$lp_id: '.$lp_id);
error_log('$_REQUEST[lp_item_id]: '.intval($_REQUEST['lp_item_id'] ?? 0)); error_log('$_REQUEST[lp_item_id]: '.(int) ($_REQUEST['lp_item_id'] ?? 0));
} }
if (!empty($_REQUEST['exeId']) && if (!empty($_REQUEST['exeId']) &&
@ -325,8 +319,8 @@ $oLP->set_previous_item($lp_item_id);
$nameTools = Security::remove_XSS($oLP->get_name()); $nameTools = Security::remove_XSS($oLP->get_name());
$save_setting = api_get_setting('show_navigation_menu'); $save_setting = api_get_setting('show_navigation_menu');
global $_setting; /*global $_setting;
$_setting['show_navigation_menu'] = 'false'; $_setting['show_navigation_menu'] = 'false';*/
$scorm_css_header = true; $scorm_css_header = true;
$lp_theme_css = $oLP->get_theme(); $lp_theme_css = $oLP->get_theme();
// Sets the css theme of the LP this call is also use at the frames (toc, nav, message). // Sets the css theme of the LP this call is also use at the frames (toc, nav, message).
@ -578,7 +572,7 @@ $template->assign('frame_ready', $frameReady);
$template->displayTemplate('@ChamiloCore/LearnPath/view.html.twig'); $template->displayTemplate('@ChamiloCore/LearnPath/view.html.twig');
// Restore a global setting. // Restore a global setting.
$_setting['show_navigation_menu'] = $save_setting; //$_setting['show_navigation_menu'] = $save_setting;
//Session::write('oLP', $lp); //Session::write('oLP', $lp);

@ -100,7 +100,7 @@ abstract class OpenofficeDocument extends learnpath
$ppt2lp_host = api_get_setting('service_ppt2lp', 'host'); $ppt2lp_host = api_get_setting('service_ppt2lp', 'host');
if ('localhost' == $ppt2lp_host) { if ('localhost' === $ppt2lp_host) {
move_uploaded_file($file['tmp_name'], $this->base_work_dir.'/'.$this->file_path); move_uploaded_file($file['tmp_name'], $this->base_work_dir.'/'.$this->file_path);
//var_dump( $this->base_work_dir.$this->created_dir.$this->file_path); //var_dump( $this->base_work_dir.$this->created_dir.$this->file_path);
$perm = api_get_setting('permissions_for_new_files'); $perm = api_get_setting('permissions_for_new_files');

@ -10,11 +10,6 @@
* @license GNU/GPL * @license GNU/GPL
*/ */
/**
* Defines the "OpenofficePresentation" child of class "OpenofficeDocument".
*/
require_once 'openoffice_document.class.php';
class OpenofficePresentation extends OpenofficeDocument class OpenofficePresentation extends OpenofficeDocument
{ {
public $take_slide_name; public $take_slide_name;

@ -13,8 +13,6 @@
/** /**
* Defines the "OpenofficeText" child of class "learnpath". * Defines the "OpenofficeText" child of class "learnpath".
*/ */
require_once 'openoffice_document.class.php';
class OpenofficeText extends OpenofficeDocument class OpenofficeText extends OpenofficeDocument
{ {
public $split_steps; public $split_steps;

@ -12,8 +12,6 @@
/** /**
* Defines the "OpenOfficeTextDocument" child of class "learnpath". * Defines the "OpenOfficeTextDocument" child of class "learnpath".
*/ */
require_once 'openoffice_document.class.php';
class OpenOfficeTextDocument extends OpenofficeDocument class OpenOfficeTextDocument extends OpenofficeDocument
{ {
public $split_steps; public $split_steps;

@ -1,6 +1,7 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CDocument; use Chamilo\CourseBundle\Entity\CDocument;
/** /**
@ -23,7 +24,7 @@ $userId = api_get_user_id();
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$em = Database::getManager(); $em = Database::getManager();
$documentRepo = $em->getRepository('ChamiloCourseBundle:CDocument'); $documentRepo = Container::getDocumentRepository();
// This page can only be shown from inside a learning path // This page can only be shown from inside a learning path
if (!$id && !$lpId) { if (!$id && !$lpId) {
@ -31,23 +32,18 @@ if (!$id && !$lpId) {
} }
/** @var CDocument $document */ /** @var CDocument $document */
$document = $documentRepo->findOneBy(['cId' => $courseId, 'iid' => $id]); $document = $documentRepo->find($id);
if (empty($document)) { if (null === $document) {
// Try with normal id Display::return_message(get_lang('The file was not found'), 'error');
/** @var CDocument $document */ exit;
$document = $documentRepo->findOneBy(['cId' => $courseId, 'id' => $id]);
if (empty($document)) {
Display::return_message(get_lang('The file was not found'), 'error');
exit;
}
} }
$documentPathInfo = pathinfo($document->getPath()); $documentText = $documentRepo->getResourceFileContent($document);
/*$documentPathInfo = pathinfo($document->getPath());
$coursePath = api_get_path(SYS_COURSE_PATH).$courseInfo['directory']; $coursePath = api_get_path(SYS_COURSE_PATH).$courseInfo['directory'];
$documentPath = '/document'.$document->getPath(); $documentPath = '/document'.$document->getPath();
$documentText = file_get_contents($coursePath.$documentPath); $documentText = file_get_contents($coursePath.$documentPath);*/
$documentText = api_remove_tags_with_space($documentText); $documentText = api_remove_tags_with_space($documentText);
$wordsInfo = preg_split('/ |\n/', $documentText, -1, PREG_SPLIT_OFFSET_CAPTURE); $wordsInfo = preg_split('/ |\n/', $documentText, -1, PREG_SPLIT_OFFSET_CAPTURE);

@ -96,7 +96,7 @@ class scorm extends learnpath
if (!empty($xmlErrors)) { if (!empty($xmlErrors)) {
if ($this->debug > 0) { if ($this->debug > 0) {
error_log('In scorm::parse_manifest() - Exception thrown when loading '.$file.' in DOMDocument'); error_log('In scorm::parse_manifest() - Exception thrown when loading DOMDocument');
} }
// Throw exception? // Throw exception?
return null; return null;
@ -356,7 +356,6 @@ class scorm extends learnpath
$myname = api_utf8_decode($oOrganization->get_name()); $myname = api_utf8_decode($oOrganization->get_name());
$lp = new CLp(); $lp = new CLp();
$lp $lp
->setCId($courseId)
->setLpType(CLp::SCORM_TYPE) ->setLpType(CLp::SCORM_TYPE)
->setName($myname) ->setName($myname)
->setRef($oOrganization->get_ref()) ->setRef($oOrganization->get_ref())
@ -366,7 +365,6 @@ class scorm extends learnpath
->setDisplayOrder($dsp) ->setDisplayOrder($dsp)
->setUseMaxScore($userMaxScore) ->setUseMaxScore($userMaxScore)
->setAsset($this->asset) ->setAsset($this->asset)
->setSessionId($sessionId)
->setParent($courseEntity) ->setParent($courseEntity)
->addCourseLink($courseEntity, api_get_session_entity()) ->addCourseLink($courseEntity, api_get_session_entity())
; ;

@ -27,8 +27,8 @@ $use_anonymous = true;
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
/** @var learnpath $oLP */ /** @var learnpath $oLP */
//$oLP = UnserializeApi::unserialize('lp', Session::read('lpobject'));
$oLP = Session::read('oLP'); $oLP = Session::read('oLP');
//$oLP = UnserializeApi::unserialize('lp', Session::read('lpobject'));
if (!is_object($oLP)) { if (!is_object($oLP)) {
error_log('New LP - scorm_api - Could not load oLP object', 0); error_log('New LP - scorm_api - Could not load oLP object', 0);
exit; exit;

@ -73,7 +73,6 @@ class SurveyUtil
$table = Database::get_course_table(TABLE_SURVEY_ANSWER); $table = Database::get_course_table(TABLE_SURVEY_ANSWER);
$sql = "DELETE FROM $table $sql = "DELETE FROM $table
WHERE WHERE
c_id = $course_id AND
user = '".Database::escape_string($user)."' AND user = '".Database::escape_string($user)."' AND
survey_id = '".intval($survey_id)."' AND survey_id = '".intval($survey_id)."' AND
question_id = '".intval($question_id)."'"; question_id = '".intval($question_id)."'";
@ -110,9 +109,6 @@ class SurveyUtil
return false; return false;
} }
// Table definition
$table_survey_answer = Database::get_course_table(TABLE_SURVEY_ANSWER);
// Make the survey anonymous // Make the survey anonymous
if (1 == $survey_data['anonymous']) { if (1 == $survey_data['anonymous']) {
$surveyUser = Session::read('surveyuser'); $surveyUser = Session::read('surveyuser');
@ -130,7 +126,6 @@ class SurveyUtil
$answer = new CSurveyAnswer(); $answer = new CSurveyAnswer();
$answer $answer
->setCId($survey_data['c_id'])
->setUser($user) ->setUser($user)
->setSurveyId($survey_id) ->setSurveyId($survey_id)
->setQuestionId($question_id) ->setQuestionId($question_id)
@ -649,7 +644,6 @@ class SurveyUtil
// Getting the question information // Getting the question information
$sql = "SELECT * FROM $table_survey_question $sql = "SELECT * FROM $table_survey_question
WHERE WHERE
c_id = $course_id AND
survey_id = $surveyId AND survey_id = $surveyId AND
survey_question NOT LIKE '%{{%' AND survey_question NOT LIKE '%{{%' AND
type <>'pagebreak' type <>'pagebreak'

@ -94,8 +94,6 @@ trait TreeRepositoryTrait
* Sets the RepositoryUtilsInterface instance * Sets the RepositoryUtilsInterface instance
* *
* @param \Gedmo\Tree\RepositoryUtilsInterface $repoUtils * @param \Gedmo\Tree\RepositoryUtilsInterface $repoUtils
*
* @return static
*/ */
public function setRepoUtils(RepositoryUtilsInterface $repoUtils) public function setRepoUtils(RepositoryUtilsInterface $repoUtils)
{ {

Loading…
Cancel
Save