- Модуль: faceid
- Путь к файлу: ~/bitrix/modules/faceid/lib/faceid.php
- Класс: BitrixFaceIdFaceId
- Вызов: FaceId::addInternal
static function addInternal($binaryImageContent, $operation, $faceTableClass, $service = null)
{
// save face locally
$response = array('success' => false, 'result' => array());
/** @var DataManager $faceTableClass */
$addResult = $faceTableClass::add(array('ID' => null));
if ($addResult->isSuccess())
{
$faceId = $addResult->getId();
// save photo locally
$fileId = CFile::SaveFile(array(
'MODULE_ID' => 'faceid',
'name' => 'face_'.$faceId.'.jpg',
'type' => 'image/jpeg',
'content' => $binaryImageContent
), 'faceid');
if (empty($fileId))
{
// rollback
static::rollbackAddInternal($faceId, $faceTableClass);
$response['result']['code'] = static::CODE_FAIL_SAVE_LOCAL_PHOTO;
}
else
{
// save photo to the cloud
$handler = new Http;
$params = array(
'image' => base64_encode($binaryImageContent),
'meta' => 'faceid:'.$faceId
);
if ($service !== null)
{
$params['service'] = $service;
}
$response = $handler->query($operation, $params);
$result = array('added' => false, 'msg' => '');
if ($response['success'])
{
$result = $response['result'];
}
// update balance
if (isset($response['status']['balance']))
{
$currentBalance = (int)$response['status']['balance'];
BitrixMainConfigOption::set('faceid', 'balance', $currentBalance);
}
if (empty($result['added']))
{
static::rollbackAddInternal($faceId, $faceTableClass, $fileId);
}
else
{
// update face with fileID and cloudID
$faceTableClass::update($faceId, array(
'FILE_ID' => $fileId,
'CLOUD_FACE_ID' => $result['face_id']
))->getId();
$response['result']['item'] = array(
'face_id' => $faceId,
'file_id' => $fileId,
'x' => $result['x'],
'y' => $result['y'],
'width' => $result['width'],
'height' => $result['height']
);
// not to confuse with local face id
unset($response['result']['face_id']);
}
}
}
else
{
$response['result']['code'] = static::CODE_FAIL;
}
return $response;
}