@@ -2254,37 +2254,42 @@ public function getPrevRecordID($conditions = [])
2254
2254
}
2255
2255
2256
2256
/**
2257
- * Vrací hodnotu daného externího ID.
2257
+ * Returns the value of the given external ID.
2258
2258
*
2259
- * @param string $want Namespace Selector . If empty,you obtain the first one.
2259
+ * @param string $want Namespace selector . If empty, returns the first one.
2260
2260
*
2261
- * @return array|string one id or array if multiplete
2261
+ * @return array|string One ID or array if multiple
2262
2262
*/
2263
2263
public function getExternalID ($ want = null )
2264
2264
{
2265
2265
$ extid = null ;
2266
2266
$ ids = $ this ->getExternalIDs ();
2267
2267
2268
+ // If $ids is an array of Relation objects, extract their 'value' property
2269
+ if (is_array ($ ids ) && isset ($ ids [0 ]) && is_object ($ ids [0 ]) && property_exists ($ ids [0 ], 'value ' )) {
2270
+ $ values = array_map (function ($ relation ) {
2271
+ return $ relation ->value ;
2272
+ }, $ ids );
2273
+ } elseif (is_object ($ ids ) && property_exists ($ ids , 'value ' )) {
2274
+ $ values = is_array ($ ids ->value ) ? $ ids ->value : [$ ids ->value ];
2275
+ } else {
2276
+ $ values = is_array ($ ids ) ? $ ids : [$ ids ];
2277
+ }
2278
+
2268
2279
if (null === $ want ) {
2269
- if (!empty ($ ids )) {
2270
- $ extid = \is_object ( $ ids ) ? ( \is_array ( $ ids -> value ) ? current ($ ids -> value ) : $ ids ) : current ( $ ids );
2280
+ if (!empty ($ values )) {
2281
+ $ extid = current ($ values );
2271
2282
}
2272
2283
} else {
2273
- if (null !== $ ids && \is_array ($ ids ->value )) {
2274
- foreach ($ ids ->value as $ id ) {
2275
- if (strstr ($ id , 'ext: ' .$ want )) {
2276
- if (null === $ extid ) {
2277
- $ extid = str_replace ('ext: ' .$ want .': ' , '' , $ id );
2284
+ foreach ($ values as $ id ) {
2285
+ if (strstr ($ id , 'ext: ' .$ want )) {
2286
+ if (null === $ extid ) {
2287
+ $ extid = str_replace ('ext: ' .$ want .': ' , '' , $ id );
2288
+ } else {
2289
+ if (is_array ($ extid )) {
2290
+ $ extid [] = str_replace ('ext: ' .$ want .': ' , '' , $ id );
2278
2291
} else {
2279
- if (\is_array ($ extid )) {
2280
- $ extid [] = str_replace ('ext: ' .$ want .': ' , '' , $ id );
2281
- } else {
2282
- $ extid = [$ extid , str_replace (
2283
- 'ext: ' .$ want .': ' ,
2284
- '' ,
2285
- $ id ,
2286
- )];
2287
- }
2292
+ $ extid = [$ extid , str_replace ('ext: ' .$ want .': ' , '' , $ id )];
2288
2293
}
2289
2294
}
2290
2295
}
0 commit comments