diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2012-08-30 18:07:00 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2012-08-30 18:07:00 +0200 |
commit | 1c043254c00023a5fe17b1131fa605ca11d823a0 (patch) | |
tree | 28ca5f235f803be8de8955b0f1bbd5713ac4dd62 /phpBB/includes | |
parent | df83f22b718e56ff06a2c35a15cec1039df35db9 (diff) | |
download | forums-1c043254c00023a5fe17b1131fa605ca11d823a0.tar forums-1c043254c00023a5fe17b1131fa605ca11d823a0.tar.gz forums-1c043254c00023a5fe17b1131fa605ca11d823a0.tar.bz2 forums-1c043254c00023a5fe17b1131fa605ca11d823a0.tar.xz forums-1c043254c00023a5fe17b1131fa605ca11d823a0.zip |
[feature/soft-delete] Add get_visibility_sql_forums based on global
The resulting query is 4-times faster, as the forum_id IN () arrays are
smaller and we need less AND/OR to build the hole query. The main difference
between those two functions is, that this one takes an array of included ids and
the _global one takes an array of excluded ids.
PHPBB3-9657
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/content_visibility.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 287c46a335..2e91521c78 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -70,6 +70,54 @@ class phpbb_content_visibility } /** + * Fetch visibility SQL for a set of forums + * @param $mode string - either "topic" or "post" + * @param $forum_ids - int array - + * @param $table_alias string - Table alias to prefix in SQL queries + * @return string with the appropriate combination SQL logic for topic/post_visibility + */ + static public function get_visibility_sql_forums($mode, $forum_ids = array(), $table_alias = '') + { + global $auth, $db, $user; + + // users can always see approved posts + $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; + + // in set notation: {approve_forums} = {m_approve} - {exclude_forums} + $approve_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_approve', true))); + if (sizeof($approve_forums)) + { + // users can view unapproved topics in certain forums. specify them. + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')'; + } + + // this is exactly the same logic as for approve forums, above + $restore_forums = array_intersect($forum_ids, array_keys($auth->acl_getf('m_restore', true))); + if (sizeof($restore_forums)) + { + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; + } + + // we also allow the user to view deleted posts he himself made + $user_restore_forums = array_diff(array_intersect($forum_ids, array_keys($auth->acl_getf('f_restore', true))), $restore_forums); + if (sizeof($user_restore_forums) && !sizeof($restore_forums)) + { + $poster_column = ($mode == 'topic') ? 'topic_poster' : 'poster_id'; + + // specify the poster ID, the visibility type, and the forums we're interested in + $where_sql .= " OR ($table_alias$poster_column = " . $user->data['user_id'] . " + AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " + AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; + } + + $where_sql .= ')'; + + return $where_sql; + } + + /** * Fetch visibility SQL for all forums on the board. * @param $mode string - either "topic" or "post" * @param $exclude_forum_ids - int array - |