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
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\CompanyMicrolearningQuiz;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
 
11
 
12
class CompanyMicrolearningQuizMapper extends MapperCommon
13
{
14
    const _TABLE = 'tbl_company_microlearning_quizzes';
15
 
16
    /**
17
     *
18
     * @var CompanyMicrolearningQuizMapper
19
     */
20
    private static $_instance;
21
 
22
    /**
23
     *
24
     * @param AdapterInterface $adapter
25
     */
26
    private function __construct($adapter)
27
    {
28
        parent::__construct($adapter);
29
    }
30
 
31
    /**
32
     *
33
     * @param AdapterInterface $adapter
34
     * @return CompanyMicrolearningQuizMapper
35
     */
36
    public static function getInstance($adapter)
37
    {
38
        if(self::$_instance == null) {
39
            self::$_instance = new CompanyMicrolearningQuizMapper ($adapter);
40
        }
41
        return self::$_instance;
42
    }
43
 
44
    /**
45
     *
46
     * @param int $id
47
     * @return CompanyMicrolearningQuiz
48
     */
49
    public function fetchOne($id)
50
    {
51
        $prototype = new CompanyMicrolearningQuiz();
52
 
53
        $select = $this->sql->select(self::_TABLE);
54
        $select->where->equalTo('id', $id);
55
 
56
        return $this->executeFetchOneObject($select, $prototype);
57
    }
58
 
59
    /**
60
     *
61
     * @param int $uuid
62
     * @return CompanyMicrolearningQuiz
63
     */
64
    public function fetchOneByUuid($uuid)
65
    {
66
        $prototype = new CompanyMicrolearningQuiz;
67
        $select = $this->sql->select(self::_TABLE);
68
        $select->where->equalTo('uuid', $uuid);
69
 
70
        return $this->executeFetchOneObject($select, $prototype);
71
    }
72
 
73
 
74
    /**
75
     *
76
     * @param int $company_id
77
     * @return CompanyMicrolearningQuiz[]
78
     */
79
    public function fetchAllActiveAndCheckOkByCompanyId($company_id)
80
    {
81
        $prototype = new CompanyMicrolearningQuiz();
82
 
83
        $select = $this->sql->select(self::_TABLE);
84
        $select->where->equalTo('company_id', $company_id);
85
        $select->where->equalTo('status', CompanyMicrolearningQuiz::STATUS_ACTIVE);
86
        $select->where->equalTo('check', CompanyMicrolearningQuiz::CHECK_OK);
87
        $select->order(['name']);
88
 
89
        return $this->executeFetchAllObject($select, $prototype);
90
    }
91
 
92
 
93
    /**
94
     *
95
     * @param CompanyMicrolearningQuiz $quiz
96
     * @return boolean
97
     */
98
    public function insert($quiz)
99
    {
100
        $hydrator = new ObjectPropertyHydrator();
101
        $values = $hydrator->extract($quiz);
102
        $values = $this->removeEmpty($values);
103
 
104
        $insert = $this->sql->insert(self::_TABLE);
105
        $insert->values($values);
106
 
107
        $result = $this->executeInsert($insert);
108
        if($result) {
109
            $quiz->id = $this->lastInsertId;
110
        }
111
        return $result;
112
    }
113
 
114
    /**
115
     *
116
     * @param CompanyMicrolearningQuiz $quiz
117
     * @return boolean
118
     */
119
    public function update($quiz)
120
    {
121
        $hydrator = new ObjectPropertyHydrator();
122
        $values = $hydrator->extract($quiz);
123
        $values = $this->removeEmpty($values);
124
 
125
 
126
        $update = $this->sql->update(self::_TABLE);
127
        $update->set($values);
128
        $update->where->equalTo('id', $quiz->id);
129
 
130
        return $this->executeUpdate($update);
131
    }
132
 
133
    /**
134
     *
135
     * @param CompanyMicrolearningQuiz $quiz
136
     * @return boolean
137
     */
138
    public function delete($quiz)
139
    {
140
        $delete = $this->sql->delete(self::_TABLE);
141
        $delete->where->equalTo('id', $quiz->id);
142
 
143
        return $this->executeDelete($delete);
144
    }
145
 
146
 
147
}