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

class DataMenuTeamsMitarbeiter extends DataMenuMainTopLeftCached
{
  private $dbw;
  private $teamIds = '';

  public function __construct($urlParam)
  {
    parent::__construct($urlParam);

    $this->dbw = DBWorkTeams::getDefaultInstance();

    $teamIds = RequestOperations::getVarValue('team');
    if (is_numeric($teamIds)) {
      $this->teamIds = array($teamIds);
    } elseif (is_array($teamIds)) {
      $this->teamIds = $teamIds;
    }

    if (is_array($this->teamIds)) {
      $this->dbw->newSearch();
      $this->dbw->fromobject->id = $this->teamIds;
    }

    $this->exportadapter = new ExpTeams();
  }

  public function _getClickPath($pName = 'Mitarbeiterteams')
  {
    
    parent::_getClickPath();
    $tmp = $pName;
    if ($this->toolsettings->clickMitarbeiterUebersichtText != '') {
      $tmp = $this->toolsettings->clickMitarbeiterUebersichtText;
    }

    $this->clickpfad .= "<span class='clickadrbold'> " . CleanOperations::cleanStringForHtml($tmp) . "</span>\n";
    
    return $this->clickpfad;
  }

  public function getsight($sightid = 664)
  {
    parent::getsight($sightid);
  }

  public function getdataarraybody()
  {
    if ($this->toolsettings->mitarbeiterTeamAuchLeere) {
      $this->dataarraybody = $this->dbw->getAll();
    } else {
      $this->dataarraybody = $this->dbw->getTeamsWithMitarbeiter();
    }
  }

  
  protected function getCacheKey()
  {
    if (!$this->toolsettings->cacheTeamsMitarbeiter) {
      return false;
    }
    $key = 'DMTeamsMitarbeiter';
    if (is_array($this->teamIds)) {
      $key .= '-' . implode('#', $this->teamIds);
    }
    if ($this->toolsettings->mitarbeiterTeamAuchLeere) {
      $key .= '-auchLeere';
    }

    return sha1($key);
  }

  protected function getTtl()
  {
    return 86400;
  }
}