Internal: Add psalm checks, fix deprecated code.

pull/3513/head
Julio Montoya 5 years ago
parent 2554afef15
commit 56968071ad
  1. 30
      psalm.xml
  2. 19
      public/main/forum/forumfunction.inc.php
  3. 15
      public/main/inc/ajax/skill.ajax.php
  4. 144
      public/main/inc/lib/AnnouncementManager.php
  5. 0
      public/main/inc/lib/SurveyTree.php
  6. 194
      public/main/inc/lib/api.lib.php
  7. 2
      public/main/inc/lib/attendance.lib.php
  8. 64
      public/main/inc/lib/career.lib.php
  9. 6
      public/main/inc/lib/extra_field.lib.php
  10. 8
      public/main/inc/lib/grade_model.lib.php
  11. 2
      public/main/inc/lib/image.lib.php
  12. 62
      public/main/inc/lib/link.lib.php
  13. 6
      public/main/inc/lib/model.lib.php
  14. 4
      public/main/inc/lib/promotion.lib.php
  15. 6
      public/main/inc/lib/skill.lib.php
  16. 2
      public/main/inc/lib/specific_fields_manager.lib.php
  17. 5
      public/main/inc/lib/statistics.lib.php
  18. 3
      public/main/inc/lib/sub_language.class.php
  19. 16
      public/main/inc/lib/system_announcements.lib.php
  20. 2
      public/main/inc/lib/timeline.lib.php
  21. 6
      public/main/inc/lib/usergroup.lib.php
  22. 5
      src/CoreBundle/Entity/SysAnnouncement.php
  23. 9
      src/CoreBundle/Framework/Container.php
  24. 6
      src/CourseBundle/Resources/config/services.yml

@ -23,9 +23,22 @@
<directory name="public/main/link" /> <directory name="public/main/link" />
<!-- <directory name="public/main/session" /> --> <!-- <directory name="public/main/session" /> -->
<!-- <directory name="public/main/exercise"/> --> <!-- <directory name="public/main/exercise"/> -->
<!-- <directory name="public/main/inc/ajax" />-->
<file name="public/main/inc/lib/access_url_edit_courses_to_url_functions.lib.php"/>
<file name="public/main/inc/lib/access_url_edit_sessions_to_url_functions.lib.php"/>
<file name="public/main/inc/lib/access_url_edit_users_to_url_functions.lib.php"/>
<file name="public/main/inc/lib/add_course.lib.inc.php"/> <file name="public/main/inc/lib/add_course.lib.inc.php"/>
<file name="public/main/inc/lib/add_courses_to_session_functions.lib.php"/>
<!-- <file name="public/main/inc/lib/agenda.lib.php"/>--> <!-- <file name="public/main/inc/lib/agenda.lib.php"/>-->
<file name="public/main/inc/lib/AnnouncementEmail.php"/>
<file name="public/main/inc/lib/AnnouncementManager.php"/>
<file name="public/main/inc/lib/api.lib.php"/>
<file name="public/main/inc/lib/array.lib.php"/>
<file name="public/main/inc/lib/attendance.lib.php"/> <file name="public/main/inc/lib/attendance.lib.php"/>
<file name="public/main/inc/lib/career.lib.php"/> <file name="public/main/inc/lib/career.lib.php"/>
<file name="public/main/inc/lib/course.lib.php"/> <file name="public/main/inc/lib/course.lib.php"/>
@ -35,17 +48,32 @@
<file name="public/main/inc/lib/course_request.lib.php"/> <file name="public/main/inc/lib/course_request.lib.php"/>
<file name="public/main/inc/lib/sessionmanager.lib.php"/> <file name="public/main/inc/lib/sessionmanager.lib.php"/>
<!-- <file name="public/main/inc/lib/skill.lib.php"/>--> <!-- <file name="public/main/inc/lib/skill.lib.php"/>-->
<file name="public/main/inc/lib/link.lib.php"/>
<file name="public/main/inc/lib/legal.lib.php"/>
<file name="public/main/inc/lib/skill.visualizer.lib.php"/> <file name="public/main/inc/lib/skill.visualizer.lib.php"/>
<file name="public/main/inc/lib/social.lib.php"/> <file name="public/main/inc/lib/social.lib.php"/>
<file name="public/main/inc/lib/sortable_table.class.php"/> <file name="public/main/inc/lib/sortable_table.class.php"/>
<file name="public/main/inc/lib/SortableTableFromArray.php"/> <file name="public/main/inc/lib/SortableTableFromArray.php"/>
<file name="public/main/inc/lib/SortableTableFromArrayConfig.php"/> <file name="public/main/inc/lib/SortableTableFromArrayConfig.php"/>
<file name="public/main/inc/lib/specific_fields_manager.lib.php"/>
<file name="public/main/inc/lib/statistics.lib.php"/>
<file name="public/main/inc/lib/SurveyTree.php"/>
<file name="public/main/inc/lib/system_announcements.lib.php"/>
<file name="public/main/inc/lib/table_sort.class.php"/>
<file name="public/main/inc/lib/tablesort.lib.php"/>
<file name="public/main/inc/lib/TeacherTimeReport.php"/>
<file name="public/main/inc/lib/text.lib.php"/>
<file name="public/main/inc/lib/thematic.lib.php"/> <file name="public/main/inc/lib/thematic.lib.php"/>
<!-- <file name="public/main/inc/lib/TicketManager.php"/>-->
<file name="public/main/inc/lib/timeline.lib.php"/>
<file name="public/main/inc/lib/UnserializeApi.php"/>
<!-- <file name="public/main/inc/lib/tracking.lib.php"/>-->
<file name="public/main/inc/lib/urlmanager.lib.php"/> <file name="public/main/inc/lib/urlmanager.lib.php"/>
<file name="public/main/inc/lib/usergroup.lib.php"/> <file name="public/main/inc/lib/usergroup.lib.php"/>
<!-- <file name="public/main/inc/lib/usermanager.lib.php"/>--> <!-- <file name="public/main/inc/lib/usermanager.lib.php"/>-->
<file name="public/main/inc/lib/userportal.lib.php"/> <file name="public/main/inc/lib/userportal.lib.php"/>
<file name="public/main/inc/lib/VideoChat.php"/>
<ignoreFiles> <ignoreFiles>
<directory name="vendor/*"/> <directory name="vendor/*"/>

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\GradebookLink;
use Chamilo\CoreBundle\Entity\ResourceLink; use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Framework\Container; use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CForumAttachment; use Chamilo\CourseBundle\Entity\CForumAttachment;
@ -1042,7 +1043,7 @@ function delete_post($post_id)
$em = Database::getManager(); $em = Database::getManager();
/** @var CForumPost $post */ /** @var CForumPost $post */
$post = $em $post = $em
->getRepository('ChamiloCourseBundle:CForumPost') ->getRepository(CForumPost::class)
->findOneBy(['cId' => $course_id, 'iid' => $post_id]); ->findOneBy(['cId' => $course_id, 'iid' => $post_id]);
if ($post) { if ($post) {
@ -1915,7 +1916,7 @@ function get_threads($forumId, $courseId = null, $sessionId = null)
*/ */
function getThreadInfo($threadId, $cId) function getThreadInfo($threadId, $cId)
{ {
$repo = Database::getManager()->getRepository('ChamiloCourseBundle:CForumThread'); $repo = Database::getManager()->getRepository(CForumThread::class);
/** @var CForumThread $forumThread */ /** @var CForumThread $forumThread */
$forumThread = $repo->findOneBy(['iid' => $threadId, 'cId' => $cId]); $forumThread = $repo->findOneBy(['iid' => $threadId, 'cId' => $cId]);
@ -1994,7 +1995,7 @@ function getPosts(
$criteria->andWhere(Criteria::expr()->eq('postParentId', $postId)); $criteria->andWhere(Criteria::expr()->eq('postParentId', $postId));
} }
$qb = $em->getRepository('ChamiloCourseBundle:CForumPost')->createQueryBuilder('p'); $qb = $em->getRepository(CForumPost::class)->createQueryBuilder('p');
$qb->select('p') $qb->select('p')
->addCriteria($criteria) ->addCriteria($criteria)
->addOrderBy('p.iid', $orderDirection); ->addOrderBy('p.iid', $orderDirection);
@ -2380,7 +2381,7 @@ function updateThread($values)
$gradebookLink = null; $gradebookLink = null;
$em = Database::getManager(); $em = Database::getManager();
if (!empty($linkInfo) && isset($linkInfo['id'])) { if (!empty($linkInfo) && isset($linkInfo['id'])) {
$gradebookLink = $em->getRepository('ChamiloCoreBundle:GradebookLink')->find($linkInfo['id']); $gradebookLink = $em->getRepository(GradebookLink::class)->find($linkInfo['id']);
} }
// values 1 or 0 // values 1 or 0
@ -2710,7 +2711,7 @@ function store_thread(
* *
* @return FormValidator * @return FormValidator
*/ */
function show_add_post_form(CForumForum $forum, CForumThread $thread, CForumPost $post = null, $action, $form_values = '', $showPreview = true) function show_add_post_form(CForumForum $forum, CForumThread $thread, CForumPost $post = null, $action, $form_values, $showPreview = true)
{ {
$_user = api_get_user_info(); $_user = api_get_user_info();
$action = isset($action) ? Security::remove_XSS($action) : ''; $action = isset($action) ? Security::remove_XSS($action) : '';
@ -3680,7 +3681,7 @@ function show_edit_post_form(
$post, $post,
$thread, $thread,
$forum, $forum,
$form_values = '', $form_values,
$id_attach = 0 $id_attach = 0
) { ) {
// Initialize the object. // Initialize the object.
@ -4133,7 +4134,7 @@ function approve_post($post_id, $action)
* This is needed to display the icon that there are unapproved messages in that thread (only the courseadmin can see * This is needed to display the icon that there are unapproved messages in that thread (only the courseadmin can see
* this). * this).
* *
* @param the $forum_id forum where we want to know the unapproved messages of * @param int $forum_id forum where we want to know the unapproved messages of
* *
* @return array returns * @return array returns
* *
@ -4163,8 +4164,6 @@ function get_unaproved_messages($forum_id)
/** /**
* This function sends the notification mails to everybody who stated that they wanted to be informed when a new post * This function sends the notification mails to everybody who stated that they wanted to be informed when a new post
* was added to a given thread. * was added to a given thread.
*
* @param array $forum reply information
*/ */
function send_notification_mails(CForumForum $forum, CForumThread $thread, $reply_info) function send_notification_mails(CForumForum $forum, CForumThread $thread, $reply_info)
{ {
@ -6424,7 +6423,7 @@ function getCountPostsWithStatus($status, $forum, $threadId = null)
$criteria->andWhere(Criteria::expr()->eq('thread', $threadId)); $criteria->andWhere(Criteria::expr()->eq('thread', $threadId));
} }
$qb = $em->getRepository('ChamiloCourseBundle:CForumPost')->createQueryBuilder('p'); $qb = $em->getRepository(CForumPost::class)->createQueryBuilder('p');
$qb->select('count(p.iid)') $qb->select('count(p.iid)')
->addCriteria($criteria); ->addCriteria($criteria);

@ -1,9 +1,14 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\SkillRelCourse;
use Chamilo\CoreBundle\Entity\SkillRelItem;
/** /**
* Responses to AJAX calls. * Responses to AJAX calls.
*/ */
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
@ -373,12 +378,12 @@ switch ($action) {
exit; exit;
} }
$em = Database::getManager(); $em = Database::getManager();
$skills = $em->getRepository('ChamiloCoreBundle:SkillRelCourse')->findBy( $skills = $em->getRepository(SkillRelCourse::class)->findBy(
['course' => $courseId, 'session' => $sessionId] ['course' => $courseId, 'session' => $sessionId]
); );
$returnSkills = []; $returnSkills = [];
/** @var \Chamilo\CoreBundle\Entity\SkillRelCourse $skill */ /** @var SkillRelCourse $skill */
foreach ($skills as $skill) { foreach ($skills as $skill) {
$returnSkills[] = [ $returnSkills[] = [
'id' => $skill->getSkill()->getId(), 'id' => $skill->getSkill()->getId(),
@ -420,9 +425,9 @@ switch ($action) {
exit; exit;
} }
$session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId); $session = api_get_session_entity($sessionId);
/** @var \Chamilo\CoreBundle\Entity\SkillRelItem $skillRelItem */ /** @var SkillRelItem $skillRelItem */
$skillRelItem = $em->getRepository('ChamiloCoreBundle:SkillRelItem')->findOneBy( $skillRelItem = $em->getRepository(SkillRelItem::class)->findOneBy(
['itemId' => $itemId, 'itemType' => $typeId, 'skill' => $skillId] ['itemId' => $itemId, 'itemType' => $typeId, 'skill' => $skillId]
); );

@ -462,6 +462,7 @@ class AnnouncementManager
return ''; return '';
} }
$stok = null;
$html = ''; $html = '';
$course = api_get_course_entity(api_get_course_int_id()); $course = api_get_course_entity(api_get_course_int_id());
$session = api_get_session_entity(api_get_session_id()); $session = api_get_session_entity(api_get_session_id());
@ -499,7 +500,6 @@ class AnnouncementManager
$alt_visibility = get_lang('Hide'); $alt_visibility = get_lang('Hide');
$setNewStatus = 'invisible'; $setNewStatus = 'invisible';
} }
global $stok;
$modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=set_visibility&status=".$setNewStatus."&id=".$id."&sec_token=".$stok."\">". $modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=set_visibility&status=".$setNewStatus."&id=".$id."&sec_token=".$stok."\">".
Display::return_icon($image_visibility.'.png', $alt_visibility, '', ICON_SIZE_SMALL)."</a>"; Display::return_icon($image_visibility.'.png', $alt_visibility, '', ICON_SIZE_SMALL)."</a>";
@ -817,14 +817,14 @@ class AnnouncementManager
$sentToAllGroup = false; $sentToAllGroup = false;
if (empty($send_to_users['groups']) && empty($send_to_users['users'])) { if (empty($send_to_users['groups']) && empty($send_to_users['users'])) {
$groupInfo = GroupManager::get_group_properties($groupId); $groupInfo = GroupManager::get_group_properties($groupId);
api_item_property_update( /*api_item_property_update(
$courseInfo, $courseInfo,
TOOL_ANNOUNCEMENT, TOOL_ANNOUNCEMENT,
$last_id, $last_id,
'AnnouncementAdded', 'AnnouncementAdded',
api_get_user_id(), api_get_user_id(),
$groupInfo $groupInfo
); );*/
$sentToAllGroup = true; $sentToAllGroup = true;
} }
@ -832,21 +832,21 @@ class AnnouncementManager
if (!empty($send_to_users['groups'])) { if (!empty($send_to_users['groups'])) {
foreach ($send_to_users['groups'] as $group) { foreach ($send_to_users['groups'] as $group) {
$groupInfo = GroupManager::get_group_properties($group); $groupInfo = GroupManager::get_group_properties($group);
api_item_property_update( /*api_item_property_update(
$courseInfo, $courseInfo,
TOOL_ANNOUNCEMENT, TOOL_ANNOUNCEMENT,
$last_id, $last_id,
'AnnouncementAdded', 'AnnouncementAdded',
api_get_user_id(), api_get_user_id(),
$groupInfo $groupInfo
); );*/
} }
} }
$groupInfo = GroupManager::get_group_properties($groupId); $groupInfo = GroupManager::get_group_properties($groupId);
if (!empty($send_to_users['users'])) { if (!empty($send_to_users['users'])) {
foreach ($send_to_users['users'] as $user) { foreach ($send_to_users['users'] as $user) {
api_item_property_update( /*api_item_property_update(
$courseInfo, $courseInfo,
TOOL_ANNOUNCEMENT, TOOL_ANNOUNCEMENT,
$last_id, $last_id,
@ -854,7 +854,7 @@ class AnnouncementManager
api_get_user_id(), api_get_user_id(),
$groupInfo, $groupInfo,
$user $user
); );*/
} }
} }
} }
@ -1171,7 +1171,7 @@ class AnnouncementManager
$result['users'][] = $link->getUser()->getId(); $result['users'][] = $link->getUser()->getId();
} }
if ($link->getGroup()) { if ($link->getGroup()) {
$result['groups'][] = $link->getGroup()->getId(); $result['groups'][] = $link->getGroup()->getIid();
} }
} }
@ -1462,6 +1462,9 @@ class AnnouncementManager
$file, $file,
$file_comment $file_comment
) { ) {
// @todo fix edition
exit;
/*
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
$table = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); $table = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
$return = 0; $return = 0;
@ -1514,7 +1517,7 @@ class AnnouncementManager
} }
} }
return $return; return $return;*/
} }
/** /**
@ -2141,129 +2144,6 @@ class AnnouncementManager
$qb->select('count(resource)'); $qb->select('count(resource)');
return $qb->getQuery()->getSingleScalarResult(); return $qb->getQuery()->getSingleScalarResult();
// students only get to see the visible announcements
if (empty($_GET['origin']) || 'learnpath' !== $_GET['origin']) {
$group_memberships = GroupManager::get_group_ids(
$courseInfo['real_id'],
$userId
);
if ((api_get_course_setting('allow_user_edit_announcement') &&
!api_is_anonymous())
) {
if (0 == api_get_group_id()) {
$cond_user_id = " AND (
ip.lastedit_user_id = '".$userId."' OR (
ip.to_user_id='".$userId."' OR
ip.to_group_id IN (0, ".implode(", ", $group_memberships).") OR
ip.to_group_id IS NULL
)
)
";
} else {
$cond_user_id = " AND (
ip.lastedit_user_id = '".$userId."'OR
ip.to_group_id IN (0, ".api_get_group_id().") OR
ip.to_group_id IS NULL
)";
}
} else {
if (0 == api_get_group_id()) {
$cond_user_id = " AND (
ip.to_user_id='".$userId."' OR
ip.to_group_id IN (0, ".implode(", ", $group_memberships).") OR
ip.to_group_id IS NULL
) ";
} else {
$cond_user_id = " AND (
ip.to_user_id='".$userId."' OR
ip.to_group_id IN (0, ".api_get_group_id().") OR
ip.to_group_id IS NULL
) ";
}
}
// the user is member of several groups => display personal announcements AND
// his group announcements AND the general announcements
if (is_array($group_memberships) && count($group_memberships) > 0) {
$sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement
INNER JOIN $tbl_item_property ip
ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id)
WHERE
announcement.c_id = $courseId AND
ip.c_id = $courseId AND
ip.tool='announcement' AND
ip.visibility='1'
$cond_user_id
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0, $maximum";
} else {
// the user is not member of any group
// this is an identified user => show the general announcements AND his personal announcements
if ($userId) {
if ((api_get_course_setting('allow_user_edit_announcement') &&
!api_is_anonymous())
) {
$cond_user_id = " AND (
ip.lastedit_user_id = '".$userId."' OR
( ip.to_user_id='".$userId."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL)
) ";
} else {
$cond_user_id = " AND ( ip.to_user_id='".$userId."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL) ";
}
$sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement
INNER JOIN $tbl_item_property ip
ON (announcement.c_id = ip.c_id AND announcement.id = ip.ref)
WHERE
announcement.c_id = $courseId AND
ip.c_id = $courseId AND
ip.tool='announcement' AND
ip.visibility='1'
$cond_user_id
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0, $maximum";
} else {
if (api_get_course_setting('allow_user_edit_announcement')) {
$cond_user_id = " AND (
ip.lastedit_user_id = '".api_get_user_id()."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL
) ";
} else {
$cond_user_id = " AND ip.to_group_id='0' ";
}
// the user is not identiefied => show only the general announcements
$sql = "SELECT
announcement.*,
ip.visibility,
ip.to_group_id,
ip.insert_user_id
FROM $tbl_announcement announcement
INNER JOIN $tbl_item_property ip
ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id)
WHERE
announcement.c_id = $courseId AND
ip.c_id = $courseId AND
ip.tool='announcement' AND
ip.visibility='1' AND
ip.to_group_id='0'
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0, $maximum";
}
}
}
} }
$result = Database::query($sql);
return Database::num_rows($result);
} }
} }

@ -4,6 +4,7 @@
use Chamilo\CoreBundle\Entity\AccessUrl; use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Language;
use Chamilo\CoreBundle\Entity\Session as SessionEntity; use Chamilo\CoreBundle\Entity\Session as SessionEntity;
use Chamilo\CoreBundle\Entity\SettingsCurrent; use Chamilo\CoreBundle\Entity\SettingsCurrent;
use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Entity\User;
@ -988,7 +989,7 @@ function api_valid_email($address)
* *
* @param bool Option to print headers when displaying error message. Default: false * @param bool Option to print headers when displaying error message. Default: false
* @param bool whether session admins should be allowed or not * @param bool whether session admins should be allowed or not
* @param bool $checkTool check if tool is available for users (user, group) * @param string $checkTool check if tool is available for users (user, group)
* *
* @return bool True if the user has access to the current course or is out of a course context, false otherwise * @return bool True if the user has access to the current course or is out of a course context, false otherwise
* *
@ -1176,45 +1177,45 @@ function api_get_navigator()
if (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Opera')) { if (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Opera')) {
$navigator = 'Opera'; $navigator = 'Opera';
list(, $version) = explode('Opera', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('Opera', $_SERVER['HTTP_USER_AGENT']);
} elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Edge')) { } elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Edge')) {
$navigator = 'Edge'; $navigator = 'Edge';
list(, $version) = explode('Edge', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('Edge', $_SERVER['HTTP_USER_AGENT']);
} elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { } elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
$navigator = 'Internet Explorer'; $navigator = 'Internet Explorer';
list(, $version) = explode('MSIE ', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('MSIE ', $_SERVER['HTTP_USER_AGENT']);
} elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome')) { } elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome')) {
$navigator = 'Chrome'; $navigator = 'Chrome';
list(, $version) = explode('Chrome', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('Chrome', $_SERVER['HTTP_USER_AGENT']);
} elseif (false !== stripos($_SERVER['HTTP_USER_AGENT'], 'Safari')) { } elseif (false !== stripos($_SERVER['HTTP_USER_AGENT'], 'Safari')) {
$navigator = 'Safari'; $navigator = 'Safari';
if (false !== stripos($_SERVER['HTTP_USER_AGENT'], 'Version/')) { if (false !== stripos($_SERVER['HTTP_USER_AGENT'], 'Version/')) {
// If this Safari does have the "Version/" string in its user agent // If this Safari does have the "Version/" string in its user agent
// then use that as a version indicator rather than what's after // then use that as a version indicator rather than what's after
// "Safari/" which is rather a "build number" or something // "Safari/" which is rather a "build number" or something
list(, $version) = explode('Version/', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('Version/', $_SERVER['HTTP_USER_AGENT']);
} else { } else {
list(, $version) = explode('Safari/', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('Safari/', $_SERVER['HTTP_USER_AGENT']);
} }
} elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox')) { } elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox')) {
$navigator = 'Firefox'; $navigator = 'Firefox';
list(, $version) = explode('Firefox', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('Firefox', $_SERVER['HTTP_USER_AGENT']);
} elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape')) { } elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape')) {
$navigator = 'Netscape'; $navigator = 'Netscape';
if (false !== stripos($_SERVER['HTTP_USER_AGENT'], 'Netscape/')) { if (false !== stripos($_SERVER['HTTP_USER_AGENT'], 'Netscape/')) {
list(, $version) = explode('Netscape', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('Netscape', $_SERVER['HTTP_USER_AGENT']);
} else { } else {
list(, $version) = explode('Navigator', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('Navigator', $_SERVER['HTTP_USER_AGENT']);
} }
} elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror')) { } elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror')) {
$navigator = 'Konqueror'; $navigator = 'Konqueror';
list(, $version) = explode('Konqueror', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('Konqueror', $_SERVER['HTTP_USER_AGENT']);
} elseif (false !== stripos($_SERVER['HTTP_USER_AGENT'], 'applewebkit')) { } elseif (false !== stripos($_SERVER['HTTP_USER_AGENT'], 'applewebkit')) {
$navigator = 'AppleWebKit'; $navigator = 'AppleWebKit';
list(, $version) = explode('Version/', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('Version/', $_SERVER['HTTP_USER_AGENT']);
} elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko')) { } elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko')) {
$navigator = 'Mozilla'; $navigator = 'Mozilla';
list(, $version) = explode('; rv:', $_SERVER['HTTP_USER_AGENT']); [, $version] = explode('; rv:', $_SERVER['HTTP_USER_AGENT']);
} }
// Now cut extra stuff around (mostly *after*) the version number // Now cut extra stuff around (mostly *after*) the version number
@ -2260,24 +2261,20 @@ function api_get_course_info($course_code = null)
/** /**
* @param int $courseId * @param int $courseId
*
* @return Course
*/ */
function api_get_course_entity($courseId = 0) function api_get_course_entity($courseId = 0): ?Course
{ {
if (empty($courseId)) { if (empty($courseId)) {
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
} }
return CourseManager::getManager()->find($courseId); return Container::getCourseRepository()->find($courseId);
} }
/** /**
* @param int $id * @param int $id
*
* @return SessionEntity|null
*/ */
function api_get_session_entity($id = 0) function api_get_session_entity($id = 0): ?SessionEntity
{ {
if (empty($id)) { if (empty($id)) {
$id = api_get_session_id(); $id = api_get_session_id();
@ -2287,21 +2284,19 @@ function api_get_session_entity($id = 0)
return null; return null;
} }
return Database::getManager()->getRepository('ChamiloCoreBundle:Session')->find($id); return Container::getSessionRepository()->find($id);
} }
/** /**
* @param int $id * @param int $id
*
* @return CGroup
*/ */
function api_get_group_entity($id = 0) function api_get_group_entity($id = 0): ?CGroup
{ {
if (empty($id)) { if (empty($id)) {
$id = api_get_group_id(); $id = api_get_group_id();
} }
return Database::getManager()->getRepository('ChamiloCourseBundle:CGroup')->find($id); return Container::getGroupRepository()->find($id);
} }
/** /**
@ -3845,9 +3840,9 @@ function api_not_allowed(
*/ */
function convert_sql_date($last_post_datetime) function convert_sql_date($last_post_datetime)
{ {
list($last_post_date, $last_post_time) = explode(' ', $last_post_datetime); [$last_post_date, $last_post_time] = explode(' ', $last_post_datetime);
list($year, $month, $day) = explode('-', $last_post_date); [$year, $month, $day] = explode('-', $last_post_date);
list($hour, $min, $sec) = explode(':', $last_post_time); [$hour, $min, $sec] = explode(':', $last_post_time);
return mktime((int) $hour, (int) $min, (int) $sec, (int) $month, (int) $day, (int) $year); return mktime((int) $hour, (int) $min, (int) $sec, (int) $month, (int) $day, (int) $year);
} }
@ -4424,8 +4419,7 @@ function api_get_language_info($languageId)
return []; return [];
} }
$language = Database::getManager() $language = Database::getManager()->find(Language::class, $languageId);
->find('ChamiloCoreBundle:Language', $languageId);
if (!$language) { if (!$language) {
return []; return [];
@ -4445,13 +4439,13 @@ function api_get_language_info($languageId)
/** /**
* @param string $code * @param string $code
* *
* @return \Chamilo\CoreBundle\Entity\Language * @return Language
*/ */
function api_get_language_from_iso($code) function api_get_language_from_iso($code)
{ {
$em = Database::getManager(); $em = Database::getManager();
return $em->getRepository('ChamiloCoreBundle:Language')->findOneBy(['isocode' => $code]); return $em->getRepository(Language::class)->findOneBy(['isocode' => $code]);
} }
/** /**
@ -4509,14 +4503,14 @@ function api_get_visual_theme()
$allow_lp_theme = api_get_course_setting('allow_learning_path_theme'); $allow_lp_theme = api_get_course_setting('allow_learning_path_theme');
if (1 == $allow_lp_theme) { if (1 == $allow_lp_theme) {
global $lp_theme_css, $lp_theme_config; /*global $lp_theme_css, $lp_theme_config;
// These variables come from the file lp_controller.php. // These variables come from the file lp_controller.php.
if (!$lp_theme_config) { if (!$lp_theme_config) {
if (!empty($lp_theme_css)) { if (!empty($lp_theme_css)) {
// LP's theme. // LP's theme.
$visual_theme = $lp_theme_css; $visual_theme = $lp_theme_css;
} }
} }*/
} }
} }
} }
@ -4525,10 +4519,10 @@ function api_get_visual_theme()
$visual_theme = 'chamilo'; $visual_theme = 'chamilo';
} }
global $lp_theme_log; /*global $lp_theme_log;
if ($lp_theme_log) { if ($lp_theme_log) {
$visual_theme = $platform_theme; $visual_theme = $platform_theme;
} }*/
} }
return $visual_theme; return $visual_theme;
@ -4928,10 +4922,8 @@ function copy_folder_course_session(
]; ];
$document_id = Database::insert($table, $params); $document_id = Database::insert($table, $params);
if ($document_id) { if ($document_id) {
$sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
Database::query($sql);
api_item_property_update( /*api_item_property_update(
$course_info, $course_info,
TOOL_DOCUMENT, TOOL_DOCUMENT,
$document_id, $document_id,
@ -4942,7 +4934,7 @@ function copy_folder_course_session(
null, null,
null, null,
$session_id $session_id
); );*/
} }
} }
} }
@ -5567,7 +5559,8 @@ function api_add_setting(
$visibility = 0 $visibility = 0
) { ) {
$em = Database::getManager(); $em = Database::getManager();
$settingRepo = $em->getRepository('ChamiloCoreBundle:SettingsCurrent');
$settingRepo = $em->getRepository(SettingsCurrent::class);
$accessUrlId = (int) $accessUrlId ?: 1; $accessUrlId = (int) $accessUrlId ?: 1;
if (is_array($value)) { if (is_array($value)) {
@ -7084,7 +7077,7 @@ function api_check_ip_in_range($ip, $range)
continue; //otherwise, get to the next range continue; //otherwise, get to the next range
} }
// the range contains a "/", so analyse completely // the range contains a "/", so analyse completely
list($net, $mask) = explode("/", $range); [$net, $mask] = explode("/", $range);
$ip_net = ip2long($net); $ip_net = ip2long($net);
// mask binary magic // mask binary magic
@ -7120,15 +7113,15 @@ function api_is_global_chat_enabled()
} }
/** /**
* @todo Fix tool_visible_by_default_at_creation labels * @param int $item_id
* @todo Add sessionId parameter to avoid using context
*
* @param int $item_id
* @param int $tool_id * @param int $tool_id
* @param int $group_id id * @param int $group_id id
* @param array $courseInfo * @param array $courseInfo
* @param int $sessionId * @param int $sessionId
* @param int $userId * @param int $userId
*
* @deprecated
*
*/ */
function api_set_default_visibility( function api_set_default_visibility(
$item_id, $item_id,
@ -7193,7 +7186,7 @@ function api_set_default_visibility(
$visibility = DocumentManager::getDocumentDefaultVisibility($courseInfo); $visibility = DocumentManager::getDocumentDefaultVisibility($courseInfo);
} }
api_item_property_update( /*api_item_property_update(
$courseInfo, $courseInfo,
$original_tool_id, $original_tool_id,
$item_id, $item_id,
@ -7204,7 +7197,7 @@ function api_set_default_visibility(
null, null,
null, null,
$sessionId $sessionId
); );*/
// Fixes default visibility for tests // Fixes default visibility for tests
switch ($original_tool_id) { switch ($original_tool_id) {
@ -7755,42 +7748,6 @@ function api_is_allowed_in_course()
return false; return false;
} }
/**
* Set the cookie to go directly to the course code $in_firstpage
* after login.
*
* @param string $value is the course code of the course to go
*/
function api_set_firstpage_parameter($value)
{
setcookie('GotoCourse', $value);
}
/**
* Delete the cookie to go directly to the course code $in_firstpage
* after login.
*/
function api_delete_firstpage_parameter()
{
setcookie('GotoCourse', '', time() - 3600);
}
/**
* @return bool if course_code for direct course access after login is set
*/
function exist_firstpage_parameter()
{
return isset($_COOKIE['GotoCourse']) && '' != $_COOKIE['GotoCourse'];
}
/**
* @return return the course_code of the course where user login
*/
function api_get_firstpage_parameter()
{
return $_COOKIE['GotoCourse'];
}
/** /**
* Return true on https install. * Return true on https install.
* *
@ -7799,7 +7756,7 @@ function api_get_firstpage_parameter()
function api_is_https() function api_is_https()
{ {
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] || !empty($_configuration['force_https_forwarded_proto']) 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] || !empty(api_get_configuration_value('force_https_forwarded_proto'))
) { ) {
$isSecured = true; $isSecured = true;
} else { } else {
@ -8708,7 +8665,12 @@ function api_unserialize_content($type, $serialized, $ignoreErrors = false)
switch ($type) { switch ($type) {
case 'career': case 'career':
case 'sequence_graph': case 'sequence_graph':
$allowedClasses = [Graph::class, VerticesMap::class, Vertices::class, Edges::class]; $allowedClasses = [
\Fhaculty\Graph\Graph::class,
\Fhaculty\Graph\Set\VerticesMap::class,
\Fhaculty\Graph\Set\Vertices::class,
\Fhaculty\Graph\Set\Edges::class,
];
break; break;
case 'lp': case 'lp':
$allowedClasses = [ $allowedClasses = [
@ -8730,34 +8692,34 @@ function api_unserialize_content($type, $serialized, $ignoreErrors = false)
break; break;
case 'course': case 'course':
$allowedClasses = [ $allowedClasses = [
Course::class, \Chamilo\CourseBundle\Component\CourseCopy\Course::class,
Announcement::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Announcement::class,
Attendance::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Attendance::class,
CalendarEvent::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\CalendarEvent::class,
CourseCopyLearnpath::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseCopyLearnpath::class,
CourseCopyTestCategory::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseCopyTestCategory::class,
CourseDescription::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseDescription::class,
CourseSession::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseSession::class,
Document::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Document::class,
Forum::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Forum::class,
ForumCategory::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumCategory::class,
ForumPost::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumPost::class,
ForumTopic::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumTopic::class,
Glossary::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Glossary::class,
GradeBookBackup::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\GradeBookBackup::class,
Link::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Link::class,
LinkCategory::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\LinkCategory::class,
Quiz::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Quiz::class,
QuizQuestion::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestion::class,
QuizQuestionOption::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestionOption::class,
ScormDocument::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\ScormDocument::class,
Survey::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Survey::class,
SurveyInvitation::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\SurveyInvitation::class,
SurveyQuestion::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\SurveyQuestion::class,
Thematic::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Thematic::class,
ToolIntro::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\ToolIntro::class,
Wiki::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Wiki::class,
Work::class, \Chamilo\CourseBundle\Component\CourseCopy\Resources\Work::class,
stdClass::class, stdClass::class,
]; ];
break; break;
@ -8767,13 +8729,13 @@ function api_unserialize_content($type, $serialized, $ignoreErrors = false)
} }
if ($ignoreErrors) { if ($ignoreErrors) {
return @Unserialize::unserialize( return @UnserializeApi::unserialize(
$serialized, $serialized,
['allowed_classes' => $allowedClasses] ['allowed_classes' => $allowedClasses]
); );
} }
return Unserialize::unserialize( return UnserializeApi::unserialize(
$serialized, $serialized,
['allowed_classes' => $allowedClasses] ['allowed_classes' => $allowedClasses]
); );

@ -252,7 +252,7 @@ class Attendance
$is_done_all_calendar = self::is_all_attendance_calendar_done($id); $is_done_all_calendar = self::is_all_attendance_calendar_done($id);
if ($is_done_all_calendar) { if ($is_done_all_calendar) {
$locked = $attendance[4]; $locked = $attendance->getLocked();
if (0 == $locked) { if (0 == $locked) {
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$message_alert = get_lang('Are you sure you want to lock the attendance?'); $message_alert = get_lang('Are you sure you want to lock the attendance?');

@ -228,25 +228,25 @@ class Career extends Model
public function get_status($career_id) public function get_status($career_id)
{ {
$table = Database::get_main_table(TABLE_CAREER); $table = Database::get_main_table(TABLE_CAREER);
$career_id = intval($career_id); $career_id = (int) $career_id;
$sql = "SELECT status FROM $table WHERE id = '$career_id'"; $sql = "SELECT status FROM $table WHERE id = '$career_id'";
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) > 0) { if (Database::num_rows($result) > 0) {
$data = Database::fetch_array($result); $data = Database::fetch_array($result);
return $data['status']; return $data['status'];
} else {
return false;
} }
return false;
} }
/** /**
* @param array $params * @param array $params
* @param bool $show_query * @param bool $showQuery
* *
* @return int * @return int
*/ */
public function save($params, $show_query = false) public function save($params, $showQuery = false)
{ {
$career = new \Chamilo\CoreBundle\Entity\Career(); $career = new \Chamilo\CoreBundle\Entity\Career();
$career $career
@ -815,16 +815,16 @@ class Career extends Model
} }
if (!empty($newGroup)) { if (!empty($newGroup)) {
$graphHtml .= '<div $graphHtml .= '<div
id ="group_'.$newGroup.'" id ="group_'.$newGroup.'"
class="group'.$newGroup.' group_class" class="group'.$newGroup.' group_class"
style="display:grid; style="display:grid;
align-self: start; align-self: start;
grid-gap: 10px; grid-gap: 10px;
justify-items: stretch; justify-items: stretch;
align-items: start; align-items: start;
align-content: start; align-content: start;
justify-content: stretch; justify-content: stretch;
grid-area:'.$minRow.'/'.$minColumn.'/'.$maxRow.'/'.$maxColumn.'">'; //style="display:grid" grid-area:'.$minRow.'/'.$minColumn.'/'.$maxRow.'/'.$maxColumn.'">'; //style="display:grid"
} }
@ -882,12 +882,12 @@ class Career extends Model
} }
$id = $vertex->getId(); $id = $vertex->getId();
$area = "$realRow/$column"; $area = "$realRow/$column";
$graphHtml .= '<div $graphHtml .= '<div
id = "row_wrapper_'.$id.'" id = "row_wrapper_'.$id.'"
data= "'.$originalRow.'-'.$column.'" data= "'.$originalRow.'-'.$column.'"
style=" style="
align-self: start; align-self: start;
justify-content: stretch; justify-content: stretch;
grid-area:'.$area.'" grid-area:'.$area.'"
>'; >';
$color = ''; $color = '';
@ -1134,8 +1134,8 @@ class Career extends Model
$groupIdTag = "group_$group"; $groupIdTag = "group_$group";
$borderLine = true === $showGroupLine ? 'border-style:solid;' : ''; $borderLine = true === $showGroupLine ? 'border-style:solid;' : '';
$graphHtml = '<div $graphHtml = '<div
id="'.$groupIdTag.'" class="career_group" id="'.$groupIdTag.'" class="career_group"
style=" '.$borderLine.' padding:15px; float:left; margin-left:'.$leftGroup.'; width:'.$widthGroup.'%">'; style=" '.$borderLine.' padding:15px; float:left; margin-left:'.$leftGroup.'; width:'.$widthGroup.'%">';
if (!empty($groupLabel)) { if (!empty($groupLabel)) {
@ -1156,8 +1156,8 @@ class Career extends Model
} }
// padding:15px; // padding:15px;
$graphHtml .= '<div $graphHtml .= '<div
id="subgroup_'.$subGroup.'" class="career_subgroup" id="subgroup_'.$subGroup.'" class="career_subgroup"
style="'.$line.' margin-bottom:20px; padding:15px; float:left; margin-left:0px; width:100%">'; style="'.$line.' margin-bottom:20px; padding:15px; float:left; margin-left:0px; width:100%">';
if (!empty($subGroupLabel)) { if (!empty($subGroupLabel)) {
$graphHtml .= '<h3>'.$subGroupLabel.'</h3>'; $graphHtml .= '<h3>'.$subGroupLabel.'</h3>';
@ -1172,8 +1172,8 @@ class Career extends Model
} }
$widthColumn = 85 / count($columnList); $widthColumn = 85 / count($columnList);
$graphHtml .= '<div $graphHtml .= '<div
id="col_'.$column.'" class="career_column" id="col_'.$column.'" class="career_column"
style="padding:15px;float:left; margin-left:'.$leftColumn.'; width:'.$widthColumn.'%">'; style="padding:15px;float:left; margin-left:'.$leftColumn.'; width:'.$widthColumn.'%">';
$maxRow = 0; $maxRow = 0;
foreach ($rows as $row => $vertex) { foreach ($rows as $row => $vertex) {
@ -1346,19 +1346,19 @@ class Career extends Model
$html .= 'jsPlumb.connect({ $html .= 'jsPlumb.connect({
source:"'.$source.'", source:"'.$source.'",
target:"'.$target.'", target:"'.$target.'",
endpoint:[ "Rectangle", { width:1, height:1 }], endpoint:[ "Rectangle", { width:1, height:1 }],
connector: ["Flowchart"], connector: ["Flowchart"],
paintStyle: connectorPaintStyle, paintStyle: connectorPaintStyle,
hoverPaintStyle: endpointHoverStyle, hoverPaintStyle: endpointHoverStyle,
anchor: ["'.$anchor.'"], anchor: ["'.$anchor.'"],
overlays: [ overlays: [
[ [
"Arrow", "Arrow",
{ {
location:1, location:1,
width:11, width:11,
length:11 length:11
} }
], ],
], ],
});'; });';

@ -1877,11 +1877,11 @@ class ExtraField extends Model
/** /**
* @param array $params * @param array $params
* @param bool $show_query * @param bool $showQuery
* *
* @return int|bool * @return int|bool
*/ */
public function save($params, $show_query = false) public function save($params, $showQuery = false)
{ {
$fieldInfo = self::get_handler_field_info_by_field_variable($params['variable']); $fieldInfo = self::get_handler_field_info_by_field_variable($params['variable']);
$params = $this->clean_parameters($params); $params = $this->clean_parameters($params);
@ -1890,7 +1890,7 @@ class ExtraField extends Model
if ($fieldInfo) { if ($fieldInfo) {
return $fieldInfo['id']; return $fieldInfo['id'];
} else { } else {
$id = parent::save($params, $show_query); $id = parent::save($params, $showQuery);
if ($id) { if ($id) {
$fieldOption = new ExtraFieldOption($this->type); $fieldOption = new ExtraFieldOption($this->type);
$params['field_id'] = $id; $params['field_id'] = $id;

@ -131,7 +131,7 @@ class GradeModel extends Model
$form->addElement('hidden', 'components['.$i.'][id]', null); $form->addElement('hidden', 'components['.$i.'][id]', null);
$template_percentage = $template_percentage =
'<div id='.$i.' style="display: '.(($i <= $nr_items) ? 'inline' : 'none').';" class="form-group"> '<div id='.$i.' style="display: '.(($i <= $nr_items) ? 'inline' : 'none').';" class="form-group">
<label for="" class="col-sm-2 control-label"> <label for="" class="col-sm-2 control-label">
{label} {label}
</label> </label>
@ -212,13 +212,13 @@ class GradeModel extends Model
/** /**
* @param array $params * @param array $params
* @param bool $show_query * @param bool $showQuery
* *
* @return bool * @return bool
*/ */
public function save($params, $show_query = false) public function save($params, $showQuery = false)
{ {
$id = parent::save($params, $show_query); $id = parent::save($params, $showQuery);
if (!empty($id)) { if (!empty($id)) {
foreach ($params['components'] as $component) { foreach ($params['components'] as $component) {
if (!empty($component['title']) && !empty($component['percentage']) && !empty($component['acronym'])) { if (!empty($component['title']) && !empty($component['percentage']) && !empty($component['acronym'])) {

@ -6,7 +6,7 @@
* This class provides a layer to manage images. * This class provides a layer to manage images.
* *
* @author Julio Montoya <gugli100@gmail.com> * @author Julio Montoya <gugli100@gmail.com>
* * @deprecated
* @todo move in a DB configuration setting * @todo move in a DB configuration setting
*/ */
class Image class Image

@ -70,12 +70,12 @@ class Link extends Model
* updating the item_property table. * updating the item_property table.
* *
* @param array $params * @param array $params
* @param bool $show_query Whether to show the query in logs when * @param bool $showQuery Whether to show the query in logs when
* calling parent's save method * calling parent's save method
* *
* @return bool True if link could be saved, false otherwise * @return bool True if link could be saved, false otherwise
*/ */
public function save($params, $show_query = null) public function save($params, $showQuery = null)
{ {
$course_info = $this->getCourse(); $course_info = $this->getCourse();
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
@ -127,13 +127,11 @@ class Link extends Model
// Looking for the largest order number for this category. // Looking for the largest order number for this category.
$link = new CLink(); $link = new CLink();
$link $link
->setCId($course_id)
->setUrl($urllink) ->setUrl($urllink)
->setTitle($title) ->setTitle($title)
->setDescription($description) ->setDescription($description)
->setOnHomepage($onhomepage) ->setOnHomepage($onhomepage)
->setTarget($target) ->setTarget($target)
->setSessionId($session_id)
->setCategory($category) ->setCategory($category)
; ;
@ -317,13 +315,13 @@ class Link extends Model
} }
// Looking for the largest order number for this category. // Looking for the largest order number for this category.
$result = Database:: query( /*$result = Database:: query(
"SELECT MAX(display_order) FROM $tbl_categories "SELECT MAX(display_order) FROM $tbl_categories
WHERE c_id = $course_id " WHERE c_id = $course_id "
); );
list($orderMax) = Database:: fetch_row($result); [$orderMax] = Database:: fetch_row($result);
$order = $orderMax + 1; $order = $orderMax + 1;
$order = (int) $order; $order = (int) $order;*/
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$repo = Container::getLinkCategoryRepository(); $repo = Container::getLinkCategoryRepository();
@ -332,11 +330,9 @@ class Link extends Model
$category = new CLinkCategory(); $category = new CLinkCategory();
$category $category
->setSessionId($session_id)
->setCId($course_id)
->setCategoryTitle($category_title) ->setCategoryTitle($category_title)
->setDescription($description) ->setDescription($description)
->setDisplayOrder($order) // ->setDisplayOrder($order)
->setParent($courseEntity) ->setParent($courseEntity)
->addCourseLink($courseEntity, $sessionEntity) ->addCourseLink($courseEntity, $sessionEntity)
; ;
@ -545,7 +541,7 @@ class Link extends Model
c_id = $course_id AND c_id = $course_id AND
category_id='".intval($values['category_id'])."'"; category_id='".intval($values['category_id'])."'";
$result = Database:: query($sql); $result = Database:: query($sql);
list($max_display_order) = Database:: fetch_row($result); [$max_display_order] = Database:: fetch_row($result);
$max_display_order++; $max_display_order++;
} else { } else {
$max_display_order = $row['display_order']; $max_display_order = $row['display_order'];
@ -563,11 +559,11 @@ class Link extends Model
Database::update( Database::update(
$tbl_link, $tbl_link,
$params, $params,
['c_id = ? AND iid = ?' => [$course_id, $id]] ['iid = ?' => [$course_id, $id]]
); );
// Update search enchine and its values table if enabled. // Update search enchine and its values table if enabled.
if ('true' == api_get_setting('search_enabled')) { if ('true' === api_get_setting('search_enabled')) {
$course_int_id = api_get_course_int_id(); $course_int_id = api_get_course_int_id();
$course_id = api_get_course_id(); $course_id = api_get_course_id();
$link_title = Database:: escape_string($values['title']); $link_title = Database:: escape_string($values['title']);
@ -704,14 +700,6 @@ class Link extends Model
} }
} }
// "WHAT'S NEW" notification: update table last_toolEdit.
api_item_property_update(
$_course,
TOOL_LINK,
$id,
'LinkUpdated',
api_get_user_id()
);
Display::addFlash(Display::return_message(get_lang('The link has been modified.'))); Display::addFlash(Display::return_message(get_lang('The link has been modified.')));
} }
@ -1022,6 +1010,7 @@ class Link extends Model
$linksAdded = []; $linksAdded = [];
foreach ($links as $link) { foreach ($links as $link) {
$linkId = $link->getIid(); $linkId = $link->getIid();
$resourceLink = $link->getFirstResourceLink();
if (in_array($linkId, $linksAdded)) { if (in_array($linkId, $linksAdded)) {
continue; continue;
@ -1036,10 +1025,14 @@ class Link extends Model
} }
// Validation when belongs to a session. // Validation when belongs to a session.
$session_img = api_get_session_image( $session_img = '';
$link->getSessionId(), $session = $resourceLink->getSession();
$_user['status'] if ($session) {
); $session_img = api_get_session_image(
$session->getId(),
$_user['status']
);
}
$toolbar = ''; $toolbar = '';
$link_validator = ''; $link_validator = '';
@ -1063,7 +1056,7 @@ class Link extends Model
] ]
); );
if ($sessionId == $link->getSessionId()) { if ($session && $sessionId == $session->getId()) {
$url = api_get_self().'?'.api_get_cidreq().'&action=editlink&id='.$linkId; $url = api_get_self().'?'.api_get_cidreq().'&action=editlink&id='.$linkId;
$title = get_lang('Edit'); $title = get_lang('Edit');
$toolbar .= Display::toolbarButton( $toolbar .= Display::toolbarButton(
@ -1111,7 +1104,7 @@ class Link extends Model
break; break;
} }
if ($sessionId == $link->getSessionId()) { if ($session && $sessionId == $session->getId()) {
$moveLinkParams = [ $moveLinkParams = [
'id' => $linkId, 'id' => $linkId,
'scope' => 'category', 'scope' => 'category',
@ -1315,7 +1308,7 @@ Do you really want to delete this category and its links ?')."')) return false;\
$sortDirection = 'ASC'; $sortDirection = 'ASC';
} }
$sql = "SELECT id, display_order FROM $movetable $sql = "SELECT id, display_order FROM $tbl_categories
WHERE c_id = $courseId WHERE c_id = $courseId
ORDER BY display_order $sortDirection"; ORDER BY display_order $sortDirection";
$linkresult = Database:: query($sql); $linkresult = Database:: query($sql);
@ -1586,7 +1579,8 @@ Do you really want to delete this category and its links ?')."')) return false;\
if ($showActionLinks) { if ($showActionLinks) {
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
if ($session_id == $category->getSessionId()) { if ($category->getFirstResourceLink() && $category->getFirstResourceLink()->getSession() &&
$session_id == $category->getFirstResourceLink()->getSession()->getId()) {
$header .= $strVisibility; $header .= $strVisibility;
$header .= self::showCategoryAdminTools($category, $counter, count($categories)); $header .= self::showCategoryAdminTools($category, $counter, count($categories));
} else { } else {
@ -1874,18 +1868,18 @@ Do you really want to delete this category and its links ?')."')) return false;\
private static function moveLinkDisplayOrder($id, $direction) private static function moveLinkDisplayOrder($id, $direction)
{ {
$em = Database::getManager(); $em = Database::getManager();
$repo = Container::getLinkRepository();
/** @var CLink $link */ /** @var CLink $link */
$link = $em->find('ChamiloCourseBundle:CLink', $id); $link = $repo->find($id);
if (!$link) { if (!$link) {
return false; return false;
} }
$compareLinks = $em $compareLinks = $repo
->getRepository('ChamiloCourseBundle:CLink')
->findBy( ->findBy(
[ [
'cId' => $link->getCId(),
'categoryId' => $link->getCategory() ? $link->getCategory()->getIid() : 0, 'categoryId' => $link->getCategory() ? $link->getCategory()->getIid() : 0,
], ],
['displayOrder' => $direction] ['displayOrder' => $direction]
@ -1896,7 +1890,7 @@ Do you really want to delete this category and its links ?')."')) return false;\
/** @var CLink $compareLink */ /** @var CLink $compareLink */
foreach ($compareLinks as $compareLink) { foreach ($compareLinks as $compareLink) {
if ($compareLink->getId() !== $link->getId()) { if ($compareLink->getIid() !== $link->getIid()) {
$prevLink = $compareLink; $prevLink = $compareLink;
continue; continue;

@ -152,11 +152,11 @@ class Model
* Saves an element into the DB. * Saves an element into the DB.
* *
* @param array $params * @param array $params
* @param bool $show_query Whether to show the query in logs or not (passed to Database::insert()) * @param bool $showQuery Whether to show the query in logs or not (passed to Database::insert())
* *
* @return bool|int * @return bool|int
*/ */
public function save($params, $show_query = false) public function save($params, $showQuery = false)
{ {
$params = $this->clean_parameters($params); $params = $this->clean_parameters($params);
@ -188,7 +188,7 @@ class Model
} }
if (!empty($params)) { if (!empty($params)) {
$id = Database::insert($this->table, $params, $show_query); $id = Database::insert($this->table, $params, $showQuery);
if (is_numeric($id)) { if (is_numeric($id)) {
return $id; return $id;
} }

@ -288,11 +288,11 @@ class Promotion extends Model
/** /**
* @param array $params * @param array $params
* @param bool $show_query * @param bool $showQuery
* *
* @return bool * @return bool
*/ */
public function save($params, $show_query = false) public function save($params, $showQuery = false)
{ {
$promotion = new \Chamilo\CoreBundle\Entity\Promotion(); $promotion = new \Chamilo\CoreBundle\Entity\Promotion();

@ -76,14 +76,14 @@ class SkillProfile extends Model
* Call the save method of the parent class and the SkillRelProfile object. * Call the save method of the parent class and the SkillRelProfile object.
* *
* @param array $params * @param array $params
* @param bool $show_query Whether to show the query in parent save() method * @param bool $showQuery Whether to show the query in parent save() method
* *
* @return mixed Profile ID or false if incomplete params * @return mixed Profile ID or false if incomplete params
*/ */
public function save($params, $show_query = false) public function save($params, $showQuery = false)
{ {
if (!empty($params)) { if (!empty($params)) {
$profile_id = parent::save($params, $show_query); $profile_id = parent::save($params, $showQuery);
if ($profile_id) { if ($profile_id) {
$skill_rel_profile = new SkillRelProfile(); $skill_rel_profile = new SkillRelProfile();
if (isset($params['skills'])) { if (isset($params['skills'])) {

@ -148,7 +148,7 @@ function get_specific_field_values_list(
} }
/** /**
* @param char $prefix xapian prefix * @param string $prefix xapian prefix
* @param string $course_code * @param string $course_code
* @param string $tool_id Constant from mainapi.lib.php * @param string $tool_id Constant from mainapi.lib.php
* @param int $ref_id representative id inside one tool item * @param int $ref_id representative id inside one tool item

@ -1437,9 +1437,7 @@ class Statistics
*/ */
private static function getLoginsByDate($startDate, $endDate) private static function getLoginsByDate($startDate, $endDate)
{ {
/** @var DateTime $startDate */
$startDate = api_get_utc_datetime("$startDate 00:00:00"); $startDate = api_get_utc_datetime("$startDate 00:00:00");
/** @var DateTime $endDate */
$endDate = api_get_utc_datetime("$endDate 23:59:59"); $endDate = api_get_utc_datetime("$endDate 23:59:59");
if (empty($startDate) || empty($endDate)) { if (empty($startDate) || empty($endDate)) {
@ -1472,8 +1470,7 @@ class Statistics
GROUP BY u.id"; GROUP BY u.id";
$stmt = Database::query($sql); $stmt = Database::query($sql);
$result = Database::store_result($stmt, 'ASSOC');
return $result; return Database::store_result($stmt, 'ASSOC');
} }
} }

@ -3,6 +3,7 @@
/** /**
* Class SubLanguageManager. * Class SubLanguageManager.
* @deprecated
*/ */
class SubLanguageManager class SubLanguageManager
{ {
@ -80,7 +81,7 @@ class SubLanguageManager
$table = Database::get_main_table(TABLE_MAIN_LANGUAGE); $table = Database::get_main_table(TABLE_MAIN_LANGUAGE);
$parent_id = intval($parent_id); $parent_id = intval($parent_id);
$sub_language_id = intval($sub_language_id); $sub_language_id = intval($sub_language_id);
$sql = "SELECT * FROM $table $sql = "SELECT * FROM $table
WHERE WHERE
parent_id = $parent_id AND parent_id = $parent_id AND
id = $sub_language_id"; id = $sub_language_id";

@ -2,6 +2,8 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\SysAnnouncement;
/** /**
* Class SystemAnnouncementManager. * Class SystemAnnouncementManager.
*/ */
@ -92,8 +94,6 @@ class SystemAnnouncementManager
$announcements = Database::query($sql); $announcements = Database::query($sql);
if (Database::num_rows($announcements) > 0) { if (Database::num_rows($announcements) > 0) {
$query_string = ereg_replace('announcement=[1-9]+', '', $_SERVER['QUERY_STRING']);
$query_string = ereg_replace('&$', '', $query_string);
$url = api_get_self(); $url = api_get_self();
echo '<div class="system_announcements">'; echo '<div class="system_announcements">';
echo '<h3>'.get_lang('Portal news').'</h3>'; echo '<h3>'.get_lang('Portal news').'</h3>';
@ -101,11 +101,7 @@ class SystemAnnouncementManager
while ($announcement = Database::fetch_object($announcements)) { while ($announcement = Database::fetch_object($announcements)) {
if ($id != $announcement->id) { if ($id != $announcement->id) {
if (strlen($query_string) > 0) { $show_url = 'news_list.php#'.$announcement->id;
$show_url = 'news_list.php#'.$announcement->id;
} else {
$show_url = 'news_list.php#'.$announcement->id;
}
$display_date = api_convert_and_format_date($announcement->display_date, DATE_FORMAT_LONG); $display_date = api_convert_and_format_date($announcement->display_date, DATE_FORMAT_LONG);
echo '<a name="'.$announcement->id.'"></a> echo '<a name="'.$announcement->id.'"></a>
<div class="system_announcement"> <div class="system_announcement">
@ -119,7 +115,7 @@ class SystemAnnouncementManager
echo '<div class="system_announcement"> echo '<div class="system_announcement">
<div class="system_announcement_title">' <div class="system_announcement_title">'
.$announcement->display_date.' .$announcement->display_date.'
<a name="ann'.$announcement->id.'" href="'.$url.'?'.$query_string.'#ann'.$announcement->id.'">'. <a name="ann'.$announcement->id.'" href="'.$url.'?#ann'.$announcement->id.'">'.
$announcement->title.' $announcement->title.'
</a> </a>
</div>'; </div>';
@ -607,7 +603,7 @@ class SystemAnnouncementManager
$promotionId = 0 $promotionId = 0
) { ) {
$em = Database::getManager(); $em = Database::getManager();
$announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); $announcement = $em->find(SysAnnouncement::class, $id);
if (!$announcement) { if (!$announcement) {
return false; return false;
} }
@ -931,7 +927,7 @@ class SystemAnnouncementManager
* @param string $visible see self::VISIBLE_* constants * @param string $visible see self::VISIBLE_* constants
* @param int $id The identifier of the announcement to display * @param int $id The identifier of the announcement to display
* *
* @return string * @return array
*/ */
public static function getAnnouncements($visible, $id = null): array public static function getAnnouncements($visible, $id = null): array
{ {

@ -106,7 +106,7 @@ class Timeline extends Model
* @param string url * @param string url
* @param string action add, edit * @param string action add, edit
* *
* @return obj form validator obj * @return FormValidator
*/ */
public function return_form($url, $action) public function return_form($url, $action)
{ {

@ -1314,11 +1314,11 @@ class UserGroup extends Model
/** /**
* @param $params * @param $params
* @param bool $show_query * @param bool $showQuery
* *
* @return bool|int * @return bool|int
*/ */
public function save($params, $show_query = false) public function save($params, $showQuery = false)
{ {
$params['updated_at'] = $params['created_at'] = api_get_utc_datetime(); $params['updated_at'] = $params['created_at'] = api_get_utc_datetime();
$params['group_type'] = isset($params['group_type']) ? self::SOCIAL_CLASS : self::NORMAL_CLASS; $params['group_type'] = isset($params['group_type']) ? self::SOCIAL_CLASS : self::NORMAL_CLASS;
@ -1329,7 +1329,7 @@ class UserGroup extends Model
if ($this->allowTeachers()) { if ($this->allowTeachers()) {
$params['author_id'] = api_get_user_id(); $params['author_id'] = api_get_user_id();
} }
$id = parent::save($params, $show_query); $id = parent::save($params, $showQuery);
if ($id) { if ($id) {
if ($this->getUseMultipleUrl()) { if ($this->getUseMultipleUrl()) {
$this->subscribeToUrl($id, api_get_current_access_url_id()); $this->subscribeToUrl($id, api_get_current_access_url_id());

@ -5,6 +5,7 @@
namespace Chamilo\CoreBundle\Entity; namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/** /**
* SysAnnouncement. * SysAnnouncement.
@ -82,6 +83,8 @@ class SysAnnouncement
/** /**
* @var string * @var string
* *
* @Assert\NotBlank()
*
* @ORM\Column(name="title", type="string", length=250, nullable=false) * @ORM\Column(name="title", type="string", length=250, nullable=false)
*/ */
protected $title; protected $title;
@ -89,6 +92,8 @@ class SysAnnouncement
/** /**
* @var string * @var string
* *
* @Assert\NotBlank()
*
* @ORM\Column(name="content", type="text", nullable=false) * @ORM\Column(name="content", type="text", nullable=false)
*/ */
protected $content; protected $content;

@ -12,6 +12,7 @@ use Chamilo\CoreBundle\Repository\CourseRepository;
use Chamilo\CoreBundle\Repository\IllustrationRepository; use Chamilo\CoreBundle\Repository\IllustrationRepository;
use Chamilo\CoreBundle\Repository\SequenceRepository; use Chamilo\CoreBundle\Repository\SequenceRepository;
use Chamilo\CoreBundle\Repository\SequenceResourceRepository; use Chamilo\CoreBundle\Repository\SequenceResourceRepository;
use Chamilo\CoreBundle\Repository\SessionRepository;
use Chamilo\CoreBundle\Repository\UserRepository; use Chamilo\CoreBundle\Repository\UserRepository;
use Chamilo\CoreBundle\ToolChain; use Chamilo\CoreBundle\ToolChain;
use Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository; use Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository;
@ -329,6 +330,14 @@ class Container
return self::$container->get(CourseRepository::class); return self::$container->get(CourseRepository::class);
} }
/**
* @return SessionRepository
*/
public static function getSessionRepository()
{
return self::$container->get(SessionRepository::class);
}
/** /**
* @return CourseCategoryRepository|object|null * @return CourseCategoryRepository|object|null
*/ */

@ -35,9 +35,3 @@ services:
# arguments: # arguments:
# $entityName: 'Chamilo\CoreBundle\Entity\Illustration' # $entityName: 'Chamilo\CoreBundle\Entity\Illustration'
# $repository: 'Chamilo\CoreBundle\Repository\IllustrationRepository' # $repository: 'Chamilo\CoreBundle\Repository\IllustrationRepository'
# Entity repository as a service
# Event Listeners

Loading…
Cancel
Save