Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forum show deleted threads #2151

Merged
merged 14 commits into from Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 16 additions & 11 deletions site/app/controllers/forum/ForumController.php
Expand Up @@ -88,6 +88,9 @@ public function run() {
}
}

private function showDeleted() {
return ($this->core->getUser()->getGroup() <= 2 && isset($_COOKIE['show_deleted']) && $_COOKIE['show_deleted'] == "1");
}

private function returnUserContentToPage($error, $isThread, $thread_id){
//Notify User
Expand Down Expand Up @@ -470,14 +473,14 @@ private function editPost(){
return null;
}

private function getSortedThreads($categories_ids){
private function getSortedThreads($categories_ids, $show_deleted = false){
$current_user = $this->core->getUser()->getId();
if($this->isValidCategories($categories_ids)) {
$announce_threads = $this->core->getQueries()->loadAnnouncements($categories_ids);
$reg_threads = $this->core->getQueries()->loadThreads($categories_ids);
$announce_threads = $this->core->getQueries()->loadAnnouncements($categories_ids, $show_deleted);
$reg_threads = $this->core->getQueries()->loadThreads($categories_ids, $show_deleted);
} else {
$announce_threads = $this->core->getQueries()->loadAnnouncementsWithoutCategory();
$reg_threads = $this->core->getQueries()->loadThreadsWithoutCategory();
$announce_threads = $this->core->getQueries()->loadAnnouncementsWithoutCategory($show_deleted);
$reg_threads = $this->core->getQueries()->loadThreadsWithoutCategory($show_deleted);
}
$favorite_threads = $this->core->getQueries()->loadPinnedThreads($current_user);

Expand Down Expand Up @@ -520,12 +523,13 @@ private function getSortedThreads($categories_ids){

public function getThreads(){

$show_deleted = $this->showDeleted();
$categories_ids = array_key_exists('thread_categories', $_POST) && !empty($_POST["thread_categories"]) ? explode("|", $_POST['thread_categories']) : array();
foreach ($categories_ids as &$id) {
$id = (int)$id;
}
$max_thread = 0;
$threads = $this->getSortedThreads($categories_ids, $max_thread);
$threads = $this->getSortedThreads($categories_ids, $max_thread, $show_deleted);

$currentCategoriesIds = array_key_exists('currentCategoriesId', $_POST) ? explode("|", $_POST["currentCategoriesId"]) : array();
$currentThreadId = array_key_exists('currentThreadId', $_POST) && !empty($_POST["currentThreadId"]) && is_numeric($_POST["currentThreadId"]) ? (int)$_POST["currentThreadId"] : -1;
Expand All @@ -544,7 +548,8 @@ public function showThreads(){
$category_id = in_array('thread_category', $_POST) ? $_POST['thread_category'] : -1;

$max_thread = 0;
$threads = $this->getSortedThreads(array($category_id), $max_thread);
$show_deleted = $this->showDeleted();
$threads = $this->getSortedThreads(array($category_id), $max_thread, $show_deleted);

$current_user = $this->core->getUser()->getId();

Expand All @@ -556,18 +561,18 @@ public function showThreads(){
if(!empty($_REQUEST["thread_id"])){
$thread_id = (int)$_REQUEST["thread_id"];
if($option == "alpha"){
$posts = $this->core->getQueries()->getPostsForThread($current_user, $thread_id, 'alpha');
$posts = $this->core->getQueries()->getPostsForThread($current_user, $thread_id, $show_deleted, 'alpha');
} else {
$posts = $this->core->getQueries()->getPostsForThread($current_user, $thread_id, 'tree');
$posts = $this->core->getQueries()->getPostsForThread($current_user, $thread_id, $show_deleted, 'tree');
}

}

if(empty($_REQUEST["thread_id"]) || empty($posts)) {
$posts = $this->core->getQueries()->getPostsForThread($current_user, -1);
$posts = $this->core->getQueries()->getPostsForThread($current_user, -1, $show_deleted);
}

$this->core->getOutput()->renderOutput('forum\ForumThread', 'showForumThreads', $user, $posts, $threads, $option, $max_thread);
$this->core->getOutput()->renderOutput('forum\ForumThread', 'showForumThreads', $user, $posts, $threads, $show_deleted, $option, $max_thread);
}

private function getAllowedCategoryColor() {
Expand Down
33 changes: 19 additions & 14 deletions site/app/libraries/database/DatabaseQueries.php
Expand Up @@ -110,31 +110,35 @@ public function insertSubmittyUser(User $user) {
throw new NotImplementedException();
}

public function loadAnnouncements($categories_ids){
public function loadAnnouncements($categories_ids, $show_deleted = false){
assert(count($categories_ids) > 0);
$query_multiple_qmarks = "?".str_repeat(",?", count($categories_ids)-1);
$query_parameters = array_merge( array(count($categories_ids)), $categories_ids );
$query_delete = $show_deleted?"true":"deleted = false";

$this->course_db->query("SELECT t.*, array_to_string(array_agg(e.category_id),'|') as categories_ids, array_to_string(array_agg(w.category_desc),'|') as categories_desc, array_to_string(array_agg(w.color),'|') as categories_color FROM threads t, thread_categories e, categories_list w WHERE deleted = false and pinned = true and t.id = e.thread_id and e.category_id = w.category_id GROUP BY t.id HAVING ? = (SELECT count(*) FROM thread_categories tc WHERE tc.thread_id = t.id and category_id IN (".$query_multiple_qmarks.")) ORDER BY t.id DESC", $query_parameters);
$this->course_db->query("SELECT t.*, array_to_string(array_agg(e.category_id),'|') as categories_ids, array_to_string(array_agg(w.category_desc),'|') as categories_desc, array_to_string(array_agg(w.color),'|') as categories_color FROM threads t, thread_categories e, categories_list w WHERE {$query_delete} and pinned = true and t.id = e.thread_id and e.category_id = w.category_id GROUP BY t.id HAVING ? = (SELECT count(*) FROM thread_categories tc WHERE tc.thread_id = t.id and category_id IN (".$query_multiple_qmarks.")) ORDER BY t.id DESC", $query_parameters);
return $this->course_db->rows();
}

public function loadAnnouncementsWithoutCategory(){
$this->course_db->query("SELECT t.*, array_to_string(array_agg(e.category_id),'|') as categories_ids, array_to_string(array_agg(w.category_desc),'|') as categories_desc, array_to_string(array_agg(w.color),'|') as categories_color FROM threads t, thread_categories e, categories_list w WHERE deleted = false and pinned = true and t.id = e.thread_id and e.category_id = w.category_id GROUP BY t.id ORDER BY t.id DESC");
return $this->course_db->rows();
public function loadAnnouncementsWithoutCategory($show_deleted = false){
$query_delete = $show_deleted?"true":"deleted = false";
$this->course_db->query("SELECT t.*, array_to_string(array_agg(e.category_id),'|') as categories_ids, array_to_string(array_agg(w.category_desc),'|') as categories_desc, array_to_string(array_agg(w.color),'|') as categories_color FROM threads t, thread_categories e, categories_list w WHERE {$query_delete} and pinned = true and t.id = e.thread_id and e.category_id = w.category_id GROUP BY t.id ORDER BY t.id DESC");
return $this->course_db->rows();
}

public function loadThreadsWithoutCategory(){
$this->course_db->query("SELECT t.*, array_to_string(array_agg(e.category_id),'|') as categories_ids, array_to_string(array_agg(w.category_desc),'|') as categories_desc, array_to_string(array_agg(w.color),'|') as categories_color FROM threads t, thread_categories e, categories_list w WHERE deleted = false and pinned = false and t.id = e.thread_id and e.category_id = w.category_id GROUP BY t.id ORDER BY t.id DESC");
return $this->course_db->rows();
public function loadThreadsWithoutCategory($show_deleted = false){
$query_delete = $show_deleted?"true":"deleted = false";
$this->course_db->query("SELECT t.*, array_to_string(array_agg(e.category_id),'|') as categories_ids, array_to_string(array_agg(w.category_desc),'|') as categories_desc, array_to_string(array_agg(w.color),'|') as categories_color FROM threads t, thread_categories e, categories_list w WHERE {$query_delete} and pinned = false and t.id = e.thread_id and e.category_id = w.category_id GROUP BY t.id ORDER BY t.id DESC");
return $this->course_db->rows();
}

public function loadThreads($categories_ids) {
public function loadThreads($categories_ids, $show_deleted = false) {
assert(count($categories_ids) > 0);
$query_multiple_qmarks = "?".str_repeat(",?", count($categories_ids)-1);
$query_parameters = array_merge( array(count($categories_ids)), $categories_ids );
$query_delete = $show_deleted?"true":"deleted = false";

$this->course_db->query("SELECT t.*, array_to_string(array_agg(e.category_id),'|') as categories_ids, array_to_string(array_agg(w.category_desc),'|') as categories_desc, array_to_string(array_agg(w.color),'|') as categories_color FROM threads t, thread_categories e, categories_list w WHERE deleted = false and pinned = false and t.id = e.thread_id and e.category_id = w.category_id GROUP BY t.id HAVING ? = (SELECT count(*) FROM thread_categories tc WHERE tc.thread_id = t.id and category_id IN (".$query_multiple_qmarks.")) ORDER BY t.id DESC", $query_parameters);
$this->course_db->query("SELECT t.*, array_to_string(array_agg(e.category_id),'|') as categories_ids, array_to_string(array_agg(w.category_desc),'|') as categories_desc, array_to_string(array_agg(w.color),'|') as categories_color FROM threads t, thread_categories e, categories_list w WHERE {$query_delete} and pinned = false and t.id = e.thread_id and e.category_id = w.category_id GROUP BY t.id HAVING ? = (SELECT count(*) FROM thread_categories tc WHERE tc.thread_id = t.id and category_id IN (".$query_multiple_qmarks.")) ORDER BY t.id DESC", $query_parameters);
return $this->course_db->rows();
}

Expand Down Expand Up @@ -2212,20 +2216,21 @@ public function getCategories(){
return $this->course_db->rows();
}

public function getPostsForThread($current_user, $thread_id, $option = "tree"){
public function getPostsForThread($current_user, $thread_id, $show_deleted = false, $option = "tree"){
$query_delete = $show_deleted?"true":"deleted = false";
if($thread_id == -1) {
$announcement_id = $this->existsAnnouncements();
if($announcement_id == -1){
$this->course_db->query("SELECT MAX(id) as max from threads WHERE deleted = false and pinned = false");
$this->course_db->query("SELECT MAX(id) as max from threads WHERE {$query_delete} and pinned = false");
$thread_id = $this->course_db->rows()[0]["max"];
} else {
$thread_id = $announcement_id;
}
}
if($option == 'alpha'){
$this->course_db->query("SELECT posts.*, users.user_lastname FROM posts INNER JOIN users ON posts.author_user_id=users.user_id WHERE thread_id=? AND deleted = false ORDER BY user_lastname, posts.timestamp;", array($thread_id));
$this->course_db->query("SELECT posts.*, users.user_lastname FROM posts INNER JOIN users ON posts.author_user_id=users.user_id WHERE thread_id=? AND {$query_delete} ORDER BY user_lastname, posts.timestamp;", array($thread_id));
} else {
$this->course_db->query("SELECT * FROM posts WHERE thread_id=? AND deleted = false ORDER BY timestamp ASC", array($thread_id));
$this->course_db->query("SELECT * FROM posts WHERE thread_id=? AND {$query_delete} ORDER BY timestamp ASC", array($thread_id));
}

$result_rows = $this->course_db->rows();
Expand Down
19 changes: 16 additions & 3 deletions site/app/views/forum/ForumThreadView.php
Expand Up @@ -144,7 +144,7 @@ public function searchResult($threads){
for a specific thread, in addition to all of the threads
that have been created to be displayed in the left panel.
*/
public function showForumThreads($user, $posts, $threads, $display_option, $max_thread) {
public function showForumThreads($user, $posts, $threads, $show_deleted, $display_option, $max_thread) {
if(!$this->forumAccess()){
$this->core->redirect($this->core->buildUrl(array('component' => 'navigation')));
return;
Expand Down Expand Up @@ -228,8 +228,15 @@ function changeName(element, user, visible_username, anon){
<a class="btn btn-primary" style="position:relative;top:3px;left:5px;" title="Create thread" onclick="resetScrollPosition();" href="{$this->core->buildUrl(array('component' => 'forum', 'page' => 'create_thread'))}"><i class="fa fa-plus-circle"></i> Create Thread</a>
HTML;
if($this->core->getUser()->getGroup() <= 2){

if($show_deleted) {
$show_deleted_class = "active";
$show_deleted_action = "alterShowDeletedStatus(0);";
} else {
$show_deleted_class = "";
$show_deleted_action = "alterShowDeletedStatus(1);";
}
$return .= <<<HTML
<a class="btn btn-primary {$show_deleted_class}" style="margin-left:10px;position:relative;top:3px;right:5px;display:inline-block;" title="Show Deleted Threads" onclick="{$show_deleted_action}">Show Deleted Threads</a>
<a class="btn btn-primary" style="margin-left:10px;position:relative;top:3px;right:5px;display:inline-block;" title="Show Stats" onclick="resetScrollPosition();" href="{$this->core->buildUrl(array('component' => 'forum', 'page' => 'show_stats'))}">Stats</a>
HTML;
}
Expand Down Expand Up @@ -572,6 +579,9 @@ public function displayThreadList($threads, $filtering, &$activeThreadAnnounceme
if($this->core->getQueries()->viewedThread($current_user, $thread["id"])){
$class .= " viewed";
}
if($thread["deleted"]) {
$class .= " deleted";
}

//fix legacy code
$titleDisplay = html_entity_decode($thread['title'], ENT_QUOTES | ENT_HTML5, 'UTF-8');
Expand Down Expand Up @@ -672,6 +682,9 @@ public function createPost($thread_id, $post, $function_date, $title_html, $firs
if($this->core->getQueries()->isStaffPost($post["author_user_id"])){
$classes .= " important";
}
if($post["deleted"]) {
$classes .= " deleted";
}
$offset = min(($reply_level - 1) * 30, 180);

$return = <<<HTML
Expand Down Expand Up @@ -778,7 +791,7 @@ public function createPost($thread_id, $post, $function_date, $title_html, $firs
$edit_button_title = "Edit post";
}
$return .= <<<HTML
<a class="post_button" style="bottom: 1px;position:relative; display:inline-block; color:red; float:right;" onClick="deletePost( {$post['thread_id']}, {$post['id']}, '{$post['author_user_id']}', '{$function_date($date,'n/j g:i A')}' )" title="Remove post"><i class="fa fa-times" aria-hidden="true"></i></a>
<a class="post_button" style="bottom: 1px;position:relative; display:inline-block; float:right;" onClick="deletePost( {$post['thread_id']}, {$post['id']}, '{$post['author_user_id']}', '{$function_date($date,'n/j g:i A')}' )" title="Remove post"><i class="fa fa-trash" aria-hidden="true"></i></a>
<a class="post_button" style="position:relative; display:inline-block; color:black; float:right;" onClick="editPost({$post['id']}, {$post['thread_id']}, {$shouldEditThread})" title="{$edit_button_title}"><i class="fa fa-edit" aria-hidden="true"></i></a>
HTML;
}
Expand Down
8 changes: 8 additions & 0 deletions site/public/css/server.css
Expand Up @@ -577,6 +577,14 @@ table tr.table-header {
background-color: #21C2F6;
}

.deleted {
background-color: #FFCCCC !important;
}

.deleted.active {
background-color: #FF9999;
}

.important {
/* THIS IS WHERE THE BACKGROUND COLOR FOR POSTS IS */
border-style: solid;
Expand Down
7 changes: 6 additions & 1 deletion site/public/js/server.js
Expand Up @@ -1634,6 +1634,11 @@ function saveScrollLocationOnRefresh(id){
});
}

function alterShowDeletedStatus(newStatus) {
document.cookie = "show_deleted=" + newStatus + "; path=/;";
location.reload();
}

function modifyThreadList(currentThreadId, currentCategoriesId){
var categories_value = $("#thread_category").val();
categories_value = (categories_value == null)?"":categories_value.join("|");
Expand All @@ -1644,7 +1649,7 @@ function modifyThreadList(currentThreadId, currentCategoriesId){
data: {
thread_categories: categories_value,
currentThreadId: currentThreadId,
currentCategoriesId: currentCategoriesId
currentCategoriesId: currentCategoriesId,
},
success: function(r){
var x = JSON.parse(r).html;
Expand Down