Issues (3627)

PluginBundle/Model/IntegrationEntityModel.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\PluginBundle\Model;
13
14
use Mautic\CoreBundle\Model\FormModel;
15
use Mautic\PluginBundle\Entity\IntegrationEntity;
16
use Mautic\PluginBundle\Integration\IntegrationObject;
17
18
/**
19
 * Class IntegrationEntityModel.
20
 */
21
class IntegrationEntityModel extends FormModel
22
{
23
    public function getIntegrationEntityRepository()
24
    {
25
        return $this->em->getRepository(IntegrationEntity::class);
26
    }
27
28
    public function logDataSync(IntegrationObject $integrationObject)
0 ignored issues
show
The parameter $integrationObject is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
    public function logDataSync(/** @scrutinizer ignore-unused */ IntegrationObject $integrationObject)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
    }
31
32
    public function getSyncedRecords(IntegrationObject $integrationObject, $integrationName, $recordList, $internalEntityId = null)
33
    {
34
        if (!$formattedRecords = $this->formatListOfContacts($recordList)) {
35
            return [];
36
        }
37
38
        $integrationEntityRepo = $this->getIntegrationEntityRepository();
39
40
        return $integrationEntityRepo->getIntegrationsEntityId(
41
            $integrationName,
42
            $integrationObject->getType(),
43
            $integrationObject->getInternalType(),
44
            $internalEntityId,
45
            null,
46
            null,
47
            false,
48
            0,
49
            0,
50
            $formattedRecords
51
        );
52
    }
53
54
    public function getRecordList($integrationObject)
55
    {
56
        $recordList = [];
57
58
        foreach ($integrationObject->getRecords() as $record) {
59
            $recordList[$record['Id']] = [
60
                'id' => $record['Id'],
61
            ];
62
        }
63
64
        return $recordList;
65
    }
66
67
    public function formatListOfContacts($recordList)
68
    {
69
        if (empty($recordList)) {
70
            return null;
71
        }
72
73
        $csList = is_array($recordList) ? implode('", "', array_keys($recordList)) : $recordList;
74
75
        return '"'.$csList.'"';
76
    }
77
78
    public function getMauticContactsById($mauticContactIds, $integrationName, $internalObject)
79
    {
80
        if (!$formattedRecords = $this->formatListOfContacts($mauticContactIds)) {
81
            return [];
82
        }
83
        $integrationEntityRepo = $this->getIntegrationEntityRepository();
84
85
        return $integrationEntityRepo->getIntegrationsEntityId(
86
            $integrationName,
87
            null,
88
            $internalObject,
89
            null,
90
            null,
91
            null,
92
            false,
93
            0,
94
            0,
95
            $formattedRecords
96
        );
97
    }
98
99
    /**
100
     * @param int $id
101
     *
102
     * @return IntegrationEntity|null
103
     */
104
    public function getEntityByIdAndSetSyncDate($id, \DateTime $dateTime)
105
    {
106
        $entity = $this->getIntegrationEntityRepository()->find($id);
107
        if ($entity) {
108
            $entity->setLastSyncDate($dateTime);
109
        }
110
111
        return $entity;
112
    }
113
}
114