Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 280 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
279 efrain 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\CompanyMicrolearningCapsuleComment;
9
use Laminas\Db\Sql\Expression;
10
use Laminas\Paginator\Paginator;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
use Laminas\Db\ResultSet\HydratingResultSet;
13
use Laminas\Paginator\Adapter\DbSelect;
14
 
15
 
16
 
17
class CompanyMicrolearningCapsuleCommentMapper extends MapperCommon
18
{
19
    const _TABLE = 'tbl_company_microlearning_capsule_comments';
20
 
21
    /**
22
     *
23
     * @var CompanyMicrolearningCapsuleCommentMapper
24
     */
25
    private static $_instance;
26
 
27
    /**
28
     *
29
     * @param AdapterInterface $adapter
30
     */
31
    private function __construct($adapter)
32
    {
33
        parent::__construct($adapter);
34
    }
35
 
36
    /**
37
     *
38
     * @param AdapterInterface $adapter
39
     * @return CompanyMicrolearningCapsuleCommentMapper
40
     */
41
    public static function getInstance($adapter)
42
    {
43
        if(self::$_instance == null) {
44
            self::$_instance = new CompanyMicrolearningCapsuleCommentMapper($adapter);
45
        }
46
        return self::$_instance;
47
    }
48
 
49
    /**
50
     *
51
     * @param int $company_id
52
     * @param int $topic_id
53
     * @param int $capsule_id
54
     * return int
55
     */
56
    public function fetchCountByCompanyIdAndTopicIdAndCapsuleId($company_id, $topic_id, $capsule_id)
57
    {
58
 
59
        $select = $this->sql->select();
60
        $select->columns(['total' => new Expression('COUNT(*)')]);
61
        $select->from(self::_TABLE);
62
        $select->where->equalTo('company_id', $company_id);
63
        $select->where->equalTo('topic_id', $topic_id);
64
        $select->where->equalTo('capsule_id', $capsule_id);
65
 
66
        $record = $this->executeFetchOneArray($select);
67
        return $record['total'];
68
    }
69
 
70
 
71
 
72
 
73
 
74
    /**
75
     *
76
     * @param int $company_id
77
     * @param int $topic_id
78
     * @param int $capsule_id
79
     * return CompanyMicrolearningCapsuleComment[]
80
     */
81
    public function fetchAllByCompanyIdAndTopicIdAndCapsuleId($company_id, $topic_id, $capsule_id)
82
    {
83
        $prototype = new CompanyMicrolearningCapsuleComment();
84
 
85
        $select = $this->sql->select();
86
        $select->from(self::_TABLE);
87
        $select->where->equalTo('company_id', $company_id);
88
        $select->where->equalTo('topic_id', $topic_id);
89
        $select->where->equalTo('capsule_id', $capsule_id);
90
 
91
        return $this->executeFetchAllObject($select, $prototype);
92
   }
93
 
94
 
95
   /**
96
    *
97
    * @param int $company_id
98
    * @param int $topic_id
99
    * @param int $capsule_id
100
    * @param string $search
101
    * @param int $page
102
    * @param int $records_per_page
103
    * @param string $order_field
104
    * @param string $order_direction
105
    * @return Paginator
106
    */
107
   public function fetchAllDataTableByCompanyIdAndTopicId($company_id, $topic_id, $capsule_id, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
108
   {
109
       $prototype = new CompanyMicrolearningCapsuleComment();
110
       $select = $this->sql->select(self::_TABLE);
111
       $select->where->equalTo('company_id', $company_id);
112
       $select->where->equalTo('topic_id', $topic_id);
113
       $select->where->equalTo('capsule_id', $capsule_id);
114
 
115
       if($search) {
116
           $select->where->like('name', '%' . $search . '%');
117
       }
118
       $select->order($order_field . ' ' . $order_direction);
119
 
120
       //echo $select->getSqlString($this->adapter->platform); exit;
121
 
122
       $hydrator   = new ObjectPropertyHydrator();
123
       $resultset  = new HydratingResultSet($hydrator, $prototype);
124
 
125
       $adapter = new DbSelect($select, $this->sql, $resultset);
126
       $paginator = new Paginator($adapter);
127
       $paginator->setItemCountPerPage($records_per_page);
128
       $paginator->setCurrentPageNumber($page);
129
 
130
 
131
       return $paginator;
132
   }
133
 
134
 
135
    /**
136
     *
137
     * @param int $id
138
     * return CompanyMicrolearningCapsuleComment
139
     */
140
    public function fetchOne($id)
141
    {
142
        $prototype = new CompanyMicrolearningCapsuleComment();
143
        $select = $this->sql->select();
144
        $select->from(self::_TABLE);
145
        $select->where->equalTo('id', $id);
146
 
147
        return $this->executeFetchOneObject($select, $prototype);
148
    }
149
 
150
 
151
 
152
 
153
    /**
154
     *
155
     * @param CompanyMicrolearningCapsuleComment $CompanyMicrolearningCapsuleComment
156
     * @return boolean
157
     */
158
    public function insert($CompanyMicrolearningCapsuleComment)
159
    {
160
        $hydrator = new ObjectPropertyHydrator();
161
        $values = $hydrator->extract($CompanyMicrolearningCapsuleComment);
162
        $values = $this->removeEmpty($values);
163
 
164
        $insert = $this->sql->insert(self::_TABLE);
165
        $insert->values($values);
166
 
167
        $response = $this->executeInsert($insert);
168
        if($response) {
169
            $CompanyMicrolearningCapsuleComment->id = $this->lastInsertId;
170
        }
171
 
172
        return $response;
173
    }
174
 
175
 
176
 
177
    /**
178
     *
179
     * @param CompanyMicrolearningCapsuleComment $CompanyMicrolearningCapsuleComment
180
     * @return boolean
181
     */
182
    public function delete($CompanyMicrolearningCapsuleComment)
183
    {
184
        $delete = $this->sql->delte(self::_TABLE);
185
        $delete->where->equalTo('id', $CompanyMicrolearningCapsuleComment->id);
186
 
187
        return $this->executeDelete($delete);
188
    }
189
 
190
}