]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - service/v4_1/SugarWebServiceImplv4_1.php
Release 6.4.2
[Github/sugarcrm.git] / service / v4_1 / SugarWebServiceImplv4_1.php
1 <?php
2 if (!defined('sugarEntry')) define('sugarEntry', true);
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38
39 /**
40  * SugarWebServiceImplv4_1.php
41  *
42  * This class is an implementation class for all the web services.  Version 4_1 adds limit/off support to the
43  * get_relationships function.  We also added the sync_get_modified_relationships function call from version
44  * one to facilitate querying for related meetings/calls contacts/users records.
45  *
46  */
47 require_once('service/v4/SugarWebServiceImplv4.php');
48 require_once('service/v4_1/SugarWebServiceUtilv4_1.php');
49
50 class SugarWebServiceImplv4_1 extends SugarWebServiceImplv4
51 {
52
53     /**
54      * Class Constructor Object
55      *
56      */
57     public function __construct()
58     {
59         self::$helperObject = new SugarWebServiceUtilv4_1();
60     }
61
62     /**
63      * Retrieve a collection of beans that are related to the specified bean and optionally return relationship data for those related beans.
64      * So in this API you can get contacts info for an account and also return all those contact's email address or an opportunity info also.
65      *
66      * @param String $session -- Session ID returned by a previous call to login.
67      * @param String $module_name -- The name of the module that the primary record is from.  This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
68      * @param String $module_id -- The ID of the bean in the specified module
69      * @param String $link_field_name -- The name of the lnk field to return records from.  This name should be the name the relationship.
70      * @param String $related_module_query -- A portion of the where clause of the SQL statement to find the related items.  The SQL query will already be filtered to only include the beans that are related to the specified bean.
71      * @param Array $related_fields - Array of related bean fields to be returned.
72      * @param Array $related_module_link_name_to_fields_array - For every related bean returrned, specify link fields name to fields info for that bean to be returned. For ex.'link_name_to_fields_array' => array(array('name' =>  'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address'))).
73      * @param Number $deleted -- false if deleted records should not be include, true if deleted records should be included.
74      * @param String $order_by -- field to order the result sets by
75      * @param Number $offset -- where to start in the return
76      * @param Number $limit -- numbet of results to return (defaults to all)
77      * @return Array 'entry_list' -- Array - The records that were retrieved
78      *                  'relationship_list' -- Array - The records link field data. The example is if asked about accounts contacts email address then return data would look like Array ( [0] => Array ( [name] => email_addresses [records] => Array ( [0] => Array ( [0] => Array ( [name] => id [value] => 3fb16797-8d90-0a94-ac12-490b63a6be67 ) [1] => Array ( [name] => email_address [value] => hr.kid.qa@example.com ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 1 ) ) [1] => Array ( [0] => Array ( [name] => id [value] => 403f8da1-214b-6a88-9cef-490b63d43566 ) [1] => Array ( [name] => email_address [value] => kid.hr@example.name ) [2] => Array ( [name] => opt_out [value] => 0 ) [3] => Array ( [name] => primary_address [value] => 0 ) ) ) ) )
79      * @exception 'SoapFault' -- The SOAP error, if any
80      */
81     function get_relationships($session, $module_name, $module_id, $link_field_name, $related_module_query, $related_fields, $related_module_link_name_to_fields_array, $deleted, $order_by = '', $offset = 0, $limit = false)
82     {
83         $return = parent::get_relationships($session, $module_name, $module_id, $link_field_name, $related_module_query, $related_fields, $related_module_link_name_to_fields_array, $deleted, $order_by);
84
85         if (is_array($return) && !empty($return['entry_list'])) {
86             $entry_list = $return['entry_list'];
87             $rel_list = $return['relationship_list'];
88             if ($limit === false || !is_numeric($limit)) {
89                 $limit = null;
90             }
91             $entry_list = array_slice($entry_list, $offset, $limit, true);
92             if (!empty($rel_list)) {
93                 $rel_list = array_slice($entry_list, $offset, $limit, true);
94             }
95
96             $return['entry_list'] = $entry_list;
97             $return['relationship_list'] = $rel_list;
98         }
99
100         return $return;
101     }
102
103
104     /**
105      * get_modified_relationships
106      *
107      * Get a list of the relationship records that have a date_modified value set within a specified date range.  This is used to
108      * help facilitate sync operations.  The module_name should be "Users" and the related_module one of "Meetings", "Calls" and
109      * "Contacts".
110      *
111      * @param xsd:string $session String of the session id
112      * @param xsd:string $module_name String value of the primary module to retrieve relationship against
113      * @param xsd:string $related_module String value of the related module to retrieve records off of
114      * @param xsd:string $from_date String value in YYYY-MM-DD HH:MM:SS format of date_start range (required)
115      * @param xsd:string $to_date String value in YYYY-MM-DD HH:MM:SS format of ending date_start range (required)
116      * @param xsd:int $offset Integer value of the offset to begin returning records from
117      * @param xsd:int $max_results Integer value of the max_results to return; -99 for unlimited
118      * @param xsd:int $deleted Integer value indicating deleted column value search (defaults to 0).  Set to 1 to find deleted records
119      * @param xsd:string $module_user_id String value of the user id (optional, but defaults to SOAP session user id anyway)  The module_user_id value
120      * here ought to be the user id of the user initiating the SOAP session
121      * @param tns:select_fields $select_fields Array value of fields to select and return as name/value pairs
122      * @param xsd:string $relationship_name String value of the relationship name to search on
123      * @param xsd:string $deletion_date String value in YYYY-MM-DD HH:MM:SS format for filtering on deleted records whose date_modified falls within range
124      * this allows deleted records to be returned as well
125      *
126      * @return Array records that match search criteria
127      */
128     function get_modified_relationships($session, $module_name, $related_module, $from_date, $to_date, $offset, $max_results, $deleted=0, $module_user_id = '', $select_fields = array(), $relationship_name = '', $deletion_date = ''){
129         global  $beanList, $beanFiles;
130         $error = new SoapError();
131         $output_list = array();
132
133         if(empty($from_date))
134         {
135             $error->set_error('invalid_call_error, missing from_date');
136             return array('result_count'=>0, 'next_offset'=>0, 'field_list'=>$select_fields, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
137         }
138
139         if(empty($to_date))
140         {
141             $error->set_error('invalid_call_error, missing to_date');
142             return array('result_count'=>0, 'next_offset'=>0, 'field_list'=>$select_fields, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
143         }
144
145         if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error))
146         {
147                 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_modified_relationships');
148                 return;
149         } // if
150
151         if(empty($beanList[$module_name]) || empty($beanList[$related_module]))
152         {
153             $error->set_error('no_module');
154             return array('result_count'=>0, 'next_offset'=>0, 'field_list'=>$select_fields, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
155         }
156
157         global $current_user;
158         if(!self::$helperObject->check_modules_access($current_user, $module_name, 'read') || !self::$helperObject->check_modules_access($current_user, $related_module, 'read')){
159             $error->set_error('no_access');
160             return array('result_count'=>0, 'next_offset'=>0, 'field_list'=>$select_fields, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
161         }
162
163         if($max_results > 0 || $max_results == '-99'){
164             global $sugar_config;
165             $sugar_config['list_max_entries_per_page'] = $max_results;
166         }
167
168         // Cast to integer
169         $deleted = (int)$deleted;
170         $query = "(m1.date_modified > " . db_convert("'".$GLOBALS['db']->quote($from_date)."'", 'datetime'). " AND m1.date_modified <= ". db_convert("'".$GLOBALS['db']->quote($to_date)."'", 'datetime')." AND {0}.deleted = $deleted)";
171         if(isset($deletion_date) && !empty($deletion_date)){
172             $query .= " OR ({0}.date_modified > " . db_convert("'".$GLOBALS['db']->quote($deletion_date)."'", 'datetime'). " AND {0}.date_modified <= ". db_convert("'".$GLOBALS['db']->quote($to_date)."'", 'datetime')." AND {0}.deleted = 1)";
173         }
174
175         if(!empty($module_user_id))
176         {
177             $query .= " AND m2.id = '".$GLOBALS['db']->quote($module_user_id)."'";
178         }
179
180         //if($related_module == 'Meetings' || $related_module == 'Calls' || $related_module = 'Contacts'){
181         $query = string_format($query, array('m1'));
182         //}
183
184         require_once('soap/SoapRelationshipHelper.php');
185         $results = retrieve_modified_relationships($module_name, $related_module, $query, $deleted, $offset, $max_results, $select_fields, $relationship_name);
186
187         $list = $results['result'];
188
189         foreach($list as $value)
190         {
191              $output_list[] = self::$helperObject->array_get_return_value($value, $results['table_name']);
192         }
193
194         $next_offset = $offset + count($output_list);
195
196         return array(
197             'result_count'=> count($output_list),
198             'next_offset' => $next_offset,
199             'entry_list' => $output_list,
200             'error' => $error->get_soap_array()
201         );
202     }
203
204 }