Changeset 17931

Show
Ignore:
Timestamp:
10/05/08 17:00:48 (2 months ago)
Author:
flack
Message:

refactored for better readability

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/org.openpsa.core/midcom/interfaces.php

    r17885 r17931  
    2929    { 
    3030        debug_push_class(__CLASS__, __FUNCTION__); 
    31          
     31         
     32        $this->define_constants(); 
     33        $this->set_acl_options(); 
     34        $this->set_workgroup_filter(); 
     35        $this->load_my_company(); 
     36 
     37        debug_pop(); 
     38        return true; 
     39    } 
     40 
     41    /** 
     42     * Load "my company" or "owner company", the group that is the main user of this instance 
     43     */ 
     44    private function load_my_company() 
     45    { 
     46        $my_company_guid = $this->_data['config']->get('owner_organization'); 
     47        $GLOBALS['org.openpsa.core:owner_organization_obj'] = false; 
     48        if (   !empty($my_company_guid) 
     49            && mgd_is_guid($my_company_guid)) 
     50        { 
     51            // For some reason this trigger error 500 
     52            //$_MIDCOM->componentloader->load_graceful('org.openpsa.contacts'); 
     53            if (!class_exists('org_openpsa_contacts_group')) 
     54            { 
     55                // Fallback to standard group object 
     56                $class = 'midcom_db_group'; 
     57            } 
     58            else 
     59            { 
     60                $class = 'org_openpsa_contacts_group'; 
     61            } 
     62            $_MIDCOM->auth->request_sudo(); 
     63            $my_company_object = new $class($my_company_guid); 
     64            $_MIDCOM->auth->drop_sudo(); 
     65            if (!$my_company_object->guid) 
     66            { 
     67                // TODO: Generate proper error 
     68                debug_pop(); 
     69                return false; 
     70            } 
     71            $GLOBALS['org.openpsa.core:owner_organization_obj'] = $my_company_object; 
     72        } 
     73    } 
     74 
     75    /** 
     76     * Make the selected workgroup filter available to all components 
     77     */ 
     78    private function set_workgroup_filter() 
     79    { 
     80        if (   !array_key_exists('org_openpsa_core_workgroup_filter', $GLOBALS) 
     81            // Sessioning kills caching and I doubt we really need this info when we don't have a user 
     82            && $_MIDGARD['user']) 
     83        { 
     84 
     85            if ($this->_data['config']->get('default_workgroup_filter') == 'me') 
     86            { 
     87                if ($_MIDCOM->auth->user) 
     88                { 
     89 
     90                    $default_filter = $_MIDCOM->auth->user->id; 
     91                } 
     92                else 
     93                { 
     94                    $default_filter = 'all'; 
     95                } 
     96            } 
     97            else 
     98            { 
     99                $default_filter = $this->_data['config']->get('default_workgroup_filter'); 
     100            } 
     101 
     102            $GLOBALS['org_openpsa_core_workgroup_filter'] = $default_filter; 
     103 
     104            /* the workgroup filter is deprecated, let's not screw caching over with it 
     105            $session = new midcom_service_session('org.openpsa.core'); 
     106            if (!$session->exists('org_openpsa_core_workgroup_filter')) 
     107            { 
     108                $session->set('org_openpsa_core_workgroup_filter', $default_filter); 
     109            } 
     110            $GLOBALS['org_openpsa_core_workgroup_filter'] = $session->get('org_openpsa_core_workgroup_filter'); 
     111            */ 
     112            $GLOBALS['org_openpsa_core_workgroup_filter'] = $default_filter; 
     113        } 
     114    } 
     115 
     116    private function define_constants() 
     117    { 
    32118        //Constant versions of wgtype bitmasks 
    33119        define('ORG_OPENPSA_WGTYPE_NONE', 0); 
     
    91177        define('ORG_OPENPSA_OBTYPE_CAMPAIGN', 9500); 
    92178        define('ORG_OPENPSA_OBTYPE_CAMPAIGN_SMART', 9501); 
     179    } 
    93180 
    94         // Make the ACL selection array available to all components 
     181    /** 
     182     * Make the ACL selection array available to all components 
     183     */ 
     184    private function set_acl_options() 
     185    { 
    95186        if (!array_key_exists('org_openpsa_core_acl_options', $GLOBALS)) 
    96187        { 
     
    103194            ); 
    104195        } 
    105  
    106         // Make the selected workgroup filter available to all components 
    107         if (   !array_key_exists('org_openpsa_core_workgroup_filter', $GLOBALS) 
    108             // Sessioning kills caching and I doubt we really need this info when we don't have a user 
    109             && $_MIDGARD['user']) 
    110         { 
    111  
    112             if ($this->_data['config']->get('default_workgroup_filter') == 'me') 
    113             { 
    114                 if ($_MIDCOM->auth->user) 
    115                 { 
    116  
    117                     $default_filter = $_MIDCOM->auth->user->id; 
    118                 } 
    119                 else 
    120                 { 
    121                     $default_filter = 'all'; 
    122                 } 
    123             } 
    124             else 
    125             { 
    126                 $default_filter = $this->_data['config']->get('default_workgroup_filter'); 
    127             } 
    128  
    129             $GLOBALS['org_openpsa_core_workgroup_filter'] = $default_filter; 
    130  
    131             /* the workgroup filter is deprecated, let's not screw caching over with it 
    132             $session = new midcom_service_session('org.openpsa.core'); 
    133             if (!$session->exists('org_openpsa_core_workgroup_filter')) 
    134             { 
    135                 $session->set('org_openpsa_core_workgroup_filter', $default_filter); 
    136             } 
    137             $GLOBALS['org_openpsa_core_workgroup_filter'] = $session->get('org_openpsa_core_workgroup_filter'); 
    138             */ 
    139             $GLOBALS['org_openpsa_core_workgroup_filter'] = $default_filter; 
    140         } 
    141  
    142         // Load "my company" or "owner company", the group that is the main user of this instance 
    143         $my_company_guid = $this->_data['config']->get('owner_organization'); 
    144         $GLOBALS['org.openpsa.core:owner_organization_obj'] = false; 
    145         if (   !empty($my_company_guid) 
    146             && mgd_is_guid($my_company_guid)) 
    147         { 
    148             // For some reason this trigger error 500 
    149             //$_MIDCOM->componentloader->load_graceful('org.openpsa.contacts'); 
    150             if (!class_exists('org_openpsa_contacts_group')) 
    151             { 
    152                 // Fallback to standard group object 
    153                 $class = 'midcom_db_group'; 
    154             } 
    155             else 
    156             { 
    157                 $class = 'org_openpsa_contacts_group'; 
    158             } 
    159             $_MIDCOM->auth->request_sudo(); 
    160             $my_company_object = new $class($my_company_guid); 
    161             $_MIDCOM->auth->drop_sudo(); 
    162             if (!$my_company_object->guid) 
    163             { 
    164                 // TODO: Generate proper error 
    165                 debug_pop(); 
    166                 return false; 
    167             } 
    168             $GLOBALS['org.openpsa.core:owner_organization_obj'] = $my_company_object; 
    169         } 
    170  
    171         debug_pop(); 
    172         return true; 
    173196    } 
    174197}