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
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
use LeadersLinked\Mapper\Common\MapperCommon;
7
use Laminas\Db\Adapter\AdapterInterface;
8
use LeadersLinked\Model\CompanyMicrolearningUser;
9
use Laminas\Db\Sql\Expression;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
 
12
 
13
 
14
class CompanyMicrolearningUserMapper extends MapperCommon
15
{
16
    const _TABLE = 'tbl_company_microlearning_users';
17
 
18
    /**
19
     *
20
     * @var CompanyMicrolearningUserMapper
21
     */
22
    private static $_instance;
23
 
24
    /**
25
     *
26
     * @param AdapterInterface $adapter
27
     */
28
    private function __construct($adapter)
29
    {
30
        parent::__construct($adapter);
31
    }
32
 
33
    /**
34
     *
35
     * @param AdapterInterface $adapter
36
     * @return CompanyMicrolearningUserMapper
37
     */
38
    public static function getInstance($adapter)
39
    {
40
        if(self::$_instance == null) {
41
            self::$_instance = new CompanyMicrolearningUserMapper($adapter);
42
        }
43
        return self::$_instance;
44
    }
45
 
46
 
47
    /**
48
     *
49
     * @param int $user_id
50
     * return int
51
     */
52
    public function fetchMaxDateChanges( $user_id )
53
    {
54
        $select = $this->sql->select();
55
        $select->columns(['max' => new Expression('MAX(updated_on)')]);
56
        $select->from(self::_TABLE);
57
        $select->where->equalTo('user_id', $user_id);
58
 
59
        $record = $this->executeFetchOneArray($select);
60
        return $record['max'];
61
    }
62
 
63
    /**
64
     *
65
     * @param int $user_id
66
     * @param int $capsule_id
67
     * return CompanyMicrolearningUser
68
     */
69
    public function fetchOneByUserIdAndCompanyId($user_id, $company_id)
70
    {
71
        $prototype = new CompanyMicrolearningUser();
72
        $select = $this->sql->select();
73
        $select->from(self::_TABLE);
74
        $select->where->equalTo('user_id', $user_id);
75
        $select->where->equalTo('company_id', $company_id);
76
 
77
        return $this->executeFetchOneObject($select, $prototype);
78
    }
79
 
80
 
81
 
82
 
83
    /**
84
     *
85
     * @param CompanyMicrolearningUser $CompanyMicrolearningUser
86
     * @return boolean
87
     */
88
    public function insert($companyMicrolearningUser)
89
    {
90
        $hydrator = new ObjectPropertyHydrator();
91
        $values = $hydrator->extract($companyMicrolearningUser);
92
        unset($values['id']);
93
       // $values = $this->removeEmpty($values);
94
 
95
        $insert = $this->sql->insert(self::_TABLE);
96
        $insert->values($values);
97
 
98
        $response = $this->executeInsert($insert);
99
        if($response) {
100
            $companyMicrolearningUser->id = $this->lastInsertId;
101
        }
102
 
103
        return $response;
104
    }
105
 
106
    /**
107
     *
108
     * @param CompanyMicrolearningUser $CompanyMicrolearningUser
109
     * @return boolean
110
     */
111
    public function update($companyMicrolearningUser)
112
    {
113
        $hydrator = new ObjectPropertyHydrator();
114
        $values = $hydrator->extract($companyMicrolearningUser);
115
        //$values = $this->removeEmpty($values);
116
 
117
        $update = $this->sql->update(self::_TABLE);
118
        $update->set($values);
119
        $update->where->equalTo('id', $companyMicrolearningUser->id);
120
 
121
        return $this->executeUpdate($update);
122
    }
123
 
124
}