Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5835 | Rev 5838 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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