diff options
Diffstat (limited to 'www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action')
19 files changed, 612 insertions, 0 deletions
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Address/Create.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Address/Create.php new file mode 100644 index 00000000..641b76f6 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Address/Create.php @@ -0,0 +1,43 @@ +<?php + +namespace Civi\Api4\Action\Address; + +use Civi\Api4\Generic\Result; + +/** + * @inheritDoc + */ +class Create extends \Civi\Api4\Generic\DAOCreateAction { + + /** + * Optional param to indicate you want the street_address field parsed into individual params + * + * @var bool + */ + protected $streetParsing = TRUE; + + /** + * Optional param to indicate you want to skip geocoding (useful when importing a lot of addresses at once, the job Geocode and Parse Addresses can execute this task after the import) + * + * @var bool + */ + protected $skipGeocode = FALSE; + + /** + * When true, apply various fixes to the address before insert. + * + * @var bool + */ + protected $fixAddress = TRUE; + + /** + * @inheritDoc + */ + public function _run(Result $result) { + $this->values['street_parsing'] = $this->streetParsing; + $this->values['skip_geocode'] = $this->skipGeocode; + $this->values['fix_address'] = $this->fixAddress; + parent::_run($result); + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Address/Update.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Address/Update.php new file mode 100644 index 00000000..862a8b9e --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Address/Update.php @@ -0,0 +1,43 @@ +<?php + +namespace Civi\Api4\Action\Address; + +use Civi\Api4\Generic\Result; + +/** + * @inheritDoc + */ +class Update extends \Civi\Api4\Generic\DAOUpdateAction { + + /** + * Optional param to indicate you want the street_address field parsed into individual params + * + * @var bool + */ + protected $streetParsing = TRUE; + + /** + * Optional param to indicate you want to skip geocoding (useful when importing a lot of addresses at once, the job Geocode and Parse Addresses can execute this task after the import) + * + * @var bool + */ + protected $skipGeocode = FALSE; + + /** + * When true, apply various fixes to the address before insert. + * + * @var bool + */ + protected $fixAddress = TRUE; + + /** + * @inheritDoc + */ + public function _run(Result $result) { + $this->values['street_parsing'] = $this->streetParsing; + $this->values['skip_geocode'] = $this->skipGeocode; + $this->values['fix_address'] = $this->fixAddress; + parent::_run($result); + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Contact/Create.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Contact/Create.php new file mode 100644 index 00000000..1bd0bcec --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Contact/Create.php @@ -0,0 +1,22 @@ +<?php + +namespace Civi\Api4\Action\Contact; + +/** + * @inheritDoc + */ +class Create extends \Civi\Api4\Generic\DAOCreateAction { + + protected function fillDefaults(&$params) { + // Guess which type of contact is being created + if (empty($params['contact_type']) && !empty($params['organization_name'])) { + $params['contact_type'] = 'Organization'; + } + if (empty($params['contact_type']) && !empty($params['household_name'])) { + $params['contact_type'] = 'Household'; + } + // Will default to Individual per fieldSpec + parent::fillDefaults($params); + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Contact/GetFields.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Contact/GetFields.php new file mode 100644 index 00000000..1d6ddf66 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Contact/GetFields.php @@ -0,0 +1,19 @@ +<?php +namespace Civi\Api4\Action\Contact; + +use Civi\Api4\Generic\DAOGetFieldsAction; + +class GetFields extends DAOGetFieldsAction { + + protected function getRecords() { + $fields = parent::getRecords(); + + $apiKeyPerms = ['edit api keys', 'administer CiviCRM']; + if ($this->checkPermissions && !\CRM_Core_Permission::check([$apiKeyPerms])) { + unset($fields['api_key']); + } + + return $fields; + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Contribution/Create.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Contribution/Create.php new file mode 100644 index 00000000..52ee63c8 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Contribution/Create.php @@ -0,0 +1,18 @@ +<?php + +namespace Civi\Api4\Action\Contribution; + +use Civi\Api4\Generic\Result; + +/** + * @inheritDoc + */ +class Create extends \Civi\Api4\Generic\DAOCreateAction { + + public function _run(Result $result) { + // Required by Contribution BAO + $this->values['skipCleanMoney'] = TRUE; + parent::_run($result); + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Create.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Create.php new file mode 100644 index 00000000..7d059b24 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Create.php @@ -0,0 +1,11 @@ +<?php + +namespace Civi\Api4\Action\CustomValue; + +/** + * @inheritDoc + */ +class Create extends \Civi\Api4\Generic\DAOCreateAction { + use \Civi\Api4\Generic\Traits\CustomValueActionTrait; + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Delete.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Delete.php new file mode 100644 index 00000000..7c521748 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Delete.php @@ -0,0 +1,11 @@ +<?php + +namespace Civi\Api4\Action\CustomValue; + +/** + * Delete one or more items, based on criteria specified in Where param. + */ +class Delete extends \Civi\Api4\Generic\DAODeleteAction { + use \Civi\Api4\Generic\Traits\CustomValueActionTrait; + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Get.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Get.php new file mode 100644 index 00000000..47f3f514 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Get.php @@ -0,0 +1,11 @@ +<?php + +namespace Civi\Api4\Action\CustomValue; + +/** + * Get fields for a custom group. + */ +class Get extends \Civi\Api4\Generic\DAOGetAction { + use \Civi\Api4\Generic\Traits\CustomValueActionTrait; + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/GetActions.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/GetActions.php new file mode 100644 index 00000000..8af9088d --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/GetActions.php @@ -0,0 +1,11 @@ +<?php + +namespace Civi\Api4\Action\CustomValue; + +/** + * @inheritDoc + */ +class GetActions extends \Civi\Api4\Action\GetActions { + use \Civi\Api4\Generic\Traits\CustomValueActionTrait; + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/GetFields.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/GetFields.php new file mode 100644 index 00000000..733776b7 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/GetFields.php @@ -0,0 +1,34 @@ +<?php + +namespace Civi\Api4\Action\CustomValue; + +use Civi\Api4\Service\Spec\SpecGatherer; +use Civi\Api4\Service\Spec\SpecFormatter; + +/** + * Get fields for a custom group. + */ +class GetFields extends \Civi\Api4\Generic\DAOGetFieldsAction { + use \Civi\Api4\Generic\Traits\CustomValueActionTrait; + + protected function getRecords() { + $fields = $this->_itemsToGet('name'); + /** @var SpecGatherer $gatherer */ + $gatherer = \Civi::container()->get('spec_gatherer'); + $spec = $gatherer->getSpec('Custom_' . $this->getCustomGroup(), $this->getAction(), $this->includeCustom); + return SpecFormatter::specToArray($spec->getFields($fields), (array) $this->select, $this->loadOptions); + } + + /** + * @inheritDoc + */ + public function getParamInfo($param = NULL) { + $info = parent::getParamInfo($param); + if (!$param) { + // This param is meaningless here. + unset($info['includeCustom']); + } + return $info; + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Replace.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Replace.php new file mode 100644 index 00000000..457be9ca --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Replace.php @@ -0,0 +1,11 @@ +<?php + +namespace Civi\Api4\Action\CustomValue; + +/** + * Given a set of records, will appropriately update the database. + */ +class Replace extends \Civi\Api4\Generic\BasicReplaceAction { + use \Civi\Api4\Generic\Traits\CustomValueActionTrait; + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Update.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Update.php new file mode 100644 index 00000000..14f66f29 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/CustomValue/Update.php @@ -0,0 +1,11 @@ +<?php + +namespace Civi\Api4\Action\CustomValue; + +/** + * Update one or more records with new values. Use the where clause to select them. + */ +class Update extends \Civi\Api4\Generic\DAOUpdateAction { + use \Civi\Api4\Generic\Traits\CustomValueActionTrait; + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Entity/Get.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Entity/Get.php new file mode 100644 index 00000000..020c6398 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Entity/Get.php @@ -0,0 +1,102 @@ +<?php + +namespace Civi\Api4\Action\Entity; + +use Civi\Api4\CustomGroup; +use Civi\Api4\Utils\ReflectionUtils; + +/** + * Get entities + * + * @method $this setIncludeCustom(bool $value) + * @method bool getIncludeCustom() + */ +class Get extends \Civi\Api4\Generic\BasicGetAction { + + /** + * Include custom-field-based pseudo-entities? + * + * @var bool + */ + protected $includeCustom = TRUE; + + /** + * Scan all api directories to discover entities + */ + protected function getRecords() { + $entities = []; + foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { + $dir = \CRM_Utils_File::addTrailingSlash($path) . 'Civi/Api4'; + if (is_dir($dir)) { + foreach (glob("$dir/*.php") as $file) { + $matches = []; + preg_match('/(\w*).php/', $file, $matches); + $entity = ['name' => $matches[1]]; + if ($this->_isFieldSelected('description') || $this->_isFieldSelected('comment')) { + $this->addDocs($entity); + } + $entities[$matches[1]] = $entity; + } + } + } + unset($entities['CustomValue']); + + if ($this->includeCustom) { + $this->addCustomEntities($entities); + } + + ksort($entities); + return $entities; + } + + /** + * Add custom-field pseudo-entities + * + * @param $entities + * @throws \API_Exception + */ + private function addCustomEntities(&$entities) { + $customEntities = CustomGroup::get() + ->addWhere('is_multiple', '=', 1) + ->addWhere('is_active', '=', 1) + ->setSelect(['name', 'title', 'help_pre', 'help_post', 'extends']) + ->setCheckPermissions(FALSE) + ->execute(); + foreach ($customEntities as $customEntity) { + $fieldName = 'Custom_' . $customEntity['name']; + $entities[$fieldName] = [ + 'name' => $fieldName, + 'description' => $customEntity['title'] . ' custom group - extends ' . $customEntity['extends'], + ]; + if (!empty($customEntity['help_pre'])) { + $entities[$fieldName]['comment'] = $this->plainTextify($customEntity['help_pre']); + } + if (!empty($customEntity['help_post'])) { + $pre = empty($entities[$fieldName]['comment']) ? '' : $entities[$fieldName]['comment'] . "\n\n"; + $entities[$fieldName]['comment'] = $pre . $this->plainTextify($customEntity['help_post']); + } + } + } + + /** + * Convert html to plain text. + * + * @param $input + * @return mixed + */ + private function plainTextify($input) { + return html_entity_decode(strip_tags($input), ENT_QUOTES | ENT_HTML5, 'UTF-8'); + } + + /** + * Add info from code docblock. + * + * @param $entity + */ + private function addDocs(&$entity) { + $reflection = new \ReflectionClass("\\Civi\\Api4\\" . $entity['name']); + $entity += ReflectionUtils::getCodeDocs($reflection); + unset($entity['package'], $entity['method']); + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Entity/GetLinks.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Entity/GetLinks.php new file mode 100644 index 00000000..ee274bf9 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Entity/GetLinks.php @@ -0,0 +1,51 @@ +<?php + +namespace Civi\Api4\Action\Entity; + +use \CRM_Core_DAO_AllCoreTables as AllCoreTables; + +/** + * Get a list of FK links between entities + */ +class GetLinks extends \Civi\Api4\Generic\BasicGetAction { + + public function getRecords() { + $result = []; + /** @var \Civi\Api4\Service\Schema\SchemaMap $schema */ + $schema = \Civi::container()->get('schema_map'); + foreach ($schema->getTables() as $table) { + $entity = AllCoreTables::getBriefName(AllCoreTables::getClassForTable($table->getName())); + // Since this is an api function, exclude tables that don't have an api + if (class_exists('\Civi\Api4\\' . $entity)) { + $item = [ + 'entity' => $entity, + 'table' => $table->getName(), + 'links' => [], + ]; + foreach ($table->getTableLinks() as $link) { + $link = $link->toArray(); + $link['entity'] = AllCoreTables::getBriefName(AllCoreTables::getClassForTable($link['targetTable'])); + $item['links'][] = $link; + } + $result[] = $item; + } + } + return $result; + } + + public function fields() { + return [ + [ + 'name' => 'entity', + ], + [ + 'name' => 'table', + ], + [ + 'name' => 'links', + 'data_type' => 'Array', + ], + ]; + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/GetActions.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/GetActions.php new file mode 100644 index 00000000..1dc4ebbb --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/GetActions.php @@ -0,0 +1,101 @@ +<?php + +namespace Civi\Api4\Action; + +use Civi\API\Exception\NotImplementedException; +use Civi\Api4\Generic\BasicGetAction; +use Civi\Api4\Utils\ActionUtil; +use Civi\Api4\Utils\ReflectionUtils; + +/** + * Get actions for an entity with a list of accepted params + */ +class GetActions extends BasicGetAction { + + private $_actions = []; + + private $_actionsToGet; + + protected function getRecords() { + $this->_actionsToGet = $this->_itemsToGet('name'); + + $entityReflection = new \ReflectionClass('\Civi\Api4\\' . $this->_entityName); + foreach ($entityReflection->getMethods(\ReflectionMethod::IS_STATIC | \ReflectionMethod::IS_PUBLIC) as $method) { + $actionName = $method->getName(); + if ($actionName != 'permissions' && $actionName[0] != '_') { + $this->loadAction($actionName); + } + } + if (!$this->_actionsToGet || count($this->_actionsToGet) > count($this->_actions)) { + $includePaths = array_unique(explode(PATH_SEPARATOR, get_include_path())); + // Search entity-specific actions (including those provided by extensions) + foreach ($includePaths as $path) { + $dir = \CRM_Utils_File::addTrailingSlash($path) . 'Civi/Api4/Action/' . $this->_entityName; + $this->scanDir($dir); + } + } + ksort($this->_actions); + return $this->_actions; + } + + /** + * @param $dir + */ + private function scanDir($dir) { + if (is_dir($dir)) { + foreach (glob("$dir/*.php") as $file) { + $matches = []; + preg_match('/(\w*).php/', $file, $matches); + $actionName = array_pop($matches); + $this->loadAction(lcfirst($actionName)); + } + } + } + + /** + * @param $actionName + */ + private function loadAction($actionName) { + try { + if (!isset($this->_actions[$actionName]) && (!$this->_actionsToGet || in_array($actionName, $this->_actionsToGet))) { + $action = ActionUtil::getAction($this->getEntityName(), $actionName); + if (is_object($action)) { + $this->_actions[$actionName] = ['name' => $actionName]; + if ($this->_isFieldSelected('description') || $this->_isFieldSelected('comment')) { + $actionReflection = new \ReflectionClass($action); + $actionInfo = ReflectionUtils::getCodeDocs($actionReflection); + unset($actionInfo['method']); + $this->_actions[$actionName] += $actionInfo; + } + if ($this->_isFieldSelected('params')) { + $this->_actions[$actionName]['params'] = $action->getParamInfo(); + } + } + } + } + catch (NotImplementedException $e) { + } + } + + public function fields() { + return [ + [ + 'name' => 'name', + 'data_type' => 'String', + ], + [ + 'name' => 'description', + 'data_type' => 'String', + ], + [ + 'name' => 'comment', + 'data_type' => 'String', + ], + [ + 'name' => 'params', + 'data_type' => 'Array', + ], + ]; + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/GroupContact/Create.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/GroupContact/Create.php new file mode 100644 index 00000000..44e61f2e --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/GroupContact/Create.php @@ -0,0 +1,38 @@ +<?php + +namespace Civi\Api4\Action\GroupContact; + +use Civi\Api4\Generic\Result; + +/** + * @inheritDoc + * + * @method $this setMethod(string $method) Indicate who added/removed the group. + * @method $this setTracking(string $tracking) Specify ip address or other tracking info. + */ +class Create extends \Civi\Api4\Generic\DAOCreateAction { + + /** + * String to indicate who added/removed the group. + * + * @var string + */ + protected $method = 'API'; + + /** + * IP address or other tracking info about who performed this group subscription. + * + * @var string + */ + protected $tracking = ''; + + /** + * @inheritDoc + */ + public function _run(Result $result) { + $this->values['method'] = $this->method; + $this->values['tracking'] = $this->tracking; + parent::_run($result); + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/GroupContact/Update.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/GroupContact/Update.php new file mode 100644 index 00000000..edb8a902 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/GroupContact/Update.php @@ -0,0 +1,38 @@ +<?php + +namespace Civi\Api4\Action\GroupContact; + +use Civi\Api4\Generic\Result; + +/** + * @inheritDoc + * + * @method $this setMethod(string $method) Indicate who added/removed the group. + * @method $this setTracking(string $tracking) Specify ip address or other tracking info. + */ +class Update extends \Civi\Api4\Generic\DAOUpdateAction { + + /** + * String to indicate who added/removed the group. + * + * @var string + */ + protected $method = 'API'; + + /** + * IP address or other tracking info about who performed this group subscription. + * + * @var string + */ + protected $tracking = ''; + + /** + * @inheritDoc + */ + public function _run(Result $result) { + $this->values['method'] = $this->method; + $this->values['tracking'] = $this->tracking; + parent::_run($result); + } + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Navigation/Get.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Navigation/Get.php new file mode 100644 index 00000000..dcecc06a --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Navigation/Get.php @@ -0,0 +1,19 @@ +<?php + +namespace Civi\Api4\Action\Navigation; + +/** + * @inheritDoc + * + * Fetch items from the navigation menu. By default this will fetch items from the current domain. + */ +class Get extends \Civi\Api4\Generic\DAOGetAction { + + /** + * @inheritDoc + */ + protected $where = [ + ['domain_id', '=', 'current_domain'], + ]; + +} diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Participant/Get.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Participant/Get.php new file mode 100644 index 00000000..c5efec93 --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Action/Participant/Get.php @@ -0,0 +1,18 @@ +<?php + +namespace Civi\Api4\Action\Participant; + +/** + * @inheritDoc + */ +class Get extends \Civi\Api4\Generic\DAOGetAction { + + /** + * @inheritDoc + * $example->addWhere('contact_id.contact_type', 'IN', array('Individual', 'Household')) + */ + protected $where = [ + ['is_test', '=', 0], + ]; + +} |