rename "Models" to "BAO" in paths and namespaces

This commit is contained in:
Marc Michalsky forumZFD 2020-10-05 17:01:47 +02:00
parent 4b2047fdb0
commit aef6b64004
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
11 changed files with 82 additions and 50 deletions

View file

@ -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() {
}

View file

@ -0,0 +1,9 @@
<?php
namespace CRM\TwingleCampaign\BAO;
class TwingleCampaign {
}

View file

@ -0,0 +1,9 @@
<?php
namespace CRM\TwingleCampaign\BAO;
class TwingleEvent {
}

View file

@ -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) {

View file

@ -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)

View file

@ -1,9 +0,0 @@
<?php
namespace CRM\TwingleCampaign\Models;
class TwingleCampaign {
}

View file

@ -1,9 +0,0 @@
<?php
namespace CRM\TwingleCampaign\Models;
class TwingleEvent {
}