-
-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25504 from eileenmcnaughton/cust_ex
dev/core#4112 Separate code to handle exporting legacy custom searches into the extension
- Loading branch information
Showing
4 changed files
with
80 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
ext/legacycustomsearches/CRM/Contact/Form/Search/Action/Export.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC https://civicrm.org/licensing | ||
*/ | ||
class CRM_Contact_Form_Search_Action_Export extends CRM_Core_Form_Task { | ||
|
||
public function preProcess(): void { | ||
$this->preventAjaxSubmit(); | ||
self::exportCustom($this->get('customSearchClass'), | ||
$this->get('formValues'), | ||
$this->get(CRM_Utils_Sort::SORT_ORDER) | ||
); | ||
} | ||
|
||
/** | ||
* @param $customSearchClass | ||
* @param $formValues | ||
* @param $order | ||
*/ | ||
public static function exportCustom($customSearchClass, $formValues, $order) { | ||
$ext = CRM_Extension_System::singleton()->getMapper(); | ||
if (!$ext->isExtensionClass($customSearchClass)) { | ||
require_once str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php'; | ||
} | ||
else { | ||
require_once $ext->classToPath($customSearchClass); | ||
} | ||
$search = new $customSearchClass($formValues); | ||
|
||
$includeContactIDs = FALSE; | ||
if ($formValues['radio_ts'] == 'ts_sel') { | ||
$includeContactIDs = TRUE; | ||
} | ||
|
||
$sql = $search->all(0, 0, $order, $includeContactIDs); | ||
|
||
$columns = $search->columns(); | ||
|
||
$header = array_keys($columns); | ||
$fields = array_values($columns); | ||
|
||
$rows = []; | ||
$dao = CRM_Core_DAO::executeQuery($sql); | ||
$alterRow = FALSE; | ||
if (method_exists($search, 'alterRow')) { | ||
$alterRow = TRUE; | ||
} | ||
while ($dao->fetch()) { | ||
$row = []; | ||
|
||
foreach ($fields as $field) { | ||
$unqualified_field = CRM_Utils_Array::First(array_slice(explode('.', $field), -1)); | ||
$row[$field] = $dao->$unqualified_field; | ||
} | ||
if ($alterRow) { | ||
$search->alterRow($row); | ||
} | ||
$rows[] = $row; | ||
} | ||
|
||
CRM_Core_Report_Excel::writeCSVFile(ts('CiviCRM Contact Search'), $header, $rows); | ||
CRM_Utils_System::civiExit(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters