Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4235 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
4235 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
 
7
use LeadersLinked\Mapper\Common\MapperCommon;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use LeadersLinked\Model\DiscoveryContactInteraction;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
use Laminas\Paginator\Paginator;
14
 
15
 
16
class DiscoveryContactInteractionMapper extends MapperCommon
17
{
18
    const _TABLE = 'tbl_discovery_contact_interactions';
19
 
20
    /**
21
     *
22
     * @var DiscoveryContactInteractionMapper
23
     */
24
    private static $_instance;
25
 
26
    /**
27
     *
28
     * @param AdapterInterface $adapter
29
     */
30
    private function __construct($adapter)
31
    {
32
        parent::__construct($adapter);
33
    }
34
 
35
    /**
36
     *
37
     * @param AdapterInterface $adapter
38
     * @return DiscoveryContactInteractionMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new DiscoveryContactInteractionMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /**
49
     *
50
     * @param int $id
51
     * @return DiscoveryContactInteraction
52
     */
53
    public function fetchOne($id)
54
    {
55
 
56
        $select = $this->sql->select(self::_TABLE);
57
        $select->where->equalTo('id', $id);
58
 
59
        $prototype = new DiscoveryContactInteraction();
60
        return $this->executeFetchOneObject($select, $prototype);
61
    }
62
 
63
    /**
64
     *
6330 efrain 65
     * @param int $contact_id
66
     * @param int $interaction_type_id
67
     * @return DiscoveryContactInteraction
68
     */
69
    public function fetchByContactIdAndInteractionTypeId($contact_id, $interaction_type_id)
70
    {
71
 
72
        $select = $this->sql->select(self::_TABLE);
73
        $select->where->equalTo('contact_id', $contact_id);
74
        $select->where->equalTo('interaction_type_id', $interaction_type_id);
75
 
76
 
77
        $prototype = new DiscoveryContactInteraction();
78
        return $this->executeFetchOneObject($select, $prototype);
79
    }
80
 
81
 
82
    /**
83
     *
4235 efrain 84
     * @param string $uuid
85
     * @return DiscoveryContactInteraction
86
     */
87
    public function fetchOneByUuid($uuid)
88
    {
89
 
90
        $select = $this->sql->select(self::_TABLE);
91
        $select->where->equalTo('uuid', $uuid);
92
 
93
        $prototype = new DiscoveryContactInteraction();
94
        return $this->executeFetchOneObject($select, $prototype);
95
    }
96
 
97
    /**
98
     *
99
     * @param int $company_id
100
     * @param int $contact_id
101
     * @param int $page
102
     * @param int $records_per_page
103
     * @return Paginator
104
     */
105
    public function fetchAllDataTableForCompanyIdAndContactId($company_id, $contact_id,  $page = 1, $records_per_page = 10)
106
    {
107
        $prototype = new DiscoveryContactInteraction();
108
        $select = $this->sql->select(self::_TABLE);
109
        $select->where->equalTo('company_id', $company_id);
110
        $select->where->equalTo('contact_id', $contact_id);
111
        $select->order('added_on DESC');
112
 
113
        $hydrator   = new ObjectPropertyHydrator();
114
        $resultset  = new HydratingResultSet($hydrator, $prototype);
115
 
116
        $adapter = new DbSelect($select, $this->sql, $resultset);
117
        $paginator = new Paginator( $adapter);
118
        $paginator->setItemCountPerPage($records_per_page);
119
        $paginator->setCurrentPageNumber($page);
120
 
121
 
122
        return $paginator;
123
    }
124
 
125
 
126
    /**
127
     *
128
     * @param DiscoveryContactInteraction $record
129
     * @return boolean
130
     */
131
    public function insert($record)
132
    {
133
        $hydrator = new ObjectPropertyHydrator();
134
        $values = $hydrator->extract($record);
135
        $values = $this->removeEmpty($values);
136
 
137
        $insert = $this->sql->insert(self::_TABLE);
138
        $insert->values($values);
139
        $result = $this->executeInsert($insert);
140
 
141
        if($result) {
142
            $record->id = $this->lastInsertId;
143
        }
144
 
145
        return $result;
146
    }
147
 
148
 
6330 efrain 149
    /**
150
     *
151
     * @param array $values
152
     * @return boolean
153
     */
154
    public function insertRaw($values)
155
    {
156
        $insert = $this->sql->insert(self::_TABLE);
157
        $insert->values($values);
158
        return $this->executeInsert($insert);
159
 
160
    }
4235 efrain 161
 
162
 
163
 
164
    /**
165
     *
166
     * @param DiscoveryContactInteraction $record
167
     * @return boolean
168
     */
169
    public function delete($record)
170
    {
171
        $delete = $this->sql->delete(self::_TABLE);
172
        $delete->where->equalTo('id', $record->id);
173
 
174
        return $this->executeDelete($delete);
175
 
176
    }
177
 
178
 
179
}