Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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