rename "Models" to "BAO" in paths and namespaces
This commit is contained in:
parent
4b2047fdb0
commit
aef6b64004
11 changed files with 82 additions and 50 deletions
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||
use CRM\TwingleCampaign\Models as Models;
|
||||
use CRM\TwingleCampaign\BAO as BAO;
|
||||
|
||||
include E::path() . '/CRM/TwingleCampaign/Upgrader/models/CampaignType.php';
|
||||
include E::path() . '/CRM/TwingleCampaign/Upgrader/models/CustomField.php';
|
||||
include E::path() . '/CRM/TwingleCampaign/Upgrader/models/CustomGroup.php';
|
||||
include E::path() . '/CRM/TwingleCampaign/Upgrader/BAO/CampaignType.php';
|
||||
include E::path() . '/CRM/TwingleCampaign/Upgrader/BAO/CustomField.php';
|
||||
include E::path() . '/CRM/TwingleCampaign/Upgrader/BAO/CustomGroup.php';
|
||||
|
||||
/**
|
||||
* Collection of upgrade steps.
|
||||
|
@ -53,26 +53,26 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
|
|||
|
||||
// Create campaign types
|
||||
foreach ($campaign_info['campaign_types'] as $campaign_type) {
|
||||
new Models\CampaignType($campaign_type);
|
||||
new BAO\CampaignType($campaign_type);
|
||||
}
|
||||
foreach (Models\CampaignType::getCampaignTypes() as $campaign_type) {
|
||||
foreach (BAO\CampaignType::getCampaignTypes() as $campaign_type) {
|
||||
$campaign_type->create();
|
||||
}
|
||||
|
||||
// Create custom groups
|
||||
foreach ($campaign_info['custom_groups'] as $custom_group) {
|
||||
foreach (Models\CampaignType::getCampaignTypes() as $campaign_type) {
|
||||
foreach (BAO\CampaignType::getCampaignTypes() as $campaign_type) {
|
||||
if ($campaign_type->getName() == $custom_group['campaign_type']) {
|
||||
$custom_group['extends_entity_column_value'] = $campaign_type->getValue();
|
||||
}
|
||||
}
|
||||
$cg = new Models\CustomGroup($custom_group);
|
||||
$cg = new BAO\CustomGroup($custom_group);
|
||||
$cg->create();
|
||||
}
|
||||
|
||||
// Create custom fields
|
||||
foreach ($campaign_info['custom_fields'] as $custom_field) {
|
||||
$cf = new Models\CustomField($custom_field);
|
||||
$cf = new BAO\CustomField($custom_field);
|
||||
$cf->create();
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
|
|||
|
||||
// Delete campaign types
|
||||
foreach ($campaign_info['campaign_types'] as $campaign_type) {
|
||||
$result = Models\CampaignType::fetch($campaign_type['name']);
|
||||
$result = BAO\CampaignType::fetch($campaign_type['name']);
|
||||
if ($result) {
|
||||
$result->delete();
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base {
|
|||
|
||||
// Delete custom groups
|
||||
foreach ($campaign_info['custom_groups'] as $custom_group) {
|
||||
$result = Models\CustomGroup::fetch($custom_group['name']);
|
||||
$result = BAO\CustomGroup::fetch($custom_group['name']);
|
||||
if ($result) {
|
||||
$result->delete();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace CRM\TwingleCampaign\Models;
|
||||
namespace CRM\TwingleCampaign\BAO;
|
||||
|
||||
use CRM_Civirules_Utils_LoggerFactory as Civi;
|
||||
|
||||
|
@ -106,7 +106,7 @@ class CampaignType {
|
|||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return \CRM\TwingleCampaign\Models\CampaignType|null
|
||||
* @return \CRM\TwingleCampaign\BAO\CampaignType|null
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public static function fetch($name) {
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace CRM\TwingleCampaign\Models;
|
||||
namespace CRM\TwingleCampaign\BAO;
|
||||
|
||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||
|
||||
|
@ -138,7 +138,7 @@ class CustomField {
|
|||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return array|\CRM\TwingleCampaign\Models\CustomField
|
||||
* @return array|\CRM\TwingleCampaign\BAO\CustomField
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public static function fetch($name = NULL) {
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace CRM\TwingleCampaign\Models;
|
||||
namespace CRM\TwingleCampaign\BAO;
|
||||
|
||||
use CRM_Civirules_Utils_LoggerFactory as Civi;
|
||||
|
||||
|
@ -105,7 +105,7 @@ class CustomGroup {
|
|||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return Models\CustomGroup
|
||||
* @return BAO\CustomGroup
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public static function fetch($name) {
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace CRM\TwingleCampaign\Models;
|
||||
namespace CRM\TwingleCampaign\BAO;
|
||||
|
||||
use CRM_Core_BAO_Setting;
|
||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||
use CRM\TwingleCampaign\Models\TwingleProject as TwingleProject;
|
||||
use CRM\TwingleCampaign\BAO\TwingleProject as TwingleProject;
|
||||
|
||||
include_once E::path() . '/api/v3/TwingleSync/models/TwingleProject.php';
|
||||
include_once E::path() . '/api/v3/TwingleSync/BAO/TwingleProject.php';
|
||||
|
||||
class TwingleApiCall {
|
||||
|
||||
|
@ -139,7 +139,16 @@ class TwingleApiCall {
|
|||
$result['state'] == 'TwingleProject already exists' &&
|
||||
$values['last_update'] < $project->lastUpdate()
|
||||
) {
|
||||
$result = $this->updateProject($project->export());
|
||||
// If this is a test do not make database changes
|
||||
if ($is_test) {
|
||||
$result = TwingleProject::fetch($values['id'])->getResponse(
|
||||
'TwingleProject ready to push'
|
||||
);
|
||||
}
|
||||
else {
|
||||
$result = $this->updateProject($project->export());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Return a response of the synchronization
|
||||
|
@ -151,12 +160,30 @@ class TwingleApiCall {
|
|||
|
||||
}
|
||||
|
||||
public function updateProject(array $values, bool $is_test = FALSE) {
|
||||
// TODO: Implement $is_test
|
||||
/**
|
||||
* @param array $values
|
||||
* @param bool $is_test
|
||||
*
|
||||
* @return array
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateProject(array $values) {
|
||||
|
||||
// Prepare url for curl
|
||||
$url = $this->protocol . 'project' . $this->baseUrl . $values['id'];
|
||||
return $this->curlPost($url, $values);
|
||||
|
||||
// Send curl
|
||||
$result = $this->curlPost($url, $values);
|
||||
|
||||
// Update TwingleProject in Civi with results from api call
|
||||
$updated_project = new TwingleProject($result, TwingleProject::TWINGLE);
|
||||
$updated_project->create();
|
||||
return $updated_project->getResponse("TwingleProject pushed to Twingle");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function updateEvent() {
|
||||
}
|
||||
|
9
api/v3/TwingleSync/BAO/TwingleCampaign.php
Normal file
9
api/v3/TwingleSync/BAO/TwingleCampaign.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace CRM\TwingleCampaign\BAO;
|
||||
|
||||
|
||||
class TwingleCampaign {
|
||||
|
||||
}
|
9
api/v3/TwingleSync/BAO/TwingleEvent.php
Normal file
9
api/v3/TwingleSync/BAO/TwingleEvent.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace CRM\TwingleCampaign\BAO;
|
||||
|
||||
|
||||
class TwingleEvent {
|
||||
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace CRM\TwingleCampaign\Models;
|
||||
namespace CRM\TwingleCampaign\BAO;
|
||||
|
||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||
use DateTime;
|
||||
use CRM\TwingleCampaign\Models\CustomField as CustomField;
|
||||
use CRM\TwingleCampaign\BAO\CustomField as CustomField;
|
||||
|
||||
include_once E::path() . '/CRM/TwingleCampaign/Upgrader/models/CustomField.php';
|
||||
include_once E::path() . '/CRM/TwingleCampaign/Upgrader/BAO/CustomField.php';
|
||||
|
||||
|
||||
class TwingleProject {
|
||||
|
@ -40,6 +40,8 @@ class TwingleProject {
|
|||
* @param string $origin
|
||||
* Origin of the array. It can be one of two constants:
|
||||
* TwingleProject::TWINGLE|CIVICRM
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(array $values, string $origin) {
|
||||
|
||||
|
@ -183,10 +185,13 @@ class TwingleProject {
|
|||
* Export values
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function export() {
|
||||
$values = $this->values;
|
||||
$this->formatForExport($values);
|
||||
self::formatValues($values, self::OUT);
|
||||
self::translateKeys($values, self::OUT);
|
||||
unset($values['campaign_type_id']);
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
@ -246,7 +251,7 @@ class TwingleProject {
|
|||
*
|
||||
* @param $id
|
||||
*
|
||||
* @return \CRM\TwingleCampaign\Models\TwingleProject
|
||||
* @return \CRM\TwingleCampaign\BAO\TwingleProject
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
|
@ -324,7 +329,7 @@ class TwingleProject {
|
|||
|
||||
// Set the direction of the translation
|
||||
if ($direction == self::OUT) {
|
||||
array_flip($fields);
|
||||
$translations = array_flip($translations);
|
||||
}
|
||||
// Throw error if $direction constant does not match IN or OUT
|
||||
elseif ($direction != self::IN) {
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||
use CRM\TwingleCampaign\Models\TwingleApiCall as TwingleApiCall;
|
||||
use CRM\TwingleCampaign\BAO\TwingleApiCall as TwingleApiCall;
|
||||
|
||||
include_once E::path() . '/api/v3/TwingleSync/models/TwingleApiCall.php';
|
||||
include_once E::path() . '/api/v3/TwingleSync/BAO/TwingleApiCall.php';
|
||||
|
||||
/**
|
||||
* TwingleSync.Get API specification (optional)
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace CRM\TwingleCampaign\Models;
|
||||
|
||||
|
||||
class TwingleCampaign {
|
||||
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace CRM\TwingleCampaign\Models;
|
||||
|
||||
|
||||
class TwingleEvent {
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue