Skip to content

Commit deb3229

Browse files
authored
Merge pull request #188 from Mdwiki-TD/update_new
Refactoring of Results Table Generation
2 parents ca97957 + a619452 commit deb3229

27 files changed

+657
-507
lines changed

src/backend/include_first/include.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
include_once __DIR__ . '/backend/include_first/include.php';
55
*/
66
foreach (glob(__DIR__ . "/*.php") as $filename) {
7-
if ($filename == __FILE__) {
8-
continue;
9-
}
7+
if ($filename == __FILE__) continue;
108
include_once $filename;
119
}

src/backend/results/get_titles/fetch_cat_data.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ function get_cat_exists_and_missing($cat, $depth, $code, $use_cache = true): arr
2626
$exists = array_intersect($members, $exists);
2727
// ---
2828
// change from ("{"6":"Video:Cancer"}") to (["Video:Cancer"])
29-
// $exists = array_values($exists);
29+
$exists = array_values($exists);
3030
// ---
3131
// Find missing members
3232
$missing = array_diff($members, $exists);
3333
// ---
34-
$missing = array_unique($missing);
34+
$missing = array_values(array_unique($missing));
3535
// ---
3636
// test_print("End of get_cat exists_and_missing <br>===============================");
3737
return [$exists, $missing];

src/backend/results/get_titles/get_results.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
/*
66
Usage:
77
8-
use function Results\GetResults\get_results; // get_results($cat, $camp, $depth, $code)
8+
use function Results\GetResults\get_results;
99
1010
*/
1111

12-
use Tables\SqlTables\TablesSql;
1312
use function Results\FetchCatData\get_cat_exists_and_missing;
1413
use function Results\SparqlBot\filter_existing_out;
1514
use function TD\Render\TestPrint\test_print;
@@ -35,7 +34,7 @@ function getinprocess($missing, $code)
3534
return $titles;
3635
}
3736

38-
function get_results($cat, $camp, $depth, $code, $filter_sparql): array
37+
function get_results($cat, $camp, $depth, $code, $filter_sparql, $cat2): array
3938
{
4039
// Get existing and missing pages
4140
// ---
@@ -53,8 +52,6 @@ function get_results($cat, $camp, $depth, $code, $filter_sparql): array
5352
test_print("Items missing: " . count($items_missing));
5453

5554
// Check for a secondary category
56-
$cat2 = TablesSql::$s_camps_cat2[$camp] ?? '';
57-
5855
if (!empty($cat2) && $cat2 !== $cat) {
5956
$items_missing = filter_items_missing_cat2($items_missing, $cat2, $depth);
6057
}
@@ -63,7 +60,7 @@ function get_results($cat, $camp, $depth, $code, $filter_sparql): array
6360
test_print("Length of existing pages: $len_of_exists_pages");
6461

6562
// Remove duplicates from missing items
66-
$missing = array_unique($items_missing);
63+
$missing = array_values(array_unique($items_missing));
6764

6865
// Get in-process items
6966
$inprocess = getinprocess($missing, $code);
@@ -72,11 +69,14 @@ function get_results($cat, $camp, $depth, $code, $filter_sparql): array
7269
// Remove in-process items from missing list
7370
if ($len_inprocess > 0) {
7471
$missing = array_diff($missing, array_column($inprocess, 'title'));
75-
// $missing = array_values($missing);
72+
$missing = array_values($missing);
7673
}
7774

7875
$summary = create_summary($code, $cat, count($inprocess), count($missing), $len_of_exists_pages);
7976

77+
// sort $items_exists by keys
78+
ksort($items_exists);
79+
8080
return [
8181
"inprocess" => $inprocess,
8282
"exists" => $items_exists,

src/backend/results/getcats.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CategoryFetcher
3535
*/
3636
public function __construct(
3737
array $options = [],
38-
string $endPoint = '',
38+
string $endPoint = ''
3939
) {
4040
$this->options = $options;
4141
$this->endPoint = (!empty($endPoint)) ? $endPoint : 'https://mdwiki.org/w/api.php';
@@ -413,10 +413,10 @@ function make_options(): array
413413
* @return array
414414
*/
415415

416-
function get_mdwiki_cat_members(string $cat, int $depth = 0, bool $use_cache = true): array
416+
function get_mdwiki_cat_members(string $cat, $depth = 0, bool $use_cache = true): array
417417
{
418418
$endPoint = 'https://mdwiki.org/w/api.php';
419-
419+
$depth = (int) $depth;
420420
$options = make_options();
421421

422422
$fetcher = new CategoryFetcher($options, $endPoint);

src/backend/results/helps.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ function filter_items_missing_cat2($items_missing, $cat2, $depth)
102102
// ---
103103
$cat2_members = get_mdwiki_cat_members($cat2, $depth, true);
104104
// ---
105-
$items_missing = array_intersect($items_missing, $cat2_members);
106-
test_print("Items missing after intersecting with cat2: " . count($items_missing));
105+
$new_missing = array_intersect($items_missing, $cat2_members);
107106
// ---
108-
return $items_missing;
107+
$new_missing = array_values($new_missing);
108+
// ---
109+
test_print("Items missing after intersecting with cat2: " . count($new_missing) . ", before: " . count($items_missing));
110+
// ---
111+
return $new_missing;
109112
}
110113

111114
function create_summary($code, $cat, $len_inprocess, $len_missing, $len_of_exists_pages)

src/backend/results/include.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
foreach (glob(__DIR__ . "/sparql_bots/*.php") as $filename) {
4+
include_once $filename;
5+
}
6+
7+
foreach (glob(__DIR__ . "/get_titles/*.php") as $filename) {
8+
include_once $filename;
9+
}
10+
11+
foreach (glob(__DIR__ . "/new_way/*.php") as $filename) {
12+
include_once $filename;
13+
}
14+
15+
foreach (glob(__DIR__ . "/*.php") as $filename) {
16+
if ($filename == __FILE__) continue;
17+
if (basename($filename) === "getcats_new.php") continue;
18+
include_once $filename;
19+
}
20+
21+
foreach (glob(__DIR__ . "/rows/*.php") as $filename) {
22+
include_once $filename;
23+
}

src/backend/results/new_way/fetch_cat_data.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111

1212
use function Results\GetCats\get_mdwiki_cat_members;
1313
use function TD\Render\TestPrint\test_print;
14+
use function SQLorAPI\Funcs\get_lang_pages_by_cat;
1415

1516
function get_cat_exists_and_missing_new($exists_via_td, $cat, $depth, $code, $use_cache = true): array
1617
{
18+
// ---
19+
if (empty($exists_via_td)) {
20+
$exists_via_td = get_lang_pages_by_cat($code, $cat);
21+
$exists_via_td = array_column($exists_via_td, null, "title");
22+
}
23+
// ---
1724
// Fetch category members
1825
$members = get_mdwiki_cat_members($cat, $depth, $use_cache);
1926
// ---
@@ -38,14 +45,10 @@ function get_cat_exists_and_missing_new($exists_via_td, $cat, $depth, $code, $us
3845
// ---
3946
$exists = array_map($func, $exists);
4047
// ---
41-
// change from ("{"6":"Video:Cancer"}") to (["Video:Cancer"])
42-
// $exists = array_values($exists);
43-
// ---
4448
// Find missing members
4549
$missing = array_diff($members, array_keys($exists));
46-
4750
// ---
48-
$missing = array_unique($missing);
51+
$missing = array_values(array_unique($missing));
4952
// ---
5053
// test_print("End of get_cat exists_and_missing <br>===============================");
5154
return [$exists, $missing];

src/backend/results/new_way/get_results.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
1010
*/
1111

12-
use Tables\SqlTables\TablesSql;
1312
use function Results\FetchCatDataNew\get_cat_exists_and_missing_new;
1413
use function Results\SparqlBot\filter_existing_out_new;
1514
use function TD\Render\TestPrint\test_print;
@@ -99,7 +98,7 @@ function getinprocess_n($missing, $code)
9998
return $titles;
10099
}
101100

102-
function get_results_new($cat, $camp, $depth, $code, $filter_sparql): array
101+
function get_results_new($cat, $camp, $depth, $code, $filter_sparql, $cat2): array
103102
{
104103
// Get existing and missing pages
105104
// ---
@@ -140,7 +139,6 @@ function get_results_new($cat, $camp, $depth, $code, $filter_sparql): array
140139
test_print("Items missing: " . count($items_missing));
141140

142141
// Check for a secondary category
143-
$cat2 = TablesSql::$s_camps_cat2[$camp] ?? '';
144142

145143
if (!empty($cat2) && $cat2 !== $cat) {
146144
$items_missing = filter_items_missing_cat2($items_missing, $cat2, $depth);
@@ -150,7 +148,7 @@ function get_results_new($cat, $camp, $depth, $code, $filter_sparql): array
150148
test_print("Length of existing pages: $len_of_exists_pages");
151149

152150
// Remove duplicates from missing items
153-
$missing = array_unique($items_missing);
151+
$missing = array_values(array_unique($items_missing));
154152

155153
// Get in-process items
156154
$inprocess = getinprocess_n($missing, $code);
@@ -159,11 +157,14 @@ function get_results_new($cat, $camp, $depth, $code, $filter_sparql): array
159157
// Remove in-process items from missing list
160158
if ($len_inprocess > 0) {
161159
$missing = array_diff($missing, array_column($inprocess, 'title'));
162-
// $missing = array_values($missing);
160+
$missing = array_values($missing);
163161
}
164162

165163
$summary = create_summary($code, $cat, count($inprocess), count($missing), $len_of_exists_pages);
166164

165+
// sort $items_exists by keys
166+
ksort($items_exists);
167+
167168
return [
168169
"inprocess" => $inprocess,
169170
"exists" => $items_exists,

src/css/sidebars.css

Lines changed: 0 additions & 134 deletions
This file was deleted.

src/footer.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ function copy_target_text(id) {
5454
textarea.select();
5555
document.execCommand("copy");
5656
}
57-
$(".Dropdown_menu_toggle").on("click", function() {
58-
$(".div_menu").toggleClass("mactive");
59-
});
6057

6158
$('.sortable').DataTable({
6259
stateSave: true,

0 commit comments

Comments
 (0)