<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

  
  class SemesterHlAPI
  {
    
    public function getSemester($pKurse = true, $pHinterlegung = true, $pCheckInternetAktiv = false, $pSort = true)
    {
      $semester = array();
      
      if ($pKurse) {
        if ($pCheckInternetAktiv) {
          $dbop = DBOperation::getInstance(1, true);
          $dbwk = new DBWorkKurseINetAktiv();
          $dbwk->fromobject = $dbwk->getNewObject();
          $dbwk->toobject = $dbwk->getNewObject();
          $sql = 'SELECT DISTINCT semester FROM kurse k WHERE 1 = 1';
          $sql .= $dbwk->getSearchSQL('k.');
          $dbop->clear();
          $dbop->query($sql);
          while ($dbop->selectNextRow()) {
            array_push($semester, $dbop->fieldbyname('semester'));
          }
        } else {
          $dbwk = new DBWorkKurse();
          $semester = $dbwk->getAllSemester();
        }
      }
      
      if ($pHinterlegung) {
        $dbwksem = new DBWorkHLSemester();
        foreach ($dbwksem->getAll() as $allsemester) {
          if (!in_array($allsemester->sem, $semester)) {
            array_push($semester, $allsemester->sem);
          }
        }
      }
      if ($pSort) {
        sort($semester);
      }

      return $semester;
    }
  }