Skip to content

Commit 459ba9e

Browse files
Forum: minor, cleaning code with phpcs
1 parent b405c55 commit 459ba9e

File tree

10 files changed

+156
-125
lines changed

10 files changed

+156
-125
lines changed

public/main/forum/editpost.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/* For licensing terms, see /license.txt */
46

57
use Chamilo\CoreBundle\Enums\ActionIcon;
@@ -23,6 +25,7 @@
2325
* - quoting a message.
2426
*
2527
* @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
28+
*
2629
* @Copyright Ghent University
2730
* @Copyright Patrick Cool
2831
*/
@@ -107,16 +110,19 @@ function setFocus() {
107110
$userId = api_get_user_id();
108111

109112
$repo = Container::getForumRepository();
113+
110114
/** @var CForum $forum */
111115
$forum = $repo->find($forumId);
112116

113117
$repoThread = Container::getForumThreadRepository();
118+
114119
/** @var CForumThread $thread */
115120
$thread = $repoThread->find($_GET['thread']);
116121

117122
$category = $forum->getForumCategory();
118123

119124
$postRepo = Container::getForumPostRepository();
125+
120126
/** @var CForumPost $post */
121127
$post = $postRepo->find($_GET['post']);
122128

@@ -176,7 +182,7 @@ function setFocus() {
176182
'name' => prepare4display($forum->getTitle()),
177183
];
178184
$interbreadcrumb[] = [
179-
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.(int) ($_GET['thread']),
185+
'url' => api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forumId.'&thread='.(int) $_GET['thread'],
180186
'name' => prepare4display($thread->getTitle()),
181187
];
182188
$interbreadcrumb[] = ['url' => 'javascript: void (0);', 'name' => get_lang('Edit a post')];
@@ -185,7 +191,7 @@ function setFocus() {
185191
$table_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
186192

187193
/* Header */
188-
$htmlHeadXtra[] = <<<JS
194+
$htmlHeadXtra[] = <<<'JS'
189195
<script>
190196
$(function() {
191197
$('#reply-add-attachment').on('click', function(e) {
@@ -209,20 +215,20 @@ function setFocus() {
209215
// 4. if editing of replies is not allowed
210216
// The only exception is the course manager
211217
// I have split this is several pieces for clarity.
212-
if (!api_is_allowed_to_create_course() &&
213-
(
214-
(false === $categoryIsVisible) ||
215-
false === $forumIsVisible
218+
if (!api_is_allowed_to_create_course()
219+
&& (
220+
(false === $categoryIsVisible)
221+
|| false === $forumIsVisible
216222
) && (!api_is_course_admin())
217223
) {
218224
api_not_allowed(true);
219225
}
220226

221-
if (!api_is_allowed_to_edit(null, true) &&
222-
(
223-
($category->getLocked()) ||
224-
0 != $forum->getLocked() ||
225-
0 != $thread->getLocked()
227+
if (!api_is_allowed_to_edit(null, true)
228+
&& (
229+
$category->getLocked()
230+
|| 0 != $forum->getLocked()
231+
|| 0 != $thread->getLocked()
226232
)
227233
) {
228234
api_not_allowed(true);
@@ -234,9 +240,9 @@ function setFocus() {
234240

235241
$group_id = api_get_group_id();
236242

237-
if (!api_is_allowed_to_edit(null, true) &&
238-
0 == $forum->getAllowEdit() &&
239-
!GroupManager::isTutorOfGroup(api_get_user_id(), $groupEntity)
243+
if (!api_is_allowed_to_edit(null, true)
244+
&& 0 == $forum->getAllowEdit()
245+
&& !GroupManager::isTutorOfGroup(api_get_user_id(), $groupEntity)
240246
) {
241247
api_not_allowed(true);
242248
}
@@ -246,7 +252,7 @@ function setFocus() {
246252
// Action links
247253
if ('learnpath' !== $origin) {
248254
$actions = '';
249-
//$actions .= '<span style="float:right;">'.search_link().'</span>';
255+
// $actions .= '<span style="float:right;">'.search_link().'</span>';
250256
if ('group' === $origin) {
251257
$actions .= '<a href="../group/group_space.php?'.api_get_cidreq().'">'.
252258
Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Back to').' '.get_lang('Groups')).
@@ -263,8 +269,8 @@ function setFocus() {
263269
}
264270

265271
/* Display Forum Category and the Forum information */
266-
/*New display forum div*/
267-
/*New display forum div*/
272+
/* New display forum div */
273+
/* New display forum div */
268274
echo '<div class="forum_title">';
269275
echo '<h1>';
270276
echo Display::url(

public/main/forum/editthread.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/* For licensing terms, see /license.txt */
46

57
use Chamilo\CoreBundle\Enums\ActionIcon;
68
use Chamilo\CoreBundle\Framework\Container;
79
use Chamilo\CourseBundle\Entity\CForum;
810

9-
1011
/**
1112
* Edit a Forum Thread.
1213
*
@@ -84,6 +85,7 @@ function setFocus() {
8485
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : 0;
8586

8687
$repo = Container::getForumRepository();
88+
8789
/** @var CForum $forum */
8890
$forum = $repo->find($forumId);
8991
if (empty($forum)) {
@@ -92,7 +94,7 @@ function setFocus() {
9294

9395
$courseEntity = api_get_course_entity();
9496
$sessionEntity = api_get_session_entity();
95-
//$forumIsVisible = $forum->isVisible($courseEntity, $sessionEntity);
97+
// $forumIsVisible = $forum->isVisible($courseEntity, $sessionEntity);
9698

9799
$category = $forum->getForumCategory();
98100
$categoryIsVisible = $category->isVisible($courseEntity) && !api_get_session_id();
@@ -108,7 +110,7 @@ function setFocus() {
108110
$courseInfo = api_get_course_info();
109111
$courseId = $courseInfo['real_id'];
110112

111-
$gradebookId = (int) (api_is_in_gradebook());
113+
$gradebookId = (int) api_is_in_gradebook();
112114

113115
/* Is the user allowed here? */
114116

@@ -120,15 +122,15 @@ function setFocus() {
120122
}
121123

122124
// 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
123-
if (!api_is_allowed_to_edit(false, true) &&
124-
(($categoryIsVisible && 0 != $category->getLocked()) || 0 != $forum->getLocked())
125+
if (!api_is_allowed_to_edit(false, true)
126+
&& (($categoryIsVisible && 0 != $category->getLocked()) || 0 != $forum->getLocked())
125127
) {
126128
api_not_allowed();
127129
}
128130

129131
// 3. new threads are not allowed and the user is not a course manager
130-
if (!api_is_allowed_to_edit(false, true) &&
131-
1 != $forum->getAllowNewThreads()
132+
if (!api_is_allowed_to_edit(false, true)
133+
&& 1 != $forum->getAllowNewThreads()
132134
) {
133135
api_not_allowed();
134136
}
@@ -189,7 +191,7 @@ function setFocus() {
189191
$tableLink = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
190192

191193
/* Header */
192-
$htmlHeadXtra[] = <<<JS
194+
$htmlHeadXtra[] = <<<'JS'
193195
<script>
194196
$(function() {
195197
$('[name="thread_qualify_gradebook"]:checkbox').change(function () {
@@ -240,7 +242,7 @@ function setFocus() {
240242
if ((api_is_course_admin() || api_is_session_general_coach() || api_is_course_tutor()) && $threadId) {
241243
// Thread qualify
242244
if (Gradebook::is_active()) {
243-
//Loading gradebook select
245+
// Loading gradebook select
244246
GradebookUtils::load_gradebook_select_in_tool($form);
245247
$form->addElement(
246248
'checkbox',
@@ -298,8 +300,8 @@ function setFocus() {
298300
if (!empty($threadData)) {
299301
$defaults['thread_qualify_gradebook'] = $gradeThisThread;
300302
$defaults['thread_title'] = prepare4display($threadData['threadTitle']);
301-
$defaults['thread_sticky'] = (string) ((int) ($threadData['threadSticky']));
302-
$defaults['thread_peer_qualify'] = (int) ($threadData['threadPeerQualify']);
303+
$defaults['thread_sticky'] = (string) ((int) $threadData['threadSticky']);
304+
$defaults['thread_peer_qualify'] = (int) $threadData['threadPeerQualify'];
303305
$defaults['numeric_calification'] = $threadData['threadQualifyMax'];
304306
$defaults['calification_notebook_title'] = $threadData['threadTitleQualify'];
305307
$defaults['weight_calification'] = $threadData['threadWeight'];
@@ -318,6 +320,7 @@ function setFocus() {
318320
updateThread($values);
319321
SkillModel::saveSkills($form, ITEM_TYPE_FORUM_THREAD, $threadId);
320322
header('Location: '.$redirectUrl);
323+
321324
exit;
322325
}
323326
}

public/main/forum/forumqualify.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/* For licensing terms, see /license.txt */
46

57
use Chamilo\CoreBundle\Framework\Container;
68
use Chamilo\CourseBundle\Entity\CForum;
79
use Chamilo\CourseBundle\Entity\CForumThread;
810

9-
1011
/**
1112
* @todo fix all this qualify files avoid including files, use classes POO jmontoya
1213
*/
@@ -71,7 +72,7 @@ function setFocus() {
7172
$nameTools = get_lang('Forums');
7273
$this_section = SECTION_COURSES;
7374
$message = '';
74-
//are we in a lp ?
75+
// are we in a lp ?
7576
$origin = api_get_origin();
7677

7778
$currentUserId = api_get_user_id();
@@ -84,8 +85,10 @@ function setFocus() {
8485

8586
$repo = Container::getForumRepository();
8687
$repoThread = Container::getForumThreadRepository();
88+
8789
/** @var CForum $forumEntity */
8890
$forumEntity = $repo->find($forumId);
91+
8992
/** @var CForumThread $threadEntity */
9093
$threadEntity = $repoThread->find($threadId);
9194

@@ -108,7 +111,7 @@ function setFocus() {
108111
$score = 0;
109112

110113
if (isset($_POST['idtextqualify'])) {
111-
$score = (float) ($_POST['idtextqualify']);
114+
$score = (float) $_POST['idtextqualify'];
112115

113116
if ($score <= $maxQualify) {
114117
saveThreadScore(
@@ -130,6 +133,7 @@ function setFocus() {
130133
'list' => 'qualify',
131134
])
132135
);
136+
133137
exit;
134138
}
135139

@@ -228,15 +232,15 @@ function hidecontent(content){
228232

229233
$currentUrl = api_get_self().'?forum='.$forumId.'&'.api_get_cidreq().'&thread='.$threadId;
230234

231-
if ('delete' === $action &&
232-
isset($_GET['content']) &&
233-
isset($_GET['id']) && api_is_allowed_to_edit(false, true)
235+
if ('delete' === $action
236+
&& isset($_GET['content'], $_GET['id'])
237+
&& api_is_allowed_to_edit(false, true)
234238
) {
235239
deletePost($postEntity);
236240
api_location($currentUrl);
237241
}
238-
if (('invisible' === $action || 'visible' === $action) &&
239-
isset($_GET['id']) && api_is_allowed_to_edit(false, true)
242+
if (('invisible' === $action || 'visible' === $action)
243+
&& isset($_GET['id']) && api_is_allowed_to_edit(false, true)
240244
) {
241245
approvePost($postEntity, $action);
242246
api_location($currentUrl);
@@ -269,7 +273,7 @@ function hidecontent(content){
269273
);
270274

271275
$url = api_get_path(WEB_CODE_PATH).'forum/forumqualify.php?'.
272-
api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId.'&user='.(int) ($_GET['user']).'&user_id='.(int) ($_GET['user']);
276+
api_get_cidreq().'&forum='.$forumId.'&thread='.$threadId.'&user='.(int) $_GET['user'].'&user_id='.(int) $_GET['user'];
273277

274278
$userToQualifyInfo = api_get_user_info($userIdToQualify);
275279
$form = new FormValidator('forum-thread-qualify', 'post', $url);
@@ -363,13 +367,13 @@ function hidecontent(content){
363367
if (isset($_GET['type']) && 'false' === $_GET['type']) {
364368
$buttons = '<a
365369
class="btn btn--plain"
366-
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">'.
370+
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">'.
367371
get_lang('more recent').'</a> <a class="btn btn--plain disabled" >'.get_lang('older').'</a>';
368372
} else {
369373
$buttons = '<a class="btn btn--plain">'.get_lang('more recent').'</a>
370374
<a
371375
class="btn btn--plain"
372-
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">'.
376+
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">'.
373377
get_lang('older').'</a>';
374378
}
375379

@@ -397,5 +401,5 @@ class="btn btn--plain"
397401
}
398402

399403
if ('learnpath' !== $origin) {
400-
Display:: display_footer();
404+
Display::display_footer();
401405
}

public/main/forum/forumsearch.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/* For licensing terms, see /license.txt */
46

57
use Chamilo\CoreBundle\Enums\ActionIcon;
@@ -87,6 +89,7 @@ function setFocus() {
8789

8890
$forumId = isset($_GET['forum']) ? (int) ($_GET['forum']) : 0;
8991
$repo = Container::getForumRepository();
92+
9093
/** @var CForum $forumEntity */
9194
$forumEntity = $repo->find($forumId);
9295

@@ -106,7 +109,7 @@ function setFocus() {
106109
$groupId = api_get_group_id();
107110

108111
if ('group' === $origin) {
109-
$group_properties = GroupManager:: get_group_properties($groupId);
112+
$group_properties = GroupManager::get_group_properties($groupId);
110113
$interbreadcrumb[] = [
111114
'url' => api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq(),
112115
'name' => get_lang('Groups'),
@@ -163,5 +166,5 @@ function setFocus() {
163166

164167
// Footer
165168
if ('learnpath' !== $origin) {
166-
Display :: display_footer();
169+
Display::display_footer();
167170
}

public/main/forum/iframe_thread.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/* For licensing terms, see /license.txt */
46

57
use Chamilo\CoreBundle\Framework\Container;
@@ -56,9 +58,10 @@
5658
/* Is the user allowed here? */
5759
// if the user is not a course administrator and the forum is hidden
5860
// then the user is not allowed here.
59-
if (!api_is_allowed_to_create_course() &&
60-
(false == $forumEntity->isVisible($courseEntity) ||
61-
false == $threadEntity->isVisible($courseEntity)
61+
if (!api_is_allowed_to_create_course()
62+
&& (
63+
false == $forumEntity->isVisible($courseEntity)
64+
|| false == $threadEntity->isVisible($courseEntity)
6265
)
6366
) {
6467
api_not_allowed(false);
@@ -82,7 +85,7 @@
8285
while ($row = Database::fetch_array($result)) {
8386
$content .= '<tr>';
8487
$content .= '<td rowspan="2" class="forum_message_left">';
85-
$username = api_htmlentities(sprintf(get_lang('Login: %s'), $row['username']), ENT_QUOTES);
88+
$username = api_htmlentities(sprintf(get_lang('Login: %s'), $row['username']), \ENT_QUOTES);
8689
if ('0' == $row['id']) {
8790
$name = $row['poster_name'];
8891
} else {

0 commit comments

Comments
 (0)