| 811 | | // TODO: Try to figure a way to use collector based on reflection data for this (and why not for get_parent_guid_uncached as well) |
|---|
| 812 | | \$object = new {$this->_class_definition['midcom_class_name']}(\$object_guid); |
|---|
| 813 | | if ( !is_object(\$object) |
|---|
| 814 | | || !method_exists(\$object, 'get_parent_guid_uncached')) |
|---|
| 815 | | { |
|---|
| 816 | | return null; |
|---|
| 817 | | } |
|---|
| 818 | | return \$object->get_parent_guid_uncached(); |
|---|
| | 815 | EOF; |
|---|
| | 816 | $reflector = new midgard_reflection_property($this->_class_definition['new_class_name']); |
|---|
| | 817 | $up_property = midgard_object_class::get_property_up($this->_class_definition['new_class_name']); |
|---|
| | 818 | if (!empty($up_property)) |
|---|
| | 819 | { |
|---|
| | 820 | $target_property = $reflector->get_link_target($up_property); |
|---|
| | 821 | $this->_class_string .= "\n"; |
|---|
| | 822 | $this->_class_string .= <<<EOF |
|---|
| | 823 | // Up takes precedence over parent |
|---|
| | 824 | \$mc = new midgard_collector('{$this->_class_definition['new_class_name']}', 'guid', \$object_guid); |
|---|
| | 825 | \$mc->set_key_property('{$up_property}'); |
|---|
| | 826 | \$mc->execute(); |
|---|
| | 827 | \$link_values = \$mc->list_keys(); |
|---|
| | 828 | if (!empty(\$link_values)) |
|---|
| | 829 | { |
|---|
| | 830 | list (\$link_value, \$dummy) = each(\$link_values); |
|---|
| | 831 | unset(\$mc, \$link_values, \$dummy); |
|---|
| | 832 | \$mc2 = new midgard_collector('{$this->_class_definition['new_class_name']}', '{$target_property}', \$link_value); |
|---|
| | 833 | \$mc2->set_key_property('guid'); |
|---|
| | 834 | \$mc2->execute(); |
|---|
| | 835 | \$guids = \$mc2->list_keys(); |
|---|
| | 836 | if (!is_array(\$guids)) |
|---|
| | 837 | { |
|---|
| | 838 | unset(\$mc2, \$guids, \$link_value); |
|---|
| | 839 | return null; |
|---|
| | 840 | } |
|---|
| | 841 | list (\$parent_guid, \$dummy) = each(\$guids); |
|---|
| | 842 | unset(\$mc2, \$guids, \$link_value, \$dummy); |
|---|
| | 843 | return \$parent_guid; |
|---|
| | 844 | } |
|---|
| | 845 | else |
|---|
| | 846 | { |
|---|
| | 847 | unset(\$mc, \$link_values); |
|---|
| | 848 | } |
|---|
| | 849 | EOF; |
|---|
| | 850 | } |
|---|
| | 851 | |
|---|
| | 852 | $parent_property = midgard_object_class::get_property_parent($this->_class_definition['new_class_name']); |
|---|
| | 853 | if (!empty($parent_property)) |
|---|
| | 854 | { |
|---|
| | 855 | $target_property = $reflector->get_link_target($parent_property); |
|---|
| | 856 | $target_class = $reflector->get_link_name($parent_property); |
|---|
| | 857 | $this->_class_string .= "\n"; |
|---|
| | 858 | $this->_class_string .= <<<EOF |
|---|
| | 859 | \$mc = new midgard_collector('{$this->_class_definition['new_class_name']}', 'guid', \$object_guid); |
|---|
| | 860 | \$mc->set_key_property('{$parent_property}'); |
|---|
| | 861 | \$mc->execute(); |
|---|
| | 862 | \$link_values = \$mc->list_keys(); |
|---|
| | 863 | if (!empty(\$link_values)) |
|---|
| | 864 | { |
|---|
| | 865 | list (\$link_value, \$dummy) = each(\$link_values); |
|---|
| | 866 | unset(\$mc, \$link_values, \$dummy); |
|---|
| | 867 | \$mc2 = new midgard_collector('{$target_class}', '{$target_property}', \$link_value); |
|---|
| | 868 | \$mc2->set_key_property('guid'); |
|---|
| | 869 | \$mc2->execute(); |
|---|
| | 870 | \$guids = \$mc2->list_keys(); |
|---|
| | 871 | if (!is_array(\$guids)) |
|---|
| | 872 | { |
|---|
| | 873 | unset(\$mc2, \$guids, \$link_value); |
|---|
| | 874 | return null; |
|---|
| | 875 | } |
|---|
| | 876 | list (\$parent_guid, \$dummy) = each(\$guids); |
|---|
| | 877 | unset(\$mc2, \$guids, \$link_value, \$dummy); |
|---|
| | 878 | return \$parent_guid; |
|---|
| | 879 | } |
|---|
| | 880 | else |
|---|
| | 881 | { |
|---|
| | 882 | unset(\$mc, \$link_values); |
|---|
| | 883 | } |
|---|
| | 884 | EOF; |
|---|
| | 885 | } |
|---|
| | 886 | |
|---|
| | 887 | $this->_class_string .= "\n"; |
|---|
| | 888 | $this->_class_string .= <<<EOF |
|---|
| | 889 | return null; |
|---|