winix/plugins/thread/showthreads.cpp

145 lines
2.3 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2012, Tomasz Sowa
* All rights reserved.
*
*/
#include <algorithm>
#include "showthreads.h"
#include "functions.h"
namespace Thread
{
ShowThreads::ShowThreads()
{
fun.url = L"showthreads";
}
void ShowThreads::SetTDb(TDb * ptdb)
{
tdb = ptdb;
}
void ShowThreads::SetThreadInfo(ThreadInfo * pthread_info)
{
thread_info = pthread_info;
}
bool ShowThreads::HasAccess()
{
if( cur->request->is_item )
return false;
if( system->mounts.pmount->type != thread_info->mount_type_thread )
return false;
return true;
}
bool ShowThreads::Sort::operator()(const Item * item1, const Item * item2)
{
if( sort_type == 0 )
{
// sorting by url
return item1->url < item2->url;
}
else
{
// sorting by date
return item1->date_creation > item2->date_creation;
}
}
void ShowThreads::ReadFiles()
{
// reading files
DbItemQuery iq;
iq.SetAll(false, false);
iq.sel_url = true;
iq.sel_subject = true;
iq.sel_date = true;
iq.sel_user_id = true;
iq.sel_group_id = true;
iq.sel_guest_name = true;
iq.sel_privileges = true;
iq.sel_date = true;
iq.WhereParentId(cur->request->dir_tab.back()->id);
iq.WhereType(Item::file);
iq.WhereFileType(WINIX_ITEM_FILETYPE_NONE);
db->GetItems(thread_info->item_tab, iq);
system->CheckAccessToItems(thread_info->item_tab);
}
void ShowThreads::CreatePointers()
{
// creating a pointers table
thread_info->item_sort_tab.resize(thread_info->item_tab.size());
for(size_t i=0 ; i<thread_info->item_tab.size() ; ++i)
thread_info->item_sort_tab[i] = &thread_info->item_tab[i];
}
void ShowThreads::SortPointers()
{
int sort_type = 1;
if( cur->request->ParamValue(L"sort") == L"url" )
sort_type = 0;
std::vector<Item*> & table = thread_info->item_sort_tab;
std::sort(table.begin(), table.end(), Sort(this, sort_type));
}
void ShowThreads::ReadThreads()
{
// reading threads for the files
file_id_tab.resize(thread_info->item_sort_tab.size());
for(size_t i=0 ; i<thread_info->item_sort_tab.size() ; ++i)
file_id_tab[i] = thread_info->item_sort_tab[i]->id;
tdb->GetThreads(file_id_tab, thread_info->thread_tab);
}
void ShowThreads::MakeGet()
{
thread_info->Clear();
ReadFiles();
CreatePointers();
SortPointers();
ReadThreads();
}
} // namespace