Internal: Add psalm checks, fix deprecated code.

pull/3513/head
Julio Montoya 4 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. 192
      public/main/inc/lib/api.lib.php
  7. 2
      public/main/inc/lib/attendance.lib.php
  8. 10
      public/main/inc/lib/career.lib.php
  9. 6
      public/main/inc/lib/extra_field.lib.php
  10. 6
      public/main/inc/lib/grade_model.lib.php
  11. 2
      public/main/inc/lib/image.lib.php
  12. 56
      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. 1
      public/main/inc/lib/sub_language.class.php
  19. 14
      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/session" /> -->
<!-- <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_courses_to_session_functions.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/career.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/sessionmanager.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/social.lib.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/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/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/usergroup.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/VideoChat.php"/>
<ignoreFiles>
<directory name="vendor/*"/>

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\GradebookLink;
use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CForumAttachment;
@ -1042,7 +1043,7 @@ function delete_post($post_id)
$em = Database::getManager();
/** @var CForumPost $post */
$post = $em
->getRepository('ChamiloCourseBundle:CForumPost')
->getRepository(CForumPost::class)
->findOneBy(['cId' => $course_id, 'iid' => $post_id]);
if ($post) {
@ -1915,7 +1916,7 @@ function get_threads($forumId, $courseId = null, $sessionId = null)
*/
function getThreadInfo($threadId, $cId)
{
$repo = Database::getManager()->getRepository('ChamiloCourseBundle:CForumThread');
$repo = Database::getManager()->getRepository(CForumThread::class);
/** @var CForumThread $forumThread */
$forumThread = $repo->findOneBy(['iid' => $threadId, 'cId' => $cId]);
@ -1994,7 +1995,7 @@ function getPosts(
$criteria->andWhere(Criteria::expr()->eq('postParentId', $postId));
}
$qb = $em->getRepository('ChamiloCourseBundle:CForumPost')->createQueryBuilder('p');
$qb = $em->getRepository(CForumPost::class)->createQueryBuilder('p');
$qb->select('p')
->addCriteria($criteria)
->addOrderBy('p.iid', $orderDirection);
@ -2380,7 +2381,7 @@ function updateThread($values)
$gradebookLink = null;
$em = Database::getManager();
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
@ -2710,7 +2711,7 @@ function store_thread(
*
* @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();
$action = isset($action) ? Security::remove_XSS($action) : '';
@ -3680,7 +3681,7 @@ function show_edit_post_form(
$post,
$thread,
$forum,
$form_values = '',
$form_values,
$id_attach = 0
) {
// 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).
*
* @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
*
@ -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
* was added to a given thread.
*
* @param array $forum reply information
*/
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));
}
$qb = $em->getRepository('ChamiloCourseBundle:CForumPost')->createQueryBuilder('p');
$qb = $em->getRepository(CForumPost::class)->createQueryBuilder('p');
$qb->select('count(p.iid)')
->addCriteria($criteria);

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

@ -462,6 +462,7 @@ class AnnouncementManager
return '';
}
$stok = null;
$html = '';
$course = api_get_course_entity(api_get_course_int_id());
$session = api_get_session_entity(api_get_session_id());
@ -499,7 +500,6 @@ class AnnouncementManager
$alt_visibility = get_lang('Hide');
$setNewStatus = 'invisible';
}
global $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>";
@ -817,14 +817,14 @@ class AnnouncementManager
$sentToAllGroup = false;
if (empty($send_to_users['groups']) && empty($send_to_users['users'])) {
$groupInfo = GroupManager::get_group_properties($groupId);
api_item_property_update(
/*api_item_property_update(
$courseInfo,
TOOL_ANNOUNCEMENT,
$last_id,
'AnnouncementAdded',
api_get_user_id(),
$groupInfo
);
);*/
$sentToAllGroup = true;
}
@ -832,21 +832,21 @@ class AnnouncementManager
if (!empty($send_to_users['groups'])) {
foreach ($send_to_users['groups'] as $group) {
$groupInfo = GroupManager::get_group_properties($group);
api_item_property_update(
/*api_item_property_update(
$courseInfo,
TOOL_ANNOUNCEMENT,
$last_id,
'AnnouncementAdded',
api_get_user_id(),
$groupInfo
);
);*/
}
}
$groupInfo = GroupManager::get_group_properties($groupId);
if (!empty($send_to_users['users'])) {
foreach ($send_to_users['users'] as $user) {
api_item_property_update(
/*api_item_property_update(
$courseInfo,
TOOL_ANNOUNCEMENT,
$last_id,
@ -854,7 +854,7 @@ class AnnouncementManager
api_get_user_id(),
$groupInfo,
$user
);
);*/
}
}
}
@ -1171,7 +1171,7 @@ class AnnouncementManager
$result['users'][] = $link->getUser()->getId();
}
if ($link->getGroup()) {
$result['groups'][] = $link->getGroup()->getId();
$result['groups'][] = $link->getGroup()->getIid();
}
}
@ -1462,6 +1462,9 @@ class AnnouncementManager
$file,
$file_comment
) {
// @todo fix edition
exit;
/*
$courseInfo = api_get_course_info();
$table = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
$return = 0;
@ -1514,7 +1517,7 @@ class AnnouncementManager
}
}
return $return;
return $return;*/
}
/**
@ -2141,129 +2144,6 @@ class AnnouncementManager
$qb->select('count(resource)');
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\Course;
use Chamilo\CoreBundle\Entity\Language;
use Chamilo\CoreBundle\Entity\Session as SessionEntity;
use Chamilo\CoreBundle\Entity\SettingsCurrent;
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 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
*
@ -1176,45 +1177,45 @@ function api_get_navigator()
if (false !== strpos($_SERVER['HTTP_USER_AGENT'], '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')) {
$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')) {
$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')) {
$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')) {
$navigator = 'Safari';
if (false !== stripos($_SERVER['HTTP_USER_AGENT'], 'Version/')) {
// If this Safari does have the "Version/" string in its user agent
// then use that as a version indicator rather than what's after
// "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 {
list(, $version) = explode('Safari/', $_SERVER['HTTP_USER_AGENT']);
[, $version] = explode('Safari/', $_SERVER['HTTP_USER_AGENT']);
}
} elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], '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')) {
$navigator = '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 {
list(, $version) = explode('Navigator', $_SERVER['HTTP_USER_AGENT']);
[, $version] = explode('Navigator', $_SERVER['HTTP_USER_AGENT']);
}
} elseif (false !== strpos($_SERVER['HTTP_USER_AGENT'], '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')) {
$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')) {
$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
@ -2260,24 +2261,20 @@ function api_get_course_info($course_code = null)
/**
* @param int $courseId
*
* @return Course
*/
function api_get_course_entity($courseId = 0)
function api_get_course_entity($courseId = 0): ?Course
{
if (empty($courseId)) {
$courseId = api_get_course_int_id();
}
return CourseManager::getManager()->find($courseId);
return Container::getCourseRepository()->find($courseId);
}
/**
* @param int $id
*
* @return SessionEntity|null
*/
function api_get_session_entity($id = 0)
function api_get_session_entity($id = 0): ?SessionEntity
{
if (empty($id)) {
$id = api_get_session_id();
@ -2287,21 +2284,19 @@ function api_get_session_entity($id = 0)
return null;
}
return Database::getManager()->getRepository('ChamiloCoreBundle:Session')->find($id);
return Container::getSessionRepository()->find($id);
}
/**
* @param int $id
*
* @return CGroup
*/
function api_get_group_entity($id = 0)
function api_get_group_entity($id = 0): ?CGroup
{
if (empty($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)
{
list($last_post_date, $last_post_time) = explode(' ', $last_post_datetime);
list($year, $month, $day) = explode('-', $last_post_date);
list($hour, $min, $sec) = explode(':', $last_post_time);
[$last_post_date, $last_post_time] = explode(' ', $last_post_datetime);
[$year, $month, $day] = explode('-', $last_post_date);
[$hour, $min, $sec] = explode(':', $last_post_time);
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 [];
}
$language = Database::getManager()
->find('ChamiloCoreBundle:Language', $languageId);
$language = Database::getManager()->find(Language::class, $languageId);
if (!$language) {
return [];
@ -4445,13 +4439,13 @@ function api_get_language_info($languageId)
/**
* @param string $code
*
* @return \Chamilo\CoreBundle\Entity\Language
* @return Language
*/
function api_get_language_from_iso($code)
{
$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');
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.
if (!$lp_theme_config) {
if (!empty($lp_theme_css)) {
// LP's theme.
$visual_theme = $lp_theme_css;
}
}
}*/
}
}
}
@ -4525,10 +4519,10 @@ function api_get_visual_theme()
$visual_theme = 'chamilo';
}
global $lp_theme_log;
/*global $lp_theme_log;
if ($lp_theme_log) {
$visual_theme = $platform_theme;
}
}*/
}
return $visual_theme;
@ -4928,10 +4922,8 @@ function copy_folder_course_session(
];
$document_id = Database::insert($table, $params);
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,
TOOL_DOCUMENT,
$document_id,
@ -4942,7 +4934,7 @@ function copy_folder_course_session(
null,
null,
$session_id
);
);*/
}
}
}
@ -5567,7 +5559,8 @@ function api_add_setting(
$visibility = 0
) {
$em = Database::getManager();
$settingRepo = $em->getRepository('ChamiloCoreBundle:SettingsCurrent');
$settingRepo = $em->getRepository(SettingsCurrent::class);
$accessUrlId = (int) $accessUrlId ?: 1;
if (is_array($value)) {
@ -7084,7 +7077,7 @@ function api_check_ip_in_range($ip, $range)
continue; //otherwise, get to the next range
}
// the range contains a "/", so analyse completely
list($net, $mask) = explode("/", $range);
[$net, $mask] = explode("/", $range);
$ip_net = ip2long($net);
// mask binary magic
@ -7120,15 +7113,15 @@ function api_is_global_chat_enabled()
}
/**
* @todo Fix tool_visible_by_default_at_creation labels
* @todo Add sessionId parameter to avoid using context
*
* @param int $item_id
* @param int $tool_id
* @param int $group_id id
* @param array $courseInfo
* @param int $sessionId
* @param int $userId
*
* @deprecated
*
*/
function api_set_default_visibility(
$item_id,
@ -7193,7 +7186,7 @@ function api_set_default_visibility(
$visibility = DocumentManager::getDocumentDefaultVisibility($courseInfo);
}
api_item_property_update(
/*api_item_property_update(
$courseInfo,
$original_tool_id,
$item_id,
@ -7204,7 +7197,7 @@ function api_set_default_visibility(
null,
null,
$sessionId
);
);*/
// Fixes default visibility for tests
switch ($original_tool_id) {
@ -7755,42 +7748,6 @@ function api_is_allowed_in_course()
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.
*
@ -7799,7 +7756,7 @@ function api_get_firstpage_parameter()
function api_is_https()
{
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;
} else {
@ -8708,7 +8665,12 @@ function api_unserialize_content($type, $serialized, $ignoreErrors = false)
switch ($type) {
case 'career':
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;
case 'lp':
$allowedClasses = [
@ -8730,34 +8692,34 @@ function api_unserialize_content($type, $serialized, $ignoreErrors = false)
break;
case 'course':
$allowedClasses = [
Course::class,
Announcement::class,
Attendance::class,
CalendarEvent::class,
CourseCopyLearnpath::class,
CourseCopyTestCategory::class,
CourseDescription::class,
CourseSession::class,
Document::class,
Forum::class,
ForumCategory::class,
ForumPost::class,
ForumTopic::class,
Glossary::class,
GradeBookBackup::class,
Link::class,
LinkCategory::class,
Quiz::class,
QuizQuestion::class,
QuizQuestionOption::class,
ScormDocument::class,
Survey::class,
SurveyInvitation::class,
SurveyQuestion::class,
Thematic::class,
ToolIntro::class,
Wiki::class,
Work::class,
\Chamilo\CourseBundle\Component\CourseCopy\Course::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Announcement::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Attendance::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\CalendarEvent::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseCopyLearnpath::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseCopyTestCategory::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseDescription::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseSession::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Document::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Forum::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumCategory::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumPost::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumTopic::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Glossary::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\GradeBookBackup::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Link::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\LinkCategory::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Quiz::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestion::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestionOption::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\ScormDocument::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Survey::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\SurveyInvitation::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\SurveyQuestion::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Thematic::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\ToolIntro::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Wiki::class,
\Chamilo\CourseBundle\Component\CourseCopy\Resources\Work::class,
stdClass::class,
];
break;
@ -8767,13 +8729,13 @@ function api_unserialize_content($type, $serialized, $ignoreErrors = false)
}
if ($ignoreErrors) {
return @Unserialize::unserialize(
return @UnserializeApi::unserialize(
$serialized,
['allowed_classes' => $allowedClasses]
);
}
return Unserialize::unserialize(
return UnserializeApi::unserialize(
$serialized,
['allowed_classes' => $allowedClasses]
);

@ -252,7 +252,7 @@ class Attendance
$is_done_all_calendar = self::is_all_attendance_calendar_done($id);
if ($is_done_all_calendar) {
$locked = $attendance[4];
$locked = $attendance->getLocked();
if (0 == $locked) {
if (api_is_platform_admin()) {
$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)
{
$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'";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$data = Database::fetch_array($result);
return $data['status'];
} else {
return false;
}
return false;
}
/**
* @param array $params
* @param bool $show_query
* @param bool $showQuery
*
* @return int
*/
public function save($params, $show_query = false)
public function save($params, $showQuery = false)
{
$career = new \Chamilo\CoreBundle\Entity\Career();
$career

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

@ -212,13 +212,13 @@ class GradeModel extends Model
/**
* @param array $params
* @param bool $show_query
* @param bool $showQuery
*
* @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)) {
foreach ($params['components'] as $component) {
if (!empty($component['title']) && !empty($component['percentage']) && !empty($component['acronym'])) {

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

@ -70,12 +70,12 @@ class Link extends Model
* updating the item_property table.
*
* @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
*
* @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_id = $course_info['real_id'];
@ -127,13 +127,11 @@ class Link extends Model
// Looking for the largest order number for this category.
$link = new CLink();
$link
->setCId($course_id)
->setUrl($urllink)
->setTitle($title)
->setDescription($description)
->setOnHomepage($onhomepage)
->setTarget($target)
->setSessionId($session_id)
->setCategory($category)
;
@ -317,13 +315,13 @@ class Link extends Model
}
// Looking for the largest order number for this category.
$result = Database:: query(
/*$result = Database:: query(
"SELECT MAX(display_order) FROM $tbl_categories
WHERE c_id = $course_id "
);
list($orderMax) = Database:: fetch_row($result);
[$orderMax] = Database:: fetch_row($result);
$order = $orderMax + 1;
$order = (int) $order;
$order = (int) $order;*/
$session_id = api_get_session_id();
$repo = Container::getLinkCategoryRepository();
@ -332,11 +330,9 @@ class Link extends Model
$category = new CLinkCategory();
$category
->setSessionId($session_id)
->setCId($course_id)
->setCategoryTitle($category_title)
->setDescription($description)
->setDisplayOrder($order)
// ->setDisplayOrder($order)
->setParent($courseEntity)
->addCourseLink($courseEntity, $sessionEntity)
;
@ -545,7 +541,7 @@ class Link extends Model
c_id = $course_id AND
category_id='".intval($values['category_id'])."'";
$result = Database:: query($sql);
list($max_display_order) = Database:: fetch_row($result);
[$max_display_order] = Database:: fetch_row($result);
$max_display_order++;
} else {
$max_display_order = $row['display_order'];
@ -563,11 +559,11 @@ class Link extends Model
Database::update(
$tbl_link,
$params,
['c_id = ? AND iid = ?' => [$course_id, $id]]
['iid = ?' => [$course_id, $id]]
);
// 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_id = api_get_course_id();
$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.')));
}
@ -1022,6 +1010,7 @@ class Link extends Model
$linksAdded = [];
foreach ($links as $link) {
$linkId = $link->getIid();
$resourceLink = $link->getFirstResourceLink();
if (in_array($linkId, $linksAdded)) {
continue;
@ -1036,10 +1025,14 @@ class Link extends Model
}
// Validation when belongs to a session.
$session_img = '';
$session = $resourceLink->getSession();
if ($session) {
$session_img = api_get_session_image(
$link->getSessionId(),
$session->getId(),
$_user['status']
);
}
$toolbar = '';
$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;
$title = get_lang('Edit');
$toolbar .= Display::toolbarButton(
@ -1111,7 +1104,7 @@ class Link extends Model
break;
}
if ($sessionId == $link->getSessionId()) {
if ($session && $sessionId == $session->getId()) {
$moveLinkParams = [
'id' => $linkId,
'scope' => 'category',
@ -1315,7 +1308,7 @@ Do you really want to delete this category and its links ?')."')) return false;\
$sortDirection = 'ASC';
}
$sql = "SELECT id, display_order FROM $movetable
$sql = "SELECT id, display_order FROM $tbl_categories
WHERE c_id = $courseId
ORDER BY display_order $sortDirection";
$linkresult = Database:: query($sql);
@ -1586,7 +1579,8 @@ Do you really want to delete this category and its links ?')."')) return false;\
if ($showActionLinks) {
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 .= self::showCategoryAdminTools($category, $counter, count($categories));
} else {
@ -1874,18 +1868,18 @@ Do you really want to delete this category and its links ?')."')) return false;\
private static function moveLinkDisplayOrder($id, $direction)
{
$em = Database::getManager();
$repo = Container::getLinkRepository();
/** @var CLink $link */
$link = $em->find('ChamiloCourseBundle:CLink', $id);
$link = $repo->find($id);
if (!$link) {
return false;
}
$compareLinks = $em
->getRepository('ChamiloCourseBundle:CLink')
$compareLinks = $repo
->findBy(
[
'cId' => $link->getCId(),
'categoryId' => $link->getCategory() ? $link->getCategory()->getIid() : 0,
],
['displayOrder' => $direction]
@ -1896,7 +1890,7 @@ Do you really want to delete this category and its links ?')."')) return false;\
/** @var CLink $compareLink */
foreach ($compareLinks as $compareLink) {
if ($compareLink->getId() !== $link->getId()) {
if ($compareLink->getIid() !== $link->getIid()) {
$prevLink = $compareLink;
continue;

@ -152,11 +152,11 @@ class Model
* Saves an element into the DB.
*
* @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
*/
public function save($params, $show_query = false)
public function save($params, $showQuery = false)
{
$params = $this->clean_parameters($params);
@ -188,7 +188,7 @@ class Model
}
if (!empty($params)) {
$id = Database::insert($this->table, $params, $show_query);
$id = Database::insert($this->table, $params, $showQuery);
if (is_numeric($id)) {
return $id;
}

@ -288,11 +288,11 @@ class Promotion extends Model
/**
* @param array $params
* @param bool $show_query
* @param bool $showQuery
*
* @return bool
*/
public function save($params, $show_query = false)
public function save($params, $showQuery = false)
{
$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.
*
* @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
*/
public function save($params, $show_query = false)
public function save($params, $showQuery = false)
{
if (!empty($params)) {
$profile_id = parent::save($params, $show_query);
$profile_id = parent::save($params, $showQuery);
if ($profile_id) {
$skill_rel_profile = new SkillRelProfile();
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 $tool_id Constant from mainapi.lib.php
* @param int $ref_id representative id inside one tool item

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

@ -3,6 +3,7 @@
/**
* Class SubLanguageManager.
* @deprecated
*/
class SubLanguageManager
{

@ -2,6 +2,8 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\SysAnnouncement;
/**
* Class SystemAnnouncementManager.
*/
@ -92,8 +94,6 @@ class SystemAnnouncementManager
$announcements = Database::query($sql);
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();
echo '<div class="system_announcements">';
echo '<h3>'.get_lang('Portal news').'</h3>';
@ -101,11 +101,7 @@ class SystemAnnouncementManager
while ($announcement = Database::fetch_object($announcements)) {
if ($id != $announcement->id) {
if (strlen($query_string) > 0) {
$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);
echo '<a name="'.$announcement->id.'"></a>
<div class="system_announcement">
@ -119,7 +115,7 @@ class SystemAnnouncementManager
echo '<div class="system_announcement">
<div class="system_announcement_title">'
.$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.'
</a>
</div>';
@ -607,7 +603,7 @@ class SystemAnnouncementManager
$promotionId = 0
) {
$em = Database::getManager();
$announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id);
$announcement = $em->find(SysAnnouncement::class, $id);
if (!$announcement) {
return false;
}
@ -931,7 +927,7 @@ class SystemAnnouncementManager
* @param string $visible see self::VISIBLE_* constants
* @param int $id The identifier of the announcement to display
*
* @return string
* @return array
*/
public static function getAnnouncements($visible, $id = null): array
{

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

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

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

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

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

Loading…
Cancel
Save