Exemplo n.º 1
0
 public function SetVar($locale = null, $property, $object, $text = null, $FK)
 {
     if ($locale == null) {
         throw new Exception("Locale missing in " . __FUNCTION__ . " for property '{$property}' in class '{$object}'.");
     }
     if (!is_numeric($locale)) {
         throw new Exception("Locale ({$locale}) not numeric in " . __FUNCTION__ . " for property '{$property}' in class '{$object}'. (Value: '{$text}')");
     }
     @fprintf(STDOUT, "DBG9 %s/%s\n", __CLASS__, __FUNCTION__);
     #SED_DELETE_ON_ROLL
     $property = strtolower($property);
     if (is_null($text)) {
         @fprintf(STDOUT, "DBG9 %s - Seaching Collection...\n", __FUNCTION__);
         #SED_DELETE_ON_ROLL
         $i18n =& $this->GetI18N($property, $locale);
         if ($i18n != null) {
             return $i18n->Text();
         } else {
             @fprintf(STDOUT, "DBG9 %s - Text NOT found. Falling back...\n", __FUNCTION__);
             #SED_DELETE_ON_ROLL
             $gs =& GlobalSingleton::GetInstance();
             $objLocales =& $gs->GetLocales();
             $objLocale =& $objLocales->LowestSequence();
             @fprintf(STDOUT, "DBG9 %s - Got lowest seq: %s.\n", __FUNCTION__, $objLocale->LocaleID());
             #SED_DELETE_ON_ROLL
             do {
                 $fallbackLocale = $objLocale->LocaleID();
                 if ($fallbackLocale != $locale) {
                     @fprintf(STDOUT, "DBG9 \t%s - Trying locale: %s. \n", __FUNCTION__, $fallbackLocale);
                     #SED_DELETE_ON_ROLL
                     $i18n =& $this->GetI18N($property, $fallbackLocale);
                     if ($i18n != null) {
                         $ret = $i18n->Text();
                         @fprintf(STDOUT, "DBG9 %s - Text Found. Returning: '%s'\n", __FUNCTION__, $ret);
                         #SED_DELETE_ON_ROLL
                         return $ret;
                     }
                 }
             } while ($objLocale =& $objLocale->NextSequence());
             @fprintf(STDOUT, "DBG9 %s - Match NOT found. Returning empty string\n", __FUNCTION__);
             #SED_DELETE_ON_ROLL
             return "";
         }
     } else {
         $gs =& GlobalSingleton::GetInstance();
         $objLocales =& $gs->GetLocales();
         $locales =& $objLocales->GetBy('LocaleID', $locale);
         if ($locales->Count() == 0) {
             throw new Exception("Attempting to assign '{$text}' to {$property} for invalid locale ({$locale})");
         }
         @fprintf(STDOUT, "DBG9 %s - Text given: '%s'\n", __FUNCTION__, $text);
         #SED_DELETE_ON_ROLL
         $i18n =& $this->GetI18N($property, $locale);
         if ($i18n == null) {
             @fprintf(STDOUT, "DBG9 %s - I18N NOT found. Adding new...\n", __FUNCTION__);
             #SED_DELETE_ON_ROLL
             $i18n = new I18N();
             $i18n->LocaleID($locale);
             $i18n->Property($property);
             $i18n->Text($text);
             @fprintf(STDOUT, "DBG9 %s - Adding...(%s)\n", __FUNCTION__, $i18n->ToString());
             #SED_DELETE_ON_ROLL
             $this->Add(&$i18n);
         } else {
             @fprintf(STDOUT, "DBG9 %s - I18N found. Setting new val ('{$text}').\n", __FUNCTION__);
             #SED_DELETE_ON_ROLL
             $i18n->Text($text);
         }
     }
 }