Change class names to meet naming convention
+ removed namespaces
This commit is contained in:
parent
fc545b7f1c
commit
a53b61775a
14 changed files with 35 additions and 257 deletions
|
@ -1,16 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use CRM_TwingleCampaign_Utils_ExtensionCache as Cache;
|
||||||
|
use CRM_TwingleCampaign_BAO_CampaignType as CampaignType;
|
||||||
|
use CRM_TwingleCampaign_BAO_TwingleProject as TwingleProject;
|
||||||
|
use CRM_TwingleCampaign_BAO_TwingleEvent as TwingleEvent;
|
||||||
|
use CRM_TwingleCampaign_BAO_TwingleCampaign as TwingleCampaign;
|
||||||
|
|
||||||
namespace CRM\TwingleCampaign\BAO;
|
abstract class CRM_TwingleCampaign_BAO_Campaign {
|
||||||
|
|
||||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
|
||||||
use CRM\TwingleCampaign\Utils\ExtensionCache as Cache;
|
|
||||||
use DateTime;
|
|
||||||
use Exception;
|
|
||||||
use CiviCRM_API3_Exception;
|
|
||||||
|
|
||||||
|
|
||||||
abstract class Campaign {
|
|
||||||
|
|
||||||
// IN means: heading into CiviCRM database
|
// IN means: heading into CiviCRM database
|
||||||
public const IN = 'IN';
|
public const IN = 'IN';
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace CRM\TwingleCampaign\BAO;
|
|
||||||
|
|
||||||
use CRM_Civirules_Utils_LoggerFactory as Civi;
|
|
||||||
|
|
||||||
class CampaignType {
|
class CRM_TwingleCampaign_BAO_CampaignType {
|
||||||
|
|
||||||
private static $campaignTypes = [];
|
private static $campaignTypes = [];
|
||||||
private $id;
|
private $id;
|
||||||
|
@ -62,7 +60,7 @@ class CampaignType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$campaignType = CampaignType::fetch($this->name);
|
$campaignType = self::fetch($this->name);
|
||||||
foreach ($this as $var => $value) {
|
foreach ($this as $var => $value) {
|
||||||
if (array_key_exists($var, $campaignType->getSetAttributes())) {
|
if (array_key_exists($var, $campaignType->getSetAttributes())) {
|
||||||
$this->$var = $campaignType->getSetAttributes()[$var];
|
$this->$var = $campaignType->getSetAttributes()[$var];
|
||||||
|
@ -106,7 +104,7 @@ class CampaignType {
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @return \CRM\TwingleCampaign\BAO\CampaignType|null
|
* @return CRM_TwingleCampaign_BAO_CampaignType|null
|
||||||
* @throws \CiviCRM_API3_Exception
|
* @throws \CiviCRM_API3_Exception
|
||||||
*/
|
*/
|
||||||
public static function fetch(string $name) {
|
public static function fetch(string $name) {
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace CRM\TwingleCampaign\BAO;
|
class CRM_TwingleCampaign_BAO_Configuration {
|
||||||
|
|
||||||
use Civi;
|
|
||||||
|
|
||||||
class Configuration {
|
|
||||||
|
|
||||||
private static $settingsKeys = [
|
private static $settingsKeys = [
|
||||||
'twingle_api_key',
|
'twingle_api_key',
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace CRM\TwingleCampaign\BAO;
|
|
||||||
|
|
||||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||||
|
|
||||||
class CustomField {
|
class CRM_TwingleCampaign_BAO_CustomField {
|
||||||
|
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
|
@ -159,7 +156,7 @@ class CustomField {
|
||||||
* @param string|null $name
|
* @param string|null $name
|
||||||
* The name of the field you wish to instantiate.
|
* The name of the field you wish to instantiate.
|
||||||
*
|
*
|
||||||
* @return array|\CRM\TwingleCampaign\BAO\CustomField
|
* @return array|CRM_TwingleCampaign_BAO_CustomField
|
||||||
* The required CustomField or an array with all custom fields.
|
* The required CustomField or an array with all custom fields.
|
||||||
*
|
*
|
||||||
* @throws \CiviCRM_API3_Exception
|
* @throws \CiviCRM_API3_Exception
|
||||||
|
@ -184,7 +181,7 @@ class CustomField {
|
||||||
|
|
||||||
// Recursive method call with all custom field names from the json file
|
// Recursive method call with all custom field names from the json file
|
||||||
foreach ($campaign_info['custom_fields'] as $custom_field) {
|
foreach ($campaign_info['custom_fields'] as $custom_field) {
|
||||||
$result = CustomField::fetch($custom_field['name']);
|
$result = self::fetch($custom_field['name']);
|
||||||
array_push($customFields, $result);
|
array_push($customFields, $result);
|
||||||
}
|
}
|
||||||
return $customFields;
|
return $customFields;
|
||||||
|
@ -258,7 +255,7 @@ class CustomField {
|
||||||
public static function getMapping() {
|
public static function getMapping() {
|
||||||
|
|
||||||
// Get an array with all custom fields
|
// Get an array with all custom fields
|
||||||
$customFields = CustomField::fetch();
|
$customFields = self::fetch();
|
||||||
|
|
||||||
$customFieldMapping = [];
|
$customFieldMapping = [];
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
class CRM_TwingleCampaign_BAO_CustomGroup {
|
||||||
namespace CRM\TwingleCampaign\BAO;
|
|
||||||
|
|
||||||
use CRM_Civirules_Utils_LoggerFactory as Civi;
|
|
||||||
|
|
||||||
class CustomGroup {
|
|
||||||
|
|
||||||
private $id;
|
private $id;
|
||||||
private $title;
|
private $title;
|
||||||
|
@ -106,7 +101,7 @@ class CustomGroup {
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
*
|
*
|
||||||
* @return CustomGroup
|
* @return self
|
||||||
* @throws \CiviCRM_API3_Exception
|
* @throws \CiviCRM_API3_Exception
|
||||||
*/
|
*/
|
||||||
public static function fetch($name) {
|
public static function fetch($name) {
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
class CRM_TwingleCampaign_BAO_OptionValue {
|
||||||
namespace CRM\TwingleCampaign\BAO;
|
|
||||||
|
|
||||||
|
|
||||||
class OptionValue {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,15 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace CRM\TwingleCampaign\BAO;
|
use CRM_TwingleCampaign_BAO_TwingleProject as TwingleProject;
|
||||||
|
|
||||||
use API_Exception;
|
class CRM_TwingleCampaign_BAO_TwingleApiCall {
|
||||||
use Civi;
|
|
||||||
use CRM_Core_BAO_Setting;
|
|
||||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
|
|
||||||
class TwingleApiCall {
|
|
||||||
|
|
||||||
private $apiKey;
|
private $apiKey;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use CRM_TwingleCampaign_BAO_Campaign as Campaign;
|
||||||
|
|
||||||
namespace CRM\TwingleCampaign\BAO;
|
class CRM_TwingleCampaign_BAO_TwingleCampaign extends Campaign {
|
||||||
|
|
||||||
|
|
||||||
class TwingleCampaign extends Campaign {
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,19 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use CRM_TwingleCampaign_Utils_ExtensionCache as Cache;
|
||||||
|
use CRM_TwingleCampaign_BAO_Campaign as Campaign;
|
||||||
|
use CRM_TwingleCampaign_BAO_TwingleApiCall as TwingleApiCall;
|
||||||
|
use CRM_TwingleCampaign_BAO_Configuration as Configuration;
|
||||||
|
|
||||||
namespace CRM\TwingleCampaign\BAO;
|
class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign {
|
||||||
|
|
||||||
use Civi;
|
|
||||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
|
||||||
use CRM\TwingleCampaign\Utils\ExtensionCache as Cache;
|
|
||||||
use Exception;
|
|
||||||
use CiviCRM_API3_Exception;
|
|
||||||
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/BAO/Campaign.php';
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/BAO/Configuration.php';
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/Utils/ExtensionCache.php';
|
|
||||||
|
|
||||||
class TwingleEvent extends Campaign {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TwingleEvent constructor.
|
* TwingleEvent constructor.
|
||||||
|
@ -68,7 +60,7 @@ class TwingleEvent extends Campaign {
|
||||||
|
|
||||||
// Instantiate TwingleEvent
|
// Instantiate TwingleEvent
|
||||||
try {
|
try {
|
||||||
$event = new TwingleEvent(
|
$event = new self(
|
||||||
$values,
|
$values,
|
||||||
self::TWINGLE
|
self::TWINGLE
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,19 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use CRM_TwingleCampaign_Utils_ExtensionCache as Cache;
|
||||||
|
use CRM_TwingleCampaign_BAO_Campaign as Campaign;
|
||||||
|
use CRM_TwingleCampaign_BAO_TwingleApiCall as TwingleApiCall;
|
||||||
|
|
||||||
namespace CRM\TwingleCampaign\BAO;
|
class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
|
||||||
|
|
||||||
use Civi;
|
|
||||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
|
||||||
use CRM\TwingleCampaign\Utils\ExtensionCache as Cache;
|
|
||||||
use CRM\TwingleCampaign\BAO\Campaign;
|
|
||||||
use Exception;
|
|
||||||
use CiviCRM_API3_Exception;
|
|
||||||
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/BAO/Campaign.php';
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/Utils/ExtensionCache.php';
|
|
||||||
|
|
||||||
class TwingleProject extends Campaign {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TwingleProject constructor.
|
* TwingleProject constructor.
|
||||||
|
@ -66,7 +57,7 @@ class TwingleProject extends Campaign {
|
||||||
|
|
||||||
// Instantiate TwingleProject
|
// Instantiate TwingleProject
|
||||||
try {
|
try {
|
||||||
$project = new TwingleProject(
|
$project = new self(
|
||||||
$values,
|
$values,
|
||||||
self::TWINGLE
|
self::TWINGLE
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace CRM\TwingleCampaign\Utils;
|
use CRM_TwingleCampaign_BAO_CustomField as CustomField;
|
||||||
|
|
||||||
use Civi;
|
|
||||||
use CRM\TwingleCampaign\BAO\CustomField as CustomField;
|
|
||||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||||
use Exception;
|
|
||||||
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/BAO/CustomField.php';
|
include_once E::path() . '/CRM/TwingleCampaign/BAO/CustomField.php';
|
||||||
|
|
||||||
|
@ -14,7 +10,7 @@ include_once E::path() . '/CRM/TwingleCampaign/BAO/CustomField.php';
|
||||||
*
|
*
|
||||||
* @package CRM\TwingleCampaign\Utilities
|
* @package CRM\TwingleCampaign\Utilities
|
||||||
*/
|
*/
|
||||||
class ExtensionCache {
|
class CRM_TwingleCampaign_Utils_ExtensionCache {
|
||||||
|
|
||||||
protected static $_instance = NULL;
|
protected static $_instance = NULL;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
use CRM_TwingleCampaign_ExtensionUtil as E;
|
||||||
use CRM\TwingleCampaign\Utils\ExtensionCache as Cache;
|
use CRM_TwingleCampaign_Utils_ExtensionCache as Cache;
|
||||||
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/Utils/ExtensionCache.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TwingleForm.Get API specification (optional)
|
* TwingleForm.Get API specification (optional)
|
||||||
|
|
|
@ -1,115 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use CRM\TwingleCampaign\BAO\TwingleApiCall as TwingleApiCall;
|
|
||||||
use CRM\TwingleCampaign\BAO\TwingleProject;
|
|
||||||
use CRM\TwingleCampaign\BAO\TwingleEvent;
|
|
||||||
use CRM\TwingleCampaign\BAO\TwingleCampaign;
|
|
||||||
use CRM_TwingleCampaign_ExtensionUtil as E;
|
|
||||||
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/BAO/TwingleApiCall.php';
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/BAO/TwingleProject.php';
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/BAO/TwingleEvent.php';
|
|
||||||
include_once E::path() . '/CRM/TwingleCampaign/BAO/TwingeCampaign.php';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TwingleSync.Post API specification (optional)
|
|
||||||
* This is used for documentation and validation.
|
|
||||||
*
|
|
||||||
* @param array $spec description of fields supported by this API call
|
|
||||||
*
|
|
||||||
* @see https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
|
|
||||||
*/
|
|
||||||
function _civicrm_api3_twingle_sync_Post_spec(array &$spec) {
|
|
||||||
$spec['twingle_api_key'] = [
|
|
||||||
'name' => 'twingle_api_key',
|
|
||||||
'title' => E::ts('Twingle API key'),
|
|
||||||
'type' => CRM_Utils_Type::T_STRING,
|
|
||||||
'api.required' => 0,
|
|
||||||
'description' => E::ts('The key to access the Twingle API'),
|
|
||||||
];
|
|
||||||
$spec['limit'] = [
|
|
||||||
'name' => 'limit',
|
|
||||||
'title' => E::ts('Limit'),
|
|
||||||
'type' => CRM_Utils_Type::T_INT,
|
|
||||||
'api.required' => 0,
|
|
||||||
'description' => E::ts('Limit for the number of events that should get requested per call to the Twingle API'),
|
|
||||||
];
|
|
||||||
$spec['is_test'] = [
|
|
||||||
'name' => 'is_test',
|
|
||||||
'title' => E::ts('Test'),
|
|
||||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
|
||||||
'api.required' => 0,
|
|
||||||
'description' => E::ts('If this is set true, no database change will be made'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TwingleSync.Post API
|
|
||||||
*
|
|
||||||
* @param array $params
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* API result descriptor
|
|
||||||
*
|
|
||||||
* @throws \CiviCRM_API3_Exception
|
|
||||||
* @throws \API_Exception
|
|
||||||
* @see civicrm_api3_create_success
|
|
||||||
*/
|
|
||||||
function civicrm_api3_twingle_sync_Post(array $params) {
|
|
||||||
$result_values = [];
|
|
||||||
|
|
||||||
// Who is calling?
|
|
||||||
$api_key = $_REQUEST['api_key'];
|
|
||||||
$user = CRM_Core_DAO::getFieldValue(
|
|
||||||
'CRM_Contact_DAO_Contact',
|
|
||||||
$api_key,
|
|
||||||
'id',
|
|
||||||
'api_key'
|
|
||||||
);
|
|
||||||
|
|
||||||
// Is this call a test?
|
|
||||||
$is_test = (boolean) $params['is_test'];
|
|
||||||
|
|
||||||
// If function call provides an API key, use it instead of the API key set
|
|
||||||
// on the extension settings page
|
|
||||||
$apiKey = empty($params['twingle_api_key'])
|
|
||||||
? trim(Civi::settings()->get('twingle_api_key'))
|
|
||||||
: trim($params['twingle_api_key']);
|
|
||||||
// If function call does not provide a limit, set a default value
|
|
||||||
$limit = ($params['limit']) ?? NULL;
|
|
||||||
$twingleApi = new TwingleApiCall($apiKey, $limit);
|
|
||||||
|
|
||||||
// Get all projects from Twingle
|
|
||||||
$projects = $twingleApi->getProject();
|
|
||||||
|
|
||||||
// Create projects as campaigns if they do not exist and store results in
|
|
||||||
// $result_values
|
|
||||||
$i = 0;
|
|
||||||
foreach ($projects as $project) {
|
|
||||||
if (is_array($project)) {
|
|
||||||
$result_values['sync']['projects'][$i++] =
|
|
||||||
TwingleProject::sync($project, $twingleApi, $is_test);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all events from projects of type "event" and create them as campaigns
|
|
||||||
// if they do not exist yet
|
|
||||||
$j = 0;
|
|
||||||
foreach ($result_values['sync']['projects'] as $project) {
|
|
||||||
if ($project['project_type'] == 'event') {
|
|
||||||
$events = $twingleApi->getEvent($project['project_id']);
|
|
||||||
if (is_array($events)) {
|
|
||||||
foreach ($events as $event) {
|
|
||||||
if ($event) {
|
|
||||||
$result_values['sync']['events'][$j++] =
|
|
||||||
TwingleEvent::sync($event, $twingleApi, $user, $is_test);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return civicrm_api3_create_success($result_values);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Civi\Test\HeadlessInterface;
|
|
||||||
use Civi\Test\HookInterface;
|
|
||||||
use Civi\Test\TransactionalInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TwingleSync.Get API Test Case
|
|
||||||
* This is a generic test class implemented with PHPUnit.
|
|
||||||
* @group headless
|
|
||||||
*/
|
|
||||||
class api_v3_TwingleSync_GetTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface, TransactionalInterface {
|
|
||||||
use \Civi\Test\Api3TestTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up for headless tests.
|
|
||||||
*
|
|
||||||
* Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
|
|
||||||
*
|
|
||||||
* See: https://docs.civicrm.org/dev/en/latest/testing/phpunit/#civitest
|
|
||||||
*/
|
|
||||||
public function setUpHeadless() {
|
|
||||||
return \Civi\Test::headless()
|
|
||||||
->installMe(__DIR__)
|
|
||||||
->apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The setup() method is executed before the test is executed (optional).
|
|
||||||
*/
|
|
||||||
public function setUp() {
|
|
||||||
parent::setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The tearDown() method is executed after the test was executed (optional)
|
|
||||||
* This can be used for cleanup.
|
|
||||||
*/
|
|
||||||
public function tearDown() {
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple example test case.
|
|
||||||
*
|
|
||||||
* Note how the function name begins with the word "test".
|
|
||||||
*/
|
|
||||||
public function testApiExample() {
|
|
||||||
$result = civicrm_api3('TwingleSync', 'Get', array('magicword' => 'sesame'));
|
|
||||||
$this->assertEquals('Twelve', $result['values'][12]['name']);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue