/** * Get Default language * @return Language */ public function getDefaultLanguage($cacheMinutes = null, $tryToAutoCreateDefaultLanguage = true) { $qb = new QueryBuilder(); $qb->select(new Field('*', 'l'))->from(Tbl::get("TBL_HOST_LANGUAGE"), 'hl')->leftJoin(Tbl::get("TBL_LANGUAGES", "Language"), 'l', $qb->expr()->equal(new Field('lang_id', 'hl'), new Field('id', 'l')))->where($qb->expr()->equal(new Field('host_id', 'hl'), $this->host->id))->andWhere($qb->expr()->equal(new Field('default', 'hl'), 1)); $this->query->exec($qb->getSQL(), $cacheMinutes); if ($this->query->countRecords()) { $lang_data = $this->query->fetchRecord(); $l = new Language(); Language::setData($lang_data, $l); return $l; } elseif ($tryToAutoCreateDefaultLanguage) { $defaultLanguage = parent::getDefaultLanguage(); try { $this->addHostLanguage($this->host, $defaultLanguage); $this->setHostsDefaultLanguage($this->host, $defaultLanguage); } catch (MySqlException $e) { } return $this->getDefaultLanguage(0, false); } throw new RuntimeException("Default language not defined for '" . $this->host->host . "'"); }