Vengo subito al dunque.
Il fatto sarebbe far "comunicare" joomla con il crm vtiger, parlare poi di integrazione è tuttaltra cosa, anche perchè, non sono un programmatore. Vorrei però arrivare almeno a capire quale strada sia possibile percorrere o, comunque sia, si fa esperienza...
...sul sito ufficiale di vtiger c'è questa pagina che spiega come far richieste al cmr tramite webservice.
http://wiki.vtiger.com/index.php/vtiger510:WebServices_tutorialsDal codice dei tutorial riportato nei vari esempi, viene utilizzata la classe HTTP_client, che fa parte delle librerie pear, presenti solo in parte in joomla. Infatti, ciò che riguarda l' oggetto HTTP_CLIENT non è presente nelle librerie pear di joomla (almeno fino alla verione 1.5.22 di joomla). Tale oggetto http_client risulta essere utile per l' invio delle richieste al crm.
Sempre dal codice del tutorial, viene spesso utilizzata la funzione "Zend_JSON::decode" che fa parte delle librerie zend, non presenti in joomla. Tale funzione, risulta molto utile per "decodificare" le risposte ricevute dal crm.
Ho provato a cercare fra le api di joomla, per vedere se era presente qualche funzionalità simile ma, a meno che la mia ignoranza sulle api joomla non venga confermata, non ho trovato nulla di simile.
Allora, non ho fatto altro che integrare tali "mancanze" ed aggiugerle alle librerie già presenti nella distribuzione di joomla, più o meno 200k di codice, facendo attenzione anche alle dipendenze.
A questo punto, provando alcuni esempi riportati nel tutorial di vtiger, tutto ha funzionato egregiamente. Per esempio, creando un file php contenente il seguente codice ed eseguedolo, si ottiene come output "grezzo" la lista dei prodotti presenti su vtiger. Quello che mi chiedevo e se , in una ipotetica installazione di un componente, plugin, etc., è giusto aggiungere librerire a quelle già presenti nella distribuzione ufficiale di joomla, ciò per avere ulteriori funzionalità altrimenti non presenti o difficilmente riproducibili.
<?php
/*
*/
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require('libraries/joomla/factory.php');
// initialize the application
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
//e.g.challengeToken
require('libraries/pear/Client.php');
require('libraries/Zend/json.php');
$endpointUrl = "http://localhost/vtigercrm/webservice.php";
//username of the user who is to logged in.
$userName="admin";
$httpc = new HTTP_CLIENT();
//getchallenge request must be a GET request.
$httpc->get("$endpointUrl?operation=getchallenge&username=".$userName);
$response = $httpc->currentResponse();
//decode the json encode response from the server.
$jsonResponse = Zend_JSON::decode($response['body']);
//check for whether the requested operation was successful or not.
if($jsonResponse['success']==false)
//handle the failure case.
die('getchallenge failed:'.$jsonResponse['error']['errorMsg']);
//operation was successful get the token from the reponse.
$challengeToken = $jsonResponse['result']['token'];
echo $challengeToken;
//LOGIN
//access key of the user admin, found on my preferences page.
$userAccessKey = '5wNd96KZLMxdpEpK';
//create md5 string concatenating user accesskey from my preference page
//and the challenge token obtained from get challenge result.
$generatedKey = md5($challengeToken.$userAccessKey);
//login request must be POST request.
$httpc->post("$endpointUrl",
array('operation'=>'login', 'username'=>$userName,
'accessKey'=>$generatedKey), true);
$response = $httpc->currentResponse();
//decode the json encode response from the server.
$jsonResponse = Zend_JSON::decode($response['body']);
//operation was successful get the token from the reponse.
if($jsonResponse['success']==false)
//handle the failure case.
die('login failed:'.$jsonResponse['error']['errorMsg']);
//login successful extract sessionId and userId from LoginResult to it can used for further calls.
$sessionId = $jsonResponse['result']['sessionName'];
$userId = $jsonResponse['result']['userId'];
echo $userId;
//QUERY SUI PRODOTTI VTIGER
//sessionId is obtained from loginResult.
$query = "select * from Products;";
//urlencode to as its sent over http.
$queryParam = urlencode($query);
//sessionId is obtained from login result.
$params = "sessionName=$sessionId&operation=query&query=$queryParam";
//query must be GET Request.
$httpc->get("$endpointUrl?$params");
$response = $httpc->currentResponse();
//decode the json encode response from the server.
$jsonResponse = Zend_JSON::decode($response['body']);
//operation was successful get the token from the reponse.
if($jsonResponse['success']==false)
//handle the failure case.
die('query failed:'.$jsonResponse['errorMsg']);
//Array of vtigerObjects
$retrievedObjects = $jsonResponse['result'];
foreach ($retrievedObjects as $a) {
echo '<br />';
foreach ($a as $b) {
echo $b ;
}}
?>