Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6282 | Rev 6284 | 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
    {
6283 anderson 66
        $select = $this->sql->select(self::_TABLE);
5845 anderson 67
        $select->columns([
5847 anderson 68
            'added_on',
5857 anderson 69
            //'activity' => new Expression('SUM(LABEL_RECORD_CONTACT_ADDED)'),
5850 anderson 70
            'user_id' => new Expression('COUNT(user_id)')
5845 anderson 71
        ]);
5858 anderson 72
        //$select->where->equalTo('user_id', $user_id);
5838 anderson 73
        $select->where->between('added_on', $start_date, $end_date);
74
        $select->where->equalTo('activity', 'LABEL_RECORD_CONTACT_ADDED');
75
        $select->group('added_on');
76
        $select->order('added_on ASC');
77
 
78
        //echo $select->getSqlString($this->adapter->platform); exit;
79
 
80
 
81
        return $this->executeFetchAllArray($select);
82
    }
83
 
5836 anderson 84
    /**
85
     *
4235 efrain 86
     * @param int $id
87
     * @return DiscoveryContactLogMapper
88
     */
89
    public function fetchOne($id)
90
    {
5833 anderson 91
 
4235 efrain 92
        $select = $this->sql->select(self::_TABLE);
93
        $select->where->equalTo('id', $id);
5833 anderson 94
 
4235 efrain 95
        $prototype = new DiscoveryContactLog();
96
        return $this->executeFetchOneObject($select, $prototype);
97
    }
5833 anderson 98
 
4235 efrain 99
    /**
100
     *
101
     * @param string $uuid
102
     * @return DiscoveryContactLogMapper
103
     */
104
    public function fetchOneByUuid($uuid)
105
    {
5833 anderson 106
 
4235 efrain 107
        $select = $this->sql->select(self::_TABLE);
108
        $select->where->equalTo('uuid', $uuid);
5833 anderson 109
 
4235 efrain 110
        $prototype = new DiscoveryContactLog();
111
        return $this->executeFetchOneObject($select, $prototype);
112
    }
5833 anderson 113
 
4235 efrain 114
    /**
115
     *
116
     * @param int $company_id
117
     * @param int $contact_id
118
     * @param int $page
119
     * @param int $records_per_page
120
     * @return Paginator
121
     */
122
    public function fetchAllDataTableForCompanyIdAndContactId($company_id, $contact_id,  $page = 1, $records_per_page = 10)
123
    {
124
        $prototype = new DiscoveryContactLog();
125
        $select = $this->sql->select(self::_TABLE);
126
        $select->where->equalTo('company_id', $company_id);
127
        $select->where->equalTo('contact_id', $contact_id);
128
        $select->order('added_on DESC');
5833 anderson 129
 
4235 efrain 130
        $hydrator   = new ObjectPropertyHydrator();
131
        $resultset  = new HydratingResultSet($hydrator, $prototype);
5833 anderson 132
 
4235 efrain 133
        $adapter = new DbSelect($select, $this->sql, $resultset);
5833 anderson 134
        $paginator = new Paginator($adapter);
4235 efrain 135
        $paginator->setItemCountPerPage($records_per_page);
136
        $paginator->setCurrentPageNumber($page);
5833 anderson 137
 
138
 
4235 efrain 139
        return $paginator;
140
    }
5833 anderson 141
 
142
 
4235 efrain 143
    /**
144
     *
145
     * @param DiscoveryContactLog $record
146
     * @return boolean
147
     */
148
    public function insert($record)
149
    {
150
        $hydrator = new ObjectPropertyHydrator();
151
        $values = $hydrator->extract($record);
152
        $values = $this->removeEmpty($values);
5833 anderson 153
 
4235 efrain 154
        $insert = $this->sql->insert(self::_TABLE);
155
        $insert->values($values);
156
        $result = $this->executeInsert($insert);
5833 anderson 157
 
158
        if ($result) {
4235 efrain 159
            $record->id = $this->lastInsertId;
160
        }
5833 anderson 161
 
4235 efrain 162
        return $result;
163
    }
164
 
5833 anderson 165
 
166
 
167
 
168
 
169
 
4235 efrain 170
    /**
171
     *
172
     * @param DiscoveryContactLog $record
173
     * @return boolean
174
     */
175
    public function delete($record)
176
    {
177
        $delete = $this->sql->delete(self::_TABLE);
178
        $delete->where->equalTo('id', $record->id);
5833 anderson 179
 
4235 efrain 180
        return $this->executeDelete($delete);
181
    }
5833 anderson 182
}