Skip to content
Snippets Groups Projects
CopyToDb.php 7.44 KiB
Newer Older
Carsten  Rose's avatar
Carsten Rose committed
<?php

require_once(__DIR__ . '/Constants.php');
require_once(__DIR__ . '/Database.php');


class CopyToDb {

    private $db = null;

    public function __construct() {
        $this->db = new Database(DB_INDEX_DEFAULT);

    }

    /**
     * @param $module
     * @return array
     */
    private function cleanModule($module) {
        foreach ($module as $key => $value) {
            $new[$key] = $value[0] ?? null;
        }
        return ($new);
    }

    /**
     * Parse and write all MODULES
     *
     * @param $moduleAll
     * @return void
     * @throws Exception
     */
    private function module($moduleAll) {
Carsten  Rose's avatar
Carsten Rose committed

        print "Copy Module to DB.\n";
        $this->db->sql("TRUNCATE module_tab");

        foreach ($moduleAll as $module) {
Carsten  Rose's avatar
Carsten Rose committed

            $module = $this->cleanModule($module);
            $this->db->sql("INSERT INTO module_tab
             
                           (`otype`,`objid`,`langu`,`short`,`stext`,`sm_category`,`buchbar`,`valid_begda`,
                           `valid_endda`,`cancel_begda`,`cancel_endda`,`cpmax`,`vvz_url`,`vb_tab`,`diszip_tab`)
                            
                           VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", ROW_REGULAR,

Carsten  Rose's avatar
Carsten Rose committed
                [$module['OTYPE'] ?? '', $module['OBJID'] ?? '', $module['LANGU'] ?? '', $module['SHORT'] ?? '',
                    $module['STEXT'] ?? '', $module['SM_CATEGORY'] ?? '', $module['BUCHBAR'] ?? '',
                    $module['VALID_BEGDA'] ?? '', $module['VALID_ENDDA'] ?? '', $module['CANCEL_BEGDA'] ?? '',
                    $module['CANCEL_ENDDA'] ?? '', $module['CPMAX'] ?? '', $module['VVZ_URL'] ?? '', 'vb_tab', 'diszip_tab']);
        }
    }

    /**
     * @param $eventAll
     * @return void
     * @throws Exception
     */
    private function termin($objid, array $terminEvent) {

//        print "Copy Termin to DB.\n";
        foreach ($terminEvent as $termin) {
            $raum ='';
            if (isset($termin['RAUM_TAB'])) {
                if (is_array($termin['RAUM_TAB']['RAUM']??'')) {
                    $raum = $termin['RAUM_TAB']['RAUM'][0];
                }
            }
            $this->db->sql("INSERT INTO termin_tab (`event_objid`,`evdat`,`beguz`,`enduz`,`raum`) VALUES (?,?,?,?,?)"
                , ROW_REGULAR, [$objid, $termin['EVDAT'][0] ?? '', $termin['BEGUZ'][0] ?? '', $termin['ENDUZ'][0] ?? '', $raum]);
        }
    }

bbaer's avatar
bbaer committed
    function public terminSingle($termin) {
        $this->db->sql("INSERT INTO termin_tab (`event_objid`,`evdat`,`beguz`,`enduz`) VALUES (?,?,?,?,?)"
                , ROW_REGULAR, [$objid, $termin['EVDAT'][0] ?? '', $termin->BEGUZ ?? '', $termin->ENDUZ ?? '']);
    }

    /**
     * @param $eventAll
     * @return void
     * @throws Exception
     */
    private function event($eventAll) {

        print "Copy Event/Termin/Raum to DB.\n";
        $this->db->sql("TRUNCATE event_tab");
        $this->db->sql("TRUNCATE termin_tab");

        foreach ($eventAll as $event) {
            $this->db->sql("INSERT INTO event_tab (`objid`,`short`,`stext`,`vvz_url`) VALUES (?,?,?,?)"
                , ROW_REGULAR, [$event['OBJID'][0] ?? '', $event['SHORT'][0] ?? '', $event['STEXT'][0] ?? '', $event['VVZ_URL'][0] ?? '']);

            if (isset($event['TERMIN_TAB'])) {
                $this->termin($event['OBJID'][0] , $event['TERMIN_TAB']);
            }
        }
    }

bbaer's avatar
bbaer committed
    public function eventSingle($event) {
        $this->db->sql("INSERT INTO event_tab (`objid`,`short`,`stext`,`vvz_url`) VALUES (?,?,?,?)"
                , ROW_REGULAR, [$event->OBJID ?? '', $event->SHORT ?? '', $event->STEXT ?? '', $event->VVZ_URL ?? '']);
    }

bbaer's avatar
bbaer committed
    /**
     * @param $personAll
     * @return void
     * @throws Exception
     */
bbaer's avatar
bbaer committed
    private function person($personAll) {
bbaer's avatar
bbaer committed

bbaer's avatar
bbaer committed
        print "Copy Person to DB." . PHP_EOL;
bbaer's avatar
bbaer committed
        $this->db->sql("TRUNCATE person_tab");
bbaer's avatar
bbaer committed

bbaer's avatar
bbaer committed
        foreach ($personAll as $person) {
bbaer's avatar
bbaer committed
            $this->db->sql("INSERT INTO person_tab (`pernr`, `vname`, `name1`, `itim_short`, `itim_mail`, `email`, `gesch`, `pub_titel`, `titel`, `persk`, `spsl`, `funktionscode`, `fachrunicode`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"
bbaer's avatar
bbaer committed
                , ROW_REGULAR, [$person['PERNR'][0] ?? '', $person['VNAME'][0] ?? '', $person['NAME1'][0] ?? '', $person['ITIM_SHORT'][0] ?? '', $person['ITIM_MAIL'][0] ?? '', $person['EMAIL'][0] ?? '', $person['GESCH'][0] ?? '', $person['PUB_TITEL'][0] ?? '', $person['TITEL'][0] ?? '', $person['PERSK'][0] ?? '', $person['SPSL'][0] ?? '', $person['FUNKTIONSCODE'][0] ?? '', $person['FACHRUNICODE'][0] ?? '']);
        }
    }

    public function personSingle($person) {
bbaer's avatar
bbaer committed
        $this->db->sql("INSERT INTO person_tab (`pernr`, `vname`, `name1`, `itim_short`, `itim_mail`, `email`, `gesch`, `pub_titel`, `titel`, `persk`, `sprsl`, `funktionscode`, `fachrunicode`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"
bbaer's avatar
bbaer committed
            , ROW_REGULAR, [$person->PERNR ?? '', $person->VNAME ?? '', $person->NAME1 ?? '', $person->ITIM_SHORT ?? '', $person->ITIM_MAIL ?? '', $person->EMAIL ?? '', $person->GESCH ?? 0, $person->PUB_TITEL ?? '', $person->TITEL ?? '', $person->PERSK ?? '', $person->SPRSL ?? '', $person->FUNKTIONSCODE ?? '', $person->FACHRUNICODE ?? '']);
bbaer's avatar
bbaer committed
    }

bbaer's avatar
bbaer committed
    private function relation($relationAll) {
        print "Copy Relations to DB." . PHP_EOL;
        $this->db->sql("TRUNCATE relation_tab");

        foreach ($relationAll as $relation) {
            $this->db->sql("INSERT INTO relation_tab (`otype`, `objid`, `relat`, `sclas`, `sobid`, `aw_based`) VALUES (?,?,?,?,?,?)"
                , ROW_REGULAR, [$relation['OTYPE'][0] ?? '', $relation['OBJID'][0] ?? '', $relation['RELAT'][0] ?? '', $relation['SCLAS'][0] ?? '', $relation['SOBID'][0] ?? '', $relation['AW_BASED'][0] ?? NULL]);
        }
    }

bbaer's avatar
bbaer committed
    public function relationSingle($relation) {
        $this->db->sql("INSERT INTO relation_tab (`otype`, `objid`, `relat`, `sclas`, `sobid`, `aw_based`) VALUES (?,?,?,?,?,?)"
                , ROW_REGULAR, [$relation->OTYPE ?? '', $relation->OBJID ?? '', $relation->RELAT ?? '', $relation->SCLAS ?? '', $relation->SOBID ?? '', $relation->AW_BASED ?? NULL]);
    }

bbaer's avatar
bbaer committed
    public function bookingSingle($booking) {
        $this->db->sql("INSERT INTO booking_tab (`adatanr`, `smstatus`, `cpattemp`, `norm_val`, `bookdate`, `booktime`, `packnumber`, `alt_scaleid`, `id`, `bookreason`, `lockflag`, `cobok`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
            , ROW_REGULAR, [$booking->ADATANR ?? '', $booking->SMSTATUS ?? '', $booking->CPATTEMP ?? '', $booking->NORM_VAL ?? '', $booking->BOOKDATE, $booking->BOOKTIME, $booking->PACKNUMBER, $booking->ALT_SCALEID ?? '', $booking->ID ?? '', $booking->BOOKREASON ?? '', $booking->LOCKFLAG ?? '', $booking->COBOK ?? '']);
    }

    public function truncate($target) {
        if ($target == "master") {
bbaer's avatar
bbaer committed
            $this->db->sql("TRUNCATE event_tab");
            $this->db->sql("TRUNCATE termin_tab");
            $this->db->sql("TRUNCATE module_tab");
            $this->db->sql("TRUNCATE person_tab");
bbaer's avatar
bbaer committed
            $this->db->sql("TRUNCATE booking_tab");
        } else {
            $this->db->sql("TRUNCATE relation_tab");
        }
        
bbaer's avatar
bbaer committed
    }

bbaer's avatar
bbaer committed



    /**
     * Write Data
     *
     * @param array $fullData
     * @return void
     * @throws Exception
     */
    public function process(array $fullData) {

//        $this->module($fullData['DATA'][0]['MASTERDATA']['MODULE_TAB']);
        $this->event($fullData['DATA'][0]['MASTERDATA']['EVENT_TAB']);
        //$this->person($fullData['DATA'][0]['MASTERDATA']['PERSON_TAB']);
        //$this->relation($fullData['DATA'][0]['MASTERDATA']['RELATION_TAB']);
Carsten  Rose's avatar
Carsten Rose committed
}