3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2020
36 * This implements the profile page for all contacts. It uses a selector
37 * object to do the actual dispay. The fields displayd are controlled by
40 class CRM_Profile_Page_Listings
extends CRM_Core_Page
{
43 * All the fields that are listings related.
50 * The custom fields for this domain.
54 protected $_customFields;
57 * The input params from the request.
64 * The group id that we are editing.
71 * State whether to display search form or not.
78 * Should we display a map.
85 * Store profile ids if multiple profile ids are passed using comma separated.
86 * Currently lets implement this functionality only for dialog mode
89 protected $_profileIds = [];
92 * Extracts the parameters from the request and constructs information for
93 * the selector object to do a query
96 public function preProcess() {
98 $this->_search
= TRUE;
100 $search = CRM_Utils_Request
::retrieve('search', 'Boolean', $this, FALSE, 0, 'GET');
101 if (isset($search) && $search == 0) {
102 $this->_search
= FALSE;
105 $this->_gid
= $this->get('gid');
106 $this->_profileIds
= $this->get('profileIds');
108 $gids = explode(',', CRM_Utils_Request
::retrieve('gid', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
110 if ((count($gids) > 1) && !$this->_profileIds
&& empty($this->_profileIds
)) {
112 foreach ($gids as $pfId) {
113 $this->_profileIds
[] = CRM_Utils_Type
::escape($pfId, 'Positive');
117 // check if we are rendering mixed profiles
118 if (CRM_Core_BAO_UFGroup
::checkForMixProfiles($this->_profileIds
)) {
119 CRM_Core_Error
::fatal(ts('You cannot combine profiles of multiple types.'));
122 $this->_gid
= $this->_profileIds
[0];
123 $this->set('profileIds', $this->_profileIds
);
124 $this->set('gid', $this->_gid
);
128 $this->_gid
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET');
131 if (empty($this->_profileIds
)) {
135 $gids = $this->_profileIds
;
138 $this->_fields
= CRM_Core_BAO_UFGroup
::getListingFields(CRM_Core_Action
::UPDATE
,
139 CRM_Core_BAO_UFGroup
::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup
::LISTINGS_VISIBILITY
,
140 FALSE, $gids, FALSE, 'Profile',
141 CRM_Core_Permission
::SEARCH
144 $this->_customFields
= CRM_Core_BAO_CustomField
::getFieldsForImport(NULL, FALSE, FALSE, FALSE, TRUE, TRUE);
150 'preferred_communication_method',
159 foreach ($this->_fields
as $name => $field) {
160 if ((substr($name, 0, 6) == 'custom') && !empty($field['is_search_range'])) {
161 $from = CRM_Utils_Request
::retrieve($name . '_from', 'String', $this);
162 $to = CRM_Utils_Request
::retrieve($name . '_to', 'String', $this);
165 $value[$name . '_from'] = $from;
166 $value[$name . '_to'] = $to;
169 $value[$name . '_from'] = $from;
172 $value[$name . '_to'] = $to;
175 elseif ((substr($name, 0, 7) == 'custom_') &&
176 (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField',
177 substr($name, 7), 'html_type'
180 $value = trim(CRM_Utils_Request
::retrieve($name, 'String',
181 $this, FALSE, NULL, 'REQUEST'
183 if (!empty($value) &&
184 !((substr($value, 0, 1) == '%') &&
185 (substr($value, -1, 1) == '%')
188 $value = '%' . $value . '%';
191 elseif (CRM_Utils_Array
::value('html_type', $field) == 'Multi-Select State/Province'
192 || CRM_Utils_Array
::value('html_type', $field) == 'Multi-Select Country'
194 $value = CRM_Utils_Request
::retrieve($name, 'String', $this, FALSE, NULL, 'REQUEST');
195 if (!is_array($value)) {
196 $value = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, substr($value, 1, -1));
199 elseif ($name == 'contact_sub_type') {
200 $v = CRM_Utils_Request
::retrieve($name, 'String', $this, FALSE, NULL, 'REQUEST');
201 if ($v && !is_array($v)) {
202 $v = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($v, CRM_Core_DAO
::VALUE_SEPARATOR
));
205 foreach ($v as $item) {
211 $value = CRM_Utils_Request
::retrieve($name, 'String',
212 $this, FALSE, NULL, 'REQUEST'
216 if (($name == 'group' ||
$name == 'tag') && !empty($value) && !is_array($value)) {
217 $v = explode(',', $value);
219 foreach ($v as $item) {
224 $customField = CRM_Utils_Array
::value($name, $this->_customFields
);
226 if (!empty($_POST) && empty($_POST[$name])) {
228 // reset checkbox/radio because a form does not send null checkbox values
229 if (in_array($customField['html_type'],
230 ['Multi-Select', 'CheckBox', 'Multi-Select State/Province', 'Multi-Select Country', 'Radio', 'Select']
232 // only reset on a POST submission if we don't see any value
234 $this->set($name, $value);
237 elseif (in_array($name, $resetArray)) {
239 $this->set($name, $value);
243 if (isset($value) && $value != NULL) {
244 if (!is_array($value)) {
245 $value = trim($value);
247 $operator = CRM_Utils_Request
::retrieve($name . '_operator', 'String', $this);
249 $this->_params
[$name . '_operator'] = $operator;
251 if ((substr($name, 0, 6) == 'custom') && !empty($field['is_search_range'])) {
252 $this->_params +
= $value;
255 $this->_params
[$name] = $this->_fields
[$name]['value'] = $value;
260 // set the prox params
261 // need to ensure proximity searching is enabled
271 foreach ($proximityVars as $var) {
272 $value = CRM_Utils_Request
::retrieve("prox_{$var}",
274 $this, FALSE, NULL, 'REQUEST'
277 $this->_params
["prox_{$var}"] = $value;
281 // set the params in session
282 $session = CRM_Core_Session
::singleton();
283 $session->set('profileParams', $this->_params
);
287 * Run this page (figure out the action needed and perform it).
290 public function run() {
293 $this->assign('recentlyViewed', FALSE);
294 // override later (if possible):
295 $this->assign('ufGroupName', 'unknown');
298 $ufgroupDAO = new CRM_Core_DAO_UFGroup();
299 $ufgroupDAO->id
= $this->_gid
;
300 if (!$ufgroupDAO->find(TRUE)) {
301 CRM_Core_Error
::fatal();
306 // set the title of the page
307 if ($ufgroupDAO->title
) {
308 CRM_Utils_System
::setTitle($ufgroupDAO->title
);
310 if ($ufgroupDAO->name
) {
311 $this->assign('ufGroupName', $ufgroupDAO->name
);
315 $this->assign('isReset', TRUE);
317 $formController = new CRM_Core_Controller_Simple('CRM_Profile_Form_Search',
318 ts('Search Profile'),
321 $formController->setEmbedded(TRUE);
322 $formController->set('gid', $this->_gid
);
323 $formController->process();
325 $searchError = FALSE;
326 // check if there is a POST
327 if (!empty($_POST)) {
328 if ($formController->validate() !== TRUE) {
333 // also get the search tpl name
334 $this->assign('searchTPL', $formController->getHookedTemplateFileName());
336 $this->assign('search', $this->_search
);
338 // search if search returned a form error?
339 if ((empty($_GET['reset']) ||
!empty($_GET['force'])) &&
342 $this->assign('isReset', FALSE);
344 $gidString = $this->_gid
;
345 if (empty($this->_profileIds
)) {
349 $gids = $this->_profileIds
;
350 $gidString = implode(',', $this->_profileIds
);
357 $map = $ufgroupDAO->is_map
;
358 $linkToUF = $ufgroupDAO->is_uf_link
;
359 $editLink = $ufgroupDAO->is_edit_link
;
363 $this->assign('mapURL',
364 CRM_Utils_System
::url('civicrm/profile/map',
365 "map=1&gid={$gidString}&reset=1"
369 if (!empty($this->_params
['group'])) {
370 foreach ($this->_params
['group'] as $key => $val) {
372 unset($this->_params
['group'][$key]);
377 // the selector will override this if the user does have
378 // edit permissions as determined by the mask, CRM-4341
379 // do not allow edit for anon users in joomla frontend, CRM-4668
380 $config = CRM_Core_Config
::singleton();
381 if (!CRM_Core_Permission
::check('access CiviCRM') ||
382 $config->userFrameworkFrontend
== 1
387 $selector = new CRM_Profile_Selector_Listings($this->_params
, $this->_customFields
, $gids,
388 $map, $editLink, $linkToUF
391 $controller = new CRM_Core_Selector_Controller($selector,
392 $this->get(CRM_Utils_Pager
::PAGE_ID
),
393 $this->get(CRM_Utils_Sort
::SORT_ID
),
394 CRM_Core_Action
::VIEW
,
396 CRM_Core_Selector_Controller
::TEMPLATE
398 $controller->setEmbedded(TRUE);
402 //CRM-6862 -run form controller after
403 //selector, since it erase $_POST
404 $formController->run();
406 return parent
::run();
410 * Get the list of contacts for a profile.
416 public static function getProfileContact($gid) {
417 $session = CRM_Core_Session
::singleton();
418 $params = $session->get('profileParams');
421 $ufGroupParam = ['id' => $gid];
422 CRM_Core_BAO_UFGroup
::retrieve($ufGroupParam, $details);
424 // make sure this group can be mapped
425 if (!$details['is_map']) {
426 CRM_Core_Error
::statusBounce(ts('This profile does not have the map feature turned on.'));
429 $groupId = CRM_Utils_Array
::value('limit_listings_group_id', $details);
431 // add group id to params if a uf group belong to a any group
433 if (!empty($params['group'])) {
434 $params['group'][$groupId] = 1;
437 $params['group'] = [$groupId => 1];
441 $fields = CRM_Core_BAO_UFGroup
::getListingFields(
442 CRM_Core_Action
::VIEW
,
443 CRM_Core_BAO_UFGroup
::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup
::LISTINGS_VISIBILITY
,
448 $returnProperties = CRM_Contact_BAO_Contact
::makeHierReturnProperties($fields);
449 $returnProperties['contact_type'] = 1;
450 $returnProperties['sort_name'] = 1;
452 $queryParams = CRM_Contact_BAO_Query
::convertFormValues($params, 1);
453 $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $fields);
455 $additionalWhereClause = 'contact_a.is_deleted = 0';
457 $ids = $query->searchQuery(0, 0, NULL,
460 $additionalWhereClause
463 $contactIds = explode(',', $ids);
469 * @param string $suffix
471 * @return null|string
473 public function checkTemplateFileExists($suffix = '') {
475 $templateFile = "CRM/Profile/Page/{$this->_gid}/Listings.{$suffix}tpl";
476 $template = CRM_Core_Page
::getTemplate();
477 if ($template->template_exists($templateFile)) {
478 return $templateFile;
481 // lets see if we have customized by name
482 $ufGroupName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid
, 'name');
484 $templateFile = "CRM/Profile/Page/{$ufGroupName}/Listings.{$suffix}tpl";
485 if ($template->template_exists($templateFile)) {
486 return $templateFile;
494 * Use the form name to create the tpl file name.
498 public function getTemplateFileName() {
499 $fileName = $this->checkTemplateFileExists();
500 return $fileName ?
$fileName : parent
::getTemplateFileName();
504 * Default extra tpl file basically just replaces .tpl with .extra.tpl
505 * i.e. we dont override
509 public function overrideExtraTemplateFileName() {
510 $fileName = $this->checkTemplateFileExists('extra.');
511 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();