|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -use Elgg\Database\Select; |
4 |
| - |
5 |
| -$object_types = elgg_extract('object', elgg_entity_types_with_capability('searchable'), []); |
6 |
| - |
7 | 3 | echo elgg_view('output/longtext', [
|
8 | 4 | 'value' => elgg_echo('entity_view_counter:settings:description'),
|
9 | 5 | ]);
|
10 | 6 |
|
11 |
| -// get counts for all subtypes |
12 |
| -// this could take a while |
13 |
| -set_time_limit(0); |
14 |
| - |
15 |
| -$select = Select::fromTable('annotations', 'a'); |
16 |
| -$e = $select->joinEntitiesTable('a', 'entity_guid'); |
17 |
| -$select->select('count(*) as total') |
18 |
| - ->addSelect("{$e}.type") |
19 |
| - ->addSelect("{$e}.subtype") |
20 |
| - ->where($select->compare("{$e}.type", '=', 'object', ELGG_VALUE_STRING)) |
21 |
| - ->andWhere($select->compare("{$e}.subtype", 'in', $object_types, ELGG_VALUE_STRING)) |
22 |
| - ->andWhere($select->compare('a.name', '=', ENTITY_VIEW_COUNTER_ANNOTATION_NAME, ELGG_VALUE_STRING)) |
23 |
| - ->groupBy("{$e}.type") |
24 |
| - ->addGroupBy("{$e}.subtype"); |
25 |
| - |
26 |
| -$counts = elgg()->db->getData($select, function ($row) { |
27 |
| - return (array) $row; |
28 |
| -}); |
29 |
| -// order counts into easier format |
30 |
| -$ordered_counts = []; |
31 |
| -foreach ($counts as $count) { |
32 |
| - $ordered_counts[$count['subtype']] = (int) $count['total']; |
33 |
| -} |
34 |
| - |
35 | 7 | // listing
|
36 | 8 | $row = [
|
37 | 9 | elgg_format_element('th', [], elgg_echo('entity_view_counter:settings:entity_type')),
|
38 |
| - elgg_format_element('th', ['class' => 'center'], elgg_echo('entity_view_counter:settings:num_views')), |
39 | 10 | elgg_format_element('th', ['class' => 'center'], elgg_echo('entity_view_counter:settings:delete')),
|
40 | 11 | ];
|
41 | 12 |
|
|
48 | 19 | ]);
|
49 | 20 |
|
50 | 21 | $rows = [];
|
| 22 | + |
| 23 | +$object_types = elgg_extract('object', elgg_entity_types_with_capability('searchable'), []); |
51 | 24 | foreach ($object_types as $subtype) {
|
52 | 25 | $row = [];
|
53 | 26 |
|
|
60 | 33 | 'switch' => true,
|
61 | 34 | ]));
|
62 | 35 |
|
63 |
| - $count = elgg_extract($subtype, $ordered_counts, 0); |
64 |
| - $row[] = elgg_format_element('td', ['class' => 'center'], $count); |
65 |
| - |
66 |
| - if ($count > 0) { |
67 |
| - $row[] = elgg_format_element('td', ['class' => 'center'], elgg_view('output/url', [ |
68 |
| - 'text' => false, |
69 |
| - 'href' => elgg_generate_action_url('entity_view_counter/admin/reset_counter', [ |
70 |
| - 'subtype' => $subtype, |
71 |
| - ]), |
72 |
| - 'icon' => 'delete', |
73 |
| - 'title' => elgg_echo('delete'), |
74 |
| - 'confirm' => elgg_echo('deleteconfirm:plural'), |
75 |
| - 'class' => 'entity-view-counter-reset', |
76 |
| - ])); |
77 |
| - } else { |
78 |
| - $row[] = elgg_format_element('td', [], ' '); |
79 |
| - } |
| 36 | + $row[] = elgg_format_element('td', ['class' => 'center'], elgg_view('output/url', [ |
| 37 | + 'text' => false, |
| 38 | + 'href' => elgg_generate_action_url('entity_view_counter/admin/reset_counter', [ |
| 39 | + 'subtype' => $subtype, |
| 40 | + ]), |
| 41 | + 'icon' => 'delete', |
| 42 | + 'title' => elgg_echo('delete'), |
| 43 | + 'confirm' => elgg_echo('deleteconfirm:plural'), |
| 44 | + 'class' => 'entity-view-counter-reset', |
| 45 | + ])); |
80 | 46 |
|
81 | 47 | $rows[] = elgg_format_element('tr', [], implode(PHP_EOL, $row));
|
82 | 48 | }
|
|
0 commit comments