Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| 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\CompanyFollower;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Log\LoggerInterface;
10
use LeadersLinked\Mapper\Common\MapperCommon;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
use Laminas\Db\Sql\Expression;
13
 
14
class CompanyFollowerMapper extends MapperCommon
15
{
16
    const _TABLE = 'tbl_company_followers';
17
 
18
 
19
    /**
20
     *
21
     * @var CompanyFollowerMapper
22
     */
23
    private static $_instance;
24
 
25
    /**
26
     *
27
     * @param AdapterInterface $adapter
28
     */
29
    private function __construct($adapter)
30
    {
31
        parent::__construct($adapter);
32
    }
33
 
34
    /**
35
     *
36
     * @param AdapterInterface $adapter
37
     * @return CompanyFollowerMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new CompanyFollowerMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
 
48
    /**
49
     *
50
     * @param int $user_id
51
     * @return int
52
     */
53
    public function getCountFollowers($company_id)
54
    {
55
        $select = $this->sql->select(self::_TABLE);
56
        $select->columns(['total' => new Expression('COUNT(*)')]);
57
        $select->where->equalTo('company_id', $company_id);
58
 
59
        $record = $this->executeFetchOneArray($select);
60
        return $record['total'];
61
    }
62
 
63
 
64
    /**
65
     *
66
     * @param int $user_id
67
     * @return int
68
     */
69
    public function getCountFollowing($follower_id)
70
    {
71
        $select = $this->sql->select(self::_TABLE);
72
        $select->columns(['total' => new Expression('COUNT(*)')]);
73
        $select->where->equalTo('follower_id', $follower_id);
74
 
75
        $record = $this->executeFetchOneArray($select);
76
        return $record['total'];
77
    }
78
 
79
    /**
80
     *
81
     * @param int $follower_id
82
     * @return CompanyFollower[]
83
     */
84
    public function fetchAllByFollowerId($follower_id)
85
    {
86
        $prototype = new CompanyFollower();
87
 
88
        $select = $this->sql->select(self::_TABLE);
89
        $select->where->equalTo('follower_id', $follower_id);
90
 
91
        return $this->executeFetchAllObject($select, $prototype);
92
    }
93
 
94
 
95
 
96
    /**
97
     *
98
     * @param int $company_id
99
     * @return CompanyFollower[]
100
     */
101
    public function fetchAllByCompanyId($company_id)
102
    {
103
        $prototype = new CompanyFollower();
104
 
105
        $select = $this->sql->select(self::_TABLE);
106
        $select->where->equalTo('company_id', $company_id);
107
 
108
        return $this->executeFetchAllObject($select, $prototype);
109
    }
110
 
111
 
112
 
113
    /**
114
     *
115
     * @param int $company_id
116
     * @param int $user_id
117
     * @return CompanyFollower
118
     */
119
    public function fetchOneByCompanyIdAndUserId($company_id, $user_id)
120
    {
121
        $select = $this->sql->select(self::_TABLE);
122
        $select->where->equalTo('company_id', $company_id)->and->equalTo('follower_id', $user_id);
123
 
124
        $prototype = new CompanyFollower();
125
        return $this->executeFetchOneObject($select, $prototype);
126
 
127
    }
128
 
129
    /**
130
     *
131
     * @param int $company_id
132
     * @param int $user_id
133
     * @return boolean
134
     */
135
    public function deleteByCompanyIdAndUserId($company_id, $user_id)
136
    {
137
        $delete = $this->sql->delete(self::_TABLE);
138
        $delete->where->equalTo('company_id', $company_id)->and->equalTo('follower_id', $user_id);
139
 
140
        return $this->executeDelete($delete);
141
 
142
    }
143
 
144
    /**
145
     *
146
     * @param CompanyFollower $companyFollower
147
     * @return boolean
148
     */
149
    public function insert($companyFollower)
150
    {
151
        $hydrator = new ObjectPropertyHydrator();
152
        $values = $hydrator->extract($companyFollower);
153
        $values = $this->removeEmpty($values);
154
 
155
        $insert = $this->sql->insert(self::_TABLE);
156
        $insert->values($values);
157
 
158
        return $this->executeInsert($insert);
159
 
160
 
161
 
162
 
163
    }
164
 
165
}