protected $url, $sessionId;
- /// CONSTRUCTEUR
+ /// CONSTRUCTOR
function __construct($url = 'http://sugar/service/v4_1/rest.php', $sessionId = null) {
//define('sugarEntry', TRUE);
$this -> url = $url;
$parameters = array(
'user_auth' => array(
'user_name' => $login,
- 'password' => md5($pass),
+ 'password' => $pass //md5($pass),
),
);
//The name of the module from which to retrieve records
'module_name' => $moduleName,
//The SQL WHERE clause without the word "where".
- 'query' => $sqlWhereClause,//"accounts.name = 'SDIS 40'",
+ 'query' => $sqlWhereClause,
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => $sqlOrderByClause,
//The record offset from which to start.
//A list of fields to include in the results.
'select_fields' => $requestedInfos,
//The maximum number of results to return.
- 'max_results' => 1,
- 'wl_list_max_entries_per_page' => 2,
+ 'max_results' => 100000,
+ 'wl_list_max_entries_per_page' => 100000,
//If deleted records should be included in results.
'deleted' => 0,
//If only records marked as favorites should be returned.
return $response;
}
-}
+ public function updateOrCreateEntryModule($moduleName, $parameters) {
+ $set_entry_parameters = array(
+ //session id
+ "session" => $this -> sessionId,
+
+ //The name of the module from which to retrieve records.
+ "module_name" => $moduleName,
+
+ //Record attributes
+ "name_value_list" => /*array(
+ //to update a record, you will nee to pass in a record id as commented below
+ //array("name" => "id", "value" => "9b170af9-3080-e22b-fbc1-4fea74def88f"),
+ array("name" => "name", "value" => $parameters['name']),
+ ),*/$parameters
+ );
+ $json = json_encode($set_entry_parameters);
-/*
+ $postArgs = array(
+ 'method' => 'set_entry',
+ 'input_type' => 'JSON',
+ 'response_type' => 'JSON',
+ 'rest_data' => $json,
+ );
+ $postArgs = http_build_query($postArgs);
-echo "Liste des clients :";
+ // Make the REST call, returning the result
+ $response = $this -> callRest($this -> url, $postArgs);
-?>
-<table>
- <tr>
- <th>Nom</th>
- <th>Adresse</th>
- <th>Tel</th>
- </tr>
- <?php foreach($result->entry_list as $account) { ?>
- <tr>
- <?php echo "<td>".$account->name_value_list->name->value."</td>"; ?>
- <?php echo "<td>".$account->name_value_list->billing_address_street->value."</td>"; ?>
- <?php echo "<td>".$account->name_value_list->phone_office->value."</td>"; ?>
- </tr>
- <?php } ?>
-</table>
-<?php
-*/
-
-/*
-$get_entry_list_parameters = array(
- //session id
- 'session' => $sessionId,
- //The name of the module from which to retrieve records
- 'module_name' => 'Opportunities',
- //The SQL WHERE clause without the word "where".
- 'query' => "",//"accounts.name = 'SDIS 40'",
- //The SQL ORDER BY clause without the phrase "order by".
- 'order_by' => "",
- //The record offset from which to start.
- 'offset' => 0,
- //A list of fields to include in the results.
- 'select_fields' => array(
- //'id',
- 'name',
- 'date_closed',
- 'account_name'
- ),*/
- //A list of link names and the fields to be returned for each link name.
- /*'link_name_to_fields_array' => array(
- array(
- 'name' => 'email_addresses',
- 'value' => array(
- 'email_address',
- 'opt_out',
- 'primary_address'
- ),
- ),
- ),*/
- //The maximum number of results to return.
- /*'max_results' => 1,
- 'wl_list_max_entries_per_page' => 1,
- //If deleted records should be included in results.
- 'deleted' => 0,
- //If only records marked as favorites should be returned.
- 'favorites' => false,
-);
-
-$json = json_encode($get_entry_list_parameters);
-
-$postArgs = array(
- 'method' => 'get_entry_list',
- 'input_type' => 'JSON',
- 'response_type' => 'JSON',
- 'rest_data' => $json,
-);
-
-$postArgs = http_build_query($postArgs);
-
-// Make the REST call, returning the result
-$response = $client->callRest($url, $postArgs);
-
-// Convert the result from JSON format to a PHP array
-$result = json_decode($response);
-
-echo "Liste des fiches d'installation :";
-
-?>
-<table>
- <tr>
- <th>Nom</th>
- <th>Date de fin</th>
- <th>Nom du compte</th>
- </tr>
- <?php foreach($result->entry_list as $opportunity) { ?>
- <tr>
- <?php echo "<td>".$opportunity->name_value_list->name->value."</td>"; ?>
- <?php echo "<td>".$opportunity->name_value_list->date_closed->value."</td>"; ?>
- <?php echo "<td>".$opportunity->name_value_list->account_name->value."</td>"; ?>
- </tr>
- <?php } ?>
-</table>
-}*/
\ No newline at end of file
+ return $response;
+ }
+
+ public function createRelationship($moduleName, $parameters) {
+ $set_relationship_parameters = array(
+ //session id
+ "session" => $this -> sessionId,
+
+ //The name of the primary module
+ "module_name" => $moduleName,
+
+ //The ID of the specified primary module bean.
+ 'module_id' => $parameters['primary_module_id'],
+
+ //The relationship name of the linked field from which to relate records.
+ 'link_field_name' => $parameters['link_name'],
+ //The list of record ids to relate
+ 'related_ids' => array($parameters['related_module_id']),
+ //Sets the value for relationship based fields
+ /*'name_value_list' => array(
+ array(
+ 'name' => 'contact_role',
+ 'value' => 'Other'
+ ),
+ ),*/
+ //Whether or not to delete the relationship. 0:create, 1:delete
+ 'delete'=> 0,
+
+ );
+
+ $json = json_encode($set_relationship_parameters);
+
+ $postArgs = array(
+ 'method' => 'set_relationship',
+ 'input_type' => 'JSON',
+ 'response_type' => 'JSON',
+ 'rest_data' => $json,
+ );
+
+ $postArgs = http_build_query($postArgs);
+
+ // Make the REST call, returning the result
+ $response = $this -> callRest($this -> url, $postArgs);
+
+ return $response;
+ }
+
+ public function getRelationships($moduleName, $parameters, $requestedInfos, $sqlWhereClause = '') {
+ $get_relationships_parameters = array(
+ //session id
+ "session" => $this -> sessionId,
+
+ //The name of the primary module
+ "module_name" => $moduleName,
+
+ //The ID of the specified primary module bean.
+ 'module_id' => $parameters['primary_module_id'],
+
+ //The relationship name of the linked field from which to relate records.
+ 'link_field_name' => $parameters['link_name'],
+
+ 'related_module_query' => $sqlWhereClause,
+
+ //Sets the value for relationship based fields
+ 'related_fields' => $requestedInfos,
+ //Whether or not to delete the relationship. 0:create, 1:delete
+ 'delete'=> 0,
+
+ //order by
+ //'order_by' => ' opportunities.name ',
+
+ //offset
+ //'offset' => 0,
+
+ //limit
+ //'limit' => 200,
+ );
+
+ $json = json_encode($get_relationships_parameters);
+
+ $postArgs = array(
+ 'method' => 'get_relationships',
+ 'input_type' => 'JSON',
+ 'response_type' => 'JSON',
+ 'rest_data' => $json,
+ );
+
+ $postArgs = http_build_query($postArgs);
+
+ // Make the REST call, returning the result
+ $response = $this -> callRest($this -> url, $postArgs);
+
+ return $response;
+ }
+
+}