| @@ 3039-3073 (lines=35) @@ | ||
| 3036 | * @param $fieldName string |
|
| 3037 | * @return string | null - will return null on a missing value |
|
| 3038 | */ |
|
| 3039 | public function relField($fieldName) { |
|
| 3040 | $component = $this; |
|
| 3041 | ||
| 3042 | // We're dealing with relations here so we traverse the dot syntax |
|
| 3043 | if(strpos($fieldName, '.') !== false) { |
|
| 3044 | $relations = explode('.', $fieldName); |
|
| 3045 | $fieldName = array_pop($relations); |
|
| 3046 | foreach($relations as $relation) { |
|
| 3047 | // Inspect $component for element $relation |
|
| 3048 | if($component->hasMethod($relation)) { |
|
| 3049 | // Check nested method |
|
| 3050 | $component = $component->$relation(); |
|
| 3051 | } elseif($component instanceof SS_List) { |
|
| 3052 | // Select adjacent relation from DataList |
|
| 3053 | $component = $component->relation($relation); |
|
| 3054 | } elseif($component instanceof DataObject |
|
| 3055 | && ($dbObject = $component->dbObject($relation)) |
|
| 3056 | ) { |
|
| 3057 | // Select db object |
|
| 3058 | $component = $dbObject; |
|
| 3059 | } else { |
|
| 3060 | user_error("$relation is not a relation/field on ".get_class($component), E_USER_ERROR); |
|
| 3061 | } |
|
| 3062 | } |
|
| 3063 | } |
|
| 3064 | ||
| 3065 | // Bail if the component is null |
|
| 3066 | if(!$component) { |
|
| 3067 | return null; |
|
| 3068 | } |
|
| 3069 | if($component->hasMethod($fieldName)) { |
|
| 3070 | return $component->$fieldName(); |
|
| 3071 | } |
|
| 3072 | return $component->$fieldName; |
|
| 3073 | } |
|
| 3074 | ||
| 3075 | /** |
|
| 3076 | * Temporary hack to return an association name, based on class, to get around the mangle |
|
| @@ 2520-2554 (lines=35) @@ | ||
| 2517 | * @param $fieldName string |
|
| 2518 | * @return string | null - will return null on a missing value |
|
| 2519 | */ |
|
| 2520 | public function relField($fieldName) { |
|
| 2521 | $component = $this; |
|
| 2522 | ||
| 2523 | // We're dealing with relations here so we traverse the dot syntax |
|
| 2524 | if(strpos($fieldName, '.') !== false) { |
|
| 2525 | $relations = explode('.', $fieldName); |
|
| 2526 | $fieldName = array_pop($relations); |
|
| 2527 | foreach($relations as $relation) { |
|
| 2528 | // Inspect $component for element $relation |
|
| 2529 | if($component->hasMethod($relation)) { |
|
| 2530 | // Check nested method |
|
| 2531 | $component = $component->$relation(); |
|
| 2532 | } elseif($component instanceof SS_List) { |
|
| 2533 | // Select adjacent relation from DataList |
|
| 2534 | $component = $component->relation($relation); |
|
| 2535 | } elseif($component instanceof DataObject |
|
| 2536 | && ($dbObject = $component->dbObject($relation)) |
|
| 2537 | ) { |
|
| 2538 | // Select db object |
|
| 2539 | $component = $dbObject; |
|
| 2540 | } else { |
|
| 2541 | user_error("$relation is not a relation/field on ".get_class($component), E_USER_ERROR); |
|
| 2542 | } |
|
| 2543 | } |
|
| 2544 | } |
|
| 2545 | ||
| 2546 | // Bail if the component is null |
|
| 2547 | if(!$component) { |
|
| 2548 | return null; |
|
| 2549 | } |
|
| 2550 | if ($component->hasMethod($fieldName)) { |
|
| 2551 | return $component->$fieldName(); |
|
| 2552 | } |
|
| 2553 | return $component->$fieldName; |
|
| 2554 | } |
|
| 2555 | } |
|
| 2556 | ||