Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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