-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
andrey-tech
committed
Jun 10, 2020
0 parents
commit cc33d64
Showing
21 changed files
with
6,642 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
examples/ | ||
|
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019-2020 andrey-tech | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,36 @@ | ||
# Bitrix24 API PHP Wrapper | ||
|
||
 | ||
|
||
Обертка на PHP7+ для работы с REST API [Битрикс24](https://dev.1c-bitrix.ru/rest_help/) с использованием механизма входящих вебхуков, | ||
троттлингом запросов к серверу и логированием. | ||
|
||
**Документация находится в процессе разработки.** | ||
|
||
<!-- MarkdownTOC levels="1,2,3,4,5,6" autoanchor="true" autolink="true" --> | ||
|
||
- [Требования](#%D0%A2%D1%80%D0%B5%D0%B1%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F) | ||
- [Автор](#%D0%90%D0%B2%D1%82%D0%BE%D1%80) | ||
- [Лицензия](#%D0%9B%D0%B8%D1%86%D0%B5%D0%BD%D0%B7%D0%B8%D1%8F) | ||
|
||
<!-- /MarkdownTOC --> | ||
|
||
<a id="%D0%A2%D1%80%D0%B5%D0%B1%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F"></a> | ||
## Требования | ||
|
||
- PHP >= 7.0. | ||
- Произвольный автозагрузчик классов, реализующий стандарт [PSR-4](https://www.php-fig.org/psr/psr-4/). | ||
|
||
|
||
|
||
|
||
|
||
<a id="%D0%90%D0%B2%D1%82%D0%BE%D1%80"></a> | ||
## Автор | ||
|
||
© 2019-2020 andrey-tech | ||
|
||
<a id="%D0%9B%D0%B8%D1%86%D0%B5%D0%BD%D0%B7%D0%B8%D1%8F"></a> | ||
## Лицензия | ||
|
||
Данная библиотека распространяется на условиях лицензии [MIT](./LICENSE). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,34 @@ | ||
<?php | ||
|
||
/** | ||
* Обработчик исключений к классах пространства имен \App | ||
* | ||
* @author andrey-tech | ||
* @copyright 2019-2020 andrey-tech | ||
* @see https://github.com/andrey-tech/ | ||
* @license MIT | ||
* | ||
* @version 1.0.1 | ||
* | ||
* v1.0.0 (28.05.2019) Начальный релиз | ||
* v1.0.1 (26.06.2019) Изменения для App | ||
* | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace App; | ||
|
||
class AppException extends \Exception | ||
{ | ||
/** | ||
* Добавляет идентификационную строку App: в сообщение об исключении | ||
* @param string $message Сообщение об исключении | ||
* @param int $code Код исключения | ||
* @param \Exception|null $previous Предыдущее исключение | ||
*/ | ||
public function __construct(string $message = '', $code = 0, \Exception $previous = null) | ||
{ | ||
parent::__construct("App: " . $message, $code, $previous); | ||
} | ||
} |
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,103 @@ | ||
<?php | ||
|
||
/** | ||
* Трейт Actibity. Методы для работы с делами в системе Bitrix24. | ||
* | ||
* @author andrey-tech | ||
* @copyright 2019-2020 andrey-tech | ||
* @see https://github.com/andrey-tech/bitrix24-api-php | ||
* @license MIT | ||
* | ||
* @version 1.0.0 | ||
* | ||
* v1.0.0 (02.12.2019) Начальная версия | ||
* | ||
*/ | ||
declare(strict_types = 1); | ||
|
||
namespace App\Bitrix24; | ||
|
||
trait Activity | ||
{ | ||
/** | ||
* Возвращает списoк названий полей активности | ||
* @return array | ||
*/ | ||
public function getActivityFields() | ||
{ | ||
return $this->request('crm.activity.fields'); | ||
} | ||
|
||
/** | ||
* Возвращает активность по ID | ||
* @param int|string $activityId ID активности | ||
* @return array|null | ||
*/ | ||
public function getActivity($activityId) | ||
{ | ||
$activity = $this->request( | ||
'crm.activity.get', | ||
[ | ||
'id' => $activityId | ||
] | ||
); | ||
|
||
return $activity; | ||
} | ||
|
||
/** | ||
* Добавляет активность | ||
* @param array $fields Список полей активности | ||
* @return int | ||
*/ | ||
public function addActivity(array $fields = []) | ||
{ | ||
$result = $this->request( | ||
'crm.activity.add', | ||
[ | ||
'fields' => $fields | ||
] | ||
); | ||
|
||
return $result; | ||
} | ||
|
||
// ------------------------------------------------------------------------ | ||
|
||
/** | ||
* Пакетно добавляет активности | ||
* @param array $activities Массив параметров активностей | ||
* @return array Массив id активностей | ||
*/ | ||
public function addActivities(array $activities = []) :array | ||
{ | ||
// Id добавленных активностей | ||
$activityResults = []; | ||
|
||
while ($activitiesChunk = array_splice($activities, 0, $this->batchSize)) { | ||
// Формируем массив команд на добавление активностей | ||
$commandParams = []; | ||
foreach ($activitiesChunk as $index => $activity) { | ||
$commandParams[ $index ] = [ | ||
'fields' => $activity | ||
]; | ||
} | ||
$commands = $this->buildCommands('crm.activity.add', $commandParams); | ||
$activityResult = $this->batchRequest($commands); | ||
|
||
// Сравниваем число команд и число id в ответе | ||
$sent = count($commandParams); | ||
$received = count($activityResult); | ||
if ($received != $sent) { | ||
$jsonResponse = $this->toJSON($this->lastResponse); | ||
throw new Bitrix24Exception( | ||
"Невозможно пакетно добавить активности ({$sent}/{$received}): {$jsonResponse}" | ||
); | ||
} | ||
|
||
$activityResults = array_merge($activityResults, $activityResult); | ||
} | ||
|
||
return $activityResults; | ||
} | ||
} |
Oops, something went wrong.