-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathsync.php
741 lines (662 loc) · 21.5 KB
/
sync.php
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
<?php
/**
*
* This file is part of the phpBB Customisation Database package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\titania;
use phpbb\titania\contribution\type\collection as type_collection;
/**
* Sync handler for Titania
*
* Hopefully we never need to use this, but we probably will at some point, so put all sync stuff in here for easy access (and not to take up extra space in other files when they will rarely, if ever, be needed)
*/
class sync
{
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\titania\cache\service */
protected $cache;
/** @var \phpbb\titania\attachment\attachment */
protected $attachment;
/** @var \phpbb\titania\search\manager */
protected $search_manager;
/** @var type_collection */
protected $types;
/** @var string */
protected $attachments_table;
/** @var string */
protected $authors_table;
/** @var string */
protected $categories_table;
/** @var string */
protected $contrib_coauthors_table;
/** @var string */
protected $contrib_faq_table;
/** @var string */
protected $contrib_in_categories_table;
/** @var string */
protected $contribs_table;
/** @var string */
protected $posts_table;
/** @var string */
protected $queue_table;
/** @var string */
protected $revisions_table;
/** @var string */
protected $topics_table;
/**
* Constructor
*
* @param \phpbb\db\driver\driver_interface $db
* @param cache\service $cache
* @param attachment\attachment $attachment
* @param search\manager $search_manager
* @param type_collection $types
*/
public function __construct(\phpbb\db\driver\driver_interface $db, cache\service $cache, \phpbb\titania\attachment\attachment $attachment, search\manager $search_manager, type_collection $types)
{
$this->db = $db;
$this->cache = $cache;
$this->attachment = $attachment;
$this->search_manager = $search_manager;
$this->types = $types;
$this->attachments_table = TITANIA_ATTACHMENTS_TABLE;
$this->authors_table = TITANIA_AUTHORS_TABLE;
$this->categories_table = TITANIA_CATEGORIES_TABLE;
$this->contrib_coauthors_table = TITANIA_CONTRIB_COAUTHORS_TABLE;
$this->contrib_faq_table = TITANIA_CONTRIB_FAQ_TABLE;
$this->contrib_in_categories_table = TITANIA_CONTRIB_IN_CATEGORIES_TABLE;
$this->contribs_table = TITANIA_CONTRIBS_TABLE;
$this->posts_table = TITANIA_POSTS_TABLE;
$this->queue_table = TITANIA_QUEUE_TABLE;
$this->revisions_table = TITANIA_REVISIONS_TABLE;
$this->topics_table = TITANIA_TOPICS_TABLE;
}
/**
* Sync attachments
*/
public function attachments($mode, $attachment_id = false)
{
switch ($mode)
{
case 'hash' :
$sql = 'SELECT *
FROM ' . $this->attachments_table .
(($attachment_id !== false) ? 'WHERE attachment_id = ' . (int) $attachment_id : '');
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$this->attachment->__set_array($row);
$file = $this->attachment->get_filepath();
if (file_exists($file))
{
$md5 = md5_file($file);
if ($md5 != $row['hash'])
{
$sql = 'UPDATE ' . $this->attachments_table . '
SET hash = "' . $this->db->sql_escape($md5) . '"
WHERE attachment_id = ' . $row['attachment_id'];
$this->db->sql_query($sql);
}
}
}
$this->db->sql_freeresult($result);
break;
}
}
/**
* Sync authors
*
* @param string $mode The mode (count)
* @param int|bool $user_id (Optional) User id to limit to. Defaults to false.
*/
public function authors($mode, $user_id = false)
{
switch ($mode)
{
case 'count' :
// Reset the count for all authors first
$sql_ary = array(
'author_contribs' => 0,
);
foreach ($this->types->get_all() as $type_id => $class)
{
if (!isset($class->author_count))
{
continue;
}
$sql_ary[$class->author_count] = 0;
}
$sql = 'UPDATE ' . $this->authors_table . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary);
$this->db->sql_query($sql);
$sql = 'SELECT DISTINCT(contrib_user_id) AS user_id
FROM ' . $this->contribs_table .
(($user_id) ? ' WHERE contrib_user_id = ' . (int) $user_id : '');
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$sql_ary = $this->_get_author_count($row['user_id']);
// sql_affectedrows does not work if the count is 0 across the board
$sql = 'SELECT author_id
FROM ' . $this->authors_table . '
WHERE user_id = ' . (int) $row['user_id'];
$this->db->sql_query($sql);
$author_id = $this->db->sql_fetchfield('author_id');
$this->db->sql_freeresult();
if ($author_id)
{
// Increment/Decrement the contrib counter for the new owner
$sql = 'UPDATE ' . $this->authors_table . '
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
WHERE user_id = ' . (int) $row['user_id'];
$this->db->sql_query($sql);
}
else
{
$author = new \titania_author($row['user_id']);
$author->__set_array($sql_ary);
$author->submit();
}
}
$this->db->sql_freeresult($result);
break;
}
}
/**
* Sync categories
*
* @param string $mode The mode (count)
* @param int|bool $cat_id (Optional) Category id to limit to. Defaults to false.
*/
public function categories($mode, $cat_id = false)
{
switch ($mode)
{
case 'count' :
$sql = 'SELECT category_id, category_contribs
FROM ' . $this->categories_table .
(($cat_id) ? ' WHERE category_id = ' . (int) $cat_id : '');
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$contrib_count = $this->_get_contrib_count($row['category_id']);
if ($row['category_contribs'] != $contrib_count)
{
$sql = 'UPDATE ' . $this->categories_table . '
SET category_contribs = ' . (int) $contrib_count . '
WHERE category_id = ' . (int) $row['category_id'];
$this->db->sql_query($sql);
}
}
$this->db->sql_freeresult($result);
break;
}
}
/**
* Sync contribs
*
* @param string $mode The mode (validated)
* @param int|bool $contrib_id Contrib id to limit to
* @param int|bool $start For indexing only
* @param int|bool $limit For indexing only
*/
public function contribs($mode, $contrib_id = false, $start = false, $limit = false)
{
switch ($mode)
{
case 'validated' :
$sql = 'SELECT contrib_id, contrib_status
FROM ' . $this->contribs_table .
(($contrib_id) ? ' AND contrib_id = ' . (int) $contrib_id : '');
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$sql = 'SELECT COUNT(revision_id) AS cnt
FROM ' . $this->revisions_table . '
WHERE contrib_id = ' . $row['contrib_id'] . '
AND revision_status = ' . ext::TITANIA_REVISION_APPROVED;
$result1 = $this->db->sql_query($sql);
$cnt = $this->db->sql_fetchfield('cnt', false, $result1);
$this->db->sql_freeresult($result1);
if (($cnt > 0 && $row['contrib_status'] == ext::TITANIA_CONTRIB_NEW) || ($cnt == 0 && $row['contrib_status'] == ext::TITANIA_CONTRIB_APPROVED))
{
$sql = 'UPDATE ' . $this->contribs_table . ' SET contrib_status = ' . (($cnt > 0) ? ext::TITANIA_CONTRIB_APPROVED : ext::TITANIA_CONTRIB_NEW) . '
WHERE contrib_id = ' . $row['contrib_id'];
$this->db->sql_query($sql);
}
}
$this->db->sql_freeresult($result);
break;
case 'faq_count' :
$contribs = array();
$sql = 'SELECT faq_access, contrib_id
FROM ' . $this->contrib_faq_table;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$flags = count::update_flags($row['faq_access']);
$contribs[$row['contrib_id']] = count::increment(((isset($contribs[$row['contrib_id']])) ? $contribs[$row['contrib_id']] : ''), $flags);
}
$this->db->sql_freeresult($result);
foreach ($contribs as $contrib_id => $count)
{
$sql = 'UPDATE ' . $this->contribs_table . '
SET contrib_faq_count = \'' . $this->db->sql_escape($count) . '\'
WHERE contrib_id = ' . $contrib_id;
$this->db->sql_query($sql);
}
break;
case 'index' :
$data = $contribs = array();
$sql = 'SELECT * FROM ' . $this->contribs_table . '
ORDER BY contrib_id ASC';
if ($start === false || $limit === false)
{
$result = $this->db->sql_query($sql);
}
else
{
$result = $this->db->sql_query_limit($sql, (int) $limit, (int) $start);
}
while ($row = $this->db->sql_fetchrow($result))
{
$data[$row['contrib_id']] = array(
'object_type' => ext::TITANIA_CONTRIB,
'object_id' => $row['contrib_id'],
'title' => $row['contrib_name'],
'text' => $row['contrib_desc'],
'text_uid' => $row['contrib_desc_uid'],
'text_bitfield' => $row['contrib_desc_bitfield'],
'text_options' => $row['contrib_desc_options'],
'author' => $row['contrib_user_id'],
'date' => $row['contrib_last_update'],
'url' => serialize(array(
'contrib_type' => $this->types->get($row['contrib_type'])->url,
'contrib' => $row['contrib_name_clean'],
)),
'approved' => (in_array($row['contrib_status'], array(ext::TITANIA_CONTRIB_APPROVED, ext::TITANIA_CONTRIB_DOWNLOAD_DISABLED))) ? true : false,
'categories' => explode(',', $row['contrib_categories']),
);
$contribs[] = $row['contrib_id'];
}
$this->db->sql_freeresult($result);
$sql = 'SELECT DISTINCT contrib_id, phpbb_version_branch, phpbb_version_revision
FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . '
WHERE ' . $this->db->sql_in_set('contrib_id', $contribs) . '
AND revision_validated = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$phpbb_versions[$row['contrib_id']][] = $row;
}
$this->db->sql_freeresult($result);
foreach ($data as $contrib_id => $contrib_data)
{
if (isset($phpbb_versions[$contrib_id]))
{
$data[$contrib_id]['phpbb_versions'] = versions::order_phpbb_version_list_from_db(
$this->cache,
$phpbb_versions[$contrib_id]
);
}
}
$this->search_manager->mass_index($data);
break;
}
}
/**
* Sync topics
*
* @param string $mode The mode (post_count - topics_posts field)
* @param int|bool $topic_id (Optional) Topic id to limit to. Defaults to false.
*/
public function topics($mode, $topic_id = false)
{
switch ($mode)
{
// Sync the topics_posts field
case 'post_count' :
$sql = 'SELECT topic_id, topic_posts
FROM ' . $this->topics_table .
(($topic_id) ? ' WHERE topic_id = ' . (int) $topic_id : '') . '
ORDER BY topic_id ASC';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$post_count = $this->_get_post_count($row['topic_id']);
if ($row['topic_posts'] != $post_count)
{
$sql = 'UPDATE ' . $this->topics_table . '
SET topic_posts = "' . $post_count . '"
WHERE topic_id = ' . (int) $row['topic_id'];
$this->db->sql_query($sql);
}
}
$this->db->sql_freeresult($result);
break;
case 'queue_discussion_category' :
$sql = 'SELECT t.topic_id, c.contrib_type
FROM ' . $this->topics_table . ' t, ' . $this->contribs_table . ' c
WHERE c.contrib_id = t.parent_id
AND t.topic_type = ' . ext::TITANIA_QUEUE_DISCUSSION .
(($topic_id) ? ' AND topic_id = ' . (int) $topic_id : '') . '
ORDER BY topic_id ASC';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$sql = 'UPDATE ' . $this->topics_table . '
SET topic_category = ' . $row['contrib_type'] . '
WHERE topic_id = ' . $row['topic_id'];
$this->db->sql_query($sql);
}
$this->db->sql_freeresult($result);
break;
}
}
/**
* Sync posts.
*
* @param string $mode
* @param int|bool $start For indexing
* @param int|bool $limit For indexing
*/
public function posts($mode, $start = false, $limit = false)
{
switch ($mode)
{
case 'index' :
$data = array();
$post = new \titania_post;
$sql = 'SELECT p.*, t.topic_id, t.topic_type, t.topic_subject_clean, t.parent_id, q.queue_type, c.contrib_type
FROM ' . $this->posts_table . ' p, ' . $this->topics_table . ' t
LEFT JOIN ' . TITANIA_QUEUE_TABLE . ' q
ON (t.parent_id = q.queue_id AND t.topic_type = ' . ext::TITANIA_QUEUE . ')
LEFT JOIN ' . $this->contribs_table . ' c
ON (t.parent_id = c.contrib_id AND t.topic_type <> ' . ext::TITANIA_QUEUE . ')
WHERE t.topic_id = p.topic_id
ORDER BY p.post_id ASC';
if ($start === false || $limit === false)
{
$result = $this->db->sql_query($sql);
}
else
{
$result = $this->db->sql_query_limit($sql, (int) $limit, (int) $start);
}
while ($row = $this->db->sql_fetchrow($result))
{
$post->__set_array($row);
$post->topic->__set_array($row);
$data[] = array(
'object_type' => $post->post_type,
'object_id' => $post->post_id,
'parent_id' => $post->topic->parent_id,
'title' => $post->post_subject,
'text' => $post->post_text,
'text_uid' => $post->post_text_uid,
'text_bitfield' => $post->post_text_bitfield,
'text_options' => $post->post_text_options,
'author' => $post->post_user_id,
'date' => $post->post_time,
'url' => serialize($post->get_url_params()),
'approved' => $post->post_approved,
'access_level' => $post->post_access,
'parent_contrib_type' => (int) ($post->post_type == ext::TITANIA_QUEUE) ? $row['queue_type'] : $row['contrib_type'],
);
}
$this->db->sql_freeresult($result);
$this->search_manager->mass_index($data);
break;
}
}
/**
* Sync FAQ
*
* @param string $mode
*/
public function faqs($mode)
{
switch ($mode)
{
case 'index' :
$this->search_manager->truncate(ext::TITANIA_FAQ);
$data = array();
$sql = 'SELECT f.*, c.contrib_name_clean, c.contrib_type
FROM ' . $this->contrib_faq_table . ' f, ' . $this->contribs_table . ' c
WHERE c.contrib_id = f.contrib_id';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$data[] = array(
'object_type' => ext::TITANIA_FAQ,
'object_id' => $row['faq_id'],
'title' => $row['faq_subject'],
'text' => $row['faq_text'],
'text_uid' => $row['faq_text_uid'],
'text_bitfield' => $row['faq_text_bitfield'],
'text_options' => $row['faq_text_options'],
'author' => 0,
'date' => 0,
'url' => serialize(array(
'contrib_type' => $this->types->get($row['contrib_type'])->url,
'contrib' => $row['contrib_name_clean'],
'id' => $row['faq_id'],
)),
'access_level' => $row['faq_access'],
);
}
$this->db->sql_freeresult($result);
$this->search_manager->mass_index($data);
break;
}
}
/**
* Sync queue
*
* @param string $mode
* @param int|bool $queue_id (Optional) Queue id to limit to. Defaults to false.
*/
public function queue($mode, $queue_id = false)
{
switch ($mode)
{
case 'update_first_queue_post' :
$queue = new \titania_queue;
$contrib = new \titania_contribution;
$sql = 'SELECT *
FROM ' . $this->queue_table . ' q, ' . $this->contribs_table . ' c
WHERE c.contrib_id = q.contrib_id' .
(($queue_id) ? ' AND queue_id = ' . (int) $queue_id : '');
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$contrib->__set_array($row);
$contrib->set_type($row['contrib_type']);
$queue->__set_array($row);
$queue->update_first_queue_post(false, $contrib);
}
$this->db->sql_freeresult($result);
unset($queue);
break;
case 'revision_queue_id' :
$sql = 'SELECT queue_id, revision_id
FROM ' . $this->queue_table;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$sql = 'UPDATE ' . $this->revisions_table . '
SET revision_queue_id = ' . (int) $row['queue_id'] . '
WHERE revision_id = ' . (int) $row['revision_id'];
$this->db->sql_query($sql);
}
$this->db->sql_freeresult($result);
break;
}
}
/**
* Get contrib count for a category.
*
* @param $category_id
* @return int
*/
public function _get_contrib_count($category_id)
{
// Bundle up the children in a nice array
$child_list = array($category_id);
$sql = 'SELECT left_id, right_id
FROM ' . $this->categories_table . '
WHERE category_id = ' . (int) $category_id . '
ORDER BY left_id ASC';
$result = $this->db->sql_query($sql);
$cat_row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
if (!$cat_row)
{
return 0;
}
$sql = 'SELECT category_id
FROM ' . $this->categories_table . '
WHERE left_id > ' . $cat_row['left_id'] . '
AND right_id < ' . $cat_row['right_id'];
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$child_list[] = $row['category_id'];
}
$this->db->sql_freeresult($result);
$sql_ary = array(
'SELECT' => 'COUNT(DISTINCT c.contrib_id) AS cnt',
'FROM' => array(
$this->contrib_in_categories_table => 'cic',
$this->contribs_table => 'c',
),
'WHERE' => 'cic.contrib_id = c.contrib_id
AND ' . $this->db->sql_in_set('cic.category_id', array_map('intval', $child_list)) . '
AND c.contrib_visible = 1
AND ' . $this->db->sql_in_set('c.contrib_status', array(ext::TITANIA_CONTRIB_APPROVED, ext::TITANIA_CONTRIB_DOWNLOAD_DISABLED)),
);
$sql = $this->db->sql_build_query('SELECT', $sql_ary);
$this->db->sql_query($sql, 3600);
$cnt = (int) $this->db->sql_fetchfield('cnt');
$this->db->sql_freeresult();
return $cnt;
}
/**
* Get post counts for a topic.
*
* @param int $topic_id
* @return string Returns counts in db storable form
*/
public function _get_post_count($topic_id)
{
$sql = 'SELECT COUNT(post_id) AS cnt
FROM ' . $this->posts_table . '
WHERE topic_id = ' . (int) $topic_id . '
AND post_access = ' . access::TEAM_LEVEL . '
AND post_deleted = 0
AND post_approved = 1';
$result = $this->db->sql_query($sql);
$teams = $this->db->sql_fetchfield('cnt', false, $result);
$this->db->sql_freeresult($result);
$sql = 'SELECT COUNT(post_id) AS cnt
FROM ' . $this->posts_table . '
WHERE topic_id = ' . (int) $topic_id . '
AND post_access = ' . access::AUTHOR_LEVEL . '
AND post_deleted = 0
AND post_approved = 1';
$result = $this->db->sql_query($sql);
$authors = $this->db->sql_fetchfield('cnt', false, $result);
$this->db->sql_freeresult($result);
$sql = 'SELECT COUNT(post_id) AS cnt
FROM ' . $this->posts_table . '
WHERE topic_id = ' . (int) $topic_id . '
AND post_access = ' . access::PUBLIC_LEVEL . '
AND post_deleted = 0
AND post_approved = 1';
$result = $this->db->sql_query($sql);
$public = $this->db->sql_fetchfield('cnt', false, $result);
$this->db->sql_freeresult($result);
$sql = 'SELECT COUNT(post_id) AS cnt
FROM ' . $this->posts_table . '
WHERE topic_id = ' . (int) $topic_id . '
AND post_deleted <> 0';
$result = $this->db->sql_query($sql);
$deleted = $this->db->sql_fetchfield('cnt', false, $result);
$this->db->sql_freeresult($result);
$sql = 'SELECT COUNT(post_id) AS cnt
FROM ' . $this->posts_table . '
WHERE topic_id = ' . (int) $topic_id . '
AND post_deleted = 0
AND post_approved = 0';
$result = $this->db->sql_query($sql);
$unapproved = $this->db->sql_fetchfield('cnt', false, $result);
$this->db->sql_freeresult($result);
return count::to_db(array(
'teams' => $teams,
'authors' => $authors,
'public' => $public,
'deleted' => $deleted,
'unapproved' => $unapproved,
));
}
/**
* Get the contrib count for a user.
*
* @param int $user_id
* @return array
*/
public function _get_author_count($user_id)
{
$sql_ary = array(
'author_contribs' => 0,
);
foreach ($this->types->get_all() as $type_id => $class)
{
if (!isset($class->author_count))
{
continue;
}
$sql_ary[$class->author_count] = 0;
}
// Count the contribution totals for each user
foreach ($this->types->get_all() as $type_id => $class)
{
// Main authors
$sql = 'SELECT COUNT(contrib_id) AS cnt
FROM ' . $this->contribs_table . '
WHERE contrib_type = ' . (int) $type_id . '
AND contrib_user_id = ' . (int) $user_id . '
AND ' . $this->db->sql_in_set('contrib_status', array(ext::TITANIA_CONTRIB_APPROVED, ext::TITANIA_CONTRIB_DOWNLOAD_DISABLED));
$this->db->sql_query($sql);
$cnt = $this->db->sql_fetchfield('cnt');
$sql_ary['author_contribs'] += $cnt;
if (isset($class->author_count))
{
$sql_ary[$class->author_count] += $cnt;
}
// Co-authors
$sql = 'SELECT COUNT(c.contrib_id) AS cnt
FROM ' . $this->contrib_coauthors_table . ' cc, ' . $this->contribs_table . ' c
WHERE c.contrib_type = ' . (int) $type_id . '
AND cc.user_id = ' . (int) $user_id . '
AND c.contrib_id = cc.contrib_id
AND ' . $this->db->sql_in_set('c.contrib_status', array(ext::TITANIA_CONTRIB_APPROVED, ext::TITANIA_CONTRIB_DOWNLOAD_DISABLED));
$this->db->sql_query($sql);
$cnt = $this->db->sql_fetchfield('cnt');
$sql_ary['author_contribs'] += $cnt;
if (isset($class->author_count))
{
$sql_ary[$class->author_count] += $cnt;
}
}
return $sql_ary;
}
}