Internal: Fix queries, use iid instead of id

pull/3466/head
Julio Montoya 4 years ago
parent 1d8cb8fe80
commit 5c080a9113
  1. 11
      public/main/exercise/question.class.php
  2. 5
      public/main/forum/forumfunction.inc.php
  3. 4
      public/main/gradebook/gradebook_add_link.php
  4. 10
      public/main/gradebook/gradebook_edit_link.php
  5. 27
      public/main/gradebook/gradebook_flatview.php
  6. 1
      public/main/gradebook/gradebook_view_result.php
  7. 2
      public/main/gradebook/index.php
  8. 10
      public/main/gradebook/lib/GradebookUtils.php
  9. 19
      public/main/gradebook/lib/be/attendancelink.class.php
  10. 4
      public/main/gradebook/lib/be/exerciselink.class.php
  11. 18
      public/main/gradebook/lib/be/forumthreadlink.class.php
  12. 6
      public/main/gradebook/lib/be/learnpathlink.class.php
  13. 4
      public/main/gradebook/lib/be/result.class.php
  14. 2
      public/main/gradebook/lib/be/studentpublicationlink.class.php
  15. 31
      public/main/inc/lib/AnnouncementManager.php
  16. 9
      public/main/inc/lib/api.lib.php
  17. 14
      public/main/inc/lib/document.lib.php
  18. 7
      public/main/inc/lib/usermanager.lib.php
  19. 4
      src/CoreBundle/Entity/AbstractResource.php
  20. 6
      src/CoreBundle/Entity/GradebookCategory.php
  21. 3
      src/CoreBundle/Resources/config/services.yml

@ -581,6 +581,7 @@ abstract class Question
$current_position = Database::result($result, 0, 0); $current_position = Database::result($result, 0, 0);
$this->updatePosition($current_position + 1); $this->updatePosition($current_position + 1);
$position = $this->position; $position = $this->position;
$exerciseEntity = $exerciseRepo->find($exerciseId);
$question = new CQuizQuestion(); $question = new CQuizQuestion();
$question $question
@ -593,15 +594,13 @@ abstract class Question
->setExtra($this->extra) ->setExtra($this->extra)
->setLevel($this->level) ->setLevel($this->level)
->setFeedback($this->feedback) ->setFeedback($this->feedback)
; ->setParent($exerciseEntity)
->addCourseLink(
$exerciseEntity = $exerciseRepo->find($exerciseId);
$question->setParent($exerciseEntity);
$question->addCourseLink(
api_get_course_entity(), api_get_course_entity(),
api_get_session_entity(), api_get_session_entity(),
api_get_group_entity() api_get_group_entity()
); )
;
$em->persist($question); $em->persist($question);
$em->flush(); $em->flush();

@ -952,8 +952,9 @@ function store_forum($values, $courseInfo = [], $returnId = false)
if ($image_moved) { if ($image_moved) {
$new_file_name = isset($new_file_name) ? $new_file_name : ''; $new_file_name = isset($new_file_name) ? $new_file_name : '';
} }
$forum->setParent($course); $forum
$forum->addCourseLink($course, $session); ->setParent($course)
->addCourseLink($course, $session);
$repo->getEntityManager()->persist($forum); $repo->getEntityManager()->persist($forum);
$repo->getEntityManager()->flush(); $repo->getEntityManager()->flush();

@ -102,7 +102,7 @@ if (isset($typeSelected) && '0' != $typeSelected) {
$sql1 = 'SELECT thread_title from '.$tbl_forum_thread.' $sql1 = 'SELECT thread_title from '.$tbl_forum_thread.'
WHERE WHERE
c_id = '.$course_info['real_id'].' AND c_id = '.$course_info['real_id'].' AND
thread_id = '.$addvalues['select_link']; iid = '.$addvalues['select_link'];
$res1 = Database::query($sql1); $res1 = Database::query($sql1);
$rowtit = Database::fetch_row($res1); $rowtit = Database::fetch_row($res1);
$course_id = api_get_course_id(); $course_id = api_get_course_id();
@ -120,7 +120,7 @@ if (isset($typeSelected) && '0' != $typeSelected) {
thread_weight= "'.api_float_val($addvalues['weight']).'", thread_weight= "'.api_float_val($addvalues['weight']).'",
thread_title_qualify = "'.$rowtit[0].'" thread_title_qualify = "'.$rowtit[0].'"
WHERE WHERE
thread_id='.$addvalues['select_link'].' AND iid ='.$addvalues['select_link'].' AND
c_id = '.$course_info['real_id'].' '; c_id = '.$course_info['real_id'].' ';
Database::query($sql); Database::query($sql);
} }

@ -73,11 +73,11 @@ if ($form->validate()) {
} }
//Update weight into forum thread //Update weight into forum thread
$sql = 'UPDATE '.$tbl_forum_thread.' SET $sql = 'UPDATE '.$tbl_forum_thread.' SET
thread_weight = '.api_float_val($final_weight).' thread_weight = '.api_float_val($final_weight).'
WHERE WHERE
c_id = '.$course_id.' AND c_id = '.$course_id.' AND
thread_id = ( iid = (
SELECT ref_id FROM '.$tbl_grade_links.' SELECT ref_id FROM '.$tbl_grade_links.'
WHERE id='.intval($_GET['editlink']).' AND type = 5 WHERE id='.intval($_GET['editlink']).' AND type = 5
)'; )';
@ -89,7 +89,7 @@ if ($form->validate()) {
UPDATE ChamiloCourseBundle:CStudentPublication w UPDATE ChamiloCourseBundle:CStudentPublication w
SET w.weight = :final_weight SET w.weight = :final_weight
WHERE w.cId = :course WHERE w.cId = :course
AND w.id = ( AND w.iid = (
SELECT l.refId FROM ChamiloCoreBundle:GradebookLink l SELECT l.refId FROM ChamiloCoreBundle:GradebookLink l
WHERE l.id = :link AND l.type = :type WHERE l.id = :link AND l.type = :type
) )

@ -269,24 +269,17 @@ if (isset($_GET['exportpdf'])) {
} else { } else {
Display::display_header(get_lang('List View')); Display::display_header(get_lang('List View'));
} }
if (isset($_GET['isStudentView']) && 'false' === $_GET['isStudentView']) { $studentView = api_is_student_view_active();
DisplayGradebook::display_header_reduce_flatview(
$cat[0], DisplayGradebook::display_header_reduce_flatview(
$showeval, $cat[0],
$showlink, $showeval,
$simple_search_form $showlink,
); $simple_search_form
$flatViewTable->display(); );
} elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] === 'teacherview')) { $flatViewTable->display();
DisplayGradebook::display_header_reduce_flatview(
$cat[0],
$showeval,
$showlink,
$simple_search_form
);
// Table if (false === $studentView) {
$flatViewTable->display();
//@todo load images with jquery //@todo load images with jquery
echo '<div id="contentArea" style="text-align: center;" >'; echo '<div id="contentArea" style="text-align: center;" >';
$flatViewTable->display_graph_by_resource(); $flatViewTable->display_graph_by_resource();

@ -2,7 +2,6 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
require_once __DIR__.'/../inc/global.inc.php'; require_once __DIR__.'/../inc/global.inc.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/fe/exportgradebook.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/fe/exportgradebook.php';

@ -457,7 +457,7 @@ if (isset($_GET['deletelink'])) {
thread_qualify_max = 0, thread_qualify_max = 0,
thread_weight = 0, thread_weight = 0,
thread_title_qualify = "" thread_title_qualify = ""
WHERE c_id = '.$course_id.' AND thread_id = ( WHERE c_id = '.$course_id.' AND iid = (
SELECT ref_id FROM '.$tbl_grade_links.' SELECT ref_id FROM '.$tbl_grade_links.'
WHERE id='.$get_delete_link.' AND type = '.LINK_FORUM_THREAD.' WHERE id='.$get_delete_link.' AND type = '.LINK_FORUM_THREAD.'
)'; )';

@ -744,17 +744,17 @@ class GradebookUtils
{ {
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$table_user = Database::get_main_table(TABLE_MAIN_USER); $table_user = Database::get_main_table(TABLE_MAIN_USER);
$sql = 'SELECT DISTINCT u.user_id, u.lastname, u.firstname, u.username, gc.created_at $sql = 'SELECT DISTINCT u.id as user_id, u.lastname, u.firstname, u.username, gc.created_at
FROM '.$table_user.' u FROM '.$table_user.' u
INNER JOIN '.$table_certificate.' gc INNER JOIN '.$table_certificate.' gc
ON u.user_id=gc.user_id '; ON u.id = gc.user_id ';
if (!is_null($cat_id) && $cat_id > 0) { if (!is_null($cat_id) && $cat_id > 0) {
$sql .= ' WHERE cat_id='.intval($cat_id); $sql .= ' WHERE cat_id='.intval($cat_id);
} }
if (!empty($userList)) { if (!empty($userList)) {
$userList = array_map('intval', $userList); $userList = array_map('intval', $userList);
$userListCondition = implode("','", $userList); $userListCondition = implode("','", $userList);
$sql .= " AND u.user_id IN ('$userListCondition')"; $sql .= " AND u.id IN ('$userListCondition')";
} }
$sql .= ' ORDER BY '.(api_sort_by_first_name() ? 'u.firstname' : 'u.lastname'); $sql .= ' ORDER BY '.(api_sort_by_first_name() ? 'u.firstname' : 'u.lastname');
$rs = Database::query($sql); $rs = Database::query($sql);
@ -1355,7 +1355,7 @@ class GradebookUtils
thread_weight = '.api_float_val($weight).' thread_weight = '.api_float_val($weight).'
WHERE WHERE
c_id = '.$course_id.' AND c_id = '.$course_id.' AND
thread_id = ( iid = (
SELECT ref_id FROM '.$table_link.' SELECT ref_id FROM '.$table_link.'
WHERE id='.$linkId.' AND type='.LINK_FORUM_THREAD.' WHERE id='.$linkId.' AND type='.LINK_FORUM_THREAD.'
) )
@ -1367,7 +1367,7 @@ class GradebookUtils
UPDATE ChamiloCourseBundle:CStudentPublication w UPDATE ChamiloCourseBundle:CStudentPublication w
SET w.weight = :final_weight SET w.weight = :final_weight
WHERE w.cId = :course WHERE w.cId = :course
AND w.id = ( AND w.iid = (
SELECT l.refId FROM ChamiloCoreBundle:GradebookLink l SELECT l.refId FROM ChamiloCoreBundle:GradebookLink l
WHERE l.id = :link AND l.type = :type WHERE l.id = :link AND l.type = :type
) )

@ -49,7 +49,7 @@ class AttendanceLink extends AbstractLink
$tbl_attendance = $this->get_attendance_table(); $tbl_attendance = $this->get_attendance_table();
$sessionId = $this->get_session_id(); $sessionId = $this->get_session_id();
$sql = 'SELECT att.id, att.name, att.attendance_qualify_title $sql = 'SELECT att.iid, att.name, att.attendance_qualify_title
FROM '.$tbl_attendance.' att FROM '.$tbl_attendance.' att
WHERE WHERE
att.c_id = '.$this->course_id.' AND att.c_id = '.$this->course_id.' AND
@ -60,14 +60,13 @@ class AttendanceLink extends AbstractLink
while ($data = Database::fetch_array($result)) { while ($data = Database::fetch_array($result)) {
if (isset($data['attendance_qualify_title']) && '' != $data['attendance_qualify_title']) { if (isset($data['attendance_qualify_title']) && '' != $data['attendance_qualify_title']) {
$cats[] = [$data['id'], $data['attendance_qualify_title']]; $cats[] = [$data['iid'], $data['attendance_qualify_title']];
} else { } else {
$cats[] = [$data['id'], $data['name']]; $cats[] = [$data['iid'], $data['name']];
} }
} }
$my_cats = isset($cats) ? $cats : [];
return $my_cats; return isset($cats) ? $cats : [];
} }
/** /**
@ -104,7 +103,7 @@ class AttendanceLink extends AbstractLink
FROM '.$this->get_attendance_table().' att FROM '.$this->get_attendance_table().' att
WHERE WHERE
att.c_id = '.$this->course_id.' AND att.c_id = '.$this->course_id.' AND
att.id = '.$this->get_ref_id().' AND att.iid = '.$this->get_ref_id().' AND
att.session_id = '.$sessionId; att.session_id = '.$sessionId;
$query = Database::query($sql); $query = Database::query($sql);
$attendance = Database::fetch_array($query, 'ASSOC'); $attendance = Database::fetch_array($query, 'ASSOC');
@ -216,8 +215,8 @@ class AttendanceLink extends AbstractLink
*/ */
public function is_valid_link() public function is_valid_link()
{ {
$sql = 'SELECT count(att.id) FROM '.$this->get_attendance_table().' att $sql = 'SELECT count(att.iid) FROM '.$this->get_attendance_table().' att
WHERE att.c_id = '.$this->course_id.' AND att.id = '.$this->get_ref_id(); WHERE att.c_id = '.$this->course_id.' AND att.iid = '.$this->get_ref_id();
$result = Database::query($sql); $result = Database::query($sql);
$number = Database::fetch_row($result); $number = Database::fetch_row($result);
@ -229,7 +228,7 @@ class AttendanceLink extends AbstractLink
// it was extracts the attendance id // it was extracts the attendance id
$sessionId = $this->get_session_id(); $sessionId = $this->get_session_id();
$sql = 'SELECT * FROM '.$this->get_attendance_table().' att $sql = 'SELECT * FROM '.$this->get_attendance_table().' att
WHERE att.c_id = '.$this->course_id.' AND att.id = '.$this->get_ref_id(); WHERE att.c_id = '.$this->course_id.' AND att.iid = '.$this->get_ref_id();
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC'); $row = Database::fetch_array($result, 'ASSOC');
$attendance_id = $row['id']; $attendance_id = $row['id'];
@ -266,7 +265,7 @@ class AttendanceLink extends AbstractLink
return false; return false;
} elseif (!isset($this->attendance_data)) { } elseif (!isset($this->attendance_data)) {
$sql = 'SELECT * FROM '.$this->get_attendance_table().' att $sql = 'SELECT * FROM '.$this->get_attendance_table().' att
WHERE att.c_id = '.$this->course_id.' AND att.id = '.$this->get_ref_id(); WHERE att.c_id = '.$this->course_id.' AND att.iid = '.$this->get_ref_id();
$query = Database::query($sql); $query = Database::query($sql);
$this->attendance_data = Database::fetch_array($query); $this->attendance_data = Database::fetch_array($query);
} }

@ -60,7 +60,7 @@ class ExerciseLink extends AbstractLink
$sqlLp = "SELECT e.iid, e.title $sqlLp = "SELECT e.iid, e.title
FROM $exerciseTable e FROM $exerciseTable e
INNER JOIN $lpItemTable i INNER JOIN $lpItemTable i
ON (e.c_id = i.c_id AND e.id = i.path) ON (e.c_id = i.c_id AND e.iid = i.path)
WHERE WHERE
e.c_id = $this->course_id AND e.c_id = $this->course_id AND
active = 0 AND active = 0 AND
@ -253,7 +253,7 @@ class ExerciseLink extends AbstractLink
ON (hp.exe_name = doc.path AND doc.c_id = hp.c_id) ON (hp.exe_name = doc.path AND doc.c_id = hp.c_id)
WHERE WHERE
hp.c_id = $courseId AND hp.c_id = $courseId AND
doc.id = $exerciseId"; doc.iid = $exerciseId";
if (!empty($stud_id)) { if (!empty($stud_id)) {
$sql .= " AND hp.exe_user_id = $stud_id "; $sql .= " AND hp.exe_user_id = $stud_id ";

@ -58,7 +58,7 @@ class ForumThreadLink extends AbstractLink
$session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)';
} }
$sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify $sql = 'SELECT tl.iid as thread_id, tl.thread_title, tl.thread_title_qualify
FROM '.$tbl_grade_links.' tl FROM '.$tbl_grade_links.' tl
WHERE WHERE
tl.c_id = '.$this->course_id.' AND tl.c_id = '.$this->course_id.' AND
@ -90,7 +90,7 @@ class ForumThreadLink extends AbstractLink
$sql = "SELECT count(*) AS number FROM $table $sql = "SELECT count(*) AS number FROM $table
WHERE WHERE
c_id = ".$this->course_id." AND c_id = ".$this->course_id." AND
thread_id = '".$this->get_ref_id()."' iid = '".$this->get_ref_id()."'
"; ";
$result = Database::query($sql); $result = Database::query($sql);
$number = Database::fetch_row($result); $number = Database::fetch_row($result);
@ -121,7 +121,7 @@ class ForumThreadLink extends AbstractLink
FROM '.Database::get_course_table(TABLE_FORUM_THREAD)." FROM '.Database::get_course_table(TABLE_FORUM_THREAD)."
WHERE WHERE
c_id = ".$this->course_id." AND c_id = ".$this->course_id." AND
thread_id = '".$this->get_ref_id()."' iid = '".$this->get_ref_id()."'
$sessionCondition $sessionCondition
"; ";
$query = Database::query($sql); $query = Database::query($sql);
@ -130,7 +130,7 @@ class ForumThreadLink extends AbstractLink
$sql = "SELECT * FROM $thread_qualify $sql = "SELECT * FROM $thread_qualify
WHERE WHERE
c_id = ".$this->course_id." AND c_id = ".$this->course_id." AND
thread_id = ".$this->get_ref_id()." iid = ".$this->get_ref_id()."
$sessionCondition $sessionCondition
"; ";
if (isset($stud_id)) { if (isset($stud_id)) {
@ -264,7 +264,7 @@ class ForumThreadLink extends AbstractLink
$sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().'
WHERE WHERE
c_id = '.$this->course_id.' AND c_id = '.$this->course_id.' AND
thread_id = '.$this->get_ref_id().' AND iid = '.$this->get_ref_id().' AND
session_id='.$sessionId; session_id='.$sessionId;
$result = Database::query($sql); $result = Database::query($sql);
$number = Database::fetch_row($result); $number = Database::fetch_row($result);
@ -279,7 +279,7 @@ class ForumThreadLink extends AbstractLink
$sql = 'SELECT * FROM '.$this->get_forum_thread_table()." $sql = 'SELECT * FROM '.$this->get_forum_thread_table()."
WHERE WHERE
c_id = '.$this->course_id.' AND c_id = '.$this->course_id.' AND
thread_id = '".$this->get_ref_id()."' AND iid = '".$this->get_ref_id()."' AND
session_id = $sessionId "; session_id = $sessionId ";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC'); $row = Database::fetch_array($result, 'ASSOC');
@ -303,7 +303,7 @@ class ForumThreadLink extends AbstractLink
if (!empty($ref_id)) { if (!empty($ref_id)) {
$sql = 'UPDATE '.$this->get_forum_thread_table().' SET $sql = 'UPDATE '.$this->get_forum_thread_table().' SET
thread_weight='.api_float_val($weight).' thread_weight='.api_float_val($weight).'
WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; WHERE c_id = '.$this->course_id.' AND iid = '.$ref_id;
Database::query($sql); Database::query($sql);
} }
} }
@ -317,7 +317,7 @@ class ForumThreadLink extends AbstractLink
thread_qualify_max = 0, thread_qualify_max = 0,
thread_weight = 0, thread_weight = 0,
thread_title_qualify = "" thread_title_qualify = ""
WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; WHERE c_id = '.$this->course_id.' AND iid = '.$ref_id;
Database::query($sql); Database::query($sql);
} }
} }
@ -343,7 +343,7 @@ class ForumThreadLink extends AbstractLink
$sql = 'SELECT * FROM '.$this->get_forum_thread_table().' $sql = 'SELECT * FROM '.$this->get_forum_thread_table().'
WHERE WHERE
c_id = '.$this->course_id.' AND c_id = '.$this->course_id.' AND
thread_id = '.$this->get_ref_id().' AND iid = '.$this->get_ref_id().' AND
'.$session_condition; '.$session_condition;
$query = Database::query($sql); $query = Database::query($sql);
$this->exercise_data = Database::fetch_array($query); $this->exercise_data = Database::fetch_array($query);

@ -40,7 +40,7 @@ class LearnpathLink extends AbstractLink
$session_condition = api_get_session_condition($session_id, true, true); $session_condition = api_get_session_condition($session_id, true, true);
} }
$sql = 'SELECT id, name FROM '.$this->get_learnpath_table().' $sql = 'SELECT iid, name FROM '.$this->get_learnpath_table().'
WHERE c_id = '.$this->course_id.' '.$session_condition.' '; WHERE c_id = '.$this->course_id.' '.$session_condition.' ';
$result = Database::query($sql); $result = Database::query($sql);
@ -192,7 +192,7 @@ class LearnpathLink extends AbstractLink
*/ */
public function is_valid_link() public function is_valid_link()
{ {
$sql = 'SELECT count(id) FROM '.$this->get_learnpath_table().' $sql = 'SELECT count(iid) FROM '.$this->get_learnpath_table().'
WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' ';
$result = Database::query($sql); $result = Database::query($sql);
$number = Database::fetch_row($result, 'NUM'); $number = Database::fetch_row($result, 'NUM');
@ -247,7 +247,7 @@ class LearnpathLink extends AbstractLink
{ {
if (!isset($this->learnpath_data)) { if (!isset($this->learnpath_data)) {
$sql = 'SELECT * FROM '.$this->get_learnpath_table().' $sql = 'SELECT * FROM '.$this->get_learnpath_table().'
WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' '; WHERE c_id = '.$this->course_id.' AND iid = '.$this->get_ref_id().' ';
$result = Database::query($sql); $result = Database::query($sql);
$this->learnpath_data = Database::fetch_array($result); $this->learnpath_data = Database::fetch_array($result);
} }

@ -150,10 +150,10 @@ class Result
$sql = "SELECT lastname, gr.id, gr.user_id, gr.evaluation_id, gr.created_at, gr.score $sql = "SELECT lastname, gr.id, gr.user_id, gr.evaluation_id, gr.created_at, gr.score
FROM $tbl_grade_results gr FROM $tbl_grade_results gr
INNER JOIN $tbl_user u INNER JOIN $tbl_user u
ON gr.user_id = u.user_id "; ON gr.user_id = u.id ";
if (!empty($userIdList)) { if (!empty($userIdList)) {
$sql .= " AND u.user_id IN ('$userIdListToString')"; $sql .= " AND u.id IN ('$userIdListToString')";
} }
$paramcount = 0; $paramcount = 0;

@ -216,7 +216,7 @@ class StudentPublicationLink extends AbstractLink
case 'first': case 'first':
default: default:
// first attempt // first attempt
$dql .= ' ORDER BY a.id'; $dql .= ' ORDER BY a.iid';
break; break;
} }

@ -483,6 +483,8 @@ class AnnouncementManager
$html .= "<table height=\"100\" width=\"100%\" cellpadding=\"5\" cellspacing=\"0\" class=\"data_table\">"; $html .= "<table height=\"100\" width=\"100%\" cellpadding=\"5\" cellspacing=\"0\" class=\"data_table\">";
$html .= "<tr><td><h2>".$title."</h2></td></tr>"; $html .= "<tr><td><h2>".$title."</h2></td></tr>";
$isVisible = $announcement->isVisible($course, $session);
if (api_is_allowed_to_edit(false, true) || if (api_is_allowed_to_edit(false, true) ||
(api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())
) { ) {
@ -492,7 +494,7 @@ class AnnouncementManager
$image_visibility = 'invisible'; $image_visibility = 'invisible';
$alt_visibility = get_lang('Visible'); $alt_visibility = get_lang('Visible');
$setNewStatus = 'visible'; $setNewStatus = 'visible';
if ($announcement->isVisible($course, $session)) { if ($isVisible) {
$image_visibility = 'visible'; $image_visibility = 'visible';
$alt_visibility = get_lang('Hide'); $alt_visibility = get_lang('Hide');
$setNewStatus = 'invisible'; $setNewStatus = 'invisible';
@ -507,6 +509,10 @@ class AnnouncementManager
"</a>"; "</a>";
} }
$html .= "<tr><th style='text-align:right'>$modify_icons</th></tr>"; $html .= "<tr><th style='text-align:right'>$modify_icons</th></tr>";
} else {
if (false === $isVisible) {
api_not_allowed(true);
}
} }
// The user id is always the current one. // The user id is always the current one.
@ -647,25 +653,22 @@ class AnnouncementManager
$session = api_get_session_entity($sessionId); $session = api_get_session_entity($sessionId);
$group = api_get_group_entity(); $group = api_get_group_entity();
$em = Database::getManager();
$announcement = new CAnnouncement(); $announcement = new CAnnouncement();
$announcement $announcement
->setContent($newContent) ->setContent($newContent)
->setTitle($title) ->setTitle($title)
->setEndDate(new DateTime($end_date)) ->setEndDate(new DateTime($end_date))
->setDisplayOrder($order) ->setDisplayOrder($order)
; ->setParent($course)
$announcement
->addCourseLink( ->addCourseLink(
$course, $course,
$session, $session,
$group $group
) )
->setParent($course)
; ;
$em = Database::getManager();
$em->persist($announcement); $em->persist($announcement);
$em->flush(); $em->flush();
$last_id = $announcement->getIid(); $last_id = $announcement->getIid();
@ -2074,9 +2077,6 @@ class AnnouncementManager
{ {
// Maximum title messages to display // Maximum title messages to display
$maximum = '12'; $maximum = '12';
// Database Table Definitions
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
@ -2124,18 +2124,19 @@ class AnnouncementManager
$qb = $repo->getResourcesByCourse($course, $session, $group); $qb = $repo->getResourcesByCourse($course, $session, $group);
$qb->select('count(resource)'); $qb->select('count(resource)');
$count = $qb->getQuery()->getSingleScalarResult(); return $qb->getQuery()->getSingleScalarResult();
return $count;
} }
} else { } else {
$user = api_get_user_entity($userId); $user = api_get_user_entity($userId);
if (null === $user) {
return 0;
}
$qb = $repo->getResourcesByCourseLinkedToUser($user, $course, $session, $group); $qb = $repo->getResourcesByCourseLinkedToUser($user, $course, $session, $group);
$qb->select('count(resource)'); $qb->select('count(resource)');
$count = $qb->getQuery()->getSingleScalarResult();
return $count; return $qb->getQuery()->getSingleScalarResult();
// students only get to see the visible announcements // students only get to see the visible announcements
if (empty($_GET['origin']) || 'learnpath' !== $_GET['origin']) { if (empty($_GET['origin']) || 'learnpath' !== $_GET['origin']) {

@ -2221,13 +2221,8 @@ function api_get_course_info($course_code = null)
{ {
if (!empty($course_code)) { if (!empty($course_code)) {
$course = Container::getCourseRepository()->findOneByCode($course_code); $course = Container::getCourseRepository()->findOneByCode($course_code);
if (empty($course)) {
return [];
}
$courseInfo = api_format_course_array($course);
return $courseInfo; return api_format_course_array($course);
} }
/*$course_code = Database::escape_string($course_code); /*$course_code = Database::escape_string($course_code);
@ -2358,7 +2353,7 @@ function api_get_course_info_by_id($id = 0)
* *
* @todo eradicate the false "id"=code field of the $_course array and use the int id * @todo eradicate the false "id"=code field of the $_course array and use the int id
*/ */
function api_format_course_array(Course $course) function api_format_course_array(Course $course = null)
{ {
if (empty($course)) { if (empty($course)) {
return []; return [];

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\ResourceFile; use Chamilo\CoreBundle\Entity\ResourceFile;
@ -1609,16 +1610,17 @@ class DocumentManager
$my_content_html = null; $my_content_html = null;
if ($document_id) { if ($document_id) {
$sql = "SELECT path FROM $tbl_document $sql = "SELECT path FROM $tbl_document
WHERE c_id = $course_id AND id = $document_id"; WHERE c_id = $course_id AND iid = $document_id";
$rs = Database::query($sql); $rs = Database::query($sql);
$new_content = ''; $new_content = '';
$all_user_info = []; $all_user_info = [];
if (Database::num_rows($rs)) { if (Database::num_rows($rs)) {
$row = Database::fetch_array($rs); $row = Database::fetch_array($rs);
$filepath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$row['path']; /*$filepath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'.$row['path'];
if (is_file($filepath)) { if (is_file($filepath)) {
$my_content_html = file_get_contents($filepath); $my_content_html = file_get_contents($filepath);
} }*/
$my_content_html = '';
$all_user_info = self::get_all_info_to_certificate( $all_user_info = self::get_all_info_to_certificate(
$user_id, $user_id,
$courseInfo, $courseInfo,
@ -1652,12 +1654,12 @@ class DocumentManager
* *
* @return array * @return array
*/ */
public static function get_all_info_to_certificate($user_id, $course_id, $sessionId, $is_preview = false) public static function get_all_info_to_certificate($user_id, $course_info, $sessionId, $is_preview = false)
{ {
$info_list = []; $info_list = [];
$user_id = (int) $user_id; $user_id = (int) $user_id;
$course_info = api_get_course_info($course_id);
$sessionId = (int) $sessionId; $sessionId = (int) $sessionId;
$courseCode = $course_info['code'];
// Portal info // Portal info
$organization_name = api_get_setting('Institution'); $organization_name = api_get_setting('Institution');
@ -1690,7 +1692,7 @@ class DocumentManager
$teacher_last_name = $teacher_info['lastname']; $teacher_last_name = $teacher_info['lastname'];
// info gradebook certificate // info gradebook certificate
$info_grade_certificate = UserManager::get_info_gradebook_certificate($courseCode, $sessionId, $user_id); $info_grade_certificate = UserManager::get_info_gradebook_certificate($course_info, $sessionId, $user_id);
$date_long_certificate = ''; $date_long_certificate = '';
$date_certificate = ''; $date_certificate = '';
$url = ''; $url = '';

@ -5287,18 +5287,19 @@ class UserManager
/** /**
* Gets the info about a gradebook certificate for a user by course. * Gets the info about a gradebook certificate for a user by course.
* *
* @param string $course_code The course code * @param array $course_info The course code
* @param int $session_id * @param int $session_id
* @param int $user_id The user id * @param int $user_id The user id
* *
* @return array if there is not information return false * @return array if there is not information return false
*/ */
public static function get_info_gradebook_certificate($course_code, $session_id, $user_id) public static function get_info_gradebook_certificate($course_info, $session_id, $user_id)
{ {
$tbl_grade_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); $tbl_grade_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$tbl_grade_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $tbl_grade_category = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$session_id = (int) $session_id; $session_id = (int) $session_id;
$user_id = (int) $user_id; $user_id = (int) $user_id;
$courseId = $course_info['real_id'];
if (empty($session_id)) { if (empty($session_id)) {
$session_condition = ' AND (session_id = "" OR session_id = 0 OR session_id IS NULL )'; $session_condition = ' AND (session_id = "" OR session_id = 0 OR session_id IS NULL )';
@ -5310,7 +5311,7 @@ class UserManager
WHERE cat_id = ( WHERE cat_id = (
SELECT id FROM '.$tbl_grade_category.' SELECT id FROM '.$tbl_grade_category.'
WHERE WHERE
course_code = "'.Database::escape_string($course_code).'" '.$session_condition.' c_id = "'.$courseId.'" '.$session_condition.'
LIMIT 1 LIMIT 1
) AND user_id='.$user_id; ) AND user_id='.$user_id;

@ -81,6 +81,10 @@ abstract class AbstractResource
public function addCourseLink(Course $course, Session $session = null, CGroup $group = null) public function addCourseLink(Course $course, Session $session = null, CGroup $group = null)
{ {
if (null === $this->getParent()) {
throw new \Exception('addCourseLink requires to set the parent.');
}
$resourceLink = new ResourceLink(); $resourceLink = new ResourceLink();
$resourceLink $resourceLink
->setVisibility(ResourceLink::VISIBILITY_PUBLISHED) ->setVisibility(ResourceLink::VISIBILITY_PUBLISHED)

@ -277,12 +277,10 @@ class GradebookCategory
* Set weight. * Set weight.
* *
* @param float $weight * @param float $weight
*
* @return GradebookCategory
*/ */
public function setWeight($weight) public function setWeight($weight): self
{ {
$this->weight = $weight; $this->weight = (float) $weight;
return $this; return $this;
} }

@ -149,8 +149,7 @@ services:
- {name: kernel.event_listener, event: kernel.controller, method: onKernelController} - {name: kernel.event_listener, event: kernel.controller, method: onKernelController}
# Locale listener # Locale listener
chamilo_core.listener.locale: Chamilo\CoreBundle\EventListener\LocaleListener:
class: Chamilo\CoreBundle\EventListener\LocaleListener
arguments: ['%kernel.default_locale%', '@chamilo.settings.manager', '@parameter_bag'] arguments: ['%kernel.default_locale%', '@chamilo.settings.manager', '@parameter_bag']
tags: tags:
- {name: kernel.event_subscriber, priority: 15} - {name: kernel.event_subscriber, priority: 15}

Loading…
Cancel
Save