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\CompanyMicrolearningQuestion;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
 
11
 
12
class CompanyMicrolearningQuestionMapper extends MapperCommon
13
{
14
    const _TABLE = 'tbl_company_microlearning_quiz_questions';
15
 
16
    /**
17
     *
18
     * @var CompanyMicrolearningQuestionMapper
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 CompanyMicrolearningQuestionMapper
35
     */
36
    public static function getInstance($adapter)
37
    {
38
        if(self::$_instance == null) {
39
            self::$_instance = new CompanyMicrolearningQuestionMapper($adapter);
40
        }
41
        return self::$_instance;
42
    }
43
 
44
    /**
45
     *
46
     * @param int $id
47
     * @return CompanyMicrolearningQuestion
48
     */
49
    public function fetchOne($id)
50
    {
51
        $prototype = new CompanyMicrolearningQuestion();
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 CompanyMicrolearningQuestion
63
     */
64
    public function fetchOneByUuid($uuid)
65
    {
66
        $prototype = new CompanyMicrolearningQuestion;
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
     * @param int $quiz_id
76
     * @return CompanyMicrolearningQuestion[]
77
     */
78
    public function fetchAllByQuizId($quiz_id)
79
    {
80
        $prototype = new CompanyMicrolearningQuestion();
81
 
82
        $select = $this->sql->select(self::_TABLE);
83
        $select->where->equalTo('quiz_id', $quiz_id);
84
 
85
        return $this->executeFetchAllObject($select, $prototype);
86
    }
87
 
88
 
89
    /**
90
     *
91
     * @param CompanyMicrolearningQuestion $question
92
     * @return boolean
93
     */
94
    public function insert($question)
95
    {
96
        $hydrator = new ObjectPropertyHydrator();
97
        $values = $hydrator->extract($question);
98
        $values = $this->removeEmpty($values);
99
        $values['maxlength'] = $question->maxlength ? $question->maxlength : 0;
100
 
101
        $insert = $this->sql->insert(self::_TABLE);
102
        $insert->values($values);
103
 
104
 
105
        $result = $this->executeInsert($insert);
106
        if($result) {
107
            $question->id = $this->lastInsertId;
108
        }
109
        return $result;
110
    }
111
 
112
    /**
113
     *
114
     * @param CompanyMicrolearningQuestion $question
115
     * @return boolean
116
     */
117
    public function update($question)
118
    {
119
        $hydrator = new ObjectPropertyHydrator();
120
        $values = $hydrator->extract($question);
121
        $values = $this->removeEmpty($values);
122
        $values['maxlength'] = $question->maxlength ? $question->maxlength : 0;
123
 
124
 
125
        $update = $this->sql->update(self::_TABLE);
126
        $update->set($values);
127
        $update->where->equalTo('id', $question->id);
128
 
129
       // echo $update->getSqlString($this->adapter->platform); exit;
130
 
131
        return $this->executeUpdate($update);
132
    }
133
 
134
    /**
135
     *
136
     * @param CompanyMicrolearningQuestion $question
137
     * @return boolean
138
     */
139
    public function delete($question)
140
    {
141
        $delete = $this->sql->delete(self::_TABLE);
142
        $delete->where->equalTo('id', $question->id);
143
 
144
        return $this->executeDelete($delete);
145
    }
146
 
147
 
148
}