The 2.0 in the name of Tine 2.0 stands for "Web 2.0". From the beginning it was clear, that we need to be open to other systems. There must be a clear separation between the business logic and the userinterface.
We solved this problem automatically by having a JavaScript userinterface which talks to a PHP based webservice via JSON. This way we have a JSON based webservice other webclients can connect to for free. We support JSON-RPC and JSON-SMD, which allows you to connect to Tine 2.0 with any language which supports HTTP and JSON.
As a heavy user of the Zend Framework, it was very sad that the Zend Framework provides Zend_Json_Server which made implementing the server side for Tine 2.0 very easy, but no Zend_Json_Client.
Up till now....
Introducing Zend_Json_Client ...
I filled the gap, by implementing Zend_Json_Client.
The Zend_Json_Client allows you to connect from other PHP based webapplications to any JSON-RPC server. So far I have the tested the implementation only against the Zend_Json_Server. As the Zend_Json_Client also supports JSON-SMD we are able to verify the request method name and number of parameters already on client side.
I modelled the Zend_Json_Client after the Zend_XmlRpc_Client and used as many parts as possible from the Zend_Json_Server classes. As a next step I need to get in contact with the maintainer of the Zend_Json classes to get the Zend_Json_Client pushed into Zend Frameworks SVN. Then it will be available to any user of Zend Framework in the future.
... and Zend_Service_Tine20
As we have a Zend_Json_Client now, we also need Zend_Service_Tine20 now. Zend_Service_Tine20 is a very thin layer on top of Zend_Json_Client which provides functions to login and logout from Tine 2.0. More is not needed as all other functionality is provided by plain JSON-RPC calls.
But how does code look like?
Connecting to Tine 2.0 is very easy now. To test the functionality lets try to do following. Insert a new contact into the addressbook and add a lead associated with this contact into the CRM. A typical situation when you have a contact formular on your public website.
// url of your Tine 2.0 installation
$tine20Url = 'http://tine20/index.php';
// login name
$tine20Loginname = 'loginname';
// password
$tine20Password = 'password';
// id of addressbook container
$addressbookContainerId = '9';
// id of CRM container
$crmContainerId = '14';
// set include path to find all needed classes
set_include_path('/var/www/tine20' . PATH_SEPARATOR . '/var/www/tine20/library' . PATH_SEPARATOR . get_include_path());
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);
// initialize Tine 2.0 service
$tine20 = new Zend_Service_Tine20($tine20Url);
// login into Tine 2.0
$response = $tine20->login($tine20Loginname, $tine20Password);
var_dump($response);
// call Tinebase.getAllRegistryData directly
$result = $tine20->call('Tinebase.getAllRegistryData');
// call Tinebase.getAllRegistryData using a Tinebase proxy class
$tinebase = $tine20->getProxy('Tinebase');
$result = $tinebase->getAllRegistryData();
// get a proxy class for the Addressbook namespace
$addressbook = $tine20->getProxy('Addressbook');
// create a new contact
$contact = $addressbook->saveContact(array(
'n_family' => 'Picard',
'n_given' => 'Jean-Luc',
'container_id' => $addressbookContainerId
));
// get a proxy class for the CRM namespace
$crm = $tine20->getProxy('Crm');
// create a new lead in the CRM and assign contact created above as costumer
$crm->saveLead(array(
'lead_name' => 'Test lead',
'leadstate_id' => 1,
'leadtype_id' => 1,
'leadsource_id' => 3,
'start' => '2009-11-13 21:00:00',
'description' => 'Added via Tine 2.0 Service',
'container_id' => $crmContainerId,
'relations' => array(array(
'type' => 'CUSTOMER',
'related_record' => $contact
))
));
// logout from Tine 2.0
$tine20->logout();
If you execute this piece of code you should have new contact in your addressbook and a new lead in your CRM.
If you have any questions feel free to ask in our
PHP Backend forum.