public function add_sessions($sessions)
 {
     global $DB;
     foreach ($sessions as $sess) {
         $sess->attendanceid = $this->id;
         $sess->id = $DB->insert_record('attendance_sessions', $sess);
         $description = file_save_draft_area_files($sess->descriptionitemid, $this->context->id, 'mod_attendance', 'session', $sess->id, array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $sess->description);
         $DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id));
         $info_array = array();
         $info_array[] = construct_session_full_date_time($sess->sessdate, $sess->duration);
         // Trigger a session added event.
         $event = \mod_attendance\event\session_added::create(array('objectid' => $this->id, 'context' => $this->context, 'other' => array('info' => implode(',', $info_array))));
         $event->add_record_snapshot('course_modules', $this->cm);
         $sess->description = $description;
         $sess->lasttaken = 0;
         $sess->lasttakenby = 0;
         $sess->studentscanmark = 0;
         $event->add_record_snapshot('attendance_sessions', $sess);
         $event->trigger();
     }
 }
 public function add_sessions($sessions)
 {
     global $DB, $CFG, $USER;
     foreach ($sessions as $sess) {
         $sess->attendanceid = $this->id;
         $sess->id = $DB->insert_record('attendance_sessions', $sess);
         $description = file_save_draft_area_files($sess->descriptionitemid, $this->context->id, 'mod_attendance', 'session', $sess->id, array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $sess->description);
         $DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id));
         $infoarray = array();
         $infoarray[] = construct_session_full_date_time($sess->sessdate, $sess->duration);
         // Trigger a session added event.
         $event = \mod_attendance\event\session_added::create(array('objectid' => $this->id, 'context' => $this->context, 'other' => array('info' => implode(',', $infoarray))));
         $event->add_record_snapshot('course_modules', $this->cm);
         $sess->description = $description;
         $sess->lasttaken = 0;
         $sess->lasttakenby = 0;
         $sess->studentscanmark = 0;
         $event->add_record_snapshot('attendance_sessions', $sess);
         $event->trigger();
         //Code that creates a qr image
         //      var_dump($sess->attendanceid);
         $url = $CFG->wwwroot;
         list($path, $filename) = attendance_create_qr_image($url . "*" . $sess->id . "*" . $this->cm->id, $sess->attendanceid, $sess->id);
         $this->attendance_submit($sess, $this->context, $path, $filename);
     }
 }
 public function add_sessions($sessions)
 {
     global $DB;
     foreach ($sessions as $sess) {
         $sess->attendanceid = $this->id;
         $sess->id = $DB->insert_record('attendance_sessions', $sess);
         $description = file_save_draft_area_files($sess->descriptionitemid, $this->context->id, 'mod_attendance', 'session', $sess->id, array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $sess->description);
         $DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id));
     }
     $info_array = array();
     $maxlog = 7;
     // Only log first 10 sessions and last session in the log info. as we can only store 255 chars.
     $i = 0;
     foreach ($sessions as $sess) {
         if ($i > $maxlog) {
             $lastsession = end($sessions);
             $info_array[] = '...';
             $info_array[] = construct_session_full_date_time($lastsession->sessdate, $lastsession->duration);
             break;
         } else {
             $info_array[] = construct_session_full_date_time($sess->sessdate, $sess->duration);
         }
         $i++;
     }
     // Trigger a report viewed event.
     $event = \mod_attendance\event\session_added::create(array('objectid' => $this->id, 'context' => $this->context, 'other' => array('info' => implode(',', $info_array))));
     $event->add_record_snapshot('course_modules', $this->cm);
     $event->add_record_snapshot('attendance', $this);
     $event->trigger();
 }