Index: plugins/sfSugarCRMPlugin/lib/sfSugarCRM.class.php =================================================================== --- plugins/sfSugarCRMPlugin/lib/sfSugarCRM.class.php (revisão 4) +++ plugins/sfSugarCRMPlugin/lib/sfSugarCRM.class.php (cópia de trabalho) @@ -28,6 +28,13 @@ $wsdl = '', /** + * The remote login ID. + * @var string + */ + $login_id = '', + + + /** * The remote user's username. * @var string */ @@ -214,7 +221,7 @@ } /** - * Fetches a array of users. + * Fetches an array of users. * * @return void */ @@ -374,4 +381,91 @@ $this->lastResponse = $response; } + + /** + * Login on SugarCRM and store the login ID + * + * @return void + */ + public function doLogin() + { + $client = sfSugarCRMSOAPClient::getInstance($this->wsdl); + + try { + + $auth = array('user_name'=> $this->username, + 'password' => $this->password, + 'version' => '1.0' + ); + + $response = $client->login($auth); + } + catch (SoapFault $exception) + { + throw $exception; + } + + $this->lastResponse = $response; + $this->login_id = $response->id; + + } + + /** + * Return the login ID from SugarCRM. Required for some functions. + * + * @return string Login ID on SugarCRM + */ + public function getLoginId() + { + if (empty($this->login_id)) + $this->doLogin(); + + return $this->login_id; + } + + /** + * Fetches an array of entries using the remote method get_entry_list() + * + * @param array $parameters Parameters passed to the get_entry_list() method + * @return void + */ + public function getEntryList($parameters) + { + $client = sfSugarCRMSOAPClient::getInstance($this->wsdl); + + $default = array( + "session" => $this->getLoginId(), + "module_name" => "Accounts", + "query" => "", + "order_by" => "", + "offset" => 0, + "select_fields" => "", + "max_results" => 1000, + "deleted" => 0 + ); + $parameters = array_merge($default, $parameters); + + try + { + + + $response = $client->get_entry_list( + $parameters["session"], + $parameters["module_name"], + $parameters["query"], + $parameters["order_by"], + $parameters["offset"], + $parameters["select_fields"], + $parameters["max_results"], + $parameters["deleted"] + ); + + } + catch (SoapFault $exception) + { + throw $exception; + } + + $this->lastResponse = $response; + } }