Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev/core#4112 Separate code to handle exporting legacy custom searche…
…s into the extension
- Loading branch information
1 parent
4efa297
commit cafb33a
Showing
4 changed files
with
79 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
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
<?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