asakusuma/sugarcrm-wrapper

dev-master / 1.1.x-dev 2016-03-10 13:14 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:16:14 UTC


README

由 Asa Kusuma 编写

http://www.asakusuma.com/

许可证:MIT

内容

  1. 关于
  2. 安装
  3. 使用示例
  4. 注意事项
  5. get_note_attachment() 示例
  6. set_note_attachment() 示例

1. 关于

  1. 通过 Composer 安装

编辑 composer.json

{
	"repositories": [
			{
				"type": "vcs",
    			"url": "https://github.com/Daursu/curl"
    		}
		],
	"require": {
		"asakusuma/sugarcrm-wrapper": "dev-master"
	},
	"minimum-stability": "dev"
}

然后使用 composer 进行安装

$ composer install

3. 使用示例

$sugar = new \Asakusuma\SugarWrapper\Rest;

$sugar->setUrl('https://sugarcrm/service/v2/rest.php');
$sugar->setUsername('user');
$sugar->setPassword('password');

$sugar->connect();

$results = $sugar->get("Accounts",array('id','name'));

print_r($results);

查看 example.php 以获取另一个示例。

4. 注意事项

  • The is_valid_id() 函数可能需要针对不同的 SugarCRM 版本进行修改。
  • SugarCRM 的不同版本有不同的 ID 格式。

5. get_note_attachment() 示例

此示例输出笔记附件的内容,给定笔记 ID。假设 $note_id 包含您要修改的笔记的 ID。

$sugar = new \Asakusuma\SugarWrapper\Rest;

$sugar->setUrl('https://sugarcrm/service/v2/rest.php');
$sugar->setUsername('user');
$sugar->setPassword('password');

$sugar->connect();

$result = $sugar->get_note_attachment($note_id);
$filename = $result['note_attachment']['filename'];
$file = $result['note_attachment']['file'];

$file = base64_decode($file);
header("Cache-Control: no-cache private");
header("Content-Description: File Transfer");
header('Content-disposition: attachment; filename='.$filename);
header("Content-Type: application/vnd.ms-excel");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '. strlen($file));
echo $file;
exit;

6. set_note_attachment() 示例

此示例说明如何从 html 表单设置笔记的附件。假设 $note_id 包含您要修改的笔记的 ID。

HTML 代码

<form method="post" action="example.php" enctype="multipart/form-data">
	<input name="note_file" type="file" />
	<input type="submit" value="Go" />
</form>

PHP 代码 (example.php)

$sugar = new \Asakusuma\SugarWrapper\Rest;

$sugar->setUrl('https://sugarcrm/service/v2/rest.php');
$sugar->setUsername('user');
$sugar->setPassword('password');

$sugar->connect();

if ($_FILES["note_file"]["error"] > 0) {
	// Error: $_FILES["file"]["error"]
} else if(isset($_FILES['note_file']['tmp_name']) && $_FILES['note_file']['tmp_name']!="") {
	$handle = fopen($_FILES['note_file']['tmp_name'], "rb");
	$filename = $_FILES['note_file']['name'];
	$contents = fread($handle, filesize($_FILES['note_file']['tmp_name']));
	$binary = base64_encode($contents);
	$file_results = $sugar->set_note_attachment($note_id,$binary,$filename);
}

7. get_available_modules() 示例

此示例说明如何获取 Sugar 中的可用模块。所有模块。这是一个在构建未来兼容的 sugarcrm 插件时很有用的函数。

PHP 代码 (example.php)

$sugar = new \Asakusuma\SugarWrapper\Rest;
$modules = $sugar->get_available_modules();

BAM! 现在,循环遍历返回并存储在 $modules 中的数组。您可以使用此数组在管理面板中显示下拉列表,显示用户想要连接到您的 sugarcrm 插件的所有模块。