forked from eileenmcnaughton/nz.co.fuzion.civixero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API4 Xero.TrackingCategoryPull and TrackingCategoryAddOption
- Loading branch information
Showing
6 changed files
with
264 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Civi\Api4\Action\Xero; | ||
|
||
use CRM_Civixero_ExtensionUtil as E; | ||
|
||
/** | ||
* This API Action creates a payment. It is based on API3 Payment.create and API3 MJWPayment.create | ||
* | ||
*/ | ||
class TrackingCategoryAddOption extends \Civi\Api4\Generic\AbstractCreateAction { | ||
|
||
/** | ||
* Connector ID (default 0) | ||
* | ||
* @var int | ||
*/ | ||
protected int $connectorID = 0; | ||
|
||
/** | ||
* @var string The Xero Tracking Category ID | ||
*/ | ||
protected string $trackingCategoryID; | ||
|
||
/** | ||
* @var string The Tracking Category option name | ||
*/ | ||
protected string $optionName; | ||
|
||
/** | ||
* | ||
* Note that the result class is that of the annotation below, not the h | ||
* in the method (which must match the parent class) | ||
* | ||
* @var \Civi\Api4\Generic\Result $result | ||
*/ | ||
public function _run(\Civi\Api4\Generic\Result $result) { | ||
$params = ['connector_id' => $this->connectorID]; | ||
$xero = new \CRM_Civixero_TrackingCategory($params); | ||
$trackingOption = $xero->addOption($this->trackingCategoryID, $this->optionName); | ||
$result->exchangeArray($trackingOption); | ||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Civi\Api4\Action\Xero; | ||
|
||
use CRM_Civixero_ExtensionUtil as E; | ||
|
||
/** | ||
* This API Action creates a payment. It is based on API3 Payment.create and API3 MJWPayment.create | ||
* | ||
*/ | ||
class TrackingCategoryPull extends \Civi\Api4\Generic\AbstractAction { | ||
|
||
/** | ||
* Connector ID (default 0) | ||
* | ||
* @var int | ||
*/ | ||
protected int $connectorID = 0; | ||
|
||
/** | ||
* | ||
* Note that the result class is that of the annotation below, not the h | ||
* in the method (which must match the parent class) | ||
* | ||
* @var \Civi\Api4\Generic\Result $result | ||
*/ | ||
public function _run(\Civi\Api4\Generic\Result $result) { | ||
$params = ['connector_id' => $this->connectorID]; | ||
$xero = new \CRM_Civixero_TrackingCategory($params); | ||
$trackingCategories = $xero->pull(); | ||
$result->exchangeArray($trackingCategories ?? []); | ||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Civi\Api4; | ||
|
||
/** | ||
* CiviCRM Xero API | ||
* | ||
* @searchable none | ||
* @since 5.19 | ||
* @package Civi\Api4 | ||
*/ | ||
class Xero extends Generic\AbstractEntity { | ||
|
||
/** | ||
* @param bool $checkPermissions | ||
* @return Generic\BasicGetFieldsAction | ||
*/ | ||
public static function getFields($checkPermissions = TRUE) { | ||
return (new Generic\BasicGetFieldsAction(__CLASS__, __FUNCTION__, function() { | ||
return []; | ||
}))->setCheckPermissions($checkPermissions); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* Auto-register "templates/" folder. | ||
* | ||
* @mixinName smarty-v2 | ||
* @mixinVersion 1.0.1 | ||
* @since 5.59 | ||
* | ||
* @param CRM_Extension_MixInfo $mixInfo | ||
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like. | ||
* @param \CRM_Extension_BootCache $bootCache | ||
* On newer deployments, this will be an instance of MixInfo. On older deployments, Civix may polyfill with a work-a-like. | ||
*/ | ||
return function ($mixInfo, $bootCache) { | ||
$dir = $mixInfo->getPath('templates'); | ||
if (!file_exists($dir)) { | ||
return; | ||
} | ||
|
||
$register = function() use ($dir) { | ||
// This implementation has a theoretical edge-case bug on older versions of CiviCRM where a template could | ||
// be registered more than once. | ||
CRM_Core_Smarty::singleton()->addTemplateDir($dir); | ||
}; | ||
|
||
// Let's figure out what environment we're in -- so that we know the best way to call $register(). | ||
|
||
if (!empty($GLOBALS['_CIVIX_MIXIN_POLYFILL'])) { | ||
// Polyfill Loader (v<=5.45): We're already in the middle of firing `hook_config`. | ||
if ($mixInfo->isActive()) { | ||
$register(); | ||
} | ||
return; | ||
} | ||
|
||
if (CRM_Extension_System::singleton()->getManager()->extensionIsBeingInstalledOrEnabled($mixInfo->longName)) { | ||
// New Install, Standard Loader: The extension has just been enabled, and we're now setting it up. | ||
// System has already booted. New templates may be needed for upcoming installation steps. | ||
$register(); | ||
return; | ||
} | ||
|
||
// Typical Pageview, Standard Loader: Defer the actual registration for a moment -- to ensure that Smarty is online. | ||
\Civi::dispatcher()->addListener('hook_civicrm_config', function() use ($mixInfo, $register) { | ||
if ($mixInfo->isActive()) { | ||
$register(); | ||
} | ||
}); | ||
|
||
}; |