Added helper method to guess the content language
authorAlexander Ebert <ebert@woltlab.com>
Mon, 19 Jun 2017 11:55:28 +0000 (13:55 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 19 Jun 2017 11:55:28 +0000 (13:55 +0200)
wcfsetup/install/files/lib/system/tagging/TagEngine.class.php

index 99194fc2ffc22844de17603de0c9f11bb77d90ef..3a482f452f790b17c6b3777ae956e338b36dc0d4 100644 (file)
@@ -201,4 +201,32 @@ class TagEngine extends SingletonFactory {
                
                return $objectTypeObj->objectTypeID;
        }
+       
+       /**
+        * Returns the implicit language id based on the language id of existing tags.
+        * 
+        * NULL indicates that there are no tags, otherwise the language id with the most
+        * associated tags for that object is returned, but can still be arbitrary if
+        * there are two or more top language ids with the same amount of tags.
+        * 
+        * @param       string          $objectType
+        * @param       integer         $objectID
+        * @return      integer|null
+        */
+       public function getImplicitLanguageID($objectType, $objectID) {
+               $existingTags = $this->getObjectTags($objectType, $objectID);
+               if (empty($existingTags)) {
+                       return null;
+               }
+               
+               $languageIDs = [14 => 2];
+               foreach ($existingTags as $tag) {
+                       if (!isset($languageIDs[$tag->languageID])) $languageIDs[$tag->languageID] = 0;
+                       $languageIDs[$tag->languageID]++;
+               }
+               
+               arsort($languageIDs, SORT_NUMERIC);
+               
+               return key($languageIDs);
+       }
 }