3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
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
88 protected $_profileIds = array();
91 * Extracts the parameters from the request and constructs information for
92 * the selector object to do a query
95 public function preProcess() {
97 $this->_search
= TRUE;
99 $search = CRM_Utils_Request
::retrieve('search', 'Boolean', $this, FALSE, 0, 'GET');
100 if (isset($search) && $search == 0) {
101 $this->_search
= FALSE;
104 $this->_gid
= $this->get('gid');
105 $this->_profileIds
= $this->get('profileIds');
107 $gids = explode(',', CRM_Utils_Request
::retrieve('gid', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
109 if ((count($gids) > 1) && !$this->_profileIds
&& empty($this->_profileIds
)) {
111 foreach ($gids as $pfId) {
112 $this->_profileIds
[] = CRM_Utils_Type
::escape($pfId, 'Positive');
116 // check if we are rendering mixed profiles
117 if (CRM_Core_BAO_UFGroup
::checkForMixProfiles($this->_profileIds
)) {
118 CRM_Core_Error
::fatal(ts('You cannot combine profiles of multiple types.'));
121 $this->_gid
= $this->_profileIds
[0];
122 $this->set('profileIds', $this->_profileIds
);
123 $this->set('gid', $this->_gid
);
127 $this->_gid
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET');
130 if (empty($this->_profileIds
)) {
134 $gids = $this->_profileIds
;
137 $this->_fields
= CRM_Core_BAO_UFGroup
::getListingFields(CRM_Core_Action
::UPDATE
,
138 CRM_Core_BAO_UFGroup
::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup
::LISTINGS_VISIBILITY
,
139 FALSE, $gids, FALSE, 'Profile',
140 CRM_Core_Permission
::SEARCH
143 $this->_customFields
= CRM_Core_BAO_CustomField
::getFieldsForImport(NULL, FALSE, FALSE, FALSE, TRUE, TRUE);
144 $this->_params
= array();
149 'preferred_communication_method',
158 foreach ($this->_fields
as $name => $field) {
159 if ((substr($name, 0, 6) == 'custom') && !empty($field['is_search_range'])) {
160 $from = CRM_Utils_Request
::retrieve($name . '_from', 'String', $this);
161 $to = CRM_Utils_Request
::retrieve($name . '_to', 'String', $this);
164 $value[$name . '_from'] = $from;
165 $value[$name . '_to'] = $to;
168 $value[$name . '_from'] = $from;
171 $value[$name . '_to'] = $to;
174 elseif ((substr($name, 0, 7) == 'custom_') &&
175 (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField',
176 substr($name, 7), 'html_type'
179 $value = trim(CRM_Utils_Request
::retrieve($name, 'String',
180 $this, FALSE, NULL, 'REQUEST'
182 if (!empty($value) &&
183 !((substr($value, 0, 1) == '%') &&
184 (substr($value, -1, 1) == '%')
187 $value = '%' . $value . '%';
190 elseif (CRM_Utils_Array
::value('html_type', $field) == 'Multi-Select State/Province'
191 || CRM_Utils_Array
::value('html_type', $field) == 'Multi-Select Country'
193 $value = CRM_Utils_Request
::retrieve($name, 'String', $this, FALSE, NULL, 'REQUEST');
194 if (!is_array($value)) {
195 $value = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, substr($value, 1, -1));
198 elseif ($name == 'contact_sub_type') {
199 $v = CRM_Utils_Request
::retrieve($name, 'String', $this, FALSE, NULL, 'REQUEST');
200 if ($v && !is_array($v)) {
201 $v = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, trim($v, CRM_Core_DAO
::VALUE_SEPARATOR
));
204 foreach ($v as $item) {
210 $value = CRM_Utils_Request
::retrieve($name, 'String',
211 $this, FALSE, NULL, 'REQUEST'
215 if (($name == 'group' ||
$name == 'tag') && !empty($value) && !is_array($value)) {
216 $v = explode(',', $value);
218 foreach ($v as $item) {
223 $customField = CRM_Utils_Array
::value($name, $this->_customFields
);
225 if (!empty($_POST) && empty($_POST[$name])) {
227 // reset checkbox/radio because a form does not send null checkbox values
228 if (in_array($customField['html_type'],
229 array('Multi-Select', 'CheckBox', 'Multi-Select State/Province', 'Multi-Select Country', 'Radio', 'Select')
231 // only reset on a POST submission if we don't see any value
233 $this->set($name, $value);
236 elseif (in_array($name, $resetArray)) {
238 $this->set($name, $value);
242 if (isset($value) && $value != NULL) {
243 if (!is_array($value)) {
244 $value = trim($value);
246 $operator = CRM_Utils_Request
::retrieve($name . '_operator', 'String', $this);
248 $this->_params
[$name . '_operator'] = $operator;
250 if ((substr($name, 0, 6) == 'custom') && !empty($field['is_search_range'])) {
251 $this->_params +
= $value;
254 $this->_params
[$name] = $this->_fields
[$name]['value'] = $value;
259 // set the prox params
260 // need to ensure proximity searching is enabled
261 $proximityVars = array(
270 foreach ($proximityVars as $var) {
271 $value = CRM_Utils_Request
::retrieve("prox_{$var}",
273 $this, FALSE, NULL, 'REQUEST'
276 $this->_params
["prox_{$var}"] = $value;
280 // set the params in session
281 $session = CRM_Core_Session
::singleton();
282 $session->set('profileParams', $this->_params
);
286 * Run this page (figure out the action needed and perform it).
289 public function run() {
292 $this->assign('recentlyViewed', FALSE);
293 // override later (if possible):
294 $this->assign('ufGroupName', 'unknown');
297 $ufgroupDAO = new CRM_Core_DAO_UFGroup();
298 $ufgroupDAO->id
= $this->_gid
;
299 if (!$ufgroupDAO->find(TRUE)) {
300 CRM_Core_Error
::fatal();
305 // set the title of the page
306 if ($ufgroupDAO->title
) {
307 CRM_Utils_System
::setTitle($ufgroupDAO->title
);
309 if ($ufgroupDAO->name
) {
310 $this->assign('ufGroupName', $ufgroupDAO->name
);
314 $this->assign('isReset', TRUE);
316 $formController = new CRM_Core_Controller_Simple('CRM_Profile_Form_Search',
317 ts('Search Profile'),
320 $formController->setEmbedded(TRUE);
321 $formController->set('gid', $this->_gid
);
322 $formController->process();
324 $searchError = FALSE;
325 // check if there is a POST
326 if (!empty($_POST)) {
327 if ($formController->validate() !== TRUE) {
332 // also get the search tpl name
333 $this->assign('searchTPL', $formController->getHookedTemplateFileName());
335 $this->assign('search', $this->_search
);
337 // search if search returned a form error?
338 if ((empty($_GET['reset']) ||
!empty($_GET['force'])) &&
341 $this->assign('isReset', FALSE);
343 $gidString = $this->_gid
;
344 if (empty($this->_profileIds
)) {
348 $gids = $this->_profileIds
;
349 $gidString = implode(',', $this->_profileIds
);
356 $map = $ufgroupDAO->is_map
;
357 $linkToUF = $ufgroupDAO->is_uf_link
;
358 $editLink = $ufgroupDAO->is_edit_link
;
362 $this->assign('mapURL',
363 CRM_Utils_System
::url('civicrm/profile/map',
364 "map=1&gid={$gidString}&reset=1"
368 if (!empty($this->_params
['group'])) {
369 foreach ($this->_params
['group'] as $key => $val) {
371 unset($this->_params
['group'][$key]);
376 // the selector will override this if the user does have
377 // edit permissions as determined by the mask, CRM-4341
378 // do not allow edit for anon users in joomla frontend, CRM-4668
379 $config = CRM_Core_Config
::singleton();
380 if (!CRM_Core_Permission
::check('access CiviCRM') ||
381 $config->userFrameworkFrontend
== 1
386 $selector = new CRM_Profile_Selector_Listings($this->_params
, $this->_customFields
, $gids,
387 $map, $editLink, $linkToUF
390 $controller = new CRM_Core_Selector_Controller($selector,
391 $this->get(CRM_Utils_Pager
::PAGE_ID
),
392 $this->get(CRM_Utils_Sort
::SORT_ID
),
393 CRM_Core_Action
::VIEW
,
395 CRM_Core_Selector_Controller
::TEMPLATE
397 $controller->setEmbedded(TRUE);
401 //CRM-6862 -run form controller after
402 //selector, since it erase $_POST
403 $formController->run();
405 return parent
::run();
409 * Get the list of contacts for a profile.
415 public static function getProfileContact($gid) {
416 $session = CRM_Core_Session
::singleton();
417 $params = $session->get('profileParams');
420 $ufGroupParam = array('id' => $gid);
421 CRM_Core_BAO_UFGroup
::retrieve($ufGroupParam, $details);
423 // make sure this group can be mapped
424 if (!$details['is_map']) {
425 CRM_Core_Error
::statusBounce(ts('This profile does not have the map feature turned on.'));
428 $groupId = CRM_Utils_Array
::value('limit_listings_group_id', $details);
430 // add group id to params if a uf group belong to a any group
432 if (!empty($params['group'])) {
433 $params['group'][$groupId] = 1;
436 $params['group'] = array($groupId => 1);
440 $fields = CRM_Core_BAO_UFGroup
::getListingFields(
441 CRM_Core_Action
::VIEW
,
442 CRM_Core_BAO_UFGroup
::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup
::LISTINGS_VISIBILITY
,
447 $returnProperties = CRM_Contact_BAO_Contact
::makeHierReturnProperties($fields);
448 $returnProperties['contact_type'] = 1;
449 $returnProperties['sort_name'] = 1;
451 $queryParams = CRM_Contact_BAO_Query
::convertFormValues($params, 1);
452 $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $fields);
454 $additionalWhereClause = 'contact_a.is_deleted = 0';
456 $ids = $query->searchQuery(0, 0, NULL,
459 $additionalWhereClause
462 $contactIds = explode(',', $ids);
468 * @param string $suffix
470 * @return null|string
472 public function checkTemplateFileExists($suffix = '') {
474 $templateFile = "CRM/Profile/Page/{$this->_gid}/Listings.{$suffix}tpl";
475 $template = CRM_Core_Page
::getTemplate();
476 if ($template->template_exists($templateFile)) {
477 return $templateFile;
480 // lets see if we have customized by name
481 $ufGroupName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid
, 'name');
483 $templateFile = "CRM/Profile/Page/{$ufGroupName}/Listings.{$suffix}tpl";
484 if ($template->template_exists($templateFile)) {
485 return $templateFile;
493 * Use the form name to create the tpl file name.
497 public function getTemplateFileName() {
498 $fileName = $this->checkTemplateFileExists();
499 return $fileName ?
$fileName : parent
::getTemplateFileName();
503 * Default extra tpl file basically just replaces .tpl with .extra.tpl
504 * i.e. we dont override
508 public function overrideExtraTemplateFileName() {
509 $fileName = $this->checkTemplateFileExists('extra.');
510 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();