Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
use LeadersLinked\Model\ProfileVisit;
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\Db\Sql\Expression;
12
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
13
 
14
 
15
class ProfileVisitMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_profile_visits';
18
 
19
 
20
    /**
21
     *
22
     * @var ProfileVisitMapper
23
     */
24
    private static $_instance;
25
 
26
    /**
27
     *
28
     * @param AdapterInterface $adapter
29
     */
30
    private function __construct($adapter)
31
    {
32
        parent::__construct($adapter);
33
    }
34
 
35
    /**
36
     *
37
     * @param AdapterInterface $adapter
38
     * @return \LeadersLinked\Mapper\ProfileVisitMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new ProfileVisitMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /**
49
     *
50
     * @param ProfileVisit $profileVisit
51
     * @return boolean
52
     */
53
    public function insert($profileVisit)
54
    {
55
        $hydrator = new ObjectPropertyHydrator();
56
        $values = $hydrator->extract($profileVisit);
57
        $values = $this->removeEmpty($values);
58
 
59
        $insert = $this->sql->insert(self::_TABLE);
60
        $insert-> values($values);
61
 
62
        return $this->executeInsert($insert);
63
    }
64
 
65
    /**
66
     *
67
     * @param int $visited_id
68
     * @return int
69
     */
70
    public function getTotalByVisitedId($visited_id)
71
    {
72
        $select = $this->sql->select(self::_TABLE);
73
        $select->columns(['total' => new Expression('COUNT(*)')]);
74
        $select->where->equalTo('visited_id', $visited_id);
75
 
76
        $record = $this->executeFetchOneArray($select);
77
 
78
        return $record['total'];
79
    }
80
 
81
    /**
82
     *
83
     * @param int $visitor_id
84
     * @param string $visited_on
85
     * @return  ProfileVisit
86
     */
87
    public function fetchOneByVisitorIdAndVisitedOn($visitor_id, $visited_on)
88
    {
89
        $prototype = new ProfileVisit();
90
 
91
        $select = $this->sql->select(self::_TABLE);
92
        $select->where->equalTo('visitor_id', $visitor_id);
93
        $select->where->equalTo('visited_on', $visited_on);
94
 
95
       return $this->executeFetchOneObject($select, $prototype);
96
    }
97
 
98
    /**
99
     *
100
     * @param int $visitor_id
101
     * @param int $visited_id
102
     * @param string $visited_on
103
     * @return  ProfileVisit
104
     */
105
    public function fetchOneByVisitorIdAndVisitedIdAndVisitedOn($visitor_id, $visited_id, $visited_on)
106
    {
107
        $prototype = new ProfileVisit();
108
 
109
        $select = $this->sql->select(self::_TABLE);
110
        $select->where->equalTo('visitor_id', $visitor_id);
111
        $select->where->equalTo('visited_id', $visited_id);
112
        $select->where->equalTo('visited_on', $visited_on);
113
 
114
        return $this->executeFetchOneObject($select, $prototype);
115
    }
116
 
117
}