Your IP : 18.118.93.246
<?php
namespace Webprofy\CRM;
defined('B_PROLOG_INCLUDED') and (B_PROLOG_INCLUDED === true) or die();
use Bitrix\Main\Entity\DataManager;
use Bitrix\Main\Localization\Loc;
Loc::loadMessages(__FILE__);
/**
* Class SettingsTable
* @package Webprofy\CRM
*/
class SettingsTable extends DataManager
{
/**
* @return string
*/
public static function getTableName()
{
return 'webprofy_crm_settings';
}
/**
* @return array
*/
public static function getMap()
{
return array(
'ID' => array(
'data_type' => 'integer',
'primary' => true,
'autocomplete' => true,
'title' => "",
),
'CLIENT_ID' => array(
'data_type' => 'string',
'title' => "",
'required' => false,
),
'CLIENT_SECRET' => array(
'data_type' => 'string',
'title' => '',
'required' => false,
),
'PORTAL_URI' => array(
'data_type' => 'string',
'title' => '',
'required' => false,
),
'ACCESS_TOKEN' => array(
'data_type' => 'string',
'title' => '',
'required' => false,
),
'REFRESH_TOKEN' => array(
'data_type' => 'string',
'title' => '',
'required' => false,
),
);
}
/**
* @return mixed
*/
public static function getAuthCode()
{
$result = self::getList(array('select'=>array('ACCESS_TOKEN')))->fetch();
return $result['ACCESS_TOKEN'];
}
/**
* @param $code
* @return array|bool
*/
public static function setAuthCode($code)
{
return self::updateSettings(array('ACCESS_TOKEN' => $code));
}
/**
* @return mixed
*/
protected static function getRecordID()
{
$result = self::getList(array('select'=>array('ID')))->fetch();
return $result['ID'];
}
/**
* @param $arData
* @param bool $id
* @return array|bool
*/
public static function updateSettings($arData, $id = false)
{
if(empty($arData)){
return;
}
if(!$id){
$id = self::getRecordID();
}
$result = self::update($id, $arData);
if($result->isSuccess()){
return true;
}
return $result->getErrorMessages();
}
public static function getData()
{
return self::getList(array('select'=>array('*')))->fetch();
}
}