Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ContactSearch.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
47  public static function getContactsByPartialFullName($partialName, $pageSize,
48  $stateMetadataAdapterClassName = null, $autoCompleteOptions = null)
49  {
50  assert('is_string($partialName)');
51  assert('is_int($pageSize)');
52  assert('$stateMetadataAdapterClassName == null || is_string($stateMetadataAdapterClassName)');
53  assert('$autoCompleteOptions == null || is_string($autoCompleteOptions)');
54  $personTableName = Person::getTableName();
55  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Contact');
56  if (!$joinTablesAdapter->isTableInFromTables('person'))
57  {
58  $joinTablesAdapter->addFromTableAndGetAliasName($personTableName, "{$personTableName}_id");
59  }
60  $metadata = array('clauses' => array(), 'structure' => '');
61  if ($stateMetadataAdapterClassName != null)
62  {
63  $stateMetadataAdapter = new $stateMetadataAdapterClassName($metadata);
64  $metadata = $stateMetadataAdapter->getAdaptedDataProviderMetadata();
65  $metadata['structure'] = '(' . $metadata['structure'] . ')';
66  }
67  $where = RedBeanModelDataProvider::makeWhere('Contact', $metadata, $joinTablesAdapter);
68  if ($where != null)
69  {
70  $where .= 'and';
71  }
72  $where .= self::getWherePartForPartialNameSearchByPartialName($partialName);
73  static::handleAutoCompleteOptions($joinTablesAdapter, $where, $autoCompleteOptions);
74  return Contact::getSubset($joinTablesAdapter, null, $pageSize, $where, "person.firstname, person.lastname");
75  }
76 
86  public static function getContactsByPartialFullNameOrAnyEmailAddress($partialNameOrEmailAddress, $pageSize,
87  $stateMetadataAdapterClassName = null,
88  $operatorType = null,
89  $autoCompleteOptions = null)
90  {
91  assert('is_string($partialNameOrEmailAddress)');
92  assert('is_int($pageSize)');
93  assert('$stateMetadataAdapterClassName == null || is_string($stateMetadataAdapterClassName)');
94  assert('$operatorType == null || is_string($operatorType)');
95  assert('$autoCompleteOptions == null || is_string($autoCompleteOptions)');
96  if ($operatorType == null)
97  {
98  $operatorType = 'startsWith';
99  }
100  $metadata = array();
101  $metadata['clauses'] = array(
102  1 => array(
103  'attributeName' => 'primaryEmail',
104  'relatedAttributeName' => 'emailAddress',
105  'operatorType' => $operatorType,
106  'value' => $partialNameOrEmailAddress,
107  ),
108  2 => array(
109  'attributeName' => 'secondaryEmail',
110  'relatedAttributeName' => 'emailAddress',
111  'operatorType' => $operatorType,
112  'value' => $partialNameOrEmailAddress,
113  ),
114  );
115  $metadata['structure'] = '((1 or 2) or partialnamesearch)';
116  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Contact');
117  if ($stateMetadataAdapterClassName != null)
118  {
119  $stateMetadataAdapter = new $stateMetadataAdapterClassName($metadata);
120  $metadata = $stateMetadataAdapter->getAdaptedDataProviderMetadata();
121  }
122  $where = RedBeanModelDataProvider::makeWhere('Contact', $metadata, $joinTablesAdapter);
123  $partialNameWherePart = self::getWherePartForPartialNameSearchByPartialName($partialNameOrEmailAddress);
124  $where = strtr(strtolower($where), array('partialnamesearch' => $partialNameWherePart));
125  static::handleAutoCompleteOptions($joinTablesAdapter, $where, $autoCompleteOptions);
126  return Contact::getSubset($joinTablesAdapter, null, $pageSize, $where, "person.firstname, person.lastname");
127  }
128 
129  protected static function getWherePartForPartialNameSearchByPartialName($partialName)
130  {
131  assert('is_string($partialName)');
132  static::sanitizeSearchTerm($partialName);
133  $fullNameSql = DatabaseCompatibilityUtil::concat(array('person.firstname',
134  '\' \'',
135  'person.lastname'));
136  return " (person.firstname like '$partialName%' or " .
137  " person.lastname like '$partialName%' or " .
138  " $fullNameSql like '$partialName%') ";
139  }
140 
148  public static function getContactsByAnyEmailAddress($emailAddress, $pageSize = null,
149  $stateMetadataAdapterClassName = null, $autoCompleteOptions = null)
150  {
151  assert('is_string($emailAddress)');
152  assert('$pageSize == null || is_int($pageSize)');
153  assert('$stateMetadataAdapterClassName == null || is_string($stateMetadataAdapterClassName)');
154  assert('$autoCompleteOptions == null || is_string($autoCompleteOptions)');
155  $metadata = array();
156  $metadata['clauses'] = array(
157  1 => array(
158  'attributeName' => 'primaryEmail',
159  'relatedAttributeName' => 'emailAddress',
160  'operatorType' => 'equals',
161  'value' => $emailAddress,
162  ),
163  2 => array(
164  'attributeName' => 'secondaryEmail',
165  'relatedAttributeName' => 'emailAddress',
166  'operatorType' => 'equals',
167  'value' => $emailAddress,
168  ),
169  );
170  $metadata['structure'] = '(1 or 2)';
171  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Contact');
172  if ($stateMetadataAdapterClassName != null)
173  {
174  $stateMetadataAdapter = new $stateMetadataAdapterClassName($metadata);
175  $metadata = $stateMetadataAdapter->getAdaptedDataProviderMetadata();
176  }
177  $where = RedBeanModelDataProvider::makeWhere('Contact', $metadata, $joinTablesAdapter);
178  static::handleAutoCompleteOptions($joinTablesAdapter, $where, $autoCompleteOptions);
179  return Contact::getSubset($joinTablesAdapter, null, $pageSize, $where);
180  }
181 
189  public static function getContactsByAnyPhone($phoneNumber, $pageSize = null,
190  $stateMetadataAdapterClassName = null, $autoCompleteOptions = null)
191  {
192  assert('is_string($phoneNumber)');
193  assert('$pageSize == null || is_int($pageSize)');
194  assert('$stateMetadataAdapterClassName == null || is_string($stateMetadataAdapterClassName)');
195  assert('$autoCompleteOptions == null || is_string($autoCompleteOptions)');
196  $metadata = array();
197  $metadata['clauses'] = array(
198  1 => array(
199  'attributeName' => 'mobilePhone',
200  'operatorType' => 'equals',
201  'value' => $phoneNumber,
202  ),
203  2 => array(
204  'attributeName' => 'officePhone',
205  'operatorType' => 'equals',
206  'value' => $phoneNumber,
207  ),
208  );
209  $metadata['structure'] = '(1 or 2)';
210  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Contact');
211  if ($stateMetadataAdapterClassName != null)
212  {
213  $stateMetadataAdapter = new $stateMetadataAdapterClassName($metadata);
214  $metadata = $stateMetadataAdapter->getAdaptedDataProviderMetadata();
215  }
216  $where = RedBeanModelDataProvider::makeWhere('Contact', $metadata, $joinTablesAdapter);
217  static::handleAutoCompleteOptions($joinTablesAdapter, $where, $autoCompleteOptions);
218  return Contact::getSubset($joinTablesAdapter, null, $pageSize, $where);
219  }
220 
230  public static function getContactsByFullName($fullName, $pageSize,
231  $stateMetadataAdapterClassName = null, $autoCompleteOptions = null)
232  {
233  assert('is_string($fullName)');
234  assert('is_int($pageSize)');
235  assert('$stateMetadataAdapterClassName == null || is_string($stateMetadataAdapterClassName)');
236  assert('$autoCompleteOptions == null || is_string($autoCompleteOptions)');
237  $personTableName = Person::getTableName();
238  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Contact');
239  if (!$joinTablesAdapter->isTableInFromTables('person'))
240  {
241  $joinTablesAdapter->addFromTableAndGetAliasName($personTableName, "{$personTableName}_id");
242  }
243  $metadata = array('clauses' => array(), 'structure' => '');
244  if ($stateMetadataAdapterClassName != null)
245  {
246  $stateMetadataAdapter = new $stateMetadataAdapterClassName($metadata);
247  $metadata = $stateMetadataAdapter->getAdaptedDataProviderMetadata();
248  $metadata['structure'] = '(' . $metadata['structure'] . ')';
249  }
250  $where = RedBeanModelDataProvider::makeWhere('Contact', $metadata, $joinTablesAdapter);
251  if ($where != null)
252  {
253  $where .= ' and ';
254  }
255  $where .= self::getWherePartForFullNameSearch($fullName);
256  static::handleAutoCompleteOptions($joinTablesAdapter, $where, $autoCompleteOptions);
257  return Contact::getSubset($joinTablesAdapter, null, $pageSize, $where, "person.firstname, person.lastname");
258  }
259 
265  protected static function getWherePartForFullNameSearch($fullName)
266  {
267  assert('is_string($fullName)');
268  static::sanitizeSearchTerm($fullName);
269  $fullNameSql = DatabaseCompatibilityUtil::concat(array('person.firstname',
270  '\' \'',
271  'person.lastname'));
272  return "$fullNameSql = '$fullName'";
273  }
274  }
275 ?>
static getContactsByFullName($fullName, $pageSize, $stateMetadataAdapterClassName=null, $autoCompleteOptions=null)
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getWherePartForFullNameSearch($fullName)
static getSubset(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $offset=null, $count=null, $where=null, $orderBy=null, $modelClassName=null, $selectDistinct=false)
static getContactsByPartialFullName($partialName, $pageSize, $stateMetadataAdapterClassName=null, $autoCompleteOptions=null)
static getContactsByPartialFullNameOrAnyEmailAddress($partialNameOrEmailAddress, $pageSize, $stateMetadataAdapterClassName=null, $operatorType=null, $autoCompleteOptions=null)
static getContactsByAnyEmailAddress($emailAddress, $pageSize=null, $stateMetadataAdapterClassName=null, $autoCompleteOptions=null)
static getTableName()
static getContactsByAnyPhone($phoneNumber, $pageSize=null, $stateMetadataAdapterClassName=null, $autoCompleteOptions=null)
Generated on Mon Jul 6 2020 07:10:32
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.