Changeset 11920

Show
Ignore:
Timestamp:
08/30/07 22:16:40 (1 year ago)
Author:
rambo
Message:

refs #102

Use reflection to generate working get_parent_guid_uncached method
to the midcom DBA base class

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.core/midcom/services/dbclassloader.php

    r11359 r11920  
    736736        ); 
    737737    } 
    738     function get_parent_guid_uncached() { return null; } 
     738    function get_parent_guid_uncached() 
     739    { 
     740EOF; 
     741        $reflector = new midgard_reflection_property($this->_class_definition['new_class_name']); 
     742        $up_property = midgard_object_class::get_property_up($this->_class_definition['new_class_name']); 
     743        if (!empty($up_property)) 
     744        { 
     745            $target_property = $reflector->get_link_target($up_property); 
     746            /** 
     747             * Taken out from the generated code as this will cause infite loop in ACL resolving, using direct QB in stead 
     748             * (when instantiating the parent ACLs will be checked in any case) 
     749             * 
     750            \$mc = {$this->_class_definition['midcom_class_name']}::new_collector('{$target_property}', \$this->{$up_property}); 
     751            */ 
     752            $this->_class_string .= "\n"; 
     753            $this->_class_string .= <<<EOF 
     754        // Up takes precedence over parent 
     755        if (!empty(\$this->{$up_property})) 
     756        { 
     757            \$mc = new midgard_collector('{$this->_class_definition['new_class_name']}', '{$target_property}', \$this->{$up_property}); 
     758            \$mc->set_key_property('guid'); 
     759            \$mc->execute(); 
     760            \$guids = \$mc->list_keys(); 
     761            if (!is_array(\$guids)) 
     762            { 
     763                return null; 
     764            } 
     765            list (\$parent_guid, \$dummy) = each(\$guids); 
     766            return \$parent_guid; 
     767        } 
     768EOF; 
     769        } 
     770        $parent_property = midgard_object_class::get_property_parent($this->_class_definition['new_class_name']); 
     771        if (!empty($parent_property)) 
     772        { 
     773            $target_property = $reflector->get_link_target($parent_property); 
     774            $target_class = $reflector->get_link_name($parent_property); 
     775            /** 
     776             * Taken out from the generated code as this will cause infite loop in ACL resolving, using direct QB in stead 
     777             * (when instantiating the parent ACLs will be checked in any case) 
     778             * 
     779            \$dummy_object = new {$target_class}(); 
     780            \$midcom_dba_classname = \$_MIDCOM->dbclassloader->get_midcom_class_name_for_mgdschema_object(\$dummy_object); 
     781            if (empty(\$midcom_dba_classname)) 
     782            { 
     783                return null; 
     784            } 
     785            \$mc = call_user_func(array(\$midcom_dba_classname, 'new_collector'), array(\$target_property, \$this->\$parent_property)); 
     786            */ 
     787            $this->_class_string .= "\n"; 
     788            $this->_class_string .= <<<EOF 
     789        if (!empty(\$this->{$parent_property})) 
     790        { 
     791            \$mc = new midgard_collector('{$target_class}', '{$target_property}', \$this->{$parent_property}); 
     792            \$mc->set_key_property('guid'); 
     793            \$mc->execute(); 
     794            \$guids = \$mc->list_keys(); 
     795            if (!is_array(\$guids)) 
     796            { 
     797                return null; 
     798            } 
     799            list (\$parent_guid, \$dummy) = each(\$guids); 
     800            return \$parent_guid; 
     801        } 
     802EOF; 
     803        } 
     804 
     805        $this->_class_string .= "\n"; 
     806        $this->_class_string .= <<<EOF 
     807        return null; 
     808    } 
    739809    function get_parent_guid_uncached_static(\$object_guid) 
    740810    {