🧹 code cleanup
This commit is contained in:
parent
9b45d4a1fa
commit
2f1e5721c1
7 changed files with 18 additions and 36 deletions
|
@ -26,7 +26,6 @@ abstract class CRM_TwingleCampaign_BAO_Campaign {
|
|||
|
||||
protected $formattedValues;
|
||||
|
||||
|
||||
/**
|
||||
* ## Campaign constructor.
|
||||
*
|
||||
|
@ -55,7 +54,6 @@ abstract class CRM_TwingleCampaign_BAO_Campaign {
|
|||
* @throws \Exception
|
||||
*/
|
||||
public function create(bool $no_hook = FALSE): bool {
|
||||
|
||||
// Prepare project values for import into database
|
||||
$values_prepared_for_import = $this->values;
|
||||
$this->formatValues(
|
||||
|
|
|
@ -27,6 +27,9 @@ class CRM_TwingleCampaign_BAO_CampaignType {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param bool $upgrade
|
||||
* If true: Does not show UF message if campaign type already exists
|
||||
*
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public function create(bool $upgrade = false) {
|
||||
|
@ -41,8 +44,7 @@ class CRM_TwingleCampaign_BAO_CampaignType {
|
|||
]
|
||||
);
|
||||
|
||||
if ($field['count'] == 0)
|
||||
{
|
||||
if ($field['count'] == 0) {
|
||||
$this->results = civicrm_api3('OptionValue', 'create', $this->getSetAttributes());
|
||||
|
||||
$this->value = array_column($this->results['values'], 'value')[0];
|
||||
|
@ -55,8 +57,7 @@ class CRM_TwingleCampaign_BAO_CampaignType {
|
|||
}
|
||||
else {
|
||||
$error_message = $this->results['error_message'];
|
||||
Civi::log()->error("Twingle Extension could not create new campaign type
|
||||
for \"$this->label\": $error_message");
|
||||
Civi::log()->error("Twingle Extension could not create new campaign type for \"$this->label\": $error_message");
|
||||
}
|
||||
}
|
||||
elseif (!$upgrade) {
|
||||
|
|
|
@ -53,11 +53,6 @@ class CRM_TwingleCampaign_BAO_CustomField {
|
|||
if (array_key_exists($var, $attributes)) {
|
||||
$this->$var = $attributes[$var];
|
||||
}
|
||||
|
||||
// translate help_post
|
||||
if ($this->help_post) {
|
||||
$this->help_post = E::ts($this->help_post);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,16 +157,9 @@ class CRM_TwingleCampaign_BAO_CustomField {
|
|||
if (!$name) {
|
||||
$result = [];
|
||||
|
||||
// Get json file with all custom fields for this extension
|
||||
$json_file = file_get_contents(E::path() .
|
||||
'/CRM/TwingleCampaign/resources/campaigns.json');
|
||||
$campaign_info = json_decode($json_file, TRUE);
|
||||
|
||||
// Log an error and throw an exception if the file cannot get read
|
||||
if (!$campaign_info) {
|
||||
Civi::log()->error("Could not read json file");
|
||||
throw new Exception('Could not read json file');
|
||||
}
|
||||
// Get array with all custom fields for this extension
|
||||
$campaign_info =
|
||||
require E::path() . '/CRM/TwingleCampaign/resources/campaigns.php';
|
||||
|
||||
// Recursive method call with all custom field names from the json file
|
||||
foreach ($campaign_info['custom_fields'] as $customField) {
|
||||
|
|
|
@ -33,11 +33,6 @@ class CRM_TwingleCampaign_BAO_OptionValue {
|
|||
if (array_key_exists($var, $attributes)) {
|
||||
$this->$var = $attributes[$var];
|
||||
}
|
||||
|
||||
// translate description
|
||||
if ($this->description) {
|
||||
$this->description = E::ts($this->description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -677,19 +677,16 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
|
|||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ## Last update
|
||||
* Returns a timestamp of the last update of the TwingleProject campaign.
|
||||
*
|
||||
* @return int|string|null
|
||||
* @return int|null
|
||||
*/
|
||||
public
|
||||
function lastUpdate(): ?int {
|
||||
public function lastUpdate(): ?int {
|
||||
return self::getTimestamp($this->values['last_update']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ## Get project id
|
||||
* Returns the **project_id** of this TwingleProject.
|
||||
|
|
|
@ -65,10 +65,12 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
|
|||
*/
|
||||
public function install() {
|
||||
// Create campaign types, custom fields and custom groups by the contents
|
||||
// of the json file "campaigns.json"
|
||||
// of the campaigns.php file
|
||||
|
||||
$campaign_info = Cache::getInstance()->getCampaigns();
|
||||
$option_values = Cache::getInstance()->getOptionValues();
|
||||
$campaign_info = require E::path() .
|
||||
'/CRM/TwingleCampaign/resources/campaigns.php';
|
||||
$option_values = require E::path() .
|
||||
'/CRM/TwingleCampaign/resources/option_values.php';
|
||||
|
||||
// Create campaign types
|
||||
foreach ($campaign_info['campaign_types'] as $campaign_type) {
|
||||
|
@ -132,7 +134,8 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
|
|||
*/
|
||||
public function uninstall() {
|
||||
|
||||
$campaign_info = Cache::getInstance()->getCampaigns();
|
||||
$campaign_info = require E::path() .
|
||||
'/CRM/TwingleCampaign/resources/campaigns.php';
|
||||
$option_values = Cache::getInstance()->getOptionValues();
|
||||
|
||||
// Delete campaign types
|
||||
|
|
|
@ -127,7 +127,7 @@ function civicrm_api3_twingle_project_Get(array $params): array {
|
|||
$query = ['options' => ['limit' => 0]];
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
if ( $key != 'id' &&
|
||||
if ($key != 'id' &&
|
||||
array_key_exists('twingle_project_' . $key, $custom_field_mapping)
|
||||
) {
|
||||
$query[$custom_field_mapping['twingle_project_' . $key]] = $value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue