Ignore:
Timestamp:
Nov 8, 2010 6:17:28 PM (3 years ago)
Author:
thomasb
Message:

List all Kolab contact folders available

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/kolab_addressbook/kolab_addressbook.php

    r4134 r4197  
    1717class kolab_addressbook extends rcube_plugin 
    1818{ 
    19     private $abook_id = 'kolab'; 
    20     private $abook; 
    21   
     19    private $kolab; 
     20    private $folders; 
     21    private $sources; 
     22 
    2223    /** 
    2324     * Required startup method of a Roundcube plugin 
     
    3233        $this->add_hook('imap_init', array($this, 'imap_init')); 
    3334 
    34         // use this address book for autocompletion queries 
    35         $config = rcmail::get_instance()->config; 
    36         $sources = (array) $config->get('autocomplete_addressbooks', array('sql')); 
    37         if (!in_array($this->abook_id, $sources)) { 
    38             $sources[] = $this->abook_id; 
    39             $config->set('autocomplete_addressbooks', $sources); 
    40         } 
    41          
    4235        // extend include path to load bundled Horde classes 
    4336        $include_path = $this->home . '/lib' . PATH_SEPARATOR . ini_get('include_path'); 
     
    5649    public function address_sources($p) 
    5750    { 
    58         // get single instance (for now) 
    59         $abook = rcube_kolab_contacts::singleton(); 
    60          
    61         // maybe here we'll add more than one item 
    62         $p['sources'][$this->abook_id] = array( 
    63             'id' => $this->abook_id, 
    64             'name' => 'Kolab', 
    65             'readonly' => $abook->readonly, 
    66             'groups' => $abook->groups, 
    67         ); 
     51        // setup Kolab backend 
     52        rcube_kolab::setup(); 
     53 
     54        // get all folders that have "contact" type 
     55        $this->kolab = Kolab_List::singleton(); 
     56        $this->folders = $this->kolab->getByType('contact'); 
     57 
     58        if (PEAR::isError($this->folders)) { 
     59            raise_error(array( 
     60              'code' => 600, 'type' => 'php', 
     61              'file' => __FILE__, 'line' => __LINE__, 
     62              'message' => "Failed to list contact folders from Kolab server:" . $this->folders->getMessage()), 
     63            true, false); 
     64        } 
     65        else { 
     66            foreach ($this->folders as $c_folder) { 
     67                // create instance of rcube_contacts 
     68                $abook_id = strtolower(asciiwords(strtr($c_folder->name, '/', '-'))); 
     69                $abook = new rcube_kolab_contacts($c_folder->name); 
     70                $this->sources[$abook_id] = $abook; 
     71                 
     72                // register this address source 
     73                $p['sources'][$abook_id] = array( 
     74                    'id' => $abook_id, 
     75                    'name' => $c_folder->name, 
     76                    'readonly' => $abook->readonly, 
     77                    'groups' => $abook->groups, 
     78                ); 
     79            } 
     80        } 
     81 
    6882        return $p; 
    6983    } 
     
    7589    public function get_address_book($p) 
    7690    { 
    77         if ($p['id'] === $this->abook_id) { 
    78             $p['instance'] = rcube_kolab_contacts::singleton(); 
     91        if ($this->sources[$p['id']]) { 
     92            $p['instance'] = $this->sources[$p['id']]; 
    7993        } 
    8094         
Note: See TracChangeset for help on using the changeset viewer.