]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - service/v4_1/SugarWebServiceImplv4_1.php
Release 6.4.1
[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 been modified within a specified date range.  This is used to
108      * help facilitate sync operations.
109      *
110      * @param xsd:string $session String of the session id
111      * @param xsd:string $module_name String value of the primary module to retrieve relationship against
112      * @param xsd:string $related_module String value of the related module to retrieve records off of
113      * @param xsd:string $from_date String value in YYYY-MM-DD HH:MM:SS format of starting date modified range
114      * @param xsd:string $to_date String value in YYYY-MM-DD HH:MM:SS format of ending date modified range
115      * @param xsd:int $offset Integer value of the offset to begin returning records from
116      * @param xsd:int $max_results Integer value of the max_results to return; -99 for unlimited
117      * @param xsd:int $deleted Integer value indicating deleted column value search (defaults to 0).  Set to 1 to find deleted records
118      * @param xsd:string $module_user_id String value of the user id to filter by (optional, no filtering by default)
119      * @param tns:select_fields $select_fields Array value of fields to select and return as name/value pairs
120      * @param xsd:string $relationship_name String value of the relationship name to search on
121      * @param xsd:string $deletion_date String value in YYYY-MM-DD HH:MM:SS format for filtering on deleted records
122      * this allows deleted records to be returned as well
123      *
124      * @return Array records that match search criteria
125      */
126     function get_modified_relationships($session, $module_name, $related_module, $from_date, $to_date, $offset, $max_results, $deleted, $module_user_id = '', $select_fields = array(), $relationship_name = '', $deletion_date = ''){
127         global  $beanList, $beanFiles;
128         $error = new SoapError();
129         $output_list = array();
130
131         if (!self::$helperObject->checkSessionAndModuleAccess($session, 'invalid_session', $module_name, 'read', 'no_access', $error)) {
132                 $GLOBALS['log']->info('End: SugarWebServiceImpl->get_modified_relationships');
133                 return;
134         } // if
135
136         if(empty($beanList[$module_name]) || empty($beanList[$related_module])){
137             $error->set_error('no_module');
138             return array('result_count'=>0, 'next_offset'=>0, 'field_list'=>$select_fields, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
139         }
140         global $current_user;
141         if(!self::$helperObject->check_modules_access($current_user, $module_name, 'read') || !self::$helperObject->check_modules_access($current_user, $related_module, 'read')){
142             $error->set_error('no_access');
143             return array('result_count'=>0, 'next_offset'=>0, 'field_list'=>$select_fields, 'entry_list'=>array(), 'error'=>$error->get_soap_array());
144         }
145
146         if($max_results > 0 || $max_results == '-99'){
147             global $sugar_config;
148             $sugar_config['list_max_entries_per_page'] = $max_results;
149         }
150
151         // Cast to integer
152         $deleted = (int)$deleted;
153         $date_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)";
154         if(isset($deletion_date) && !empty($deletion_date)){
155             $date_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)";
156         }
157
158         $in = '';
159         $ids = array(); //we do not support this right now
160         if(isset($ids) && !empty($ids))
161         {
162             foreach($ids as $value)
163             {
164                $in .= ",'" . $GLOBALS['db']->quote($value) . "'";
165             }
166             $in = '('. substr($in, 1) . ')';
167         }
168         $query = '';
169         if(isset($in) && !empty($in)){
170             $query .= "( $date_query AND m1.id IN $in) OR (m1.id NOT IN $in AND {0}.deleted = 0)";
171         } else {
172             $query .= "( {0}.deleted = 0)";
173         }
174
175         if(!empty($module_user_id))
176         {
177             $query .= " AND";
178             $query .= " m2.id = '".$GLOBALS['db']->quote($module_user_id)."'";
179         }
180
181         if($related_module == 'Meetings' || $related_module == 'Calls' || $related_module = 'Contacts'){
182             $query = string_format($query, array('m1'));
183         }
184
185         require_once('soap/SoapRelationshipHelper.php');
186         $results = retrieve_modified_relationships($module_name, $related_module, $query, $deleted, $offset, $max_results, $select_fields, $relationship_name);
187
188         $list = $results['result'];
189
190         foreach($list as $value)
191         {
192              $output_list[] = self::$helperObject->array_get_return_value($value, $results['table_name']);
193         }
194
195         $next_offset = $offset + count($output_list);
196
197         return array(
198             'result_count'=> count($output_list),
199             'next_offset' => $next_offset,
200             'entry_list' => $output_list,
201             'error' => $error->get_soap_array()
202         );
203     }
204
205 }