Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\Pipedrive\Gateway;
|
||||
|
||||
use Xentral\Components\Database\Database;
|
||||
use Xentral\Modules\Pipedrive\Exception\PipedriveConfigurationException;
|
||||
use Xentral\Modules\Pipedrive\Service\PipedriveConfigurationService;
|
||||
|
||||
final class PipedriveContactGateway
|
||||
{
|
||||
/** @var Database $db */
|
||||
private $db;
|
||||
|
||||
/** @var PipedriveConfigurationService $configurationService */
|
||||
private $configurationService;
|
||||
|
||||
/**
|
||||
* @param Database $db
|
||||
* @param PipedriveConfigurationService $configurationService
|
||||
*/
|
||||
public function __construct(Database $db, PipedriveConfigurationService $configurationService)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->configurationService = $configurationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pdContactId Pipedrive contact ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMappingByPipedriveId(int $pdContactId): array
|
||||
{
|
||||
return $this->db->fetchRow(
|
||||
'SELECT
|
||||
p.id,
|
||||
p.created_at,
|
||||
p.data,
|
||||
p.address_id
|
||||
FROM `pipedrive_contacts` AS `p`
|
||||
WHERE p.hidden = 0 AND p.pd_contact_id = :id',
|
||||
['id' => $pdContactId]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $addressId Xentral Address ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMappingByAddressId(int $addressId): array
|
||||
{
|
||||
return $this->db->fetchRow(
|
||||
'SELECT
|
||||
p.id,
|
||||
p.created_at,
|
||||
p.data,
|
||||
p.pd_contact_id
|
||||
FROM `pipedrive_contacts` AS `p`
|
||||
WHERE p.hidden = 0 AND p.address_id = :id',
|
||||
['id' => $addressId]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $addressId
|
||||
* @param bool $withStatusField
|
||||
*
|
||||
* @throws PipedriveConfigurationException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInternalAddressById(int $addressId, bool $withStatusField = false): array
|
||||
{
|
||||
$placeHolder = '';
|
||||
if ($withStatusField === true) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$leadFields = $this->configurationService->matchSelectedAddressFreeField();
|
||||
$lsField = $leadFields['pipedrive_ls_field'];
|
||||
$placeHolder = ", a.{$lsField}";
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
$sql = 'SELECT
|
||||
a.id,
|
||||
a.lead,
|
||||
a.typ,
|
||||
a.sprache,
|
||||
a.name,
|
||||
a.vorname,
|
||||
a.nachname,
|
||||
a.land,
|
||||
a.ort,
|
||||
a.plz,
|
||||
a.bundesstaat,
|
||||
a.telefon,
|
||||
a.email %s
|
||||
FROM `adresse` AS `a`
|
||||
WHERE a.geloescht = 0 AND a.id = :id';
|
||||
|
||||
return $this->db->fetchRow(sprintf($sql, $placeHolder), ['id' => $addressId]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\Pipedrive\Gateway;
|
||||
|
||||
use Xentral\Components\Database\Database;
|
||||
|
||||
final class PipedriveDealGateway
|
||||
{
|
||||
/** @var Database $db */
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* @param Database $db
|
||||
*/
|
||||
public function __construct(Database $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pdDealId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDealByPipedriveId(int $pdDealId): array
|
||||
{
|
||||
return $this->db->fetchRow(
|
||||
'SELECT
|
||||
d.id,
|
||||
d.created_at,
|
||||
d.data,
|
||||
d.wiedervorlage_id
|
||||
FROM `pipedrive_deals` AS `d`
|
||||
WHERE d.hidden = 0 AND d.pd_deal_id = :id',
|
||||
['id' => $pdDealId]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $resubmissionId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDealByResubmissionId(int $resubmissionId): array
|
||||
{
|
||||
return $this->db->fetchRow(
|
||||
'SELECT
|
||||
d.id,
|
||||
d.created_at,
|
||||
d.data,
|
||||
d.wiedervorlage_id,
|
||||
d.pd_deal_id
|
||||
FROM `pipedrive_deals` AS `d`
|
||||
WHERE d.hidden = 0 AND d.wiedervorlage_id = :id',
|
||||
['id' => $resubmissionId]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $stageId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMappingStageByResubmissionStageId(int $stageId): array
|
||||
{
|
||||
return $this->db->fetchRow(
|
||||
'SELECT
|
||||
pm.id,
|
||||
pm.created_at,
|
||||
pm.wiedervorlage_stage_id,
|
||||
pm.label,
|
||||
pm.value,
|
||||
pm.wiedervorlage_view_id,
|
||||
pm.type
|
||||
FROM `pipedrive_mappings` AS `pm`
|
||||
WHERE pm.wiedervorlage_stage_id=:resubmission_id AND pm.type =:type',
|
||||
['resubmission_id' => $stageId, 'type' => 'deals']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Xentral\Modules\Pipedrive\Gateway;
|
||||
|
||||
use Xentral\Components\Database\Database;
|
||||
|
||||
final class PipedrivePersonPropertyGateway
|
||||
{
|
||||
/** @var Database $db */
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* @param Database $db
|
||||
*/
|
||||
public function __construct(Database $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @param bool $isSystem
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLeadsByType(string $type, bool $isSystem = false): array
|
||||
{
|
||||
return $this->db->fetchAssoc(
|
||||
'SELECT
|
||||
p.id,
|
||||
p.created_at,
|
||||
p.label,
|
||||
p.value,
|
||||
p.type,
|
||||
p.wiedervorlage_stage_id
|
||||
FROM `pipedrive_mappings` AS `p` WHERE p.type = :type AND p.is_system=:system',
|
||||
['type' => $type, 'system' => (int)$isSystem]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
* @param string $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMappingByValueAndType(int $value, string $type): array
|
||||
{
|
||||
return $this->db->fetchRow(
|
||||
'SELECT
|
||||
hm.id,
|
||||
hm.created_at,
|
||||
hm.wiedervorlage_stage_id,
|
||||
hm.label,
|
||||
hm.value,
|
||||
hm.type
|
||||
FROM `pipedrive_mappings` AS `hm`
|
||||
WHERE hm.value =:value AND hm.type = :type',
|
||||
['value' => $value, 'type' => $type]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dbName
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressFreeFields(string $dbName): array
|
||||
{
|
||||
return $this->db->fetchCol(
|
||||
'SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS`
|
||||
WHERE `TABLE_SCHEMA` =:db AND `TABLE_NAME` = :table AND `COLUMN_NAME` LIKE "adressefreifeld%"',
|
||||
[
|
||||
'db' => $dbName,
|
||||
'table' => 'firmendaten',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getConfiguredFreeAddressFieldValues(): array
|
||||
{
|
||||
return $this->db->fetchCol(
|
||||
'SELECT f.wert FROM `firmendaten_werte` AS `f`
|
||||
WHERE `name` LIKE "adressetabellezusatz%" AND f.wert !="" AND f.wert IS NOT NULL'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user