diff --git a/public/main/lp/blank.php b/public/main/lp/blank.php index f35f53bf90..2249795220 100644 --- a/public/main/lp/blank.php +++ b/public/main/lp/blank.php @@ -20,6 +20,9 @@ body { background: none;} $message = ''; if (isset($_GET['error'])) { switch ($_GET['error']) { + case 'document_protected': + $message = Display::return_message(get_lang('ProtectedDocument'), 'warning'); + break; case 'document_deleted': $message = Display::return_message(get_lang('The document cannot be displayed because it has been deleted'), 'error'); break; diff --git a/public/main/lp/learnpathItem.class.php b/public/main/lp/learnpathItem.class.php index b2138bf1ff..0909749703 100644 --- a/public/main/lp/learnpathItem.class.php +++ b/public/main/lp/learnpathItem.class.php @@ -13,7 +13,7 @@ use Chamilo\CoreBundle\Framework\Container; */ class learnpathItem { - const DEBUG = 0; // Logging parameter. + public const DEBUG = 0; // Logging parameter. public $iId; public $attempt_id; // Also called "objectives" SCORM-wise. public $audio; // The path to an audio file (stored in document/audio/). @@ -252,26 +252,43 @@ class learnpathItem * Closes/stops the item viewing. Finalises runtime values. * If required, save to DB. * + * @param bool $prerequisitesCheck Needed to check if asset can be set as completed or not + * * @return bool True on success, false otherwise */ public function close() { + $debug = self::DEBUG; $this->current_stop_time = time(); $type = $this->get_type(); - if ('sco' != $type) { - if (TOOL_QUIZ == $type || TOOL_HOTPOTATOES == $type) { + if ($debug) { + error_log('Start - learnpathItem:close'); + error_log("Type: ".$type); + error_log("get_id: ".$this->get_id()); + } + if ($type !== 'sco') { + if ($type == TOOL_QUIZ || $type == TOOL_HOTPOTATOES) { $this->get_status( true, true ); // Update status (second option forces the update). } else { - $this->status = $this->possible_status[2]; + /*$this->status = $this->possible_status[2]; + if (self::DEBUG) { + error_log("STATUS changed to: ".$this->status); + }*/ } } if ($this->save_on_close) { + if ($debug) { + error_log('save_on_close'); + } $this->save(); } + if ($debug) { + error_log('End - learnpathItem:close'); + } return true; } @@ -850,10 +867,7 @@ class learnpathItem } } if (self::DEBUG > 2) { - error_log( - 'New LP - End of learnpathItem::get_prevent_reinit() - Returned '.$this->prevent_reinit, - 0 - ); + error_log('End of learnpathItem::get_prevent_reinit() - Returned '.$this->prevent_reinit); } return $this->prevent_reinit; @@ -1464,12 +1478,12 @@ class learnpathItem { $courseId = $this->courseId; $debug = self::DEBUG; - if ($debug > 0) { - error_log('learnpathItem::get_status() on item '.$this->db_id, 0); + if ($debug) { + error_log('learnpathItem::get_status() on item '.$this->db_id); } if ($check_db) { - if ($debug > 2) { - error_log('learnpathItem::get_status(): checking db', 0); + if ($debug) { + error_log('learnpathItem::get_status(): checking db'); } if (!empty($this->db_item_view_id) && !empty($courseId)) { $table = Database::get_course_table(TABLE_LP_ITEM_VIEW); @@ -2437,7 +2451,10 @@ class learnpathItem return $returnstatus; } else { - $status = $itemToCheck->get_status(false); + $status = $itemToCheck->get_status(true); + if (self::DEBUG) { + error_log('Status:'.$status); + } $returnstatus = $status == $this->possible_status[2] || $status == $this->possible_status[3]; // Check results from another sessions. @@ -2515,7 +2532,7 @@ class learnpathItem } $orstatus = false; foreach ($list as $condition) { - if (self::DEBUG > 1) { + if (self::DEBUG) { error_log( 'New LP - Found OR, adding it ('.$condition.')', 0 @@ -2805,10 +2822,7 @@ class learnpathItem } if ($debug) { - error_log( - 'New LP - End of learnpathItem::save() - Calling write_to_db()', - 0 - ); + error_log('End of learnpathItem::save() - Calling write_to_db() now'); } return $this->write_to_db(); @@ -3112,12 +3126,11 @@ class learnpathItem if ($found) { $this->status = $status; - if (self::DEBUG > 1) { + if (self::DEBUG) { error_log( 'learnpathItem::set_status() - '. 'Updated object status of item '.$this->db_id. - ' to '.$this->status, - 0 + ' to '.$this->status ); } @@ -3643,10 +3656,7 @@ class learnpathItem lp_view_id = ".$this->view_id." AND view_count = ".$this->get_attempt_id(); if ($debug) { - error_log( - 'learnpathItem::write_to_db() - Querying item_view: '.$sql, - 0 - ); + error_log('learnpathItem::write_to_db() - Querying item_view: '.$sql); } $check_res = Database::query($sql); @@ -4081,30 +4091,27 @@ class learnpathItem /** * Adds an audio file to the current item, using a file already in documents. * - * @param int $doc_id + * @param int $documentId * * @return string */ - public function add_audio_from_documents($doc_id) + public function add_audio_from_documents($documentId) { - $course_info = api_get_course_info(); - $document_data = DocumentManager::get_document_data_by_id( - $doc_id, - $course_info['code'] - ); + $courseInfo = api_get_course_info(); + $documentData = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']); - $file_path = ''; - if (!empty($document_data)) { - $file_path = basename($document_data['path']); + $path = ''; + if (!empty($documentData)) { + $path = $documentData['path']; // Store the mp3 file in the lp_item table. $table = Database::get_course_table(TABLE_LP_ITEM); $sql = "UPDATE $table SET - audio = '".Database::escape_string($file_path)."' - WHERE iid = ".intval($this->db_id); + audio = '".Database::escape_string($path)."' + WHERE iid = ".$this->db_id; Database::query($sql); } - return $file_path; + return $path; } /** diff --git a/public/main/lp/lp_ajax_save_item.php b/public/main/lp/lp_ajax_save_item.php index 8375783850..5d2c803dcf 100644 --- a/public/main/lp/lp_ajax_save_item.php +++ b/public/main/lp/lp_ajax_save_item.php @@ -62,22 +62,23 @@ function save_item( ) { $debug = 0; $return = null; + $courseCode = api_get_course_id(); + if (!empty($courseId)) { + $courseInfo = api_get_course_info_by_id($courseId); + if ($courseInfo) { + $courseCode = $courseInfo['code']; + } + } if ($debug > 0) { error_log('--------------------------------------'); - error_log('SAVE ITEM - lp_ajax_save_item.php : save_item() params: '); + error_log('SAVE ITEM - lp_ajax_save_item.php'); + error_log('--------------------------------------'); error_log("item_id: $item_id - lp_id: $lp_id - user_id: - $user_id - view_id: $view_id - item_id: $item_id"); error_log("SCORE: $score - max:$max - min: $min - status:$status"); error_log("TIME: $time - suspend: $suspend - location: $location - core_exit: $core_exit"); error_log("finish: $lmsFinish - navigatesAway: $userNavigatesAway"); - } - - $courseCode = api_get_course_id(); - if (!empty($courseId)) { - $courseInfo = api_get_course_info_by_id($courseId); - if ($courseInfo) { - $courseCode = $courseInfo['code']; - } + error_log("courseCode: $courseCode"); } $myLP = learnpath::getLpFromSession($courseCode, $lp_id, $user_id); @@ -487,9 +488,11 @@ function save_item( if (true === $scoreAsProgressSetting) { $scoreAsProgress = $myLP->getUseScoreAsProgress(); if ($scoreAsProgress) { - $score = $myLPI->get_score(); - $maxScore = $myLPI->get_max(); - $return .= "update_progress_bar('$score', '$maxScore', '$myProgressMode');"; + if (isset($score) && $score != -1) { + $score = $myLPI->get_score(); + $maxScore = $myLPI->get_max(); + $return .= "update_progress_bar('$score', '$maxScore', '$myProgressMode');"; + } $progressBarSpecial = true; } } @@ -524,7 +527,7 @@ function save_item( } // To be sure progress is updated. - $myLP->save_last(); + $myLP->save_last($score); Session::write('lpobject', serialize($myLP)); Session::write('oLP', $myLP); diff --git a/public/main/lp/lp_ajax_switch_item.php b/public/main/lp/lp_ajax_switch_item.php index 4c38adaf05..95f7e3d09c 100644 --- a/public/main/lp/lp_ajax_switch_item.php +++ b/public/main/lp/lp_ajax_switch_item.php @@ -29,10 +29,9 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it $debug = 0; $return = ''; if ($debug > 0) { - error_log( - 'In xajax_switch_item_details('.$lp_id.','.$user_id.','.$view_id.','.$current_item.','.$next_item.')', - 0 - ); + error_log('--------------------------------------'); + error_log('SWITCH'); + error_log('Params('.$lp_id.','.$user_id.','.$view_id.','.$current_item.','.$next_item.')'); } //$objResponse = new xajaxResponse(); /*$item_id may be one of: @@ -268,6 +267,7 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it $mylp->set_error_msg(''); $mylp->prerequisites_match(); // Check the prerequisites are all complete. if ($debug > 1) { + error_log($return); error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); } // Save the new item ID for the exercise tool to use. diff --git a/public/main/lp/lp_content.php b/public/main/lp/lp_content.php index eae609793c..6576e1766e 100644 --- a/public/main/lp/lp_content.php +++ b/public/main/lp/lp_content.php @@ -55,10 +55,7 @@ if ($dir) { case 1: $learnPath->stop_previous_item(); $prerequisiteCheck = $learnPath->prerequisites_match($lpItemId); - if (true === $prerequisiteCheck) { - $src = $learnPath->get_link('http', $lpItemId); - $learnPath->start_current_item(); // starts time counter manually if asset - $src = $learnPath->fixBlockedLinks($src); + if ($prerequisiteCheck === true) { if (WhispeakAuthPlugin::isLpItemMarked($lpItemId)) { ChamiloSession::write( @@ -67,10 +64,18 @@ if ($dir) { ); $src = api_get_path(WEB_PLUGIN_PATH).'whispeakauth/authentify.php'; + break; } + $src = $learnPath->get_link('http', $lpItemId); + if (empty($src)) { + $src = 'blank.php?'.api_get_cidreq().'&error=document_protected'; + break; + } + $learnPath->start_current_item(); // starts time counter manually if asset + $src = $learnPath->fixBlockedLinks($src); break; } - $src = 'blank.php?error=prerequisites&prerequisite_message='.Security::remove_XSS($learnPath->error); + $src = 'blank.php?'.api_get_cidreq().'&error=prerequisites&prerequisite_message='.Security::remove_XSS($learnPath->error); break; case 2: $learnPath->stop_previous_item(); @@ -80,7 +85,7 @@ if ($dir) { $src = $learnPath->get_link('http', $lpItemId); $learnPath->start_current_item(); // starts time counter manually if asset } else { - $src = 'blank.php?error=prerequisites&prerequisite_message='.Security::remove_XSS($learnPath->error); + $src = 'blank.php?'.api_get_cidreq().'&error=prerequisites&prerequisite_message='.Security::remove_XSS($learnPath->error); } break; case 3: diff --git a/public/main/lp/lp_view.php b/public/main/lp/lp_view.php index 0954595477..93878e44b5 100644 --- a/public/main/lp/lp_view.php +++ b/public/main/lp/lp_view.php @@ -297,9 +297,9 @@ $autostart = 'true'; if ($debug) { error_log('$type_quiz: '.$type_quiz); - error_log('$_REQUEST[exeId]: '.intval($_REQUEST['exeId'])); + error_log('$_REQUEST[exeId]: '.intval($_REQUEST['exeId'] ?? 0)); error_log('$lp_id: '.$lp_id); - error_log('$_REQUEST[lp_item_id]: '.intval($_REQUEST['lp_item_id'])); + error_log('$_REQUEST[lp_item_id]: '.intval($_REQUEST['lp_item_id'] ?? 0)); } if (!empty($_REQUEST['exeId']) && diff --git a/src/CoreBundle/Entity/User.php b/src/CoreBundle/Entity/User.php index 63ec4e9924..6ba20962ce 100644 --- a/src/CoreBundle/Entity/User.php +++ b/src/CoreBundle/Entity/User.php @@ -769,7 +769,6 @@ class User implements UserInterface, EquatableInterface, ResourceInterface $this->expired = false; $this->roles = []; $this->credentialsExpired = false; - } /** @@ -2458,8 +2457,8 @@ class User implements UserInterface, EquatableInterface, ResourceInterface $this->setUsername($name); } - public function setParent(AbstractResource $parent) { - + public function setParent(AbstractResource $parent) + { } /** @@ -2486,7 +2485,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface ? 0 : max( $categoryCourses->map( - /** @var CourseRelUser $courseRelUser */ + /** @var CourseRelUser $courseRelUser */ function ($courseRelUser) { return $courseRelUser->getSort(); } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20180927172830.php b/src/CoreBundle/Migrations/Schema/V200/Version20180927172830.php index 1243907c45..454b7f554b 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20180927172830.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20180927172830.php @@ -60,8 +60,6 @@ class Version20180927172830 extends AbstractMigrationChamilo $this->addSql('CREATE INDEX IDX_47A9C99F2E82C87 ON c_forum_forum (forum_last_post);'); } - - $table = $schema->getTable('c_forum_thread'); if (false === $table->hasForeignKey('FK_5DA7884C29CCBAD0')) { $this->addSql('ALTER TABLE c_forum_thread ADD CONSTRAINT FK_5DA7884C29CCBAD0 FOREIGN KEY (forum_id) REFERENCES c_forum_forum (iid)'); diff --git a/src/CourseBundle/Entity/CForumForum.php b/src/CourseBundle/Entity/CForumForum.php index 10ef8c6e47..766a30175d 100644 --- a/src/CourseBundle/Entity/CForumForum.php +++ b/src/CourseBundle/Entity/CForumForum.php @@ -6,7 +6,6 @@ namespace Chamilo\CourseBundle\Entity; use Chamilo\CoreBundle\Entity\AbstractResource; use Chamilo\CoreBundle\Entity\ResourceInterface; -use Chamilo\CoreBundle\Entity\User; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo;