Fix queries, use url() in twig, use Resources + format code

pull/3741/head
Julio Montoya 5 years ago
parent 15a1589024
commit 172c97a4d8
  1. 77
      public/main/gradebook/lib/be/surveylink.class.php
  2. 2
      public/main/lp/lp_subscribe_users_to_category.php
  3. 2
      public/main/lp/scorm.class.php
  4. 15
      public/main/mySpace/lp_tracking.php
  5. 2
      src/CoreBundle/Resources/views/LearnPath/report.html.twig
  6. 3
      src/CourseBundle/Entity/CLpItemView.php

@ -2,6 +2,8 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
/**
* Gradebook link to a survey item.
*
@ -10,7 +12,8 @@
class SurveyLink extends AbstractLink
{
private $survey_table;
private $survey_data = [];
/** @var \Chamilo\CourseBundle\Entity\CSurvey */
private $survey_data;
/**
* Constructor.
@ -28,7 +31,7 @@ class SurveyLink extends AbstractLink
{
$this->get_survey_data();
return $this->survey_data['code'].': '.self::html_to_text($this->survey_data['title']);
return $this->survey_data->getCode().': '.self::html_to_text($this->survey_data->getTitle());
}
/**
@ -38,7 +41,7 @@ class SurveyLink extends AbstractLink
{
$this->get_survey_data();
return $this->survey_data['subtitle'];
return $this->survey_data->getSubtitle();
}
/**
@ -79,24 +82,28 @@ class SurveyLink extends AbstractLink
if (empty($this->course_code)) {
exit('Error in get_all_links() : course code not set');
}
$tbl_survey = $this->get_survey_table();
$sessionId = $this->get_session_id();
$course_id = $this->getCourseId();
$sql = 'SELECT survey_id, title, code FROM '.$tbl_survey.'
WHERE c_id = '.$course_id.' AND session_id = '.$sessionId;
$result = Database::query($sql);
while ($data = Database::fetch_array($result)) {
$repo = Container::getSurveyRepository();
$course = api_get_course_entity($course_id);
$session = !empty($sessionId) ? api_get_session_entity($sessionId) : null;
$qb = $repo->getResourcesByCourse($course, $session);
$surveys = $qb->getQuery()->getResult();
$links = [];
/** @var \Chamilo\CourseBundle\Entity\CSurvey $survey */
foreach ($surveys as $survey) {
$links[] = [
$data['survey_id'],
$survey->getIid(),
api_trunc_str(
$data['code'].': '.self::html_to_text($data['title']),
$survey->getCode().': '.self::html_to_text($survey->getTitle()),
80
),
];
}
return isset($links) ? $links : [];
return $links;
}
/**
@ -114,11 +121,12 @@ class SurveyLink extends AbstractLink
$sql = "SELECT
COUNT(i.answered)
FROM $tbl_survey AS s
JOIN $tbl_survey_invitation AS i ON s.code = i.survey_code
INNER JOIN $tbl_survey_invitation AS i
ON s.code = i.survey_code
WHERE
s.c_id = $courseId AND
i.c_id = $courseId AND
s.survey_id = $ref_id AND
s.iid = $ref_id AND
i.session_id = $sessionId";
$sql_result = Database::query($sql);
@ -154,7 +162,7 @@ class SurveyLink extends AbstractLink
WHERE
s.c_id = $courseId AND
i.c_id = $courseId AND
s.survey_id = $ref_id AND
s.iid = $ref_id AND
i.session_id = $sessionId
";
@ -214,10 +222,10 @@ class SurveyLink extends AbstractLink
$sessionId = $this->get_session_id();
$courseId = $this->getCourseId();
$sql = 'SELECT count(survey_id) FROM '.$this->get_survey_table().'
$sql = 'SELECT count(iid) FROM '.$this->get_survey_table().'
WHERE
c_id = '.$courseId.' AND
survey_id = '.$this->get_ref_id().' AND
iid = '.$this->get_ref_id().' AND
session_id = '.$sessionId;
$result = Database::query($sql);
$number = Database::fetch_row($result);
@ -233,22 +241,14 @@ class SurveyLink extends AbstractLink
if (api_is_allowed_to_edit()) {
// Let students make access only through "Surveys" tool.
$tbl_name = $this->get_survey_table();
$sessionId = $this->get_session_id();
$courseId = $this->getCourseId();
$survey = $this->get_survey_data();
if ($survey) {
$survey_id = $survey->getIid();
if ('' != $tbl_name) {
$sql = 'SELECT survey_id
FROM '.$this->get_survey_table().'
WHERE
c_id = '.$courseId.' AND
survey_id = '.$this->get_ref_id().' AND
session_id = '.$sessionId;
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
$survey_id = $row['survey_id'];
return api_get_path(WEB_PATH).'main/survey/reporting.php?'.api_get_cidreq_params($this->getCourseId(), $sessionId).'&survey_id='.$survey_id;
return api_get_path(WEB_CODE_PATH).'survey/reporting.php?'.
api_get_cidreq_params($this->getCourseId(), $sessionId).'&survey_id='.$survey_id;
}
}
@ -278,25 +278,16 @@ class SurveyLink extends AbstractLink
/**
* Get the survey data from the c_survey table with the current object id.
*
* @return mixed
* @return \Chamilo\CourseBundle\Entity\CSurvey
*/
private function get_survey_data()
{
$tbl_name = $this->get_survey_table();
if ('' == $tbl_name) {
return false;
} elseif (empty($this->survey_data)) {
if (empty($this->survey_data)) {
$courseId = $this->getCourseId();
$sessionId = $this->get_session_id();
$sql = 'SELECT * FROM '.$tbl_name.'
WHERE
c_id = '.$courseId.' AND
survey_id = '.$this->get_ref_id().' AND
session_id = '.$sessionId;
$query = Database::query($sql);
$this->survey_data = Database::fetch_array($query);
$repo = Container::getSurveyRepository();
$survey = $repo->find($this->get_ref_id());
$this->survey_data = $survey;
}
return $this->survey_data;

@ -207,7 +207,7 @@ if ($allowUserGroups) {
$sessionCondition
";
Database::query($sql);
$em->merge($category);
$em->persist($category);
$em->flush();
}
header("Location: $url");

@ -319,7 +319,7 @@ class scorm extends learnpath
* @param int $userMaxScore
* @param int $sessionId
*
* @return bool Returns -1 on error
* @return null|CLp
*/
public function import_manifest($courseCode, $userMaxScore = 1, $sessionId = 0)
{

@ -13,7 +13,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$cidReset = true;
$from_myspace = false;
$from_link = '';
if (isset($_GET['from']) && 'myspace' == $_GET['from']) {
if (isset($_GET['from']) && 'myspace' === $_GET['from']) {
$from_link = '&from=myspace';
$this_section = SECTION_TRACKING;
} else {
@ -21,7 +21,7 @@ if (isset($_GET['from']) && 'myspace' == $_GET['from']) {
}
$session_id = isset($_REQUEST['id_session']) ? (int) $_REQUEST['id_session'] : api_get_session_id();
$export_csv = isset($_GET['export']) && 'csv' == $_GET['export'];
$export_csv = isset($_GET['export']) && 'csv' === $_GET['export'];
$user_id = isset($_GET['student_id']) ? (int) $_GET['student_id'] : api_get_user_id();
$courseCode = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : api_get_course_id();
$origin = api_get_origin();
@ -72,14 +72,13 @@ $interbreadcrumb[] = [
'name' => get_lang('Learner details in course'),
];
$nameTools = get_lang('Learnpath details');
$sql = 'SELECT name FROM '.Database::get_course_table(TABLE_LP_MAIN).'
WHERE c_id = '.$courseInfo['real_id'].' AND id='.$lp_id;
$rs = Database::query($sql);
$lp_title = Database::result($rs, 0, 0);
$lpRepo = \Chamilo\CoreBundle\Framework\Container::getLpRepository();
/** @var \Chamilo\CourseBundle\Entity\CLp $lp */
$lp = $lpRepo->find($lp_id);
$lp_title = $lp->getName();
$origin = 'tracking';
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$action = $_REQUEST['action'] ?? '';
switch ($action) {
case 'export_stats':
if (!api_is_allowed_to_edit(false, false, true)) {

@ -91,7 +91,7 @@
var newTD = $('<td>', {
colspan: 7
});
newTD.load('{{ _p.web_main ~ 'mySpace/lp_tracking.php?action=stats&extend_all=0&id_session=' ~ session_id ~ '&course=' ~ course_code ~ '&lp_id=' ~ lp_id ~ '&student_id=\' + userId + \'&origin=tracking_course&allow_extend=0' }} .table-responsive', function () {
newTD.load('{{ url('legacy_main', {name: 'mySpace/lp_tracking.php'}) ~ '?action=stats&extend_all=0&sid=' ~ session_id ~ '&course=' ~ course_code ~ '&lp_id=' ~ lp_id ~ '&student_id=\' + userId + \'&origin=tracking_course&allow_extend=0' }} .table-responsive', function () {
newTD.insertAfter(trHead);
});
trDetail.removeClass('hide');

@ -126,9 +126,6 @@ class CLpItemView
$this->coreExit = 'none';
}
/**
* @return int
*/
public function getIid(): int
{
return $this->iid;

Loading…
Cancel
Save