| 1 |
efrain |
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 $visited_id
|
|
|
84 |
* @return int
|
|
|
85 |
*/
|
|
|
86 |
public function getTotalByVisitedIdGroupVisitorId($visited_id)
|
|
|
87 |
{
|
|
|
88 |
$select = $this->sql->select(self::_TABLE);
|
|
|
89 |
$select->columns(['total' => new Expression('COUNT(DISTINCT(visitor_id))')]);
|
|
|
90 |
$select->where->equalTo('visited_id', $visited_id);
|
|
|
91 |
// $select->group('visitor_id');
|
|
|
92 |
|
|
|
93 |
//echo $select->getSqlString($this->adapter->platform);
|
|
|
94 |
//exit;
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
$record = $this->executeFetchOneArray($select);
|
|
|
98 |
|
|
|
99 |
return $record['total'];
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
/**
|
|
|
103 |
*
|
|
|
104 |
* @param int $visitor_id
|
|
|
105 |
* @param string $visited_on
|
|
|
106 |
* @return ProfileVisit
|
|
|
107 |
*/
|
|
|
108 |
public function fetchOneByVisitorIdAndVisitedOn($visitor_id, $visited_on)
|
|
|
109 |
{
|
|
|
110 |
$prototype = new ProfileVisit();
|
|
|
111 |
|
|
|
112 |
$select = $this->sql->select(self::_TABLE);
|
|
|
113 |
$select->where->equalTo('visitor_id', $visitor_id);
|
|
|
114 |
$select->where->equalTo('visited_on', $visited_on);
|
|
|
115 |
|
|
|
116 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
/**
|
|
|
120 |
*
|
|
|
121 |
* @param int $visitor_id
|
|
|
122 |
* @param int $visited_id
|
|
|
123 |
* @param string $visited_on
|
|
|
124 |
* @return ProfileVisit
|
|
|
125 |
*/
|
|
|
126 |
public function fetchOneByVisitorIdAndVisitedIdAndVisitedOn($visitor_id, $visited_id, $visited_on)
|
|
|
127 |
{
|
|
|
128 |
$prototype = new ProfileVisit();
|
|
|
129 |
|
|
|
130 |
$select = $this->sql->select(self::_TABLE);
|
|
|
131 |
$select->where->equalTo('visitor_id', $visitor_id);
|
|
|
132 |
$select->where->equalTo('visited_id', $visited_id);
|
|
|
133 |
$select->where->equalTo('visited_on', $visited_on);
|
|
|
134 |
|
|
|
135 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
}
|