/** * */ public function getPreferredDisplayLocaleIDs($pn_item_locale_id = null) { $vs_mode = $this->getPreference('cataloguing_display_label_mode'); $va_locale_ids = array(); switch ($vs_mode) { case 'cataloguing_locale': if ($vs_locale = $this->getPreference('cataloguing_locale')) { $t_locale = new ca_locales(); if ($t_locale->loadLocaleByCode($vs_locale)) { $va_locale_ids[$t_locale->getPrimaryKey()] = true; } } break; case 'item_locale': if ($pn_item_locale_id) { $va_locale_ids[$pn_item_locale_id] = true; } break; case 'cataloguing_and_item_locale': default: if ($vs_locale = $this->getPreference('cataloguing_locale')) { $t_locale = new ca_locales(); if ($t_locale->loadLocaleByCode($vs_locale)) { $va_locale_ids[$t_locale->getPrimaryKey()] = true; } } if ($pn_item_locale_id) { $va_locale_ids[$pn_item_locale_id] = true; } break; } return array_keys($va_locale_ids); }
public function processLocales() { require_once __CA_MODELS_DIR__ . "/ca_locales.php"; $t_locale = new ca_locales(); $t_locale->setMode(ACCESS_WRITE); // Find any existing locales $va_locales = $t_locale->getLocaleList(array('index_by_code' => true)); foreach ($va_locales as $vs_code => $va_locale) { $this->opa_locales[$vs_code] = $va_locale['locale_id']; } if ($this->ops_base_name) { $va_locales = array(); foreach ($this->opo_profile->locales->children() as $vo_locale) { $va_locales[] = $vo_locale; } foreach ($this->opo_base->locales->children() as $vo_locale) { $va_locales[] = $vo_locale; } } else { $va_locales = $this->opo_profile->locales->children(); } foreach ($va_locales as $vo_locale) { $vs_language = self::getAttribute($vo_locale, "lang"); $vs_dialect = self::getAttribute($vo_locale, "dialect"); $vs_country = self::getAttribute($vo_locale, "country"); $vb_dont_use_for_cataloguing = self::getAttribute($vo_locale, "dontUseForCataloguing"); if (isset($this->opa_locales[$vs_language . "_" . $vs_country])) { // don't insert duplicate locales continue; } $t_locale->set('name', (string) $vo_locale); $t_locale->set('country', $vs_country); $t_locale->set('language', $vs_language); if ($vs_dialect) { $t_locale->set('dialect', $vs_dialect); } $t_locale->set('dont_use_for_cataloguing', (bool) $vb_dont_use_for_cataloguing); $t_locale->insert(); if ($t_locale->numErrors()) { $this->addError("There was an error while inserting locale {$vs_language}_{$vs_country}: " . join(" ", $t_locale->getErrors())); } $this->opa_locales[$vs_language . "_" . $vs_country] = $t_locale->getPrimaryKey(); } $va_locales = $t_locale->getAppConfig()->getList('locale_defaults'); $vn_locale_id = $t_locale->localeCodeToID($va_locales[0]); if (!$vn_locale_id) { throw new Exception("The locale default is set to a non-existing locale. Try adding '" . $va_locales[0] . "' to your profile."); } return true; }