コード例 #1
0
ファイル: Translatable.php プロジェクト: ramziammar/websites
 /**
  * Get a singleton instance of a class in the most convenient language (@see choose_site_lang())
  *
  * @param string $callerClass The name of the class
  * @param string $filter A filter to be inserted into the WHERE clause.
  * @param boolean $cache Use caching (default: false)
  * @param string $orderby A sort expression to be inserted into the ORDER BY clause.
  * @return DataObject
  */
 static function get_one($callerClass, $filter = "", $cache = false, $orderby = "")
 {
     self::$language_decided = true;
     self::$reading_lang = self::default_lang();
     $record = DataObject::get_one($callerClass, $filter);
     if (!$record) {
         self::$bypass = true;
         $record = DataObject::get_one($callerClass, $filter, $cache, $orderby);
         self::$bypass = false;
         if ($record) {
             self::set_reading_lang($record->Lang);
         }
     } else {
         $langsAvailable = (array) self::get_langs_by_id($callerClass, $record->ID);
         $langsAvailable[] = self::default_lang();
         $lang = self::choose_site_lang($langsAvailable);
         if (isset($lang)) {
             $transrecord = self::get_one_by_lang($callerClass, $lang, "`{$callerClass}`.ID = {$record->ID}");
             if ($transrecord) {
                 self::set_reading_lang($lang);
                 $record = $transrecord;
             }
         }
     }
     return $record;
 }