Internal - Add psalm checks, fix/use entity calls

pull/3543/head
Julio Montoya 5 years ago
parent 2540011186
commit cb952ce49f
  1. 6
      psalm.xml
  2. 5
      public/main/calendar/agenda.php
  3. 86
      public/main/forum/forumfunction.inc.php
  4. 73
      public/main/forum/forumqualify.php
  5. 18
      public/main/forum/forumsearch.php
  6. 10
      public/main/forum/viewforum.php
  7. 13
      public/main/forum/viewforumcategory.php
  8. 20
      public/main/forum/viewthread.php
  9. 82
      public/main/inc/lib/agenda.lib.php
  10. 15
      src/CoreBundle/Entity/User.php
  11. 19
      src/CourseBundle/Entity/CForumForum.php
  12. 3
      src/CourseBundle/Entity/CForumThread.php

@ -24,10 +24,9 @@
<file name="public/main/exercise/oral_expression.class.php"/>
<file name="public/main/exercise/exercise.class.php"/>
<directory name="public/main/group"/>
<directory name="public/main/gradebook"/>
<!-- <directory name="public/main/forum"/>-->
<directory name="public/main/group"/>
<directory name="public/main/forum"/>
<directory name="public/main/link" />
<!-- <directory name="public/main/lp"/>-->
<!-- <directory name="public/main/session" />-->
@ -134,6 +133,7 @@
<directory name="src/GraphQlBundle"/>
<directory name="src/LtiBundle"/>
<file name="public/main/forum/forumfunction.inc.php"/>
<file name="public/main/admin/index.php"/>
<file name="public/main/admin/db.php"/>

@ -265,10 +265,7 @@ if ($allowToEdit) {
if (!empty($deleteAttachmentList)) {
foreach ($deleteAttachmentList as $deleteAttachmentId => $value) {
$agenda->deleteAttachmentFile(
$deleteAttachmentId,
$agenda->course
);
$agenda->deleteAttachmentFile($deleteAttachmentId);
}
}

@ -1020,7 +1020,7 @@ function delete_post($post_id)
/** @var CForumPost $post */
$post = $em
->getRepository(CForumPost::class)
->findOneBy(['cId' => $course_id, 'iid' => $post_id]);
->findOneBy(['iid' => $post_id]);
if ($post) {
$em
@ -3201,7 +3201,7 @@ function newThread(CForumForum $forum, $form_values = '', $showPreview = true)
}
/**
* @param array $threadInfo
* @param CForumThread $threadInfo
* @param int $user_id
* @param int $thread_id
* @param int $thread_qualify
@ -3215,7 +3215,7 @@ function newThread(CForumForum $forum, $form_values = '', $showPreview = true)
* @version October 2008, dokeos 1.8.6
*/
function saveThreadScore(
$threadInfo,
CForumThread $threadEntity,
$user_id,
$thread_id,
$thread_qualify = 0,
@ -3223,7 +3223,6 @@ function saveThreadScore(
$session_id = 0
) {
$table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
$table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
$course_id = api_get_course_int_id();
$session_id = (int) $session_id;
@ -3233,24 +3232,20 @@ function saveThreadScore(
$thread_id == (string) ((int) $thread_id) &&
$thread_qualify == (string) ((float) $thread_qualify)
) {
// Testing
$sql = "SELECT thread_qualify_max FROM $table_threads
WHERE c_id = $course_id AND thread_id=".$thread_id;
$res_string = Database::query($sql);
$row_string = Database::fetch_array($res_string);
if ($thread_qualify <= $row_string[0]) {
if (0 == $threadInfo['thread_peer_qualify']) {
$max = $threadEntity->getThreadQualifyMax();
if ($thread_qualify <= $max) {
if ($threadEntity->isThreadPeerQualify()) {
$sql = "SELECT COUNT(*) FROM $table_threads_qualify
WHERE
c_id = $course_id AND
user_id = $user_id AND
qualify_user_id = $currentUserId AND
thread_id = ".$thread_id;
} else {
$sql = "SELECT COUNT(*) FROM $table_threads_qualify
WHERE
c_id = $course_id AND
user_id = $user_id AND
qualify_user_id = $currentUserId AND
thread_id = ".$thread_id;
}
@ -3261,8 +3256,6 @@ function saveThreadScore(
$sql = "INSERT INTO $table_threads_qualify (c_id, user_id, thread_id,qualify,qualify_user_id,qualify_time,session_id)
VALUES (".$course_id.", '".$user_id."','".$thread_id."',".(float) $thread_qualify.", '".$currentUserId."','".$qualify_time."','".$session_id."')";
Database::query($sql);
$insertId = Database::insert_id();
return 'insert';
} else {
saveThreadScoreHistory(
@ -4086,18 +4079,18 @@ function approve_post($post_id, $action)
$table_posts = Database::get_course_table(TABLE_FORUM_POST);
$course_id = api_get_course_int_id();
if ('invisible' == $action) {
if ('invisible' === $action) {
$visibility_value = 0;
}
if ('visible' == $action) {
if ('visible' === $action) {
$visibility_value = 1;
handle_mail_cue('post', $post_id);
}
$sql = "UPDATE $table_posts SET
visible='".Database::escape_string($visibility_value)."'
WHERE c_id = $course_id AND post_id='".Database::escape_string($post_id)."'";
WHERE post_id='".Database::escape_string($post_id)."'";
$return = Database::query($sql);
if ($return) {
@ -4638,8 +4631,8 @@ function store_move_thread($values)
Database::query($sql);
// Fix group id, if forum is moved to a different group
if (!empty($forumInfo['to_group_id'])) {
/*$groupId = $forumInfo['to_group_id'];
/*if (!empty($forumInfo['to_group_id'])) {
$groupId = $forumInfo['to_group_id'];
$item = api_get_item_property_info(
$courseId,
TABLE_FORUM_THREAD,
@ -4672,8 +4665,8 @@ function store_move_thread($values)
$sessionCondition
";
Database::query($sql);
}*/
}
}*/
return get_lang('Thread moved');
}
@ -5814,9 +5807,9 @@ function get_all_post_from_user($user_id, $courseId)
$forum_results .= '<div id="social-forum">';
$forum_results .= '<div class="clear"></div><br />';
$forum_results .= '<div id="social-forum-title">'.
Display::return_icon('forum.gif', get_lang('Forum')).'&nbsp;'.Security::remove_XSS($forum['forum_title'], STUDENT).
Display::return_icon('forum.gif', get_lang('Forum')).'&nbsp;'.Security::remove_XSS($forum->getForumTitle(), STUDENT).
'<div style="float:right;margin-top:-35px">
<a href="../forum/viewforum.php?'.api_get_cidreq_params($courseId).'&forum='.$forum['forum_id'].' " >'.
<a href="../forum/viewforum.php?'.api_get_cidreq_params($courseId).'&forum='.$forum->getIid().' " >'.
get_lang('See forum').'
</a>
</div></div>';
@ -5960,8 +5953,8 @@ function forumRecursiveSort($rows, &$threads, $seed = 0, $indent = 0)
* Update forum attachment data, used to update comment and post ID.
*
* @param array $array (field => value) to update forum attachment row
* @param attach $id ID to find row to update
* @param null $courseId course ID to find row to update
* @param int $id ID to find row to update
* @param int $courseId course ID to find row to update
*
* @return int number of affected rows
*/
@ -6439,28 +6432,22 @@ function postIsEditableByStudent($forum, $post)
}
/**
* @param int $postId
* @param CForumPost $post
*
* @return bool
*/
function savePostRevision($postId)
function savePostRevision(CForumPost $post)
{
$postData = get_post_information($postId);
if (empty($postData)) {
return false;
}
$userId = api_get_user_id();
if ($postData['poster_id'] != $userId) {
if ($post->getPosterId() != $userId) {
return false;
}
$status = (int) !postNeedsRevision($postId);
$status = (int) !postNeedsRevision($post);
$extraFieldValue = new ExtraFieldValue('forum_post');
$params = [
'item_id' => $postId,
'item_id' => $post->getIid(),
'extra_ask_for_revision' => ['extra_ask_for_revision' => $status],
];
if (empty($status)) {
@ -6494,13 +6481,9 @@ function getPostRevision($postId)
return $revision;
}
/**
* @param int $postId
*
* @return bool
*/
function postNeedsRevision($postId)
function postNeedsRevision(CForumPost $post): bool
{
$postId = $post->getIid();
$extraFieldValue = new ExtraFieldValue('forum_post');
$value = $extraFieldValue->get_values_by_handler_and_field_variable(
$postId,
@ -6515,21 +6498,21 @@ function postNeedsRevision($postId)
}
/**
* @param int $postId
* @param CForumPost $post
* @param array $threadInfo
*
* @return string
*/
function getAskRevisionButton($postId, $threadInfo)
function getAskRevisionButton(CForumPost $post, $threadInfo)
{
if (false === api_get_configuration_value('allow_forum_post_revisions')) {
return '';
}
$postId = (int) $postId;
$postId = $post->getIid();
$status = 'btn-default';
if (postNeedsRevision($postId)) {
if (postNeedsRevision($post)) {
$status = 'btn-success';
}
@ -6651,13 +6634,13 @@ function getReportRecipients()
}
/**
* @param int $postId
* @param CForumPost $post
* @param array $forumInfo
* @param array $threadInfo
*
* @return bool
*/
function reportPost($postId, $forumInfo, $threadInfo)
function reportPost(CForumPost $post, $forumInfo, $threadInfo)
{
if (!reportAvailable()) {
return false;
@ -6667,18 +6650,15 @@ function reportPost($postId, $forumInfo, $threadInfo)
return false;
}
$postId = (int) $postId;
$postId = $post->getIid();
$postData = get_post_information($postId);
$currentUser = api_get_user_info();
if (!empty($postData)) {
$users = getReportRecipients();
if (!empty($users)) {
$url = api_get_path(WEB_CODE_PATH).
'forum/viewthread.php?forum='.$threadInfo['forum_id'].'&thread='.$threadInfo['thread_id'].'&'.api_get_cidreq().'&post_id='.$postId.'#post_id_'.$postId;
$postLink = Display::url(
$postData['post_title'],
$post->getPostTitle(),
$url
);
$subject = get_lang('Post reported');
@ -6692,5 +6672,5 @@ function reportPost($postId, $forumInfo, $threadInfo)
MessageManager::send_message_simple($userId, $subject, $content);
}
}
}
}

@ -2,9 +2,14 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CForumForum;
use Chamilo\CourseBundle\Entity\CForumThread;
/**
* @todo fix all this qualify files avoid including files, use classes POO jmontoya
*/
require_once __DIR__.'/../inc/global.inc.php';
require_once 'forumfunction.inc.php';
@ -19,20 +24,26 @@ $origin = api_get_origin();
$currentUserId = api_get_user_id();
$userIdToQualify = isset($_GET['user_id']) ? (int) ($_GET['user_id']) : null;
$forumId = isset($_GET['forum']) ? (int) ($_GET['forum']) : 0;
api_block_course_item_locked_by_gradebook($_GET['thread'], LINK_FORUM_THREAD);
$threadId = isset($_GET['thread']) ? (int) ($_GET['thread']) : 0;
api_block_course_item_locked_by_gradebook($threadId, LINK_FORUM_THREAD);
$nameTools = get_lang('Forums');
$allowed_to_edit = api_is_allowed_to_edit(null, true);
$currentThread = get_thread_information($forumId, $_GET['thread']);
$forumId = $currentThread['forum_id'];
$currentForum = get_forums($currentThread['forum_id']);
$threadId = $currentThread['thread_id'];
$repo = Container::getForumRepository();
$repoThread = Container::getForumThreadRepository();
/** @var CForumForum $forumEntity */
$forumEntity = $repo->find($forumId);
/** @var CForumThread $threadEntity */
$threadEntity = $repoThread->find($threadId);
$course = api_get_course_entity();
$session = api_get_session_entity();
$allowToQualify = false;
if ($allowed_to_edit) {
$allowToQualify = true;
} else {
$allowToQualify = 1 == $currentThread['thread_peer_qualify'] && 1 == $currentForum['visibility'] && $userIdToQualify != $currentUserId;
$allowToQualify = $threadEntity->isThreadPeerQualify() && $forumEntity->isVisible($course, $session) && $userIdToQualify != $currentUserId;
}
if (!$allowToQualify) {
@ -48,7 +59,7 @@ if (isset($_POST['idtextqualify'])) {
if ($score <= $maxQualify) {
saveThreadScore(
$currentThread,
$threadEntity,
$userIdToQualify,
$threadId,
$score,
@ -84,10 +95,7 @@ $htmlHeadXtra[] = '<script>
$(content).slideToggle(\'normal\');
}
</script>';
$currentForumCategory = get_forumcategory_information(
$currentForum['forum_category']
);
$category = $forumEntity->getForumCategory();
$groupId = api_get_group_id();
if (api_is_in_gradebook()) {
@ -99,7 +107,7 @@ if (api_is_in_gradebook()) {
$search = isset($_GET['search']) ? Security::remove_XSS(urlencode($_GET['search'])) : '';
if ('learnpath' == $origin) {
if ('learnpath' === $origin) {
Display::display_reduced_header();
} else {
if (!empty($groupId)) {
@ -114,12 +122,12 @@ if ('learnpath' == $origin) {
];
$interbreadcrumb[] = [
'url' => 'viewforum.php?'.api_get_cidreq().'&forum='.(int) ($_GET['forum']).'&search='.$search,
'name' => prepare4display($currentForum['forum_title']),
'name' => prepare4display($forumEntity->getForumTitle()),
];
if ('PostDeletedSpecial' != $message) {
$interbreadcrumb[] = [
'url' => 'viewthread.php?'.api_get_cidreq().'&forum='.(int) ($_GET['forum']).'&thread='.(int) ($_GET['thread']),
'name' => prepare4display($currentThread['thread_title']),
'name' => prepare4display($threadEntity->getThreadTitle()),
];
}
@ -132,24 +140,23 @@ if ('learnpath' == $origin) {
Display::display_header('');
api_display_tool_title($nameTools);
} else {
$info_thread = get_thread_information($currentForum['forum_id'], $_GET['thread']);
$interbreadcrumb[] = [
'url' => 'index.php?'.api_get_cidreq().'&search='.$search,
'name' => $nameTools,
];
$interbreadcrumb[] = [
'url' => 'viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$currentForumCategory['cat_id'].'&search='.$search,
'name' => prepare4display($currentForumCategory['cat_title']),
'url' => 'viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$category->getIid().'&search='.$search,
'name' => prepare4display($category->getCatTitle()),
];
$interbreadcrumb[] = [
'url' => 'viewforum.php?'.api_get_cidreq().'&forum='.(int) ($_GET['forum']).'&search='.$search,
'name' => prepare4display($currentForum['forum_title']),
'url' => 'viewforum.php?'.api_get_cidreq().'&forum='.$forumId.'&search='.$search,
'name' => prepare4display($forumEntity->getForumTitle()),
];
if ('PostDeletedSpecial' != $message) {
$interbreadcrumb[] = [
'url' => 'viewthread.php?'.api_get_cidreq().'&forum='.$info_thread['forum_id'].'&thread='.(int) ($_GET['thread']),
'name' => prepare4display($currentThread['thread_title']),
'url' => 'viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId,
'name' => prepare4display($threadEntity->getThreadTitle()),
];
}
// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
@ -166,18 +173,18 @@ if ('learnpath' == $origin) {
*/
$action = isset($_GET['action']) ? $_GET['action'] : '';
if ('delete' == $action &&
if ('delete' === $action &&
isset($_GET['content']) &&
isset($_GET['id']) && api_is_allowed_to_edit(false, true)
) {
$message = delete_post($_GET['id']);
}
if (('invisible' == $action || 'visible' == $action) &&
if (('invisible' === $action || 'visible' === $action) &&
isset($_GET['id']) && api_is_allowed_to_edit(false, true)
) {
$message = approve_post($_GET['id'], $action);
}
if ('move' == $action && isset($_GET['post'])) {
if ('move' === $action && isset($_GET['post'])) {
$message = move_post_form();
}
@ -212,12 +219,12 @@ $result = get_statistical_information(
);
$url = api_get_path(WEB_CODE_PATH).'forum/forumqualify.php?'.
api_get_cidreq().'&forum='.(int) ($_GET['forum']).'&thread='.$threadId.'&user='.(int) ($_GET['user']).'&user_id='.(int) ($_GET['user']);
api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId.'&user='.(int) ($_GET['user']).'&user_id='.(int) ($_GET['user']);
$userToQualifyInfo = api_get_user_info($userIdToQualify);
$form = new FormValidator('forum-thread-qualify', 'post', $url);
$form->addHeader($userToQualifyInfo['complete_name']);
$form->addLabel(get_lang('Thread'), $currentThread['thread_title']);
$form->addLabel(get_lang('Thread'), $threadEntity->getThreadTitle());
$form->addLabel(get_lang('Users in course'), $result['user_course']);
$form->addLabel(get_lang('Number of posts'), $result['post']);
$form->addLabel(get_lang('Number of posts for this user'), $result['user_post']);
@ -233,7 +240,7 @@ $form->addText(
$course = api_get_course_info();
$rows = get_thread_user_post($course['code'], $currentThread['thread_id'], $_GET['user']);
$rows = get_thread_user_post($course['code'], $threadId, $_GET['user']);
if (isset($rows)) {
$counter = 1;
foreach ($rows as $row) {
@ -306,11 +313,15 @@ $form->display();
if (api_is_allowed_to_edit() && $counter > 0) {
echo '<h4>'.get_lang('ScoreChangesHistory').'</h4>';
if (isset($_GET['type']) && 'false' === $_GET['type']) {
$buttons = '<a class="btn btn-default" href="forumqualify.php?'.api_get_cidreq().'&forum='.(int) ($_GET['forum']).'&origin='.$origin.'&thread='.$threadId.'&user='.(int) ($_GET['user']).'&user_id='.(int) ($_GET['user_id']).'&type=true&idtextqualify='.$score.'#history">'.
$buttons = '<a
class="btn btn-default"
href="forumqualify.php?'.api_get_cidreq().'&forum='.$forumId.'&origin='.$origin.'&thread='.$threadId.'&user='.(int) ($_GET['user']).'&user_id='.(int) ($_GET['user_id']).'&type=true&idtextqualify='.$score.'#history">'.
get_lang('more recent').'</a> <a class="btn btn-default disabled" >'.get_lang('older').'</a>';
} else {
$buttons = '<a class="btn btn-default">'.get_lang('more recent').'</a>
<a class="btn btn-default" href="forumqualify.php?'.api_get_cidreq().'&forum='.(int) ($_GET['forum']).'&origin='.$origin.'&thread='.$threadId.'&user='.(int) ($_GET['user']).'&user_id='.(int) ($_GET['user_id']).'&type=false&idtextqualify='.$score.'#history">'.
<a
class="btn btn-default"
href="forumqualify.php?'.api_get_cidreq().'&forum='.$forumId.'&origin='.$origin.'&thread='.$threadId.'&user='.(int) ($_GET['user']).'&user_id='.(int) ($_GET['user_id']).'&type=false&idtextqualify='.$score.'#history">'.
get_lang('older').'</a>';
}
@ -337,6 +348,6 @@ if (api_is_allowed_to_edit() && $counter > 0) {
echo $table_list;
}
if ('learnpath' != $origin) {
if ('learnpath' !== $origin) {
Display:: display_footer();
}

@ -2,6 +2,9 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CForumForum;
/**
* These files are a complete rework of the forum. The database structure is
* based on phpBB but all the code is rewritten. A lot of new functionalities
@ -30,6 +33,11 @@ api_protect_course_script(true);
// Including additional library scripts.
include 'forumfunction.inc.php';
$forumId = isset($_GET['forum']) ? (int) ($_GET['forum']) : 0;
$repo = Container::getForumRepository();
/** @var CForumForum $forumEntity */
$forumEntity = $repo->find($forumId);
// Are we in a lp ?
$origin = api_get_origin();
@ -45,7 +53,7 @@ if (api_is_in_gradebook()) {
$groupId = api_get_group_id();
if ('group' == $origin) {
if ('group' === $origin) {
$group_properties = GroupManager:: get_group_properties($groupId);
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
@ -56,8 +64,8 @@ if ('group' == $origin) {
'name' => get_lang('Group area').' ('.$group_properties['name'].')',
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.(int) ($_GET['forum']).'&'.api_get_cidreq(),
'name' => prepare4display($current_forum['forum_title']),
'url' => api_get_path(WEB_CODE_PATH).'forum/viewforum.php?origin='.$origin.'&forum='.$forumId.'&'.api_get_cidreq(),
'name' => prepare4display($forumEntity->getForumTitle()),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'forum/forumsearch.php?'.api_get_cidreq(),
@ -72,7 +80,7 @@ if ('group' == $origin) {
}
// Display the header.
if ('learnpath' == $origin) {
if ('learnpath' === $origin) {
Display::display_reduced_header();
} else {
Display::display_header($nameTools);
@ -88,6 +96,6 @@ Event::event_access_tool(TOOL_FORUM);
forum_search();
// Footer
if ('learnpath' != $origin) {
if ('learnpath' !== $origin) {
Display :: display_footer();
}

@ -502,9 +502,13 @@ if (is_array($threads)) {
}*/
$id_attach = !empty($attachment_list) ? $attachment_list['id'] : '';
$iconsEdit = '';
if ('learnpath' != $origin) {
if (api_is_allowed_to_edit(false, true) &&
!(api_is_session_general_coach() && $current_forum['session_id'] != $sessionId)
if ('learnpath' !== $origin) {
if (api_is_allowed_to_edit(false, true)
/*&& @todo fix session validation
!(
api_is_session_general_coach() &&
$current_forum['session_id'] != $sessionId
)*/
) {
$iconsEdit .= '<a href="'.$forumUrl.'editthread.php?'.api_get_cidreq()
.'&forum='.$forumId.'&thread='

@ -272,17 +272,17 @@ if ('add' !== $action) {
//echo 'student';
// it is not a group forum => show forum
// (invisible forums are already left out see get_forums function)
if ('0' == $forum['forum_of_group']) {
if ('0' == $forum->getForumOfGroup()) {
$show_forum = true;
} else {
// it is a group forum
// it is a group forum but it is public => show
if ('public' == $forum['forum_group_public_private']) {
if ('public' === $forum->getForumGroupPublicPrivate()) {
$show_forum = true;
} else {
// it is a group forum and it is private
// it is a group forum and it is private but the user is member of the group
if (in_array($forum['forum_of_group'], $groups_of_user)) {
if (in_array($forum->getForumOfGroup(), $groups_of_user)) {
$show_forum = true;
} else {
$show_forum = false;
@ -323,9 +323,10 @@ if ('add' !== $action) {
}
$session_displayed = '';
if (!empty($sessionId) && !empty($forum['session_name'])) {
// @todo fix session name
/*if (!empty($sessionId) && !empty($forum['session_name'])) {
$session_displayed = ' ('.$forum['session_name'].')';
}
}*/
// the number of topics and posts
$my_number_threads = $forum->getThreads() ? $forum->getThreads()->count() : 0;
@ -411,7 +412,7 @@ if ('add' !== $action) {
$html .= '<div class="col-md-6">';
if (!empty($forum->getForumLastPost())) {
$html .= Display::return_icon('post-item.png', null, null, ICON_SIZE_TINY).' ';
$html .= Display::dateToStringAgoAndLongDate($forum['last_post_date'])
$html .= Display::dateToStringAgoAndLongDate($forum->getForumLastPost())
.' '.get_lang('By').' '
.display_user_link($poster_id, $name);
}

@ -24,6 +24,7 @@ $my_search = null;
$moveForm = '';
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
$postId = isset($_GET['post_id']) ? $_GET['post_id'] : 0;
$threadId = isset($_GET['thread']) ? (int) $_GET['thread'] : 0;
$repo = Container::getForumRepository();
@ -43,6 +44,13 @@ if (empty($threadEntity)) {
exit;
}
$repoPost = Container::getForumPostRepository();
$postEntity = null;
if (!empty($postId)) {
/** @var CForumPost $postEntity */
$postEntity = $repoPost->find($postId);
}
$courseEntity = api_get_course_entity(api_get_course_int_id());
$sessionEntity = api_get_session_entity(api_get_session_id());
@ -146,9 +154,8 @@ switch ($my_action) {
break;
case 'report':
$postId = isset($_GET['post_id']) ? $_GET['post_id'] : 0;
$result = reportPost($postId, $forumEntity, $threadEntity);
$result = reportPost($postEntity, $forumEntity, $threadEntity);
Display::addFlash(Display::return_message(get_lang('Reported')));
header('Location: '.$currentUrl);
exit;
@ -156,8 +163,7 @@ switch ($my_action) {
break;
case 'ask_revision':
if (api_get_configuration_value('allow_forum_post_revisions')) {
$postId = isset($_GET['post_id']) ? $_GET['post_id'] : 0;
$result = savePostRevision($postId);
$result = savePostRevision($postEntity);
Display::addFlash(Display::return_message(get_lang('Saved.')));
}
header('Location: '.$currentUrl);
@ -362,7 +368,7 @@ foreach ($posts as $post) {
);
}
if ('learnpath' != $origin) {
if ('learnpath' !== $origin) {
$post['user_data'] .= Display::tag(
'p',
Display::dateToStringAgoAndLongDate($post['post_date']),
@ -466,7 +472,7 @@ foreach ($posts as $post) {
if ($post['poster_id'] == $userId) {
$revision = getPostRevision($post['post_id']);
if (empty($revision)) {
$askForRevision = getAskRevisionButton($post['post_id'], $threadEntity);
$askForRevision = getAskRevisionButton($postEntity, $threadEntity);
} else {
$postIsARevision = true;
$languageId = api_get_language_id(strtolower($revision));
@ -477,7 +483,7 @@ foreach ($posts as $post) {
}
}
} else {
if (postNeedsRevision($post['post_id'])) {
if (postNeedsRevision($postEntity)) {
$askForRevision = giveRevisionButton($post['post_id'], $threadEntity);
} else {
$revision = getPostRevision($post['post_id']);

@ -269,7 +269,7 @@ class Agenda
->setEndDate($end)
->setAllDay($allDay)
->setColor($color)
->setUser(api_get_user_id())
->setUser(api_get_user_entity())
;
$em->persist($event);
$em->flush();
@ -2932,7 +2932,7 @@ class Agenda
$courseInfo
);
if (!empty($attachment)) {
$this->deleteAttachmentFile($attachmentId, $courseInfo);
$this->deleteAttachmentFile($attachmentId);
}
$this->addAttachment($eventId, $fileUserUpload, $comment, $courseInfo);
}
@ -2941,40 +2941,27 @@ class Agenda
* This function delete a attachment file by id.
*
* @param int $attachmentId
* @param array $courseInfo
*
* @return string
*/
public function deleteAttachmentFile($attachmentId, $courseInfo)
public function deleteAttachmentFile($attachmentId)
{
$table = Database::get_course_table(TABLE_AGENDA_ATTACHMENT);
$attachmentId = (int) $attachmentId;
$courseId = $courseInfo['real_id'];
$repo = Container::getCalendarEventAttachmentRepository();
/** @var CCalendarEventAttachment $attachment */
$attachment = $repo->find($attachmentId);
if (empty($courseId) || empty($attachmentId)) {
if (empty($attachment)) {
return false;
}
$sql = "DELETE FROM $table
WHERE c_id = $courseId AND id = ".$attachmentId;
$result = Database::query($sql);
// update item_property
api_item_property_update(
$courseInfo,
'calendar_event_attachment',
$attachmentId,
'AgendaAttachmentDeleted',
api_get_user_id()
);
$repo->getEntityManager()->remove($attachment);
$repo->getEntityManager()->flush();
if (!empty($result)) {
return Display::return_message(
get_lang("The attached file has been deleted"),
'confirmation'
);
}
}
/**
* @param int $eventId
@ -3611,17 +3598,19 @@ class Agenda
$type
) {
$tbl_personal_agenda = Database::get_main_table(TABLE_PERSONAL_AGENDA);
$user_id = intval($user_id);
$user_id = (int) $user_id;
$course_link = '';
// 1. creating the SQL statement for getting the personal agenda items in MONTH view
if ("month_view" == $type or "" == $type) {
if ("month_view" === $type || "" == $type) {
// we are in month view
$sql = "SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."' ORDER BY date ASC";
$sql = "SELECT * FROM ".$tbl_personal_agenda."
WHERE user='".$user_id."' and MONTH(date)='".$month."' AND YEAR(date) = '".$year."'
ORDER BY date ASC";
}
// 2. creating the SQL statement for getting the personal agenda items in WEEK view
// we are in week view
if ("week_view" == $type) {
if ("week_view" === $type) {
$start_end_day_of_week = self::calculate_start_end_of_week(
$week,
$year
@ -3637,17 +3626,19 @@ class Agenda
$start_filter = api_get_utc_datetime($start_filter);
$end_filter = $end_year."-".$end_month."-".$end_day." 23:59:59";
$end_filter = api_get_utc_datetime($end_filter);
$sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
$sql = "SELECT * FROM ".$tbl_personal_agenda."
WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
}
// 3. creating the SQL statement for getting the personal agenda items in DAY view
if ("day_view" == $type) {
if ("day_view" === $type) {
// we are in day view
// we could use mysql date() function but this is only available from 4.1 and higher
$start_filter = $year."-".$month."-".$day." 00:00:00";
$start_filter = api_get_utc_datetime($start_filter);
$end_filter = $year."-".$month."-".$day." 23:59:59";
$end_filter = api_get_utc_datetime($end_filter);
$sql = " SELECT * FROM ".$tbl_personal_agenda." WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
$sql = "SELECT * FROM ".$tbl_personal_agenda."
WHERE user='".$user_id."' AND date>='".$start_filter."' AND date<='".$end_filter."'";
}
$result = Database::query($sql);
@ -3676,20 +3667,24 @@ class Agenda
$minute = $agendatime[1];
$second = $agendatime[2];
if ('month_view' == $type) {
if ('month_view' === $type) {
$item['calendar_type'] = 'personal';
$item['start_date'] = $item['date'];
$agendaitems[$day][] = $item;
continue;
}
// Creating the array that will be returned. If we have week or month view we have an array with the date as the key
// Creating the array that will be returned.
// If we have week or month view we have an array with the date as the key
// if we have a day_view we use a half hour as index => key 33 = 16h30
if ("day_view" !== $type) {
// This is the array construction for the WEEK or MONTH view
//Display events in agenda
$agendaitems[$day] .= "<div><i>$time_minute</i> $course_link <a href=\"myagenda.php?action=view&view=personal&day=$day&month=$month&year=$year&id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div><br />";
$agendaitems[$day] .= "<div>
<i>$time_minute</i> $course_link
<a href=\"myagenda.php?action=view&view=personal&day=$day&month=$month&year=$year&id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".
$item['title']."</a></div><br />";
} else {
// this is the array construction for the DAY view
$halfhour = 2 * $agendatime['0'];
@ -3698,7 +3693,9 @@ class Agenda
}
//Display events by list
$agendaitems[$halfhour] .= "<div><i>$time_minute</i> $course_link <a href=\"myagenda.php?action=view&view=personal&day=$day&month=$month&year=$year&id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div>";
$agendaitems[$halfhour] .= "<div>
<i>$time_minute</i> $course_link
<a href=\"myagenda.php?action=view&view=personal&day=$day&month=$month&year=$year&id=".$item['id']."#".$item['id']."\" class=\"personal_agenda\">".$item['title']."</a></div>";
}
}
@ -3706,7 +3703,7 @@ class Agenda
}
/**
* Show the monthcalender of the given month.
* Show the month calendar of the given month.
*
* @param array Agendaitems
* @param int Month number
@ -3979,11 +3976,10 @@ class Agenda
*
* @deprecated use agenda events
*/
public static function get_personal_agenda_items_between_dates(
$user_id,
$date_start = '',
$date_end = ''
) {
public static function get_personal_agenda_items_between_dates($user_id, $date_start = '', $date_end = '')
{
throw new Exception('fix get_personal_agenda_items_between_dates');
/*
$items = [];
if ($user_id != strval(intval($user_id))) {
return $items;
@ -4006,10 +4002,10 @@ class Agenda
}
// get agenda-items for every course
$courses = api_get_user_courses($user_id, false);
//$courses = api_get_user_courses($user_id, false);
$courses = CourseManager::get_courses_list_by_user_id($user_id, false);
foreach ($courses as $id => $course) {
$c = api_get_course_info_by_id($course['real_id']);
//databases of the courses
$t_a = Database::get_course_table(TABLE_AGENDA, $course['db']);
$t_ip = Database::get_course_table(
TABLE_ITEM_PROPERTY,
@ -4100,7 +4096,7 @@ class Agenda
}
}
return $items;
return $items;*/
}
/**

@ -489,7 +489,9 @@ class User implements UserInterface, EquatableInterface
/**
* @var ArrayCollection|TrackEAttempt[]
* @ORM\OneToMany(targetEntity="TrackEAccessComplete", mappedBy="user", cascade={"persist", "remove"},orphanRemoval=true)
* @ORM\OneToMany(
* targetEntity="TrackEAccessComplete", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true
* )
*/
protected $trackEAccessCompleteList;
@ -517,9 +519,10 @@ class User implements UserInterface, EquatableInterface
protected $trackECourseAccess;
/**
* @var ArrayCollection
* @var ArrayCollection|UserCourseCategory[]
*
* @ORM\OneToMany(
* targetEntity="Chamilo\CoreBundle\Entity\UserCourseCategory",
* targetEntity="UserCourseCategory",
* mappedBy="user",
* cascade={"persist", "remove"},
* orphanRemoval=true
@ -528,19 +531,19 @@ class User implements UserInterface, EquatableInterface
protected $userCourseCategories;
/**
* @var ArrayCollection
* @var ArrayCollection|UserRelCourseVote[]
* @ORM\OneToMany(targetEntity="UserRelCourseVote", mappedBy="user",cascade={"persist","remove"},orphanRemoval=true)
*/
protected $userRelCourseVotes;
/**
* @var ArrayCollection
* @var ArrayCollection|UserRelTag[]
* @ORM\OneToMany(targetEntity="UserRelTag", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
*/
protected $userRelTags;
/**
* @var ArrayCollection
* @var ArrayCollection|PersonalAgenda[]
* @ORM\OneToMany(targetEntity="PersonalAgenda",mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true)
*/
protected $personalAgendas;

@ -201,14 +201,14 @@ class CForumForum extends AbstractResource implements ResourceInterface
protected $moderated;
/**
* @var ArrayCollection
* @var ArrayCollection|CForumThread[]
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CForumThread", mappedBy="forum")
*/
protected $threads;
/**
* @var CForumPost[]
* @var ArrayCollection|CForumPost[]
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CForumPost", mappedBy="forum")
*/
@ -219,6 +219,8 @@ class CForumForum extends AbstractResource implements ResourceInterface
*/
public function __construct()
{
$this->threads = new ArrayCollection();
$this->posts = new ArrayCollection();
$this->locked = 0;
$this->forumImage = '';
$this->forumOfGroup = 0;
@ -259,10 +261,8 @@ class CForumForum extends AbstractResource implements ResourceInterface
* Set forumComment.
*
* @param string $forumComment
*
* @return CForumForum
*/
public function setForumComment($forumComment)
public function setForumComment($forumComment): self
{
$this->forumComment = $forumComment;
@ -283,10 +283,8 @@ class CForumForum extends AbstractResource implements ResourceInterface
* Set forumThreads.
*
* @param int $forumThreads
*
* @return CForumForum
*/
public function setForumThreads($forumThreads)
public function setForumThreads($forumThreads): self
{
$this->forumThreads = $forumThreads;
@ -303,6 +301,11 @@ class CForumForum extends AbstractResource implements ResourceInterface
return $this->forumThreads;
}
public function hasThread($thread)
{
return $this->threads->contains($thread);
}
/**
* Set forumPosts.
*

@ -163,7 +163,7 @@ class CForumThread extends AbstractResource implements ResourceInterface
protected $lpItemId;
/**
* @var CForumPost[]
* @var ArrayCollection|CForumPost[]
*
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CForumPost", mappedBy="thread", cascade={"persist", "remove"}, orphanRemoval=true)
*/
@ -171,6 +171,7 @@ class CForumThread extends AbstractResource implements ResourceInterface
public function __construct()
{
$this->posts = new ArrayCollection();
$this->threadPeerQualify = false;
$this->threadReplies = 0;
$this->threadViews = 0;

Loading…
Cancel
Save