Code Duplication    Length = 15-24 lines in 9 locations

Sources/Groups.php 1 location

@@ 690-705 (lines=16) @@
687
 * @param array $where_parameters The parameters for the WHERE clause
688
 * @return int The number of group requests
689
 */
690
function list_getGroupRequestCount($where, $where_parameters)
691
{
692
	global $smcFunc;
693
694
	$request = $smcFunc['db_query']('', '
695
		SELECT COUNT(*)
696
		FROM {db_prefix}log_group_requests AS lgr
697
		WHERE ' . $where,
698
		array_merge($where_parameters, array(
699
		))
700
	);
701
	list ($totalRequests) = $smcFunc['db_fetch_row']($request);
702
	$smcFunc['db_free_result']($request);
703
704
	return $totalRequests;
705
}
706
707
/**
708
 * Callback function for createList()

Sources/PostModeration.php 1 location

@@ 625-648 (lines=24) @@
622
 * @param string $approve_query Additional restrictions based on the boards the approver can see
623
 * @return int The number of unapproved attachments
624
 */
625
function list_getNumUnapprovedAttachments($approve_query)
626
{
627
	global $smcFunc;
628
629
	// How many unapproved attachments in total?
630
	$request = $smcFunc['db_query']('', '
631
		SELECT COUNT(*)
632
		FROM {db_prefix}attachments AS a
633
			INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
634
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
635
		WHERE a.approved = {int:not_approved}
636
			AND a.attachment_type = {int:attachment_type}
637
			AND {query_see_board}
638
			' . $approve_query,
639
		array(
640
			'not_approved' => 0,
641
			'attachment_type' => 0,
642
		)
643
	);
644
	list ($total_unapproved_attachments) = $smcFunc['db_fetch_row']($request);
645
	$smcFunc['db_free_result']($request);
646
647
	return $total_unapproved_attachments;
648
}
649
650
/**
651
 * Approve a post, just the one.

Sources/ModerationCenter.php 2 locations

@@ 1173-1189 (lines=17) @@
1170
 * @param string $approve_query Not used here
1171
 * @return int The number of users on the watch list
1172
 */
1173
function list_getWatchedUserCount($approve_query)
1174
{
1175
	global $smcFunc, $modSettings;
1176
1177
	$request = $smcFunc['db_query']('', '
1178
		SELECT COUNT(*)
1179
		FROM {db_prefix}members
1180
		WHERE warning >= {int:warning_watch}',
1181
		array(
1182
			'warning_watch' => $modSettings['warning_watch'],
1183
		)
1184
	);
1185
	list ($totalMembers) = $smcFunc['db_fetch_row']($request);
1186
	$smcFunc['db_free_result']($request);
1187
1188
	return $totalMembers;
1189
}
1190
1191
/**
1192
 * Callback for createList().
@@ 1302-1322 (lines=21) @@
1299
 * @param string $approve_query A query to pull only approved items
1300
 * @return int The total number of posts by watched users
1301
 */
1302
function list_getWatchedUserPostsCount($approve_query)
1303
{
1304
	global $smcFunc, $modSettings;
1305
1306
	$request = $smcFunc['db_query']('', '
1307
		SELECT COUNT(*)
1308
			FROM {db_prefix}messages AS m
1309
				INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
1310
				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
1311
			WHERE mem.warning >= {int:warning_watch}
1312
				AND {query_see_board}
1313
				' . $approve_query,
1314
		array(
1315
			'warning_watch' => $modSettings['warning_watch'],
1316
		)
1317
	);
1318
	list ($totalMemberPosts) = $smcFunc['db_fetch_row']($request);
1319
	$smcFunc['db_free_result']($request);
1320
1321
	return $totalMemberPosts;
1322
}
1323
1324
/**
1325
 * Callback for createList().

Sources/Profile-View.php 4 locations

@@ 1715-1729 (lines=15) @@
1712
 * @param array $where_vars The parameters for $where
1713
 * @return int Number of user errors
1714
 */
1715
function list_getUserErrorCount($where, $where_vars = array())
1716
{
1717
	global $smcFunc;
1718
1719
	$request = $smcFunc['db_query']('', '
1720
		SELECT COUNT(*) AS error_count
1721
		FROM {db_prefix}log_errors
1722
		WHERE ' . $where,
1723
		$where_vars
1724
	);
1725
	list ($count) = $smcFunc['db_fetch_row']($request);
1726
	$smcFunc['db_free_result']($request);
1727
1728
	return (int) $count;
1729
}
1730
1731
/**
1732
 * Gets all of the errors generated by a user's actions. Callback for the list in track_activity
@@ 1784-1799 (lines=16) @@
1781
 * @param array $where_vars The parameters for $where
1782
 * @return int Count of messages matching the IP
1783
 */
1784
function list_getIPMessageCount($where, $where_vars = array())
1785
{
1786
	global $smcFunc;
1787
1788
	$request = $smcFunc['db_query']('', '
1789
		SELECT COUNT(*) AS message_count
1790
		FROM {db_prefix}messages AS m
1791
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
1792
		WHERE {query_see_board} AND ' . $where,
1793
		$where_vars
1794
	);
1795
	list ($count) = $smcFunc['db_fetch_row']($request);
1796
	$smcFunc['db_free_result']($request);
1797
1798
	return (int) $count;
1799
}
1800
1801
/**
1802
 * Gets all the posts made from a particular IP
@@ 2225-2241 (lines=17) @@
2222
 * @param array $where_vars An array of parameters for $where
2223
 * @return int count of messages matching the IP
2224
 */
2225
function list_getLoginCount($where, $where_vars = array())
2226
{
2227
	global $smcFunc;
2228
2229
	$request = $smcFunc['db_query']('', '
2230
		SELECT COUNT(*) AS message_count
2231
		FROM {db_prefix}member_logins
2232
		WHERE id_member = {int:id_member}',
2233
		array(
2234
			'id_member' => $where_vars['current_member'],
2235
		)
2236
	);
2237
	list ($count) = $smcFunc['db_fetch_row']($request);
2238
	$smcFunc['db_free_result']($request);
2239
2240
	return (int) $count;
2241
}
2242
2243
/**
2244
 * Callback for the list in trackLogins.
@@ 2385-2403 (lines=19) @@
2382
 * @param int $memID The ID of the member
2383
 * @return int The number of profile edits
2384
 */
2385
function list_getProfileEditCount($memID)
2386
{
2387
	global $smcFunc;
2388
2389
	$request = $smcFunc['db_query']('', '
2390
		SELECT COUNT(*) AS edit_count
2391
		FROM {db_prefix}log_actions
2392
		WHERE id_log = {int:log_type}
2393
			AND id_member = {int:owner}',
2394
		array(
2395
			'log_type' => 2,
2396
			'owner' => $memID,
2397
		)
2398
	);
2399
	list ($edit_count) = $smcFunc['db_fetch_row']($request);
2400
	$smcFunc['db_free_result']($request);
2401
2402
	return (int) $edit_count;
2403
}
2404
2405
/**
2406
 * Loads up information about a user's profile edits. Callback for the list in trackEdits()

Sources/Subs-Calendar.php 1 location

@@ 982-1005 (lines=24) @@
979
 * @param int $event_id The ID of the event
980
 * @return int|bool The ID of the poster or false if the event was not found
981
 */
982
function getEventPoster($event_id)
983
{
984
	global $smcFunc;
985
986
	// A simple database query, how hard can that be?
987
	$request = $smcFunc['db_query']('', '
988
		SELECT id_member
989
		FROM {db_prefix}calendar
990
		WHERE id_event = {int:id_event}
991
		LIMIT 1',
992
		array(
993
			'id_event' => $event_id,
994
		)
995
	);
996
997
	// No results, return false.
998
	if ($smcFunc['db_num_rows'] === 0)
999
		return false;
1000
1001
	// Grab the results and return.
1002
	list ($poster) = $smcFunc['db_fetch_row']($request);
1003
	$smcFunc['db_free_result']($request);
1004
	return (int) $poster;
1005
}
1006
1007
/**
1008
 * Consolidating the various INSERT statements into this function.