Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class is used to retrieve and display a range of | |
38 | * contacts that match the given criteria (specifically for | |
39 | * results of advanced search options. | |
40 | * | |
41 | */ | |
42 | class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CRM_Core_Selector_API { | |
43 | ||
44 | /** | |
45 | * array of supported links, currenly view and edit | |
46 | * | |
47 | * @var array | |
48 | * @static | |
49 | */ | |
50 | static $_links = NULL; | |
51 | ||
52 | /** | |
53 | * we use desc to remind us what that column is, name is used in the tpl | |
54 | * | |
55 | * @var array | |
56 | * @static | |
57 | */ | |
58 | static $_columnHeaders; | |
59 | ||
60 | /** | |
61 | * The sql params we use to get the list of contacts | |
62 | * | |
63 | * @var string | |
64 | * @access protected | |
65 | */ | |
66 | protected $_params; | |
67 | ||
68 | /** | |
69 | * the public visible fields to be shown to the user | |
70 | * | |
71 | * @var array | |
72 | * @access protected | |
73 | */ | |
74 | protected $_fields; | |
75 | ||
76 | /** | |
77 | * the custom fields for this domain | |
78 | * | |
79 | * @var array | |
80 | * @access protected | |
81 | */ | |
82 | protected $_customFields; | |
83 | ||
84 | /** | |
85 | * cache the query object | |
86 | * | |
87 | * @var object | |
88 | * @access protected | |
89 | */ | |
90 | protected $_query; | |
91 | ||
92 | /** | |
93 | * cache the expanded options list if any | |
94 | * | |
95 | * @var object | |
96 | * @access protected | |
97 | */ | |
98 | protected $_options; | |
99 | ||
100 | /** | |
101 | * The group id that we are editing | |
102 | * | |
103 | * @var int | |
104 | */ | |
105 | protected $_gid; | |
106 | ||
107 | /** | |
108 | * Do we enable mapping of users | |
109 | * | |
110 | * @var boolean | |
111 | */ | |
112 | protected $_map; | |
113 | ||
114 | /** | |
115 | * Do we enable edit link | |
116 | * | |
117 | * @var boolean | |
118 | */ | |
119 | protected $_editLink; | |
120 | ||
121 | /** | |
122 | * Should we link to the UF Profile | |
123 | * | |
124 | * @var boolean | |
125 | */ | |
126 | protected $_linkToUF; | |
127 | ||
128 | /** | |
129 | * Store profile ids if multiple profile ids are passed using comma separated. | |
130 | * Currently lets implement this functionality only for dialog mode | |
131 | */ | |
132 | protected $_profileIds = array(); | |
133 | ||
134 | protected $_multiRecordTableName = NULL; | |
135 | /** | |
136 | * Class constructor | |
137 | * | |
138 | * @param string params the params for the where clause | |
139 | * | |
140 | * @return CRM_Contact_Selector_Profile | |
141 | * @access public | |
142 | */ | |
143 | function __construct( | |
144 | &$params, | |
145 | &$customFields, | |
146 | $ufGroupIds = NULL, | |
147 | $map = FALSE, | |
148 | $editLink = FALSE, | |
149 | $linkToUF = FALSE | |
150 | ) { | |
151 | $this->_params = $params; | |
152 | ||
153 | if (is_array($ufGroupIds)) { | |
154 | $this->_profileIds = $ufGroupIds; | |
155 | $this->_gid = $ufGroupIds[0]; | |
156 | } | |
157 | else { | |
158 | $this->_profileIds = array($ufGroupIds); | |
159 | $this->_gid = $ufGroupIds; | |
160 | } | |
161 | ||
162 | $this->_map = $map; | |
163 | $this->_editLink = $editLink; | |
164 | $this->_linkToUF = $linkToUF; | |
165 | ||
166 | //get the details of the uf group | |
167 | if ($this->_gid) { | |
168 | $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_UFGroup', | |
169 | $this->_gid, 'limit_listings_group_id' | |
170 | ); | |
171 | } | |
172 | ||
173 | // add group id to params if a uf group belong to a any group | |
174 | if ($groupId) { | |
175 | if (CRM_Utils_Array::value('group', $this->_params)) { | |
176 | $this->_params['group'][$groupId] = 1; | |
177 | } | |
178 | else { | |
179 | $this->_params['group'] = array($groupId => 1); | |
180 | } | |
181 | } | |
182 | ||
183 | $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::VIEW, | |
184 | CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | | |
185 | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, | |
186 | FALSE, $this->_profileIds | |
187 | ); | |
188 | ||
189 | $this->_customFields = &$customFields; | |
190 | ||
191 | $returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($this->_fields); | |
192 | $returnProperties['contact_type'] = 1; | |
193 | $returnProperties['contact_sub_type'] = 1; | |
194 | $returnProperties['sort_name'] = 1; | |
195 | ||
196 | $queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_params, 1); | |
197 | $this->_query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $this->_fields); | |
198 | ||
199 | //the below is done for query building for multirecord custom field listing | |
200 | //to show all the custom field multi valued records of a particular contact | |
201 | $this->setMultiRecordTableName($this->_fields); | |
202 | ||
203 | $this->_options = &$this->_query->_options; | |
204 | } | |
205 | //end of constructor | |
206 | ||
207 | /** | |
208 | * This method returns the links that are given for each search row. | |
209 | * | |
210 | * @return array | |
211 | * @access public | |
212 | * | |
213 | */ | |
214 | static function &links($map = FALSE, $editLink = FALSE, $ufLink = FALSE, $gids = NULL) { | |
215 | if (!self::$_links) { | |
216 | self::$_links = array(); | |
217 | ||
218 | $viewPermission = TRUE; | |
219 | if ($gids) { | |
220 | // check view permission for each profile id, in case multiple profile ids are rendered | |
221 | // then view action is disabled if any profile returns false | |
222 | foreach ($gids as $profileId) { | |
223 | $viewPermission = CRM_Core_Permission::ufGroupValid($profileId, CRM_Core_Permission::VIEW); | |
224 | if (!$viewPermission) { | |
225 | break; | |
226 | } | |
227 | } | |
228 | } | |
229 | ||
230 | if ($viewPermission) { | |
231 | self::$_links[CRM_Core_Action::VIEW] = array( | |
232 | 'name' => ts('View'), | |
233 | 'url' => 'civicrm/profile/view', | |
234 | 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%', | |
235 | 'title' => ts('View Profile Details'), | |
236 | ); | |
237 | } | |
238 | ||
239 | if ($editLink) { | |
240 | self::$_links[CRM_Core_Action::UPDATE] = array( | |
241 | 'name' => ts('Edit'), | |
242 | 'url' => 'civicrm/profile/edit', | |
243 | 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%', | |
244 | 'title' => ts('Edit'), | |
245 | ); | |
246 | } | |
247 | ||
248 | if ($ufLink) { | |
249 | self::$_links[CRM_Core_Action::PROFILE] = array( | |
250 | 'name' => ts('Website Profile'), | |
251 | 'url' => 'user/%%ufID%%', | |
252 | 'qs' => ' ', | |
253 | 'title' => ts('View Website Profile'), | |
254 | ); | |
255 | } | |
256 | ||
257 | if ($map) { | |
258 | self::$_links[CRM_Core_Action::MAP] = array( | |
259 | 'name' => ts('Map'), | |
260 | 'url' => 'civicrm/profile/map', | |
261 | 'qs' => 'reset=1&cid=%%id%%&gid=%%gid%%', | |
262 | 'title' => ts('Map'), | |
263 | ); | |
264 | } | |
265 | } | |
266 | return self::$_links; | |
267 | } | |
268 | //end of function | |
269 | ||
270 | /** | |
271 | * getter for array of the parameters required for creating pager. | |
272 | * | |
273 | * @param | |
274 | * @access public | |
275 | */ | |
276 | function getPagerParams($action, &$params) { | |
277 | $status = | |
278 | CRM_Utils_System::isNull($this->_multiRecordTableName) ? ts('Contact %%StatusMessage%%') : ts('Contact Multi Records %%StatusMessage%%'); | |
279 | $params['status'] = $status; | |
280 | $params['csvString'] = NULL; | |
281 | $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; | |
282 | ||
283 | $params['buttonTop'] = 'PagerTopButton'; | |
284 | $params['buttonBottom'] = 'PagerBottomButton'; | |
285 | } | |
286 | //end of function | |
287 | ||
288 | /** | |
289 | * returns the column headers as an array of tuples: | |
290 | * (name, sortName (key to the sort array)) | |
291 | * | |
292 | * @param string $action the action being performed | |
293 | * @param enum $output what should the result set include (web/email/csv) | |
294 | * | |
295 | * @return array the column headers that need to be displayed | |
296 | * @access public | |
297 | */ | |
298 | function &getColumnHeaders($action = NULL, $output = NULL) { | |
299 | static $skipFields = array('group', 'tag'); | |
300 | $multipleFields = array('url'); | |
301 | $direction = CRM_Utils_Sort::ASCENDING; | |
302 | $empty = TRUE; | |
303 | if (!isset(self::$_columnHeaders)) { | |
304 | self::$_columnHeaders = array(array('name' => ''), | |
305 | array( | |
306 | 'name' => ts('Name'), | |
307 | 'sort' => 'sort_name', | |
308 | 'direction' => CRM_Utils_Sort::ASCENDING, | |
ae94c3e3 | 309 | 'field_name' => 'sort_name', |
6a488035 TO |
310 | ), |
311 | ); | |
312 | ||
b2b0530a | 313 | $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); |
6a488035 TO |
314 | |
315 | foreach ($this->_fields as $name => $field) { | |
316 | // skip pseudo fields | |
317 | if (substr($name, 0, 9) == 'phone_ext') { | |
318 | continue; | |
319 | } | |
320 | ||
321 | if (CRM_Utils_Array::value('in_selector', $field) && | |
322 | !in_array($name, $skipFields) | |
323 | ) { | |
324 | ||
325 | if (strpos($name, '-') !== FALSE) { | |
326 | $value = explode('-', $name); | |
327 | $fieldName = CRM_Utils_Array::value(0, $value); | |
328 | $lType = CRM_Utils_Array::value(1, $value); | |
329 | $type = CRM_Utils_Array::value(2, $value); | |
330 | ||
331 | if (!in_array($fieldName, $multipleFields)) { | |
332 | if ($lType == 'Primary') { | |
333 | $locationTypeName = 1; | |
334 | } | |
335 | else { | |
336 | $locationTypeName = $locationTypes[$lType]; | |
337 | } | |
338 | ||
339 | if (in_array($fieldName, array( | |
340 | 'phone', 'im', 'email'))) { | |
341 | if ($type) { | |
342 | $name = "`$locationTypeName-$fieldName-$type`"; | |
343 | } | |
344 | else { | |
345 | $name = "`$locationTypeName-$fieldName`"; | |
346 | } | |
347 | } | |
348 | else { | |
349 | $name = "`$locationTypeName-$fieldName`"; | |
350 | } | |
351 | } | |
352 | else { | |
353 | $name = "website-{$lType}-{$fieldName}"; | |
354 | } | |
355 | } | |
356 | ||
357 | self::$_columnHeaders[] = array( | |
358 | 'name' => $field['title'], | |
359 | 'sort' => $name, | |
360 | 'direction' => $direction, | |
ae94c3e3 | 361 | 'field_name' => CRM_Core_BAO_UFField::isValidFieldName($name) ? $name : $fieldName, |
6a488035 TO |
362 | ); |
363 | ||
364 | $direction = CRM_Utils_Sort::DONTCARE; | |
365 | $empty = FALSE; | |
366 | } | |
367 | } | |
368 | ||
369 | // if we dont have any valid columns, dont add the implicit ones | |
370 | // this allows the template to check on emptiness of column headers | |
371 | if ($empty) { | |
372 | self::$_columnHeaders = array(); | |
373 | } | |
374 | else { | |
375 | self::$_columnHeaders[] = array('desc' => ts('Actions')); | |
376 | } | |
377 | } | |
378 | return self::$_columnHeaders; | |
379 | } | |
380 | ||
381 | /** | |
382 | * Returns total number of rows for the query. | |
383 | * | |
384 | * @param | |
385 | * | |
386 | * @return int Total number of rows | |
387 | * @access public | |
388 | */ | |
389 | function getTotalCount($action) { | |
390 | $additionalWhereClause = 'contact_a.is_deleted = 0'; | |
391 | $additionalFromClause = NULL; | |
392 | $returnQuery = NULL; | |
393 | ||
394 | if ($this->_multiRecordTableName && | |
395 | !array_key_exists($this->_multiRecordTableName, $this->_query->_whereTables)) { | |
396 | $additionalFromClause = CRM_Utils_Array::value($this->_multiRecordTableName, $this->_query->_tables); | |
397 | $returnQuery = TRUE; | |
398 | } | |
399 | ||
400 | $countVal = $this->_query->searchQuery(0, 0, NULL, TRUE, NULL, NULL, NULL, | |
401 | $returnQuery, $additionalWhereClause, NULL, $additionalFromClause | |
402 | ); | |
403 | ||
404 | if (!$returnQuery) { | |
405 | return $countVal; | |
406 | } | |
407 | ||
408 | if ($returnQuery) { | |
409 | $sql = preg_replace('/DISTINCT/', '', $countVal); | |
410 | return CRM_Core_DAO::singleValueQuery($sql); | |
411 | } | |
412 | } | |
413 | ||
414 | /** | |
415 | * Return the qill for this selector | |
416 | * | |
417 | * @return string | |
418 | * @access public | |
419 | */ | |
420 | function getQill() { | |
421 | return $this->_query->qill(); | |
422 | } | |
423 | ||
424 | /** | |
425 | * returns all the rows in the given offset and rowCount | |
426 | * | |
427 | * @param enum $action the action being performed | |
428 | * @param int $offset the row number to start from | |
429 | * @param int $rowCount the number of rows to return | |
430 | * @param string $sort the sql string that describes the sort order | |
431 | * @param enum $output what should the result set include (web/email/csv) | |
432 | * | |
433 | * @return int the total number of rows for this action | |
434 | */ | |
435 | function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { | |
436 | ||
437 | $multipleFields = array('url'); | |
438 | //$sort object processing for location fields | |
439 | if ($sort) { | |
440 | $vars = $sort->_vars; | |
441 | $varArray = array(); | |
442 | foreach ($vars as $key => $field) { | |
443 | $field = $vars[$key]; | |
444 | $fieldArray = explode('-', $field['name']); | |
445 | $fieldType = CRM_Utils_Array::value('2', $fieldArray); | |
446 | if (is_numeric(CRM_Utils_Array::value('1', $fieldArray))) { | |
447 | if (!in_array($fieldType, $multipleFields)) { | |
448 | $locationType = new CRM_Core_DAO_LocationType(); | |
449 | $locationType->id = $fieldArray[1]; | |
450 | $locationType->find(TRUE); | |
451 | if ($fieldArray[0] == 'email' || $fieldArray[0] == 'im' || $fieldArray[0] == 'phone') { | |
452 | $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "-1`"; | |
453 | } | |
454 | else { | |
455 | $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "`"; | |
456 | } | |
457 | } | |
458 | else { | |
459 | $field['name'] = "`website-" . $fieldArray[1] . "-{$fieldType}`"; | |
460 | } | |
461 | } | |
462 | $varArray[$key] = $field; | |
463 | } | |
464 | } | |
465 | ||
466 | $sort->_vars = $varArray; | |
467 | ||
468 | $additionalWhereClause = 'contact_a.is_deleted = 0'; | |
469 | $returnQuery = NULL; | |
470 | if ($this->_multiRecordTableName) { | |
471 | $returnQuery = TRUE; | |
472 | } | |
473 | ||
474 | $result = $this->_query->searchQuery($offset, $rowCount, $sort, NULL, NULL, | |
475 | NULL, NULL, $returnQuery, $additionalWhereClause | |
476 | ); | |
477 | ||
478 | if ($returnQuery) { | |
479 | $resQuery = preg_replace('/GROUP BY contact_a.id[\s]+ORDER BY/', ' ORDER BY', $result); | |
480 | $result = CRM_Core_DAO::executeQuery($resQuery); | |
481 | } | |
482 | ||
483 | // process the result of the query | |
484 | $rows = array(); | |
485 | ||
486 | // check if edit is configured in profile settings | |
487 | if ($this->_gid) { | |
488 | $editLink = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_edit_link'); | |
489 | } | |
490 | ||
491 | //FIXME : make sure to handle delete separately. CRM-4418 | |
492 | $mask = CRM_Core_Action::mask(array(CRM_Core_Permission::getPermission())); | |
493 | if ($editLink && ($mask & CRM_Core_Permission::EDIT)) { | |
494 | // do not allow edit for anon users in joomla frontend, CRM-4668 | |
495 | $config = CRM_Core_Config::singleton(); | |
496 | if (!$config->userFrameworkFrontend) { | |
497 | $this->_editLink = TRUE; | |
498 | } | |
499 | } | |
500 | $links = self::links($this->_map, $this->_editLink, $this->_linkToUF, $this->_profileIds); | |
501 | ||
b2b0530a | 502 | $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); |
6a488035 TO |
503 | |
504 | $names = array(); | |
505 | static $skipFields = array('group', 'tag'); | |
506 | ||
507 | foreach ($this->_fields as $key => $field) { | |
508 | // skip pseudo fields | |
509 | if (substr($key, 0, 9) == 'phone_ext') { | |
510 | continue; | |
511 | } | |
512 | ||
513 | if (CRM_Utils_Array::value('in_selector', $field) && | |
514 | !in_array($key, $skipFields) | |
515 | ) { | |
516 | if (strpos($key, '-') !== FALSE) { | |
517 | $value = explode('-', $key); | |
518 | $fieldName = CRM_Utils_Array::value(0, $value); | |
519 | $id = CRM_Utils_Array::value(1, $value); | |
520 | $type = CRM_Utils_Array::value(2, $value); | |
521 | ||
522 | if (!in_array($fieldName, $multipleFields)) { | |
523 | $locationTypeName = NULL; | |
524 | if (is_numeric($id)) { | |
525 | $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); | |
526 | } | |
527 | else { | |
528 | if ($id == 'Primary') { | |
529 | $locationTypeName = 1; | |
530 | } | |
531 | } | |
532 | ||
533 | if (!$locationTypeName) { | |
534 | continue; | |
535 | } | |
536 | $locationTypeName = str_replace(' ', '_', $locationTypeName); | |
537 | if (in_array($fieldName, array( | |
538 | 'phone', 'im', 'email'))) { | |
539 | if ($type) { | |
540 | $names[] = "{$locationTypeName}-{$fieldName}-{$type}"; | |
541 | } | |
542 | else { | |
543 | $names[] = "{$locationTypeName}-{$fieldName}"; | |
544 | } | |
545 | } | |
546 | else { | |
547 | $names[] = "{$locationTypeName}-{$fieldName}"; | |
548 | } | |
549 | } | |
550 | else { | |
551 | $names[] = "website-{$id}-{$fieldName}"; | |
552 | } | |
553 | } | |
554 | elseif ($field['name'] == 'id') { | |
555 | $names[] = 'contact_id'; | |
556 | } | |
557 | else { | |
558 | $names[] = $field['name']; | |
559 | } | |
560 | } | |
561 | } | |
562 | ||
563 | ||
564 | $multipleSelectFields = array('preferred_communication_method' => 1); | |
565 | $multiRecordTableId = NULL; | |
566 | if ($this->_multiRecordTableName) { | |
567 | $multiRecordTableId = "{$this->_multiRecordTableName}_id"; | |
568 | } | |
569 | ||
570 | // we need to determine of overlay profile should be shown | |
571 | $showProfileOverlay = CRM_Core_BAO_UFGroup::showOverlayProfile(); | |
572 | ||
6a488035 TO |
573 | while ($result->fetch()) { |
574 | if (isset($result->country)) { | |
575 | // the query returns the untranslated country name | |
576 | $i18n = CRM_Core_I18n::singleton(); | |
577 | $result->country = $i18n->translate($result->country); | |
578 | } | |
579 | $row = array(); | |
580 | $empty = TRUE; | |
581 | $row[] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? | |
582 | $result->contact_sub_type : $result->contact_type, | |
583 | FALSE, | |
584 | $result->contact_id, | |
585 | $showProfileOverlay | |
586 | ); | |
587 | if ($result->sort_name) { | |
ae94c3e3 | 588 | $row[] = $result->sort_name; |
6a488035 TO |
589 | $empty = FALSE; |
590 | } | |
591 | else { | |
592 | continue; | |
593 | } | |
594 | ||
595 | foreach ($names as $name) { | |
596 | if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { | |
597 | $row[] = CRM_Core_BAO_CustomField::getDisplayValue($result->$name, | |
598 | $cfID, | |
599 | $this->_options, | |
600 | $result->contact_id | |
601 | ); | |
602 | } | |
603 | elseif (substr($name, -4) == '-url' && | |
604 | !empty($result->$name) | |
605 | ) { | |
606 | $url = CRM_Utils_System::fixURL($result->$name); | |
607 | $typeId = substr($name, 0, -4) . "-website_type_id"; | |
c0c9cd82 | 608 | $typeName = CRM_Core_PseudoConstant::getValue('CRM_Core_DAO_Website', 'website_type_id', $result->$typeId); |
6a488035 TO |
609 | if ($typeName) { |
610 | $row[] = "<a href=\"$url\">{$result->$name} (${typeName})</a>"; | |
611 | } | |
612 | else { | |
613 | $row[] = "<a href=\"$url\">{$result->$name}</a>"; | |
614 | } | |
615 | } | |
616 | elseif ($name == 'preferred_language') { | |
c0c9cd82 | 617 | $row[] = CRM_Core_PseudoConstant::getValue('CRM_Contact_DAO_Contact', 'preferred_language', $result->$name); |
6a488035 TO |
618 | } |
619 | elseif ($multipleSelectFields && | |
620 | array_key_exists($name, $multipleSelectFields) | |
621 | ) { | |
622 | // FIXME: Code related to the old CRM_Quest - should be removed | |
623 | $key = $name; | |
624 | $paramsNew = array($key => $result->$name); | |
625 | if ($key == 'test_tutoring') { | |
626 | $name = array($key => array('newName' => $key, 'groupName' => 'test')); | |
627 | // for readers group | |
628 | } | |
629 | elseif (substr($key, 0, 4) == 'cmr_') { | |
630 | $name = array( | |
631 | $key => array('newName' => $key, | |
632 | 'groupName' => substr($key, 0, -3), | |
633 | )); | |
634 | } | |
635 | else { | |
636 | $name = array($key => array('newName' => $key, 'groupName' => $key)); | |
637 | } | |
638 | CRM_Core_OptionGroup::lookupValues($paramsNew, $name, FALSE); | |
639 | $row[] = $paramsNew[$key]; | |
640 | } | |
641 | elseif (strpos($name, '-im')) { | |
642 | if (!empty($result->$name)) { | |
643 | $providerId = $name . "-provider_id"; | |
c0c9cd82 | 644 | $providerName = CRM_Core_PseudoConstant::getValue('CRM_Core_DAO_IM', 'provider_id', $result->$providerId); |
6a488035 TO |
645 | $row[] = $result->$name . " ({$providerName})"; |
646 | } | |
647 | else { | |
648 | $row[] = ''; | |
649 | } | |
650 | } | |
651 | elseif (strpos($name, '-phone-')) { | |
652 | $phoneExtField = str_replace('phone', 'phone_ext', $name); | |
653 | if (isset($result->$phoneExtField)) { | |
654 | $row[] = $result->$name . " (" . $result->$phoneExtField . ")"; | |
655 | } | |
656 | else { | |
657 | $row[] = $result->$name; | |
658 | } | |
659 | } | |
660 | elseif (in_array($name, array( | |
661 | 'addressee', 'email_greeting', 'postal_greeting'))) { | |
662 | $dname = $name . '_display'; | |
663 | $row[] = $result->$dname; | |
664 | } | |
665 | elseif (in_array($name, array( | |
666 | 'birth_date', 'deceased_date'))) { | |
667 | $row[] = CRM_Utils_Date::customFormat($result->$name); | |
668 | } | |
669 | elseif (isset($result->$name)) { | |
670 | $row[] = $result->$name; | |
671 | } | |
672 | else { | |
673 | $row[] = ''; | |
674 | } | |
675 | ||
676 | if (!empty($result->$name)) { | |
677 | $empty = FALSE; | |
678 | } | |
679 | } | |
680 | ||
681 | $newLinks = $links; | |
682 | $params = array( | |
683 | 'id' => $result->contact_id, | |
684 | 'gid' => implode(',', $this->_profileIds), | |
685 | ); | |
686 | ||
687 | // pass record id param to view url for multi record view | |
688 | if ($multiRecordTableId && $newLinks) { | |
689 | if ($result->$multiRecordTableId){ | |
690 | if ($newLinks[CRM_Core_Action::VIEW]['url'] == 'civicrm/profile/view') { | |
691 | $newLinks[CRM_Core_Action::VIEW]['qs'] .= "&multiRecord=view&recordId=%%recordId%%&allFields=1"; | |
692 | $params['recordId'] = $result->$multiRecordTableId; | |
693 | } | |
694 | } | |
695 | } | |
696 | ||
697 | if ($this->_linkToUF) { | |
698 | $ufID = CRM_Core_BAO_UFMatch::getUFId($result->contact_id); | |
699 | if (!$ufID) { | |
700 | unset($newLinks[CRM_Core_Action::PROFILE]); | |
701 | } | |
702 | else { | |
703 | $params['ufID'] = $ufID; | |
704 | } | |
705 | } | |
706 | ||
707 | $row[] = CRM_Core_Action::formLink($newLinks, | |
708 | $mask, | |
709 | $params | |
710 | ); | |
711 | ||
712 | if (!$empty) { | |
713 | $rows[] = $row; | |
714 | } | |
715 | } | |
716 | return $rows; | |
717 | } | |
718 | ||
719 | /** | |
720 | * name of export file. | |
721 | * | |
722 | * @param string $output type of output | |
723 | * | |
724 | * @return string name of the file | |
725 | */ | |
726 | function getExportFileName($output = 'csv') { | |
727 | return ts('CiviCRM Profile Listings'); | |
728 | } | |
729 | ||
730 | /** | |
731 | * set the _multiRecordTableName to display the result set | |
732 | * according to multi record custom field values | |
733 | */ | |
734 | function setMultiRecordTableName($fields) { | |
735 | $customGroupId = $multiRecordTableName = NULL; | |
736 | $selectorSet = FALSE; | |
737 | ||
738 | foreach ($fields as $field => $properties) { | |
739 | if (!CRM_Core_BAO_CustomField::getKeyID($field)) { | |
740 | continue; | |
741 | } | |
742 | if ($cgId = CRM_Core_BAO_CustomField::isMultiRecordField($field)) { | |
743 | $customGroupId = CRM_Utils_System::isNull($customGroupId) ? $cgId : $customGroupId; | |
744 | ||
745 | //if the field is submitted set multiRecordTableName | |
746 | if ($customGroupId) { | |
747 | $isSubmitted = FALSE; | |
748 | foreach ($this->_query->_params as $key => $value) { | |
749 | //check the query params 'where' element | |
750 | if ($value[0] == $field) { | |
751 | $isSubmitted = TRUE; | |
752 | break; | |
753 | } | |
754 | } | |
755 | ||
756 | if ($isSubmitted) { | |
757 | $this->_multiRecordTableName = $multiRecordTableName = | |
758 | CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'table_name'); | |
759 | if ($multiRecordTableName) { | |
760 | return; | |
761 | } | |
762 | } | |
763 | ||
764 | if (CRM_Utils_Array::value('in_selector', $properties)) { | |
765 | $selectorSet = TRUE; | |
766 | } | |
767 | } | |
768 | } | |
769 | } | |
770 | ||
771 | if (!isset($customGroupId) || !$customGroupId) { | |
772 | return; | |
773 | } | |
774 | ||
775 | //if the field is in selector and not a searchable field | |
776 | //get the proper customvalue table name | |
777 | if ($selectorSet) { | |
778 | $this->_multiRecordTableName = $multiRecordTableName = | |
779 | CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'table_name'); | |
780 | } | |
781 | } //func close | |
782 | } | |
783 | //end of class | |
784 |