Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
6521 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
 
7
use LeadersLinked\Mapper\Common\MapperCommon;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use LeadersLinked\Model\MyCoachQuestionView;
10
use LeadersLinked\Model\MyCoachQuestion;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
use Laminas\Db\Sql\Expression;
13
 
14
 
15
class MyCoachQuestionViewMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_my_coach_question_views';
18
 
19
    /**
20
     *
21
     * @var MyCoachQuestionViewMapper
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 MyCoachQuestionViewMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new MyCoachQuestionViewMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $question_id
50
     * @param int $user_id
51
     * @return MyCoachQuestionView
52
     */
53
    public function fetchOneByQuestionIdAndUserId($question_id, $user_id )
54
    {
55
 
56
        $select = $this->sql->select(self::_TABLE);
57
        $select->where->equalTo('user_id', $user_id);
58
        $select->where->equalTo('question_id', $question_id);
59
 
60
        $prototype = new MyCoachQuestionView();
61
        return $this->executeFetchOneObject($select, $prototype);
62
    }
63
 
64
 
65
 
66
    /**
67
     *
68
     * @param int $question_id
69
     * @return int
70
     */
71
    public function fetchCountByQuestionId($question_id)
72
    {
73
 
74
        $select = $this->sql->select(self::_TABLE);
75
        $select->columns(['total' => new Expression('COUNT(*)') ]);
76
        $select->where->equalTo('question_id', $question_id);
77
 
78
        $record = $this->executeFetchOneArray($select);
79
        return $record['total'];
80
    }
81
 
82
 
83
 
84
 
85
    /**
86
     *
87
     * @param int $question_id
88
     * @return MyCoachQuestionView[]
89
     */
90
    public function fetchAllByQuestionId($question_id)
91
    {
92
 
93
        $select = $this->sql->select(self::_TABLE);
94
        $select->where->equalTo('question_id', $question_id);
95
 
96
 
97
        $prototype = new MyCoachQuestionView();
98
        return $this->executeFetchAllObject($select, $prototype);
99
    }
100
 
101
    /**
102
     *
103
     * @param int $question_id
104
     * @param int $user_id
105
     * @return boolean
106
     */
107
    public function deleteByQuestionIdAndUserId($question_id, $user_id )
108
    {
109
        $delete = $this->sql->delete(self::_TABLE);
110
        $delete->where->equalTo('user_id', $user_id);
111
        $delete->where->equalTo('question_id', $question_id);
112
 
113
        return $this->executeDelete($delete);
114
    }
115
 
116
 
117
    /**
118
     *
119
     * @param int $question_id
120
     * @return boolean
121
     */
122
    public function deleteAllByQuestionId($question_id )
123
    {
124
        $delete = $this->sql->delete(self::_TABLE);
125
        $delete->where->equalTo('question_id', $question_id);
126
 
127
        return $this->executeDelete($delete);
128
    }
129
 
130
 
131
 
132
    /**
133
     *
134
     * @param MyCoachQuestion $record
135
     * @return boolean
136
     */
137
    public function insert($record) {
138
        $hydrator = new ObjectPropertyHydrator();
139
        $values = $hydrator->extract($record);
140
        $values = $this->removeEmpty($values);
141
 
142
        $insert = $this->sql->insert(self::_TABLE);
143
        $insert->values($values);
144
 
145
 
146
        return $this->executeInsert($insert);
147
    }
148
 
149
 
150
}