@@ -2029,37 +2029,42 @@ public function getPrevRecordID($conditions = [])
20292029 }
20302030
20312031 /**
2032- * Vrací hodnotu daného externího ID.
2032+ * Returns the value of the given external ID.
20332033 *
2034- * @param string $want Namespace Selector . If empty,you obtain the first one.
2034+ * @param string $want Namespace selector . If empty, returns the first one.
20352035 *
2036- * @return array|string one id or array if multiplete
2036+ * @return array|string One ID or array if multiple
20372037 */
20382038 public function getExternalID ($ want = null )
20392039 {
20402040 $ extid = null ;
20412041 $ ids = $ this ->getExternalIDs ();
20422042
2043+ // If $ids is an array of Relation objects, extract their 'value' property
2044+ if (is_array ($ ids ) && isset ($ ids [0 ]) && is_object ($ ids [0 ]) && property_exists ($ ids [0 ], 'value ' )) {
2045+ $ values = array_map (function ($ relation ) {
2046+ return $ relation ->value ;
2047+ }, $ ids );
2048+ } elseif (is_object ($ ids ) && property_exists ($ ids , 'value ' )) {
2049+ $ values = is_array ($ ids ->value ) ? $ ids ->value : [$ ids ->value ];
2050+ } else {
2051+ $ values = is_array ($ ids ) ? $ ids : [$ ids ];
2052+ }
2053+
20432054 if (null === $ want ) {
2044- if (!empty ($ ids )) {
2045- $ extid = \is_object ( $ ids ) ? ( \is_array ( $ ids -> value ) ? current ($ ids -> value ) : $ ids ) : current ( $ ids );
2055+ if (!empty ($ values )) {
2056+ $ extid = current ($ values );
20462057 }
20472058 } else {
2048- if (null !== $ ids && \is_array ($ ids ->value )) {
2049- foreach ($ ids ->value as $ id ) {
2050- if (strstr ($ id , 'ext: ' .$ want )) {
2051- if (null === $ extid ) {
2052- $ extid = str_replace ('ext: ' .$ want .': ' , '' , $ id );
2059+ foreach ($ values as $ id ) {
2060+ if (strstr ($ id , 'ext: ' .$ want )) {
2061+ if (null === $ extid ) {
2062+ $ extid = str_replace ('ext: ' .$ want .': ' , '' , $ id );
2063+ } else {
2064+ if (is_array ($ extid )) {
2065+ $ extid [] = str_replace ('ext: ' .$ want .': ' , '' , $ id );
20532066 } else {
2054- if (\is_array ($ extid )) {
2055- $ extid [] = str_replace ('ext: ' .$ want .': ' , '' , $ id );
2056- } else {
2057- $ extid = [$ extid , str_replace (
2058- 'ext: ' .$ want .': ' ,
2059- '' ,
2060- $ id ,
2061- )];
2062- }
2067+ $ extid = [$ extid , str_replace ('ext: ' .$ want .': ' , '' , $ id )];
20632068 }
20642069 }
20652070 }
@@ -2070,7 +2075,7 @@ public function getExternalID($want = null)
20702075 }
20712076
20722077 /**
2073- * gives you currently loaded extermal IDs.
2078+ * Gives you currently loaded external IDs.
20742079 *
20752080 * @return array
20762081 */
0 commit comments