@@ -164,11 +164,6 @@ public static function insertUser(User $user, $date, Chat $chat = null)
164
164
}
165
165
166
166
$ user_id = $ user ->getId ();
167
- $ username = $ user ->getUsername ();
168
- $ first_name = $ user ->getFirstName ();
169
- $ last_name = $ user ->getLastName ();
170
-
171
- $ chat_id = $ chat ->getId ();
172
167
173
168
try {
174
169
//Users table
@@ -184,9 +179,9 @@ public static function insertUser(User $user, $date, Chat $chat = null)
184
179
' );
185
180
186
181
$ sth1 ->bindParam (':id ' , $ user_id , \PDO ::PARAM_INT );
187
- $ sth1 ->bindParam (':username ' , $ username , \PDO ::PARAM_STR , 255 );
188
- $ sth1 ->bindParam (':first_name ' , $ first_name , \PDO ::PARAM_STR , 255 );
189
- $ sth1 ->bindParam (':last_name ' , $ last_name , \PDO ::PARAM_STR , 255 );
182
+ $ sth1 ->bindParam (':username ' , $ user -> getUsername () , \PDO ::PARAM_STR , 255 );
183
+ $ sth1 ->bindParam (':first_name ' , $ user -> getFirstName () , \PDO ::PARAM_STR , 255 );
184
+ $ sth1 ->bindParam (':last_name ' , $ user -> getLastName () , \PDO ::PARAM_STR , 255 );
190
185
$ sth1 ->bindParam (':date ' , $ date , \PDO ::PARAM_STR );
191
186
192
187
$ status = $ sth1 ->execute ();
@@ -207,7 +202,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
207
202
' );
208
203
209
204
$ sth3 ->bindParam (':user_id ' , $ user_id , \PDO ::PARAM_INT );
210
- $ sth3 ->bindParam (':chat_id ' , $ chat_id , \PDO ::PARAM_INT );
205
+ $ sth3 ->bindParam (':chat_id ' , $ chat -> getId () , \PDO ::PARAM_INT );
211
206
212
207
$ status = $ sth3 ->execute ();
213
208
@@ -230,36 +225,20 @@ public static function insertRequest(Update $update)
230
225
return false ;
231
226
}
232
227
233
- $ update_id = $ update ->getUpdateId ();
234
228
$ message = $ update ->getMessage ();
229
+
235
230
$ from = $ message ->getFrom ();
236
231
$ chat = $ message ->getChat ();
237
232
238
- $ user_id = $ from ->getId ();
239
233
240
234
$ chat_id = $ chat ->getId ();
241
- $ chat_title = $ chat ->getTitle ();
242
235
243
236
$ date = self ::toTimestamp ($ message ->getDate ());
244
- $ message_id = $ message ->getMessageId ();
245
237
$ forward_from = $ message ->getForwardFrom ();
246
238
$ forward_date = self ::toTimestamp ($ message ->getForwardDate ());
247
- $ reply_to_message = $ message ->getReplyToMessage ();
248
- $ text = $ message ->getText ();
249
- $ audio = $ message ->getAudio ();
250
- $ document = $ message ->getDocument ();
251
239
$ photo = $ message ->getPhoto ();
252
- $ sticker = $ message ->getSticker ();
253
- $ video = $ message ->getVideo ();
254
- $ voice = $ message ->getVoice ();
255
- $ caption = $ message ->getCaption ();
256
- $ contact = $ message ->getContact ();
257
- $ location = $ message ->getLocation ();
258
240
$ new_chat_participant = $ message ->getNewChatParticipant ();
259
241
$ left_chat_participant = $ message ->getLeftChatParticipant ();
260
- $ new_chat_title = $ message ->getNewChatTitle ();
261
- $ delete_chat_photo = $ message ->getDeleteChatPhoto ();
262
- $ group_chat_created = $ message ->getGroupChatCreated ();
263
242
264
243
//inser user and the relation with the chat
265
244
self ::insertUser ($ from , $ date , $ chat );
@@ -300,7 +279,7 @@ public static function insertRequest(Update $update)
300
279
301
280
302
281
$ sth2 ->bindParam (':id ' , $ chat_id , \PDO ::PARAM_INT );
303
- $ sth2 ->bindParam (':title ' , $ chat_title , \PDO ::PARAM_STR , 255 );
282
+ $ sth2 ->bindParam (':title ' ,$ chat -> getTitle () , \PDO ::PARAM_STR , 255 );
304
283
$ sth2 ->bindParam (':date ' , $ date , \PDO ::PARAM_STR );
305
284
306
285
$ status = $ sth2 ->execute ();
@@ -322,60 +301,55 @@ public static function insertRequest(Update $update)
322
301
) ' );
323
302
324
303
325
- $ sth ->bindParam (':update_id ' , $ update_id , \PDO ::PARAM_INT );
326
- $ sth ->bindParam (':message_id ' , $ message_id , \PDO ::PARAM_INT );
327
- $ sth ->bindParam (':user_id ' , $ user_id , \PDO ::PARAM_INT );
304
+ $ sth ->bindParam (':update_id ' , $ update -> getUpdateId () , \PDO ::PARAM_INT );
305
+ $ sth ->bindParam (':message_id ' , $ message -> getMessageId () , \PDO ::PARAM_INT );
306
+ $ sth ->bindParam (':user_id ' , $ from -> getId () , \PDO ::PARAM_INT );
328
307
$ sth ->bindParam (':date ' , $ date , \PDO ::PARAM_STR );
329
308
$ sth ->bindParam (':chat_id ' , $ chat_id , \PDO ::PARAM_STR );
330
-
331
309
$ sth ->bindParam (':forward_from ' , $ forward_from , \PDO ::PARAM_STR );
332
-
333
310
$ sth ->bindParam (':forward_date ' , $ forward_date , \PDO ::PARAM_STR );
334
-
335
- $ reply_to_message = is_object ($ reply_to_message ) ? $ reply_to_message ->toJSON (): '' ;
336
- $ sth ->bindParam (':reply_to_message ' , $ reply_to_message , \PDO ::PARAM_STR );
337
- $ sth ->bindParam (':text ' , $ text , \PDO ::PARAM_STR );
338
-
339
- $ audio = is_object ($ audio ) ? $ audio ->toJSON (): '' ;
340
- $ sth ->bindParam (':audio ' , $ audio , \PDO ::PARAM_STR );
341
- $ document = is_object ($ document ) ? $ document ->toJSON (): '' ;
342
- $ sth ->bindParam (':document ' , $ document , \PDO ::PARAM_STR );
343
-
344
- //TODO what about the Entities array of photosize?
311
+ $ sth ->bindParam (':reply_to_message ' , $ message ->getReplyToMessage (), \PDO ::PARAM_STR );
312
+ $ sth ->bindParam (':text ' , $ message ->getText (), \PDO ::PARAM_STR );
313
+ $ sth ->bindParam (':audio ' , $ message ->getAudio (), \PDO ::PARAM_STR );
314
+ $ sth ->bindParam (':document ' , $ message ->getDocument (), \PDO ::PARAM_STR );
315
+ //Try with to magic shoud work
345
316
$ var = [];
346
317
if (is_array ($ photo )) {
347
318
foreach ($ photo as $ elm ) {
348
- $ var [] = json_decode ($ elm-> toJSON () , true );
319
+ $ var [] = json_decode ($ elm , true );
349
320
}
350
321
351
322
$ photo = json_encode ($ var );
352
323
} else {
353
- $ forward_from = '' ;
324
+ $ photo = '' ;
354
325
}
355
326
356
327
$ sth ->bindParam (':photo ' , $ photo , \PDO ::PARAM_STR );
357
-
358
- $ sticker = is_object ($ sticker ) ? $ sticker ->toJSON (): '' ;
359
- $ sth ->bindParam (':sticker ' , $ sticker , \PDO ::PARAM_STR );
360
- $ video = is_object ($ video ) ? $ video ->toJSON (): '' ;
361
- $ sth ->bindParam (':video ' , $ video , \PDO ::PARAM_STR );
362
- $ voice = is_object ($ voice ) ? $ voice ->toJSON (): '' ;
363
- $ sth ->bindParam (':voice ' , $ voice , \PDO ::PARAM_STR );
364
- $ sth ->bindParam (':caption ' , $ caption , \PDO ::PARAM_STR );
365
- $ contact = is_object ($ contact ) ? $ contact ->toJSON (): '' ;
366
- $ sth ->bindParam (':contact ' , $ contact , \PDO ::PARAM_STR );
367
- $ location = is_object ($ location ) ? $ location ->toJSON (): '' ;
368
- $ sth ->bindParam (':location ' , $ location , \PDO ::PARAM_STR );
369
-
328
+ $ sth ->bindParam (':sticker ' , $ message ->getSticker (), \PDO ::PARAM_STR );
329
+ $ sth ->bindParam (':video ' , $ message ->getVideo (), \PDO ::PARAM_STR );
330
+ $ sth ->bindParam (':voice ' , $ message ->getVoice (), \PDO ::PARAM_STR );
331
+ $ sth ->bindParam (':caption ' , $ message ->getCaption (), \PDO ::PARAM_STR );
332
+ $ sth ->bindParam (':contact ' , $ message ->getContact (), \PDO ::PARAM_STR );
333
+ $ sth ->bindParam (':location ' , $ message ->getLocation (), \PDO ::PARAM_STR );
370
334
$ sth ->bindParam (':new_chat_participant ' , $ new_chat_paticipant , \PDO ::PARAM_STR );
371
335
$ sth ->bindParam (':left_chat_participant ' , $ left_chat_paticipant , \PDO ::PARAM_STR );
372
-
373
- $ sth ->bindParam (':new_chat_title ' , $ new_chat_title , \PDO ::PARAM_STR );
336
+ $ sth ->bindParam (':new_chat_title ' , $ message ->getNewChatTitle (), \PDO ::PARAM_STR );
374
337
//Array of Photosize
375
- $ sth ->bindParam (':new_chat_photo ' , $ new_chat_photo , \PDO ::PARAM_STR );
376
338
377
- $ sth ->bindParam (':delete_chat_photo ' , $ delete_chat_photo , \PDO ::PARAM_STR );
378
- $ sth ->bindParam (':group_chat_created ' , $ group_chat_created , \PDO ::PARAM_STR );
339
+ $ var = [];
340
+ if (is_array ($ new_chat_photo )) {
341
+ foreach ($ new_chat_photo as $ elm ) {
342
+ $ var [] = json_decode ($ elm , true );
343
+ }
344
+
345
+ $ new_chat_photo = json_encode ($ var );
346
+ } else {
347
+ $ new_chat_photo = '' ;
348
+ }
349
+
350
+ $ sth ->bindParam (':new_chat_photo ' , $ new_chat_photo , \PDO ::PARAM_STR );
351
+ $ sth ->bindParam (':delete_chat_photo ' , $ message ->getDeleteChatPhoto (), \PDO ::PARAM_STR );
352
+ $ sth ->bindParam (':group_chat_created ' , $ message ->getGroupChatCreated (), \PDO ::PARAM_STR );
379
353
380
354
$ status = $ sth ->execute ();
381
355
0 commit comments