3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
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['from'] = $from;
168 $value['from'] = $from;
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 $this->_params
[$name] = $this->_fields
[$name]['value'] = $value;
254 // set the prox params
255 // need to ensure proximity searching is enabled
256 $proximityVars = array(
265 foreach ($proximityVars as $var) {
266 $value = CRM_Utils_Request
::retrieve("prox_{$var}",
268 $this, FALSE, NULL, 'REQUEST'
271 $this->_params
["prox_{$var}"] = $value;
275 // set the params in session
276 $session = CRM_Core_Session
::singleton();
277 $session->set('profileParams', $this->_params
);
281 * Run this page (figure out the action needed and perform it).
284 public function run() {
287 $this->assign('recentlyViewed', FALSE);
288 // override later (if possible):
289 $this->assign('ufGroupName', 'unknown');
292 $ufgroupDAO = new CRM_Core_DAO_UFGroup();
293 $ufgroupDAO->id
= $this->_gid
;
294 if (!$ufgroupDAO->find(TRUE)) {
295 CRM_Core_Error
::fatal();
300 // set the title of the page
301 if ($ufgroupDAO->title
) {
302 CRM_Utils_System
::setTitle($ufgroupDAO->title
);
304 if ($ufgroupDAO->name
) {
305 $this->assign('ufGroupName', $ufgroupDAO->name
);
309 $this->assign('isReset', TRUE);
311 $formController = new CRM_Core_Controller_Simple('CRM_Profile_Form_Search',
312 ts('Search Profile'),
315 $formController->setEmbedded(TRUE);
316 $formController->set('gid', $this->_gid
);
317 $formController->process();
319 $searchError = FALSE;
320 // check if there is a POST
321 if (!empty($_POST)) {
322 if ($formController->validate() !== TRUE) {
327 // also get the search tpl name
328 $this->assign('searchTPL', $formController->getHookedTemplateFileName());
330 $this->assign('search', $this->_search
);
332 // search if search returned a form error?
333 if ((empty($_GET['reset']) ||
!empty($_GET['force'])) &&
336 $this->assign('isReset', FALSE);
338 $gidString = $this->_gid
;
339 if (empty($this->_profileIds
)) {
343 $gids = $this->_profileIds
;
344 $gidString = implode(',', $this->_profileIds
);
351 $map = $ufgroupDAO->is_map
;
352 $linkToUF = $ufgroupDAO->is_uf_link
;
353 $editLink = $ufgroupDAO->is_edit_link
;
357 $this->assign('mapURL',
358 CRM_Utils_System
::url('civicrm/profile/map',
359 "map=1&gid={$gidString}&reset=1"
363 if (!empty($this->_params
['group'])) {
364 foreach ($this->_params
['group'] as $key => $val) {
366 unset($this->_params
['group'][$key]);
371 // the selector will override this if the user does have
372 // edit permissions as determined by the mask, CRM-4341
373 // do not allow edit for anon users in joomla frontend, CRM-4668
374 $config = CRM_Core_Config
::singleton();
375 if (!CRM_Core_Permission
::check('access CiviCRM') ||
376 $config->userFrameworkFrontend
== 1
381 $selector = new CRM_Profile_Selector_Listings($this->_params
, $this->_customFields
, $gids,
382 $map, $editLink, $linkToUF
385 $controller = new CRM_Core_Selector_Controller($selector,
386 $this->get(CRM_Utils_Pager
::PAGE_ID
),
387 $this->get(CRM_Utils_Sort
::SORT_ID
),
388 CRM_Core_Action
::VIEW
,
390 CRM_Core_Selector_Controller
::TEMPLATE
392 $controller->setEmbedded(TRUE);
396 //CRM-6862 -run form controller after
397 //selector, since it erase $_POST
398 $formController->run();
400 return parent
::run();
404 * Get the list of contacts for a profile.
410 public static function getProfileContact($gid) {
411 $session = CRM_Core_Session
::singleton();
412 $params = $session->get('profileParams');
415 $ufGroupParam = array('id' => $gid);
416 CRM_Core_BAO_UFGroup
::retrieve($ufGroupParam, $details);
418 // make sure this group can be mapped
419 if (!$details['is_map']) {
420 CRM_Core_Error
::statusBounce(ts('This profile does not have the map feature turned on.'));
423 $groupId = CRM_Utils_Array
::value('limit_listings_group_id', $details);
425 // add group id to params if a uf group belong to a any group
427 if (!empty($params['group'])) {
428 $params['group'][$groupId] = 1;
431 $params['group'] = array($groupId => 1);
435 $fields = CRM_Core_BAO_UFGroup
::getListingFields(
436 CRM_Core_Action
::VIEW
,
437 CRM_Core_BAO_UFGroup
::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup
::LISTINGS_VISIBILITY
,
442 $returnProperties = CRM_Contact_BAO_Contact
::makeHierReturnProperties($fields);
443 $returnProperties['contact_type'] = 1;
444 $returnProperties['sort_name'] = 1;
446 $queryParams = CRM_Contact_BAO_Query
::convertFormValues($params, 1);
447 $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $fields);
449 $additionalWhereClause = 'contact_a.is_deleted = 0';
451 $ids = $query->searchQuery(0, 0, NULL,
454 $additionalWhereClause
457 $contactIds = explode(',', $ids);
463 * @param string $suffix
465 * @return null|string
467 public function checkTemplateFileExists($suffix = '') {
469 $templateFile = "CRM/Profile/Page/{$this->_gid}/Listings.{$suffix}tpl";
470 $template = CRM_Core_Page
::getTemplate();
471 if ($template->template_exists($templateFile)) {
472 return $templateFile;
475 // lets see if we have customized by name
476 $ufGroupName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid
, 'name');
478 $templateFile = "CRM/Profile/Page/{$ufGroupName}/Listings.{$suffix}tpl";
479 if ($template->template_exists($templateFile)) {
480 return $templateFile;
488 * Use the form name to create the tpl file name.
492 public function getTemplateFileName() {
493 $fileName = $this->checkTemplateFileExists();
494 return $fileName ?
$fileName : parent
::getTemplateFileName();
498 * Default extra tpl file basically just replaces .tpl with .extra.tpl
499 * i.e. we dont override
503 public function overrideExtraTemplateFileName() {
504 $fileName = $this->checkTemplateFileExists('extra.');
505 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();