CustomField::fetch() gets array of all exitsting custom fields
This commit is contained in:
parent
79febdf5fc
commit
9e3ffbb43e
1 changed files with 32 additions and 13 deletions
|
@ -125,23 +125,42 @@ 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) {
|
||||||
|
|
||||||
$custom_field = civicrm_api3(
|
if (!$name) {
|
||||||
'CustomField',
|
$customFields = [];
|
||||||
'get',
|
|
||||||
[
|
$json_file = file_get_contents(E::path() .
|
||||||
'sequential' => 1,
|
'/CRM/TwingleCampaign/Upgrader/resources/campaigns.json');
|
||||||
'name' => $name
|
$campaign_info = json_decode($json_file, TRUE);
|
||||||
]
|
|
||||||
);
|
if (!$campaign_info) {
|
||||||
if ($custom_field = array_shift($custom_field['values'])) {
|
\Civi::log()->error("Could not read json file");
|
||||||
return new CustomField($custom_field);
|
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 {
|
else {
|
||||||
return NULL;
|
$custom_field = civicrm_api3(
|
||||||
|
'CustomField',
|
||||||
|
'get',
|
||||||
|
[
|
||||||
|
'sequential' => 1,
|
||||||
|
'name' => $name,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
if ($custom_field = array_shift($custom_field['values'])) {
|
||||||
|
return new CustomField($custom_field);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete() {
|
public function delete() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue