Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Ir a la última revisión | | 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
     *
65
     * @param string $uuid
66
     * @return DiscoveryContactInteraction
67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
70
 
71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('uuid', $uuid);
73
 
74
        $prototype = new DiscoveryContactInteraction();
75
        return $this->executeFetchOneObject($select, $prototype);
76
    }
77
 
78
    /**
79
     *
80
     * @param int $company_id
81
     * @param int $contact_id
82
     * @param int $page
83
     * @param int $records_per_page
84
     * @return Paginator
85
     */
86
    public function fetchAllDataTableForCompanyIdAndContactId($company_id, $contact_id,  $page = 1, $records_per_page = 10)
87
    {
88
        $prototype = new DiscoveryContactInteraction();
89
        $select = $this->sql->select(self::_TABLE);
90
        $select->where->equalTo('company_id', $company_id);
91
        $select->where->equalTo('contact_id', $contact_id);
92
        $select->order('added_on DESC');
93
 
94
        $hydrator   = new ObjectPropertyHydrator();
95
        $resultset  = new HydratingResultSet($hydrator, $prototype);
96
 
97
        $adapter = new DbSelect($select, $this->sql, $resultset);
98
        $paginator = new Paginator( $adapter);
99
        $paginator->setItemCountPerPage($records_per_page);
100
        $paginator->setCurrentPageNumber($page);
101
 
102
 
103
        return $paginator;
104
    }
105
 
106
 
107
    /**
108
     *
109
     * @param DiscoveryContactInteraction $record
110
     * @return boolean
111
     */
112
    public function insert($record)
113
    {
114
        $hydrator = new ObjectPropertyHydrator();
115
        $values = $hydrator->extract($record);
116
        $values = $this->removeEmpty($values);
117
 
118
        $insert = $this->sql->insert(self::_TABLE);
119
        $insert->values($values);
120
        $result = $this->executeInsert($insert);
121
 
122
        if($result) {
123
            $record->id = $this->lastInsertId;
124
        }
125
 
126
        return $result;
127
    }
128
 
129
 
130
 
131
 
132
 
133
 
134
    /**
135
     *
136
     * @param DiscoveryContactInteraction $record
137
     * @return boolean
138
     */
139
    public function delete($record)
140
    {
141
        $delete = $this->sql->delete(self::_TABLE);
142
        $delete->where->equalTo('id', $record->id);
143
 
144
        return $this->executeDelete($delete);
145
 
146
    }
147
 
148
 
149
}