Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | | Comparar con el anterior | 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;
192 efrain 10
use Laminas\Db\ResultSet\HydratingResultSet;
11
use Laminas\Paginator\Adapter\DbSelect;
12
use Laminas\Paginator\Paginator;
1 www 13
 
14
 
15
class CompanyMicrolearningQuestionMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_company_microlearning_quiz_questions';
18
 
19
    /**
20
     *
21
     * @var CompanyMicrolearningQuestionMapper
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 CompanyMicrolearningQuestionMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new CompanyMicrolearningQuestionMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
50
     * @return CompanyMicrolearningQuestion
51
     */
52
    public function fetchOne($id)
53
    {
54
        $prototype = new CompanyMicrolearningQuestion();
55
 
56
        $select = $this->sql->select(self::_TABLE);
57
        $select->where->equalTo('id', $id);
58
 
59
        return $this->executeFetchOneObject($select, $prototype);
60
    }
61
 
62
    /**
63
     *
64
     * @param int $uuid
65
     * @return CompanyMicrolearningQuestion
66
     */
67
    public function fetchOneByUuid($uuid)
68
    {
69
        $prototype = new CompanyMicrolearningQuestion;
70
        $select = $this->sql->select(self::_TABLE);
71
        $select->where->equalTo('uuid', $uuid);
72
 
73
        return $this->executeFetchOneObject($select, $prototype);
74
    }
75
 
76
    /**
77
     *
78
     * @param int $quiz_id
79
     * @return CompanyMicrolearningQuestion[]
80
     */
81
    public function fetchAllByQuizId($quiz_id)
82
    {
83
        $prototype = new CompanyMicrolearningQuestion();
84
 
85
        $select = $this->sql->select(self::_TABLE);
86
        $select->where->equalTo('quiz_id', $quiz_id);
87
 
88
        return $this->executeFetchAllObject($select, $prototype);
89
    }
192 efrain 90
 
91
    /**
92
     *
93
     * @param int $companyId
94
     * @param int $quizId
95
     * @param string $search
96
     * @param int $page
97
     * @param int $records_per_page
98
     * @param string $order_field
99
     * @param string $order_direction
100
     * @return Paginator
101
     *
102
     */
103
    public function fetchAllDataTableByCompanyIdAndQuizId($companyId, $quizId, $search, $page = 1, $records_per_page = 10, $order_field= 'text', $order_direction = 'ASC')
104
    {
105
        $prototype = new CompanyMicrolearningQuestion();
106
 
107
        $select = $this->sql->select(self::_TABLE);
108
        $select->where->equalTo('company_id', $companyId);
109
        $select->where->equalTo('quiz_id', $quizId);
110
 
111
 
112
        if($search) {
113
            $select->where->like('text', '%' . $search . '%');
114
        }
115
        $select->order($order_field . ' ' . $order_direction);
116
 
117
        //echo $select->getSqlString($this->adapter->platform); exit;
118
 
119
        $hydrator   = new ObjectPropertyHydrator();
120
        $resultset  = new HydratingResultSet($hydrator, $prototype);
121
 
122
        $adapter = new DbSelect($select, $this->sql, $resultset);
123
        $paginator = new Paginator($adapter);
124
        $paginator->setItemCountPerPage($records_per_page);
125
        $paginator->setCurrentPageNumber($page);
126
 
127
 
128
        return $paginator;
129
    }
1 www 130
 
131
 
132
    /**
133
     *
134
     * @param CompanyMicrolearningQuestion $question
135
     * @return boolean
136
     */
137
    public function insert($question)
138
    {
139
        $hydrator = new ObjectPropertyHydrator();
140
        $values = $hydrator->extract($question);
141
        $values = $this->removeEmpty($values);
142
        $values['maxlength'] = $question->maxlength ? $question->maxlength : 0;
143
 
144
        $insert = $this->sql->insert(self::_TABLE);
145
        $insert->values($values);
146
 
147
 
148
        $result = $this->executeInsert($insert);
149
        if($result) {
150
            $question->id = $this->lastInsertId;
151
        }
152
        return $result;
153
    }
154
 
155
    /**
156
     *
157
     * @param CompanyMicrolearningQuestion $question
158
     * @return boolean
159
     */
160
    public function update($question)
161
    {
162
        $hydrator = new ObjectPropertyHydrator();
163
        $values = $hydrator->extract($question);
164
        $values = $this->removeEmpty($values);
165
        $values['maxlength'] = $question->maxlength ? $question->maxlength : 0;
166
 
167
 
168
        $update = $this->sql->update(self::_TABLE);
169
        $update->set($values);
170
        $update->where->equalTo('id', $question->id);
171
 
172
       // echo $update->getSqlString($this->adapter->platform); exit;
173
 
174
        return $this->executeUpdate($update);
175
    }
176
 
177
    /**
178
     *
179
     * @param CompanyMicrolearningQuestion $question
180
     * @return boolean
181
     */
182
    public function delete($question)
183
    {
184
        $delete = $this->sql->delete(self::_TABLE);
185
        $delete->where->equalTo('id', $question->id);
186
 
187
        return $this->executeDelete($delete);
188
    }
189
 
190
 
191
}