You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.0 KiB
69 lines
2.0 KiB
7 years ago
|
<?php
|
||
|
/* For licensing terms, see /license.txt */
|
||
|
|
||
6 years ago
|
use Chamilo\CourseBundle\Entity\CDocument;
|
||
|
|
||
7 years ago
|
/**
|
||
6 years ago
|
* Print a read-out text inside a session.
|
||
7 years ago
|
*/
|
||
|
$_in_course = true;
|
||
|
|
||
|
require_once __DIR__.'/../inc/global.inc.php';
|
||
|
|
||
|
$current_course_tool = TOOL_LEARNPATH;
|
||
|
|
||
|
api_protect_course_script(true);
|
||
|
|
||
6 years ago
|
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||
|
$lpId = isset($_GET['lp_id']) ? (int) $_GET['lp_id'] : 0;
|
||
7 years ago
|
$courseInfo = api_get_course_info();
|
||
|
$courseCode = $courseInfo['code'];
|
||
|
$courseId = $courseInfo['real_id'];
|
||
|
$userId = api_get_user_id();
|
||
|
$sessionId = api_get_session_id();
|
||
|
|
||
|
$em = Database::getManager();
|
||
|
$documentRepo = $em->getRepository('ChamiloCourseBundle:CDocument');
|
||
|
|
||
|
// This page can only be shown from inside a learning path
|
||
|
if (!$id && !$lpId) {
|
||
|
api_not_allowed(true);
|
||
|
}
|
||
|
|
||
|
/** @var CDocument $document */
|
||
|
$document = $documentRepo->findOneBy(['cId' => $courseId, 'iid' => $id]);
|
||
|
|
||
|
if (empty($document)) {
|
||
|
// Try with normal id
|
||
|
/** @var CDocument $document */
|
||
|
$document = $documentRepo->findOneBy(['cId' => $courseId, 'id' => $id]);
|
||
|
|
||
|
if (empty($document)) {
|
||
5 years ago
|
Display::return_message(get_lang('The file was not found'), 'error');
|
||
7 years ago
|
exit;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$documentPathInfo = pathinfo($document->getPath());
|
||
|
$coursePath = api_get_path(SYS_COURSE_PATH).$courseInfo['directory'];
|
||
|
$documentPath = '/document'.$document->getPath();
|
||
|
$documentText = file_get_contents($coursePath.$documentPath);
|
||
|
$documentText = api_remove_tags_with_space($documentText);
|
||
|
|
||
7 years ago
|
$wordsInfo = preg_split('/ |\n/', $documentText, -1, PREG_SPLIT_OFFSET_CAPTURE);
|
||
|
$words = [];
|
||
|
|
||
|
foreach ($wordsInfo as $wordInfo) {
|
||
|
$words[$wordInfo[1]] = nl2br($wordInfo[0]);
|
||
|
}
|
||
7 years ago
|
|
||
|
$htmlHeadXtra[] = '<script>
|
||
|
var words = '.json_encode($words, JSON_OBJECT_AS_ARRAY).',
|
||
|
wordsCount = '.count($words).'
|
||
|
</script>';
|
||
6 years ago
|
$htmlHeadXtra[] = api_get_js('readout_text/js/start.js');
|
||
|
$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_JS_PATH).'readout_text/css/start.css');
|
||
7 years ago
|
|
||
|
$template = new Template(strip_tags($document->getTitle()));
|
||
|
$template->display_blank_template();
|