CustomField::fetch() gets array of all exitsting custom fields

This commit is contained in:
Marc Michalsky forumZFD 2020-09-29 08:47:08 +02:00
parent 79febdf5fc
commit 9e3ffbb43e
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9

View file

@ -125,14 +125,33 @@ class CustomField {
* @return \CRM\TwingleCampaign\Models\CustomField * @return \CRM\TwingleCampaign\Models\CustomField
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
*/ */
public static function fetch($name) { public static function fetch($name = NULL) {
if (!$name) {
$customFields = [];
$json_file = file_get_contents(E::path() .
'/CRM/TwingleCampaign/Upgrader/resources/campaigns.json');
$campaign_info = json_decode($json_file, TRUE);
if (!$campaign_info) {
\Civi::log()->error("Could not read json file");
throw new \Exception('Could not read json file');
}
foreach ($campaign_info['custom_fields'] as $custom_field) {
$result = CustomField::fetch($custom_field['name']);
array_push($customFields, $result);
}
return $customFields;
}
else {
$custom_field = civicrm_api3( $custom_field = civicrm_api3(
'CustomField', 'CustomField',
'get', 'get',
[ [
'sequential' => 1, 'sequential' => 1,
'name' => $name 'name' => $name,
] ]
); );
if ($custom_field = array_shift($custom_field['values'])) { if ($custom_field = array_shift($custom_field['values'])) {
@ -141,7 +160,7 @@ class CustomField {
else { else {
return NULL; return NULL;
} }
}
} }
public function delete() { public function delete() {