animafac/civicrm-api

一个库,让您能够轻松地使用 CiviCRM PHP API

1.0.0 2019-01-11 15:46 UTC

This package is not auto-updated.

Last update: 2024-09-20 20:00:48 UTC


README

此库允许您轻松使用 CiviCRM PHP API

civicrm_api3 类非常棒,但它只返回 stdClass 对象。此库使用具有有用方法和异常的全类对象。

使用

以下类可用

  • 地址
  • 联系人
  • 联系人类型
  • 国家
  • 电子邮件
  • 实体标签
  • 位置类型
  • 备注
  • 电话
  • 关系
  • 关系类型
  • 州/省
  • 标签
  • 用户
  • 网站

它们都与 CiviCRM 实体相对应。

方法

所有这些类都共享一组常用方法。

get

从该对象返回一个属性。

$contact = new Contact($id);
$contact->get('display_name');

set

向该对象添加一个属性。

$contact = new Contact($id);
$contact->set('display_name');

save

将对象保存到数据库中

$contact = new Contact();
$contact->set('display_name');
$contact->save();

delete

从数据库中删除对象。

$contact = new Contact($id);
$contact->delete();

getAll

获取此类型的所有对象。

Contact::getAll();

// Or if you only want a subset.
Contact::getAll(['contact_type' => 'Organization']);

getCount

获取此类型的对象数量。

Contact::getCount();

// Or if you only want a subset.
Contact::getCount(['contact_type' => 'Organization']);

getSingle

获取符合指定约束的单个对象。

Contact::getSingle(['first_name' => 'foo', 'last_name' => 'bar']);

设置

您可以使用 Composer 安装此库

composer require animafac/civicrm-api

然后您需要包含此库(最好是使用 Composer 自动加载器)以及 CiviCRM 的 class.api.php 文件。

use CivicrmApi\Api;
use CivicrmApi\Contact;

require_once __DIR__.'/vendor/autoload.php';
require_once 'path/to/civicrm/api/class.api.php';

Api::$path = '/path/to/civicrm/config/';

$contact = new Contact($id);
echo $contact->get('display_name');

Grunt 任务

Grunt 可以用于运行定义在 Gruntfile.js 中的自动化任务。

您首先需要使用 Yarn 安装 JavaScript 依赖项

yarn install
composer install

检查

您可以通过检查确保 JavaScript、JSON 和 PHP 文件格式正确

grunt lint

测试

您可以运行 PHPUnit 测试

grunt test

文档

可以使用 phpDocumentor 生成代码文档

grunt doc

CI

使用 Gitlab CI 在每次提交后自动运行测试。