fix bug: undefined indexes

This commit is contained in:
Marc Michalsky forumZFD 2021-02-08 17:32:56 +01:00
parent b1f0ddc5dc
commit a79e534099
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
2 changed files with 42 additions and 23 deletions

View file

@ -114,19 +114,21 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
$parent_campaign = civicrm_api3('Campaign', 'getsingle', $parent_campaign = civicrm_api3('Campaign', 'getsingle',
['id' => $parent_id]); ['id' => $parent_id]);
if (isset($parent_campaign['is_error'])) {
if ($parent_campaign['is_error'] != 1) { if ($parent_campaign['is_error'] != 1) {
throw new CiviCRM_API3_Exception($parent_campaign['error_message']);
}
}
$parent_campaign_type_id = $parent_campaign['campaign_type_id']; $parent_campaign_type_id = $parent_campaign['campaign_type_id'];
if ($parent_campaign['parent_id']) { if (isset($parent_campaign['parent_id'])) {
$parent_id = $parent_campaign['parent_id']; $parent_id = $parent_campaign['parent_id'];
} }
else { else {
break; break;
} }
} }
else {
throw new CiviCRM_API3_Exception($parent_campaign['error_message']);
}
}
// Set parent_project_id and retrieve parent_project_url // Set parent_project_id and retrieve parent_project_url
if ($parent_campaign_type_id == $twingle_project_campaign_type_id) { if ($parent_campaign_type_id == $twingle_project_campaign_type_id) {
@ -187,7 +189,8 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
* ## Create URL * ## Create URL
* Create a URL by adding a tw_cid * Create a URL by adding a tw_cid
*/ */
private function createUrl() { private
function createUrl() {
$this->values['url'] = $this->values['url'] =
$this->values['parent_project_url'] . '?tw_cid=' . $this->values['cid']; $this->values['parent_project_url'] . '?tw_cid=' . $this->values['cid'];
} }
@ -196,14 +199,16 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
/** /**
* *
*/ */
private function createCid() { private
function createCid() {
$this->values['cid'] = md5($this->id . '_' . $this->values['name']); $this->values['cid'] = md5($this->id . '_' . $this->values['name']);
} }
/** /**
* *
*/ */
private function validateCid() { private
function validateCid() {
} }
@ -211,7 +216,8 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
/** /**
* *
*/ */
private function decodeCid() { private
function decodeCid() {
} }
@ -229,7 +235,8 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
* @param string $direction * @param string $direction
* const: Campaign::OUT or Campaign::OUT * const: Campaign::OUT or Campaign::OUT
*/ */
public function translateCustomFields(array &$values, string $direction) { public
function translateCustomFields(array &$values, string $direction) {
// Translate field name to custom field name // Translate field name to custom field name
if ($direction == self::IN) { if ($direction == self::IN) {
@ -288,7 +295,8 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
* ## Delete TwingleCampaign * ## Delete TwingleCampaign
* Deletes this TwingleCampaign from CiviCRM * Deletes this TwingleCampaign from CiviCRM
*/ */
private function delete() { private
function delete() {
if ($this->id) { if ($this->id) {
try { try {
civicrm_api3('Campaign', 'delete', ['id' => $this->id]); civicrm_api3('Campaign', 'delete', ['id' => $this->id]);
@ -315,15 +323,18 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
* *
* @return array * @return array
*/ */
public function getResponse(string $status = NULL): array { public
function getResponse(string $status = NULL): array {
$response = [ $response = [
'title' => $this->values['title'],
'id' => (int) $this->id, 'id' => (int) $this->id,
]; ];
if ($status) { if ($status) {
$response['status'] = $status; $response['status'] = $status;
} }
if ($this->values['parent_project_id']) { if (isset($this->values['title'])) {
$response['title'] = $this->values['title'];
}
if (isset($this->values['parent_project_id'])) {
$response['parent_project_id'] = (int) $this->values['parent_project_id']; $response['parent_project_id'] = (int) $this->values['parent_project_id'];
} }
return $response; return $response;
@ -337,7 +348,8 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
* @param array $values * @param array $values
* values that should get updated * values that should get updated
*/ */
private function update(array $values) { private
function update(array $values) {
$filter = ExtensionCache::getInstance()->getTemplates()['TwingleCampaign']; $filter = ExtensionCache::getInstance()->getTemplates()['TwingleCampaign'];
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
if (in_array($key, $filter)) { if (in_array($key, $filter)) {
@ -355,7 +367,8 @@ class CRM_TwingleCampaign_BAO_TwingleCampaign {
* *
* @throws \CiviCRM_API3_Exception * @throws \CiviCRM_API3_Exception
*/ */
public function clone() { public
function clone() {
// TODO: implement cloning // TODO: implement cloning
} }

View file

@ -72,11 +72,15 @@ class CRM_TwingleCampaign_Utils_ExtensionCache {
// Get ids for Twingle related campaign types // Get ids for Twingle related campaign types
foreach ($this->campaigns['campaign_types'] as $campaign_type) { foreach ($this->campaigns['campaign_types'] as $campaign_type) {
$this->campaigns['campaign_types'][$campaign_type['name']]['id'] = civicrm_api3( $campaign_type_id = civicrm_api3(
'OptionValue', 'OptionValue',
'get', 'get',
['sequential' => 1, 'name' => $campaign_type['name']] ['sequential' => 1, 'name' => $campaign_type['name']]
)['values'][0]['value']; )['values'];
if ($campaign_type_id) {
$this->campaigns['campaign_types'][$campaign_type['name']]['id'] =
$campaign_type_id[0]['value'];
}
} }
} }
@ -84,8 +88,10 @@ class CRM_TwingleCampaign_Utils_ExtensionCache {
/** /**
* ## Get custom field mapping * ## Get custom field mapping
* Returns a mapping custom fields of the TwingleCampaign extension. * Returns a mapping custom fields of the TwingleCampaign extension.
* * If a **$fieldName** is provided, this method returns its custom field name * * If a **$fieldName** is provided, this method returns its custom field
* name
* * Without parameter, the method returns the whole mapping * * Without parameter, the method returns the whole mapping
*
* @param string|null $fieldName * @param string|null $fieldName
* *
* @return array|string * @return array|string