Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
8
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
9
use LeadersLinked\Mapper\Common\MapperCommon;
10
use LeadersLinked\Model\Meeting;
11
 
12
class MeetingsMapper extends MapperCommon {
13
 
14
    const __TABLE = 'tbl_meetings';
15
 
16
    /**
17
     *
18
     * @var MeetingsMapper
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 MeetingsMapper
35
      */
36
    public static function getInstance($adapter)
37
    {
38
          if (self::$_instance == null) {
39
              self::$_instance = new MeetingsMapper($adapter);
40
          }
41
 
42
          return self::$_instance;
43
    }
44
 
45
    /**
46
     *
47
     * @return Meeting[]
48
     */
49
    public function fetchAllMeetings()
50
    {
51
        $prototype = new Meeting();
52
        $select = $this->sql->select(self::__TABLE);
53
 
54
        return $this->executeFetchAllObject($select, $prototype);
55
    }
56
 
57
    /**
58
     *
59
     * @return Meeting[]
60
     */
61
    public function fetchAllPendingMeetingsWithNoBbbId()
62
    {
63
        $prototype = new Meeting;
64
        $select = $this->sql->select(self::__TABLE);
65
        $select->where->equalTo('status', Meeting::STATUS_PENDING);
66
        $select->where->isNull('bbb_id');
67
 
68
        return $this->executeFetchAllObject($select, $prototype);
69
    }
70
 
71
    /**
72
     *
73
     * @param  int $user_id
74
     * @return Meeting[]
75
     */
76
    public function fetchAllMeetingsCreatedByUserId($user_id)
77
    {
78
        $prototype = new Meeting();
79
        $select = $this->sql->select(self::__TABLE);
80
        $select->where->equalTo('user_id', $user_id);
81
 
82
        return $this->executeFetchAllObject($select, $prototype);
83
    }
84
 
85
    /**
86
     *
87
     * @param int $user_id
88
     * @return Meeting[]
89
     */
90
    public function fetchAllNotCancelledMeetingsCreatedByUserId($user_id)
91
    {
92
        $prototype = new Meeting();
93
        $select = $this->sql->select(self::__TABLE);
94
        $select->where->equalTo('user_id', $user_id);
95
        $select->where->notEqualTo('status', Meeting::STATUS_CANCELLED);
96
 
97
        return $this->executeFetchAllObject($select, $prototype);
98
    }
99
 
100
    /**
101
     *
102
     * @param int $meetingId
103
     * @return Meeting
104
     */
105
    public function fetchMeetingById($meetingId)
106
    {
107
        $prototype = new Meeting();
108
        $select = $this->sql->select(self::__TABLE);
109
        $select->where->equalTo('id', $meetingId);
110
 
111
        return $this->executeFetchOneObject($select, $prototype);
112
    }
113
 
114
    /**
115
     *
116
     * @param int $meetingId
117
     * @return Meeting
118
     */
119
    public function fetchMeetingIfNotCancelledById($meetingId)
120
    {
121
        $prototype = new Meeting();
122
        $select = $this->sql->select(self::__TABLE);
123
        $select->where->equalTo('id', $meetingId);
124
        $select->where->notEqualTo('status', Meeting::STATUS_CANCELLED);
125
 
126
        return $this->executeFetchOneObject($select, $prototype);
127
    }
128
 
129
    /**
130
     *
131
     * @param Meeting $meeting
132
     * @return boolean
133
     */
134
    public function insert($meeting) {
135
        $hydrator = new ObjectPropertyHydrator();
136
        $values = $hydrator->extract($meeting);
137
        $values = $this->removeEmpty($values);
138
 
139
        $insert = $this->sql->insert(self::__TABLE);
140
        $insert->values($values);
141
 
142
        $result = $this->executeInsert($insert);
143
        if ($result) {
144
            $meeting->id = $this->lastInsertId;
145
        }
146
 
147
        return $result;
148
    }
149
 
150
   /**
151
    *
152
    * @param int $meetingId
153
    * @return boolean
154
    */
155
   public function changeMeetingStatusToDeleteddById($meetingId)
156
   {
157
        $update = $this->sql->update(self::__TABLE);
158
        $update->set(['status' => Meeting::STATUS_DELETED]);
159
        $update->where->equalTo('id', $meetingId);
160
        return $this->executeUpdate($update);
161
    }
162
 
163
    /**
164
     *
165
     * @param int $meetingId
166
     * @return boolean
167
     */
168
    public function cancelMeetingById($meetingId)
169
    {
170
        $update = $this->sql->update(self::__TABLE);
171
        $update->set(['status' => Meeting::STATUS_CANCELLED]);
172
        $update->where->equalTo('id', $meetingId);
173
        return $this->executeUpdate($update);
174
    }
175
 
176
    /**
177
     *
178
     * @param int $meetingId
179
     * @return boolean
180
     */
181
    public function changeMeetingStatusToStartedById($meetingId)
182
    {
183
        $update = $this->sql->update(self::__TABLE);
184
        $update->set(['status' => Meeting::STATUS_STARTED]);
185
        $update->where->equalTo('id', $meetingId);
186
        return $this->executeUpdate($update);
187
    }
188
 
189
    /**
190
     *
191
     * @param string $bbb_id
192
     * @param string $attendee_password
193
     * @param string $moderator_password
194
     * @param int $meeting_id
195
     * @return boolean
196
     */
197
    public function asignBigBlueButtonInfoToMeetingId($bbb_id, $attendee_password, $moderator_password, $meeting_id)
198
    {
199
        $update = $this->sql->update(self::__TABLE);
200
        $update->set([
201
            'bbb_id' => $bbb_id,
202
            'attendee_password' => $attendee_password,
203
            'moderator_password' => $moderator_password
204
        ]);
205
        $update->where->equalTo('id', $meeting_id);
206
        return $this->executeUpdate($update);
207
    }
208
 
209
    public function fetchBbbIdFromMeetingId($id) {
210
        $prototype = new Meeting;
211
        $select = $this->sql->select(self::__TABLE);
212
        $select->columns(['bbb_id']);
213
        $select->where->equalTo('id', $id);
214
 
215
        return $this->executeFetchAllObject($select, $prototype);
216
    }
217
 
218
    public function setMeetingRecordingToReadyStatus ($meetingId) {
219
        $update = $this->sql->update(self::__TABLE);
220
        $update->set(['recording_ready' => Meeting::RECORDING_READY]);
221
        $update->where->equalTo('id', $meetingId);
222
        return $this->executeUpdate($update);
223
    }
224
 
225
    public function setMeetingReminderToSent ($meetingId) {
226
        $update = $this->sql->update(self::__TABLE);
227
        $update->set(['reminder_sent' => Meeting::REMINDER_SENT]);
228
        $update->where->equalTo('id', $meetingId);
229
        return $this->executeUpdate($update);
230
    }
231
 
232
 
233
    public function setMeetingUrlById ($meetingUrl, $meetingId) {
234
        $update = $this->sql->update(self::__TABLE);
235
        $update->set(['meeting_url' => $meetingUrl]);
236
        $update->where->equalTo('id', $meetingId);
237
        return $this->executeUpdate($update);
238
    }
239
 
240
}