2424 die ("no access " );
2525}
2626
27- $ reqSem = optional_param ('semester ' , null , PARAM_INT ); // his category origin id
27+ $ reqsem = optional_param ('semester ' , null , PARAM_INT ); // his category origin id
2828
2929set_time_limit (30 * 60 );
3030
3131
3232function create_aggregate () {
33- global $ pgDB ;
34- pg_query ($ pgDB ->connection , "DROP AGGREGATE IF EXISTS textcat_all(text); " );
35- pg_query ($ pgDB ->connection , "CREATE AGGREGATE textcat_all(
33+ global $ pgdb ;
34+ pg_query ($ pgdb ->connection , "DROP AGGREGATE IF EXISTS textcat_all(text); " );
35+ pg_query ($ pgdb ->connection , "CREATE AGGREGATE textcat_all(
3636 basetype = text,
3737 sfunc = textcat,
3838 stype = text,
@@ -41,69 +41,69 @@ function create_aggregate() {
4141}
4242
4343function get_cat_sem ($ ueid ) {
44- global $ pgDB , $ hup_stats_sem_table ;
44+ global $ pgdb , $ hupstatssemtable ;
4545 // read or (if not existing) create array
46- if (!isset ($ hup_stats_sem_table )) {
47- $ hup_stats_sem_table = [];
48- $ q_main = pg_query ($ pgDB ->connection , "SELECT ueid, semester FROM " . HIS_UEBERSCHRIFT );
49- while ($ hislsf_title = pg_fetch_object ($ q_main )) {
50- $ hup_stats_sem_table [ $ hislsf_title ->ueid ] = $ hislsf_title ->semester ;
46+ if (!isset ($ hupstatssemtable )) {
47+ $ hupstatssemtable = [];
48+ $ qmain = pg_query ($ pgdb ->connection , "SELECT ueid, semester FROM " . HIS_UEBERSCHRIFT );
49+ while ($ hislsftitle = pg_fetch_object ($ qmain )) {
50+ $ hupstatssemtable [ $ hislsftitle ->ueid ] = $ hislsftitle ->semester ;
5151 }
5252 }
53- return isset ($ hup_stats_sem_table [$ ueid ]) ? $ hup_stats_sem_table [$ ueid ] : null ;
53+ return isset ($ hupstatssemtable [$ ueid ]) ? $ hupstatssemtable [$ ueid ] : null ;
5454}
5555
5656function get_cat_veranstids_and_count ($ ueids ) {
57- global $ pgDB ;
58- $ hup_stats_veranstcount_table = [];
57+ global $ pgdb ;
58+ $ hupstatsveranstcounttable = [];
5959 if (!empty ($ ueids )) {
60- $ q_main = pg_query ($ pgDB ->connection , "SELECT veranstaltungsart, textcat_all(DISTINCT " . HIS_UEBERSCHRIFT . ".veranstid || ',') as veranstids, COUNT(DISTINCT " . HIS_UEBERSCHRIFT . ".veranstid) as c FROM " . HIS_UEBERSCHRIFT . " JOIN " . HIS_VERANSTALTUNG . " on " . HIS_UEBERSCHRIFT . ".veranstid = " . HIS_VERANSTALTUNG . ".veranstid WHERE ueid IN ( " . $ ueids . ") GROUP BY veranstaltungsart " );
61- while ($ hislsf_title = pg_fetch_object ($ q_main )) {
62- $ hup_stats_veranstcount_table [ $ hislsf_title ->veranstaltungsart ] = ["veranstids " => explode (", " , $ hislsf_title ->veranstids ), "count " => $ hislsf_title ->c ];
60+ $ qmain = pg_query ($ pgdb ->connection , "SELECT veranstaltungsart, textcat_all(DISTINCT " . HIS_UEBERSCHRIFT . ".veranstid || ',') as veranstids, COUNT(DISTINCT " . HIS_UEBERSCHRIFT . ".veranstid) as c FROM " . HIS_UEBERSCHRIFT . " JOIN " . HIS_VERANSTALTUNG . " on " . HIS_UEBERSCHRIFT . ".veranstid = " . HIS_VERANSTALTUNG . ".veranstid WHERE ueid IN ( " . $ ueids . ") GROUP BY veranstaltungsart " );
61+ while ($ hislsftitle = pg_fetch_object ($ qmain )) {
62+ $ hupstatsveranstcounttable [ $ hislsftitle ->veranstaltungsart ] = ["veranstids " => explode (", " , $ hislsftitle ->veranstids ), "count " => $ hislsftitle ->c ];
6363 }
6464 }
65- return $ hup_stats_veranstcount_table ;
65+ return $ hupstatsveranstcounttable ;
6666}
6767
6868
69- $ pgDB = new pg_lite ();
70- echo "<p>Verbindung: " . ($ pgDB ->connect () ? "ja " : "nein " ) . " ( " . $ pgDB ->connection . ")</p> " ;
69+ $ pgdb = new pg_lite ();
70+ echo "<p>Verbindung: " . ($ pgdb ->connect () ? "ja " : "nein " ) . " ( " . $ pgdb ->connection . ")</p> " ;
7171create_aggregate ();
7272
7373echo "<p><pre> " ;
7474// Root-Knoten herausfinden
75- $ toplevel_origins = get_his_toplevel_originids ();
75+ $ toplevelorigins = get_his_toplevel_originids ();
7676// echo "TOPLEVEL_IDs = ".print_r($toplevel_origins,true)."\n\n";
7777// Kategorien herausfinden
78- $ secondlevel_orinins = get_newest_sublevels (implode (", " , $ toplevel_origins ));
79- foreach ($ secondlevel_orinins as $ secondndlevel ) {
78+ $ secondlevelorinins = get_newest_sublevels (implode (", " , $ toplevelorigins ));
79+ foreach ($ secondlevelorinins as $ secondndlevel ) {
8080 // Kategoriekopien herausfinden
8181 $ secondndlevel ->txt = mb_convert_encoding ($ secondndlevel ->txt , 'UTF-8 ' , 'ISO-8859-1 ' );
8282 $ secondndlevel ->copies = $ DB ->get_records ("local_lsf_category " , ["origin " => $ secondndlevel ->origin ], null , "ueid " );
83- foreach ($ secondndlevel ->copies as $ secondlevel_copy ) {
83+ foreach ($ secondndlevel ->copies as $ secondlevelcopy ) {
8484 // Semester bestimmen
85- $ secondlevel_copy ->semester = get_cat_sem ($ secondlevel_copy ->ueid );
86- if (empty ($ reqSem ) || ($ reqSem == $ secondlevel_copy ->semester )) {
85+ $ secondlevelcopy ->semester = get_cat_sem ($ secondlevelcopy ->ueid );
86+ if (empty ($ reqsem ) || ($ reqsem == $ secondlevelcopy ->semester )) {
8787 // Alle Unterkategorien der jeweiligen Kategoriekopien sammeln
88- $ secondlevel_copy ->subs = array_keys ($ DB ->get_records ("local_lsf_categoryparenthood " , ["parent " => $ secondlevel_copy ->ueid ], null , "child " ));
88+ $ secondlevelcopy ->subs = array_keys ($ DB ->get_records ("local_lsf_categoryparenthood " , ["parent " => $ secondlevelcopy ->ueid ], null , "child " ));
8989 // Bestimme die Veranstatlungstypen und Anazahlen der jeweiligen Kategoriekopien
90- $ secondlevel_copy ->veranstcount = get_cat_veranstids_and_count (implode (", " , $ secondlevel_copy ->subs ));
90+ $ secondlevelcopy ->veranstcount = get_cat_veranstids_and_count (implode (", " , $ secondlevelcopy ->subs ));
9191 // Semesterarray erstellen (daten umformatieren)
92- if (!isset ($ sem_stats [ $ secondlevel_copy ->semester ])) {
93- $ sem_stats [ $ secondlevel_copy ->semester ] = [];
92+ if (!isset ($ semstats [ $ secondlevelcopy ->semester ])) {
93+ $ semstats [ $ secondlevelcopy ->semester ] = [];
9494 }
95- if (!isset ($ sem_stats [ $ secondlevel_copy ->semester ][$ secondndlevel ->txt ])) {
96- $ sem_stats [ $ secondlevel_copy ->semester ][$ secondndlevel ->txt ] = [];
95+ if (!isset ($ semstats [ $ secondlevelcopy ->semester ][$ secondndlevel ->txt ])) {
96+ $ semstats [ $ secondlevelcopy ->semester ][$ secondndlevel ->txt ] = [];
9797 }
98- foreach ($ secondlevel_copy ->veranstcount as $ typ => $ veranstids_and_count ) {
99- if (!isset ($ sem_stats [ $ secondlevel_copy ->semester ][$ secondndlevel ->txt ][$ typ ])) {
100- $ sem_stats [ $ secondlevel_copy ->semester ][$ secondndlevel ->txt ][$ typ ] = ["imported " => 0 , "existing " => 0 , "veranstids " => []];
98+ foreach ($ secondlevelcopy ->veranstcount as $ typ => $ veranstidsandcount ) {
99+ if (!isset ($ semstats [ $ secondlevelcopy ->semester ][$ secondndlevel ->txt ][$ typ ])) {
100+ $ semstats [ $ secondlevelcopy ->semester ][$ secondndlevel ->txt ][$ typ ] = ["imported " => 0 , "existing " => 0 , "veranstids " => []];
101101 }
102- $ sem_stats [ $ secondlevel_copy ->semester ][$ secondndlevel ->txt ][$ typ ]["veranstids " ] = array_filter (array_merge ($ sem_stats [ $ secondlevel_copy ->semester ][$ secondndlevel ->txt ][$ typ ]["veranstids " ], $ veranstids_and_count ["veranstids " ]));
103- $ sem_stats [ $ secondlevel_copy ->semester ][$ secondndlevel ->txt ][$ typ ]["existing " ] += $ veranstids_and_count ["count " ];
102+ $ semstats [ $ secondlevelcopy ->semester ][$ secondndlevel ->txt ][$ typ ]["veranstids " ] = array_filter (array_merge ($ semstats [ $ secondlevelcopy ->semester ][$ secondndlevel ->txt ][$ typ ]["veranstids " ], $ veranstidsandcount ["veranstids " ]));
103+ $ semstats [ $ secondlevelcopy ->semester ][$ secondndlevel ->txt ][$ typ ]["existing " ] += $ veranstidsandcount ["count " ];
104104 // zaehle bestehende kurse
105- foreach ($ sem_stats [ $ secondlevel_copy ->semester ][$ secondndlevel ->txt ][$ typ ]["veranstids " ] as $ veranstid ) {
106- $ sem_stats [ $ secondlevel_copy ->semester ][$ secondndlevel ->txt ][$ typ ]["imported " ] += $ DB ->record_exists ("course " , ["idnumber " => $ veranstid ]) ? 1 : 0 ;
105+ foreach ($ semstats [ $ secondlevelcopy ->semester ][$ secondndlevel ->txt ][$ typ ]["veranstids " ] as $ veranstid ) {
106+ $ semstats [ $ secondlevelcopy ->semester ][$ secondndlevel ->txt ][$ typ ]["imported " ] += $ DB ->record_exists ("course " , ["idnumber " => $ veranstid ]) ? 1 : 0 ;
107107 }
108108 }
109109 }
@@ -114,7 +114,7 @@ function get_cat_veranstids_and_count($ueids) {
114114
115115// write CSV
116116echo "Semester;Kategorie;Typ;AnzahlGesamt;AnzahlImportiert \n" ;
117- foreach ($ sem_stats as $ sem => $ stats ) {
117+ foreach ($ semstats as $ sem => $ stats ) {
118118 foreach ($ stats as $ cat => $ catstats ) {
119119 if (!empty ($ catstats )) {
120120 foreach ($ catstats as $ typ => $ count ) {
@@ -127,5 +127,5 @@ function get_cat_veranstids_and_count($ueids) {
127127
128128echo "</pre></p> " ;
129129
130- $ pgDB ->dispose ();
131- echo "<p>Verbindung geschlossen: " . (($ pgDB ->connection == null ) ? "ja " : "nein " ) . "</p> " ;
130+ $ pgdb ->dispose ();
131+ echo "<p>Verbindung geschlossen: " . (($ pgdb ->connection == null ) ? "ja " : "nein " ) . "</p> " ;
0 commit comments