-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcronjob.php
93 lines (84 loc) · 2.13 KB
/
cronjob.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
<pre><?php
require_once __DIR__ . '/include/loader.php';
$localDataPath = __DIR__ . '/resources';
$m = Model::engine();
$data = $m->getTaxonomies();
file_put_contents($localDataPath . '/taxonomyAutocomplete.json', json_encode(taxonomyAutocomplete($data['items'])));
$taxCat = taxonomyCatalog($data['items']);
file_put_contents($localDataPath . '/taxonomyCatalog.json', json_encode($taxCat));
echo 'taxonomies processed: ' . count($data['items']) . "\n"; flush();
$services = [];
$pn = 1;
do {
$ss = $m->autocomplete($pn, 'services');
if ($ss['items'])
{
foreach ($ss['items'] as $item)
$services[] = trim($item['name']);
$pn++;
}
else
continue;
} while($pn <= $ss['total_pages']);
sort($services);
file_put_contents($localDataPath . '/servicesAutocomplete.json', json_encode($services));
echo 'services processed: ' . count($services) . "\n"; flush();
$orgs = [];
$pn = 1;
do {
$oo = $m->autocomplete($pn, 'organizations');
if ($oo['items'])
{
foreach ($oo['items'] as $item)
$orgs[] = trim($item['name']);
$pn++;
}
else
continue;
} while($pn <= $oo['total_pages']);
sort($orgs);
file_put_contents($localDataPath . '/organizationsAutocomplete.json', json_encode($orgs));
echo 'orgs processed: ' . count($orgs) . "\n"; flush();
function taxonomyAutocomplete($tt)
{
$rr = [];
foreach ($tt as $t)
$rr[] = trim($t['name']);
sort($rr);
return $rr;
}
function taxonomyCatalog($tt)
{
foreach ($tt as $i=>$t)
$tt[$i]['code'] = $i;
$cat = taxonomyNode($tt);
$perColumn = ceil(count($cat) / 2);
$menu = [];
foreach (array_chunk($cat, $perColumn, true) as $i => $col)
$menu[] = [
'col' => $i,
'items' => $col
];
return $menu;
}
function taxonomyNode($tt, $level=1, $parentId='')
{
$node = [];
foreach ($tt as $i=>$t)
{
if ($t['parent_id'] == $parentId)
{
unset($tt[$i]);
$node[$t['name']] = [
'lev' => $level,
'name' => $t['name'],
'code' => $t['code'],
'url' => "services.php?searchBy=TaxonomyName&strict=true&family=true&TaxonomyName=" . urlencode($t['name']),
'items' => taxonomyNode($tt, $level+1, $t['id']),
];
}
}
ksort($node);
//echo $node; exit;
return $node;
}