Roundcube Community Forum

Third Party Contributions => API Based Plugins => Topic started by: rodrigocarneiro on August 06, 2013, 08:48:08 AM

Title: [help] Develop my own addressbook
Post by: rodrigocarneiro on August 06, 2013, 08:48:08 AM
Dear All,

I'm new to this forum, so hopefully I posted the question in the right place.

I created a new addressbook plugin from example_addressbook located inside the plugins folder in roundcube. I deduced a lot from other implementations and read something from the documentation, but I'm having a little problem when it relates to search within my addresbook.  Strangely the autocomplete on the screen to write the e-mail works fine.

I wonder if the masters have some literature to help me implement the plugin.

Thanks for any help!
Title: Re: [help] Develop my own addressbook
Post by: SKaero on August 06, 2013, 02:42:48 PM
Haven't played with the address book functions to much so I may not be of to much help, but I'll try. What do you have set for address_book_type, and the autocomplete_addressbooks options in the main.inc.php?
Title: Re: [help] Develop my own addressbook
Post by: rodrigocarneiro on August 07, 2013, 10:23:02 AM
Hello, thanks for the reply.

$rcmail_config['address_book_type'] = 'sql';
$rcmail_config['autocomplete_addressbooks'] = array('sql', 'my');

I already tried to set boot type to be equals to my autocomplete setting, but with the same result.

Note:
When i do a search in adressbook, it returns everytime the same values to my custom one, but bring correctly records of the buildin one.
Title: Re: [help] Develop my own addressbook
Post by: SKaero on August 08, 2013, 01:54:43 AM
I'm not sure I understand what your saying its doing, did you code a custom search handler?
Title: Re: [help] Develop my own addressbook
Post by: rodrigocarneiro on August 08, 2013, 01:29:49 PM
Hello again,

I'm developing a plugin that read some contacts from a custom table and presents them to users. A kind of global list. For this I started to develop on top of example_addressbook and added my code to make the magic happen. My problem is that I can not make a search in the contacts list works perfectly. Here's the code I modified from example_addressbook plugin, I hope I have been clearer now:

example_addressbook:
http://codepad.org/6mK7suxN

example_addressbook_backend:
http://codepad.org/d2rJi41o
Title: Re: [help] Develop my own addressbook
Post by: SKaero on August 08, 2013, 01:43:04 PM
Looking at your code in the example_addressbook_backend file in the search function you have a custom chunk of sql in the $where variable which you pass to the list_records function but it never gets added to the actual sql query.
Title: Re: [help] Develop my own addressbook
Post by: rodrigocarneiro on August 08, 2013, 03:16:35 PM
Sorry about that,

I modified the code to be able to show you, actually the where clause is added there, as I said earlier the autocoplete works on the page to write emails. So this is not my problem.

Thank you for your attention.
Title: Re: [help] Develop my own addressbook
Post by: SKaero on August 08, 2013, 03:23:27 PM
Ok, I'm not sure what you mean by the following:

When i do a search in adressbook, it returns everytime the same values to my custom one, but bring correctly records of the buildin one.

Is it returning any records from your custom address book handler?
Title: Re: [help] Develop my own addressbook
Post by: rodrigocarneiro on August 08, 2013, 03:43:31 PM
What i means is:

This piece of code:

$config = rcmail::get_instance()->config;
$sources = (array) $config->get('autocomplete_addressbooks', array('sql'));
if (!in_array($this->abook_id, $sources)) {
   $sources[] = $this->abook_id;
   $config->set('autocomplete_addressbooks', $sources);
}


Do the same of:

$rcmail_config['autocomplete_addressbooks'] = array('sql', 'my');


To bring result from the both addressbooks, i presume.

But, my custom addressbook, dont bring them correctly, although the sql bring. i think i forgot to implement some functioin on the class. This is why i first ask about a literature to help me to implement the plugin.
Title: Re: [help] Develop my own addressbook
Post by: SKaero on August 08, 2013, 09:09:20 PM
Does the search work if you change the address_book_type in the main.inc.php to your custom address book handler?
Title: Re: [help] Develop my own addressbook
Post by: rodrigocarneiro on August 09, 2013, 08:53:33 AM
No, i tried to put my addressbook name and a empty string:


// This indicates which type of address book to use. Possible choises:
// 'sql' (default), 'ldap' and ''.
// If set to 'ldap' then it will look at using the first writable LDAP
// address book as the primary address book and it will not display the
// SQL address book in the 'Address Book' view.
// If set to '' then no address book will be displayed or only the
// addressbook which is created by a plugin (like CardDAV).
$rcmail_config['address_book_type'] = '';
Title: Re: [help] Develop my own addressbook
Post by: SKaero on August 09, 2013, 12:01:49 PM
Can you post your full code so I can test it myself?
Title: Re: [help] Develop my own addressbook
Post by: rodrigocarneiro on August 09, 2013, 01:27:40 PM
This is all i have modified on the code. What you need is to active the plugin in config and create the table on your database with the fields:

id [int], login [varchar], nome [varchar], email [varchar], ramal [varchar], vinculo [varchar], lotacao [varchar], lista [varchar], lista_visivel [bool]
Title: Re: [help] Develop my own addressbook
Post by: SKaero on August 09, 2013, 03:51:36 PM
You said that you had modified the code that you had posted before, since the search is obviously broken in that one.
Title: Re: [help] Develop my own addressbook
Post by: rodrigocarneiro on August 09, 2013, 03:57:33 PM
Indeed, just change the code to accept the where clause, I will make the changes and repost for you.
Title: Re: [help] Develop my own addressbook
Post by: rodrigocarneiro on August 12, 2013, 09:13:07 AM
I just edited the file to add the search criteria on the query:

http://codepad.org/PCRZHlSx

Note:
This is just for testing, I want to create a plugin and make it available to the community.

Thanks again for you help.
Title: Re: [help] Develop my own addressbook
Post by: SKaero on August 17, 2013, 03:49:04 PM
I've installed your version of the plugin, to confirm when you do a search from the address book its returning all of the contacts instead of just the ones in the search correct?
Title: Re: [help] Develop my own addressbook
Post by: rodrigocarneiro on August 19, 2013, 01:22:08 PM
It returns the results of the standard addressbook plus my addressbook, but my, is always the same, but not all.

thx