Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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