-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDataControl.cs
439 lines (397 loc) · 15.3 KB
/
DataControl.cs
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
/* *********************************************************************************************
*
* WatchersNET.TagCloud - This Module displays the most frequently used words (Tags) of your Portal as a
* standard Web 2.0 Tag Cloud, or You can define your own Tags list. The Tags are links which linked to the Portal Search to
* show all Pages with that Tag.
*
* The Tag Cloud will be rendered as 3D Cloud, and as alternative for Non Flash
* Users as a list of hyperlinks in varying styles depending on a weight.
* This is similar to tag clouds in del.icio.us or Flickr.
*
* Copyright(c) Ingo Herbote ([email protected])
* All rights reserved.
* Internet: https://github.com/w8tcha/WatchersNET.TagCloud
*
* WatchersNET.TagCloud is released under the New BSD License, see below
************************************************************************************************
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/
* or other materials provided with the distribution.
*
* * Neither the name of WatchersNET nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************************************
*/
namespace WatchersNET.DNN.Modules.TagCloud
{
#region
using System;
using System.Collections.Generic;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Modules.ActiveForums;
using DotNetNuke.Modules.ActiveForums.Data;
using VRK.Controls;
using WatchersNET.DNN.Modules.TagCloud.Constants;
using WatchersNET.DNN.Modules.TagCloud.Objects;
using DataProvider = DotNetNuke.Data.DataProvider;
#endregion
/// <summary>
/// The data control.
/// </summary>
public class DataControl : PortalModuleBase
{
#region Public Methods
/// <summary>
/// Get Tag Cloud Items From Active Forums SQL
/// </summary>
/// <param name="iPortalId">
/// The PortalId of the Forums
/// </param>
/// <param name="iModuleId">
/// The Module Instance of the Active Forums
/// </param>
/// <param name="tagCount">
/// The tag Count.
/// </param>
/// <returns>
/// The Tags
/// </returns>
public static List<CloudItem> TagCloudActiveForumsTags(int iPortalId, int iModuleId, int tagCount)
{
// Get Current Forum User
var forumUser = new UserController().GetUser(iPortalId, iModuleId);
var forumIds = !string.IsNullOrEmpty(forumUser.UserForums)
? forumUser.UserForums
: GetForumsForUser(
forumUser.UserRoles, iPortalId, iModuleId);
var afTagsList = new List<CloudItem>();
using (var dr = new Common().TagCloud_Get(iPortalId, iModuleId, forumIds, tagCount))
{
while (dr.Read())
{
var item = new CloudItem
{
Weight = Convert.ToInt32(dr["Priority"]), Text = dr["TagName"].ToString()
};
afTagsList.Add(item);
}
}
return afTagsList;
}
/// <summary>
/// Gets the forums for user.
/// </summary>
/// <param name="UserRoles">The user roles.</param>
/// <param name="PortalId">The portal id.</param>
/// <param name="ModuleId">The module id.</param>
/// <param name="PermissionType">Type of the permission.</param>
/// <returns></returns>
private static string GetForumsForUser(string UserRoles, int PortalId, int ModuleId, string PermissionType = "CanView")
{
var forumsDb = new ForumsDB();
var str = string.Empty;
foreach (Forum forum in forumsDb.Forums_List(PortalId, ModuleId))
{
string AuthorizedRoles;
switch (PermissionType)
{
case "CanView":
AuthorizedRoles = forum.Security.View;
break;
case "CanRead":
AuthorizedRoles = forum.Security.Read;
break;
case "CanApprove":
AuthorizedRoles = forum.Security.ModApprove;
break;
case "CanEdit":
AuthorizedRoles = forum.Security.ModEdit;
break;
default:
AuthorizedRoles = forum.Security.View;
break;
}
if ((Permissions.HasPerm(AuthorizedRoles, UserRoles)
|| !forum.Hidden && (PermissionType == "CanView" || PermissionType == "CanRead")) && forum.Active)
{
str = $"{str}{forum.ForumID};";
}
}
return str;
}
/// <summary>
/// The tag cloud items add.
/// </summary>
/// <param name="objTag">
/// The obj tag.
/// </param>
/// <returns>
/// Returns the Tag ID of the new Tag
/// </returns>
public static int TagCloudItemsAdd(CustomTags objTag)
{
return
Convert.ToInt32(
DataProvider.Instance().ExecuteScalar(
"TagCloudItemsAdd", objTag.TagId, objTag.Weight, objTag.Tag, objTag.ModuleId, objTag.Url));
}
/// <summary>
/// The tag cloud items add ml.
/// </summary>
/// <param name="iTagId">
/// The i tag id.
/// </param>
/// <param name="sLocale">
/// The s locale.
/// </param>
/// <param name="sTag">
/// The s tag.
/// </param>
/// <param name="iModuleId">
/// The i module id.
/// </param>
/// <param name="sTagUrl">
/// The s tag url.
/// </param>
public static void TagCloudItemsAddMl(int iTagId, string sLocale, string sTag, int iModuleId, string sTagUrl)
{
DataProvider.Instance().ExecuteScalar("TagCloudItemsAddMl", iTagId, sLocale, sTag, iModuleId, sTagUrl);
}
/// <summary>
/// The tag cloud items delete.
/// </summary>
/// <param name="iTagId">
/// The i tag id.
/// </param>
/// <param name="iModulId">
/// The i modul id.
/// </param>
public static void TagCloudItemsDelete(int iTagId, int iModulId)
{
DataProvider.Instance().ExecuteNonQuery("TagCloudItemsDelete", iTagId, iModulId);
}
/// <summary>
/// The tag cloud items delete ml.
/// </summary>
/// <param name="iTagId">
/// The i tag id.
/// </param>
/// <param name="iModulId">
/// The i modul id.
/// </param>
/// <param name="sLocale">
/// The s locale.
/// </param>
public static void TagCloudItemsDeleteMl(int iTagId, int iModulId, string sLocale)
{
DataProvider.Instance().ExecuteNonQuery("TagCloudItemsDeleteMl", iTagId, iModulId, sLocale);
}
/// <summary>
/// Get All Locales of the Tag by TagID and ModuleId
/// </summary>
/// <param name="iModulId">
/// Module Id that is uses
/// </param>
/// <param name="iTagId">
/// the Tag id
/// </param>
/// <returns>
/// All Locales of the Tag
/// </returns>
public static List<Locales> TagCloudItemsGetByLocale(int iModulId, int iTagId)
{
var localesList = new List<Locales>();
using (var dr = DataProvider.Instance().ExecuteReader("TagCloudItemsGetByLocale", iModulId, iTagId))
{
while (dr.Read())
{
var locales = new Locales
{
Locale = Convert.ToString(dr["Locale"]),
TagMl = Convert.ToString(dr["Tag"]),
UrlMl = Convert.ToString(dr["TagUrl"])
};
localesList.Add(locales);
}
}
return localesList;
}
/// <summary>
/// The tag cloud items get by module.
/// </summary>
/// <param name="iModulId">
/// The module id.
/// </param>
/// <returns>
/// TagCloud Item List
/// </returns>
public static List<CustomTags> TagCloudItemsGetByModule(int iModulId)
{
var tagsList = new List<CustomTags>();
using (var dr = DataProvider.Instance().ExecuteReader("TagCloudItemsGetByModule", iModulId))
{
while (dr.Read())
{
var tag = new CustomTags
{
TagId = Convert.ToInt32(dr["TagID"]),
Weight = Convert.ToInt32(dr["Weight"]),
Tag = Convert.ToString(dr["Tag"]),
Url = Convert.ToString(dr["TagUrl"])
};
tagsList.Add(tag);
}
}
return tagsList;
}
/// <summary>
/// The tag cloud items update.
/// </summary>
/// <param name="objTag">
/// The obj tag.
/// </param>
public static void TagCloudItemsUpdate(CustomTags objTag)
{
DataProvider.Instance().ExecuteNonQuery(
"TagCloudItemsUpdate", objTag.TagId, objTag.Weight, objTag.Tag, objTag.ModuleId, objTag.Url);
}
/// <summary>
/// Get the Occurrence Count for the selected Words Id
/// </summary>
/// <param name="searchWordsId">the Id of the Word</param>
/// <returns>
/// The Count of Occurrences
/// </returns>
public static int TagCloudSearchWordsOccur(int searchWordsId)
{
using (var dr = DataProvider.Instance().ExecuteReader("TagCloud_SearchWords", searchWordsId))
{
while (dr.Read())
{
searchWordsId = Convert.ToInt32(dr["Occurrences"]);
}
}
return searchWordsId;
}
/// <summary>
/// Add ne Exclude Word
/// </summary>
/// <param name="addWord">
/// The add Word.
/// </param>
/// <returns>
/// The New Word ID
/// </returns>
public static int TagCloudExcludeWordAdd(ExcludeWord addWord)
{
return
Convert.ToInt32(
DataProvider.Instance().ExecuteScalar(
"TagCloudExcludeWordAdd", addWord.Word, addWord.ExcludeWordType, addWord.ModuleID, addWord.WordID));
}
/// <summary>
/// Update the Exclude Word
/// </summary>
/// <param name="updateWord">
/// The update Word.
/// </param>
public static void TagCloudExcludeWordUpdate(ExcludeWord updateWord)
{
DataProvider.Instance().ExecuteNonQuery(
"TagCloudExcludeWordUpdate", updateWord.Word, updateWord.ExcludeWordType, updateWord.ModuleID, updateWord.WordID);
}
/// <summary>
/// Delete the Exclude Word
/// </summary>
/// <param name="moduleId">
/// The module id.
/// </param>
/// <param name="wordId">
/// The word id.
/// </param>
public static void TagCloudExcludeWordDelete(int moduleId, int wordId)
{
DataProvider.Instance().ExecuteNonQuery("TagCloudExcludeWordDelete", moduleId, wordId);
}
/// <summary>
/// Get All Exclude Words by Module
/// </summary>
/// <param name="moduleId">
/// The module id.
/// </param>
/// <returns>
/// List with Exclude Words
/// </returns>
public static List<ExcludeWord> TagCloudExcludeWordsGetByModule(int moduleId)
{
var wordList = new List<ExcludeWord>();
using (var dr = DataProvider.Instance().ExecuteReader("TagCloudExcludeWordsGetByModule", moduleId))
{
while (dr.Read())
{
var word = new ExcludeWord
{
Word = Convert.ToString(dr["Word"]),
ExcludeWordType =
(ExcludeType)Enum.Parse(typeof(ExcludeType), Convert.ToString(dr["ExcludeWordType"])),
WordID = Convert.ToInt32(dr["WordID"]),
ModuleID = moduleId
};
wordList.Add(word);
}
}
return wordList;
}
/// <summary>
/// Get Exclude Word by moduleId and wordId
/// </summary>
/// <param name="moduleId">
/// The module id.
/// </param>
/// <param name="wordId">
/// The word id.
/// </param>
/// <returns>
/// Returns a specific Exclude Word
/// </returns>
public static ExcludeWord TagCloudExcludeWordsGetWord(int moduleId, int wordId)
{
ExcludeWord word = null;
using (var dr = DataProvider.Instance().ExecuteReader("TagCloudExcludeWordsGetWord", moduleId, wordId))
{
while (dr.Read())
{
word = new ExcludeWord
{
Word = Convert.ToString(dr["Word"]),
ExcludeWordType =
(ExcludeType)Enum.Parse(typeof(ExcludeType), Convert.ToString(dr["ExcludeWordType"])),
WordID = wordId,
ModuleID = moduleId
};
}
}
return word;
}
#endregion
}
}