File: logic.cpp

package info (click to toggle)
bibledit 5.0.764-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 230,136 kB
  • sloc: xml: 863,336; ansic: 164,208; cpp: 81,648; sh: 4,684; makefile: 406; php: 69
file content (137 lines) | stat: -rw-r--r-- 4,125 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 Copyright (©) 2003-2018 Teus Benschop.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */


#include <changes/logic.h>
#include <changes/changes.h>
#include <changes/statistics.h>
#include <changes/manage.h>
#include <tasks/logic.h>
#include <pugixml/pugixml.hpp>
#include <locale/translate.h>
#include <index/listing.h>
#include <database/logs.h>
#include <database/modifications.h>
#include <database/jobs.h>
#include <filter/string.h>
#include <webserver/request.h>


using namespace pugi;


void changes_logic_start ()
{
  tasks_logic_queue (GENERATECHANGES);
}


const char * changes_personal_category ()
{
  return "P";
}


const char * changes_bible_category ()
{
  return "B";
}


string changes_interlinks (void * webserver_request, string my_url)
{
  // The available links.
  vector <string> urls;
  vector <string> labels;
  if (changes_changes_acl (webserver_request)) {
    urls.push_back (changes_changes_url ());
    labels.push_back (translate ("View"));
  }
#ifndef HAVE_CLIENT
  if (changes_statistics_acl (webserver_request)) {
    urls.push_back (changes_statistics_url ());
    labels.push_back (translate ("Statistics"));
  }
  if (index_listing_acl (webserver_request, "revisions")) {
    urls.push_back (index_listing_url ("revisions"));
    labels.push_back (translate ("Download"));
  }
  if (changes_manage_acl (webserver_request)) {
    urls.push_back (changes_manage_url ());
    labels.push_back (translate ("Manage"));
  }
#endif

  // Generate the links in XML.
  xml_document document;
  bool first = true;
  for (unsigned int i = 0; i < urls.size (); i++) {
    if (urls[i] == my_url) continue;
    if (!first) {
      xml_node node = document.append_child ("span");
      node.text ().set (" | ");
    }
    first = false;
    xml_node a = document.append_child ("a");
    string href = "/" + urls[i];
    a.append_attribute ("href") = href.c_str();
    a.text ().set (labels[i].c_str());
  }
  
  // Convert the document to a string.
  stringstream output;
  document.print (output, "", format_raw);
  return output.str ();
}


void changes_clear_notifications_user (string jobid, string username)
{
  Database_Logs::log (translate ("Start clearing change notifications") + " " + username);
  
  Database_Modifications database_modifications;
  Database_Jobs database_jobs;

  // Get the total amount of change notifications to clear for the user.
  vector <int> identifiers = database_modifications.getNotificationIdentifiers (username);
  
  // Total notes cleared.
  int total_cleared = 0;
  
  // Feedback.
  database_jobs.setPercentage (convert_to_int (jobid), 0);
  database_jobs.setProgress (convert_to_int (jobid), translate ("Total:") + " " + convert_to_string (identifiers.size()));


  // The amount of notifications it clears in the next iteration.
  int cleared_count_in_one_go = 0;
  do {
    cleared_count_in_one_go = database_modifications.clearNotificationsUser (username);
    total_cleared += cleared_count_in_one_go;
    if (!identifiers.empty ()) {
      database_jobs.setPercentage (convert_to_int (jobid), 100 * total_cleared / identifiers.size());
    }
  } while (cleared_count_in_one_go);
  
  Webserver_Request request;
  request.database_config_user ()->setUserChangeNotificationsChecksum (username, "");
  
  database_jobs.setResult (convert_to_int (jobid), translate ("Ready clearing change notifications"));
  
  Database_Logs::log (translate ("Ready clearing change notifications") + " " + username);
}