/**
  * Insert events in bulk to the database. Overrides helper_writer.
  * @param array $events raw event data
  *
  */
 protected function insert_event_entries(array $events)
 {
     // Initializes required services.
     $xapicontroller = new xapi_controller($this->connect_xapi_repository());
     $moodlecontroller = new moodle_controller($this->connect_moodle_repository());
     $translatorcontroller = new translator_controller();
     // Emits events to other APIs.
     foreach ($events as $event) {
         // $this->error_log('');
         // $this->error_log_value('event', $event);
         $moodleevent = $moodlecontroller->createEvent($event);
         // $this->error_log_value('moodleevent', $moodleevent);
         $translatorevent = $translatorcontroller->createEvent($moodleevent);
         // $this->error_log_value('translatorevent', $translatorevent);
         $xapievent = $xapicontroller->createEvent($translatorevent);
         // $this->error_log_value('xapievent', $xapievent);
     }
 }
 public function process_events(array $events)
 {
     // Initializes required services.
     $xapicontroller = new xapi_controller($this->connect_xapi_repository());
     $moodlecontroller = new moodle_controller($this->connect_moodle_repository());
     $translatorcontroller = new translator_controller();
     // Emits events to other APIs.
     foreach ($events as $index => $event) {
         $events[$index] = (array) $event;
     }
     $this->error_log('');
     $this->error_log_value('events', $events);
     $moodleevents = $moodlecontroller->createEvents($events);
     $this->error_log_value('moodleevent', $moodleevents);
     $translatorevents = $translatorcontroller->createEvents($moodleevents);
     $this->error_log_value('translatorevents', $translatorevents);
     if (empty($translatorevents)) {
         return;
     }
     // Split statements into batches.
     $eventbatches = array($translatorevents);
     $maxbatchsize = get_config('logstore_xapi', 'maxbatchsize');
     if (!empty($maxbatchsize) && $maxbatchsize < count($translatorevents)) {
         $eventbatches = array_chunk($translatorevents, $maxbatchsize);
     }
     foreach ($eventbatches as $translatoreventsbatch) {
         $xapievents = $xapicontroller->createEvents($translatoreventsbatch);
         $this->error_log_value('xapievents', $xapievents);
     }
 }