-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_team_guest_lists.php
executable file
·1331 lines (929 loc) · 52.4 KB
/
model_team_guest_lists.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model_team_guest_lists extends CI_Model {
/*
*
* */
function __construct(){
parent::__construct();
}
/*-------------------------------------------------------------------------
| Create Methods (create)
| ------------------------------------------------------------------------ */
/**
* Creates a team_guest_list_authorization attached to a team_venue
*
* @param
* @return bool
*/
function create_team_guest_list_authorization($data){
$this->db->insert('teams_guest_list_authorizations', $data);
return $this->db->affected_rows();
}
/**
* called when a user wants to join an authorized team guest list
*
* First this method must check to see if this is the first user who wants to create a guest
* list for this week with this team_guest_list_authorization_id.
* If true, must create a record in 'teams_guest_lists'
* Then adds a record to team_guest_lists_reservations
* Then adds any entourage members to team_guest_lists_reservations_entourages
*
* @param string (user oauth uid)
* @param ...
* @param array (user's entourage)
* @param string (id of guest list)
* @param bool (table request)
* @param bool (share with facebook news feed story)
* @param bool (send text confirmation)
* @param string (phone number)
* @param int (phone carrier)
* @return array
*/
function create_team_guest_list_reservation($oauth_uid,
$team_fan_page_id,
$entourage,
$id,
$table_request,
$share_facebook,
$text_message,
$request_message,
$phone_number,
$phone_carrier,
$date_check_override = false,
$approve_override = false,
$table_min_spend = 0,
$tglr_supplied_name = '',
$vlfit_id = NULL){
$phone_number = preg_replace('/\D/', '', $phone_number);
//get the dates/epoch times of this week's start/end dates (sunday - saturday)
//+ today's date
$today_date = date('Y-m-d', time());
$this->load->helper('week_range');
//$list($human_start, $human_end, $epoch_start, $epoch_end) = week_range();
//check to make sure that this guest list ID is active (prevent someone from spoofing a request
//to join a guest list that has been decactivated).
$this->db->select('deactivated, auto_approve');
$query = $this->db->get_where('teams_guest_list_authorizations', array('id' => $id));
if(!$result = $query->row()){
return array('success' => false, 'message' => 'Unknown Error');
}
if($result->deactivated){
return array('success' => false, 'message' => 'Unavailable Guest List');
}
//Is this guest list set to auto-approve?
$auto_approve_requests = $result->auto_approve;
//if this is a table request, no-auto approve (unless it's a manual table request -- next line)
if($table_request == 1 || $table_request == '1')
$auto_approve_requests = false;
if($approve_override)
$auto_approve_requests = true;
/* --------------------- check to make sure user isn't already on guest list for this night --------------------- */
// before we create a guest list, make sure this user doesn't already have a guest list
// set up somewhere else on this same night
/* ---------------- side task --------------- */
//first we need to know what night of the week this guest list is.
$this->db->select('day, event, event_date');
$query = $this->db->get_where('teams_guest_list_authorizations', array('id' => $id));
$result = $query->row();
//this is the weekday this guest list is set up for
$guest_list_weekday = rtrim($result->day, 's'); // remove trailing 's' (how day is stored in database)
/* ---------------- end side task --------------- */
//given the weekday of this guest list, find the date of the next occurance of this weekday
if($result->event == '0')
$guest_list_next_occurance_date = date('Y-m-d', strtotime($guest_list_weekday));
else
$guest_list_next_occurance_date = $result->event_date;
$sql = "SELECT
tgl.id
FROM teams_guest_lists tgl
JOIN teams_guest_lists_reservations tglr
ON tglr.team_guest_list_id = tgl.id
WHERE tgl.date = ?
AND
tglr.user_oauth_uid = ?
AND
tglr.manual_add = 0";
// $query = $this->db->query($sql, array($guest_list_next_occurance_date, $oauth_uid));
// if($result = $query->row() && !$date_check_override){
//this user is already on a guest list for this date. return error
// $message = "You are already on a guest list for $guest_list_next_occurance_date! You cannot join two guest lists on the same night.";
// return array('success' => false, 'message' => $message);
// }
/* --------------------- end check to make sure user isn't already on guest list for this night --------------------- */
//find out if a teams_guest_lists record exists given this next occurance date and team_guest_list_id
//if one doesn't exist yet - create it
$sql = "SELECT
tgl.id as id,
tgla.id as tgla_id,
tgla.name as tgla_name,
tgla.team_fan_page_id as tgla_team_fan_page_id,
tgla.event as tgla_event,
tgla.event_date as tgla_event_date,
tv.name as tv_name,
tv.id as tv_id,
u.full_name as u_full_name,
u.email as u_email,
u.twilio_sms_number as u_twilio_sms_number
FROM teams_guest_list_authorizations tgla
JOIN teams_guest_lists tgl
ON tgla.id = tgl.team_guest_list_authorization_id
JOIN team_venues tv
ON tv.id = tgla.team_venue_id
JOIN teams_venues_pairs tvp
ON tvp.team_fan_page_id = tgla.team_fan_page_id AND tvp.team_venue_id = tv.id
JOIN teams t
ON t.fan_page_id = tvp.team_fan_page_id
JOIN managers_teams mt
ON t.fan_page_id = mt.fan_page_id
JOIN users u
ON mt.user_oauth_uid = u.oauth_uid
WHERE
tgla.id = ?
AND
tgl.date >= ?
LIMIT 1";
$query = $this->db->query($sql, array($id, $guest_list_next_occurance_date));
//necessary to create a new guest list only if one doesn't already exist
if(!$result = $query->row()){
//There is no guest list for this week already. We will now create one.
$data = array('team_guest_list_authorization_id' => $id,
'date' => $guest_list_next_occurance_date);
$this->db->insert('teams_guest_lists', $data);
$teams_guest_list_id = $this->db->insert_id();
// var_dump('1');
// var_dump($result);
// var_dump($this->db->last_query()); //die();
//retrieve row we just inserted
$query = $this->db->query($sql, array($id, $guest_list_next_occurance_date));
$result = $query->row();
}else{
$teams_guest_list_id = $result->id;
// var_dump('2');
// var_dump($result);
// var_dump($this->db->last_query()); //die();
}
$team_fan_page_id = $result->tgla_team_fan_page_id;
$tgla_id = $result->tgla_id;
$tgla_name = $result->tgla_name;
$tv_name = $result->tv_name;
$tv_id = $result->tv_id;
$manager_name = $result->u_full_name;
$manager_email = $result->u_email;
$manager_twilio_number = $result->u_twilio_sms_number;
/* --------------------------------- */
//add phone number to users table if set
if($text_message && !$approve_override && $phone_number){
$this->db->where('oauth_uid', $oauth_uid);
$this->db->update('users', array('phone_number' => preg_replace('/\D/', '', $phone_number),
'phone_carrier' => $phone_carrier));
}
/* --------------------------------- */
// Check if this user has been 'maually added' by a manager, if so -- delete manager manual add and replace with this.
if(!$approve_override)
$this->db->delete('teams_guest_lists_reservations', array('manual_add' => 1,
'user_oauth_uid' => $oauth_uid,
'team_guest_list_id' => $teams_guest_list_id));
//now add HEAD user to teams_guest_lists_reservations
$this->db->insert('teams_guest_lists_reservations', array('team_guest_list_id' => $teams_guest_list_id,
'user_oauth_uid' => $oauth_uid,
'share_facebook' => ($share_facebook == 1) ? 1 : 0,
'text_message' => ($text_message == 1) ? 1 : 0,
'request_msg' => ($request_message) ? $request_message : '',
'table_request' => ($table_request == 1) ? 1 : 0,
'manual_add' => ($approve_override) ? 1 : 0,
'approved' => ($approve_override) ? 1 : 0,
'table_min_spend' => $table_min_spend,
'supplied_name' => $tglr_supplied_name,
'venues_layout_floors_items_table_id' => (($vlfit_id && $vlfit_id != 'false') ? $vlfit_id : NULL),
'create_time' => time()));
// var_dump($this->db->last_query()); die();
$teams_guest_lists_reservations_id = $this->db->insert_id();
// var_dump($teams_guest_lists_reservations_id); die();
//send PUSHER notification to team channel (only if NOT a manual add)
if($teams_guest_lists_reservations_id){
$this->load->library('pusher');
if(!$approve_override){
$this->pusher->trigger('presence-' . $team_fan_page_id, 'team_guest_list_reservation', array('tgl_id' => $teams_guest_list_id,
'tglr_id' => $teams_guest_lists_reservations_id,
'tgla_id' => $tgla_id,
'entourage' => $entourage,
'approved' => $auto_approve_requests,
'table_request' => $table_request,
'guest_list_name' => $tgla_name,
'venue_name' => $tv_name,
'tv_id' => $tv_id,
'guest_list_date' => $guest_list_next_occurance_date,
'head_oauth_uid' => $oauth_uid,
'request_msg' => '',
'manual_add' => ($approve_override) ? 1 : 0));
$this->pusher->trigger('presence-' . $team_fan_page_id, 'pending-requests-change', null);
}
if(!$approve_override){
$email_view_data = array(
'gla_name' => $tgla_name,
'auto_approve' => $auto_approve_requests
);
$this->load->helper('run_gearman_job');
run_gearman_job('gearman_send_emails', array(
'to_emails' => json_encode(array(
$manager_email
)),
'to_names' => json_encode(array(
$manager_name
)),
'email_view' => 'view_email_guest_list_request_response',
'email_view_data' => json_encode($email_view_data)
), false);
}
}
//now add the HEAD user's entourage (if no entourage skip)
if($entourage){ // && !$approve_override
// foreach($entourage as $member){
// $insert_data[] = array('team_guest_list_reservation_id' => $teams_guest_lists_reservations_id,
// 'oauth_uid' => $member);
// }
// $this->db->insert_batch('teams_guest_lists_reservations_entourages', $insert_data);
foreach($entourage as $member){
if(is_array($member)){
if($member['oauth_uid'] == '0' || strtolower($member['oauth_uid']) == 'null')
$member['oauth_uid'] = NULL;
$insert_data[] = array('team_guest_list_reservation_id' => $teams_guest_lists_reservations_id,
'oauth_uid' => $member['oauth_uid'],
'supplied_name' => $member['name']);
}else{
if($member == '0' || strtolower($member) == 'null'){
$member = NULL;
}
$insert_data[] = array('team_guest_list_reservation_id' => $teams_guest_lists_reservations_id,
'oauth_uid' => $member);
}
}
$this->db->insert_batch('teams_guest_lists_reservations_entourages', $insert_data);
}
//if this guest list is set to auto-approve, approve the request
if($auto_approve_requests)
$this->update_team_guest_list_reservation_reject_or_approve(true,
'',
$team_fan_page_id,
$teams_guest_lists_reservations_id,
$approve_override);
if(!$approve_override && $team_fan_page_id && $team_fan_page_id != '0'){
$this->load->helper('run_gearman_job');
//send text message to promoter ------------------------------------
run_gearman_job('gearman_send_sms_notification', array(
'team_fan_page_id' => $team_fan_page_id,
'twilio_number' => $manager_twilio_number,
'user_oauth_uid' => $oauth_uid,
'guest_list_name' => $tgla_name,
'venue' => $tv_name,
'glr_id' => $teams_guest_lists_reservations_id,
'request_msg' => ($request_message) ? $request_message : '',
'entourage' => $entourage,
'auto_approved' => $auto_approve_requests,
'table_request' => ($table_request == 1) ? true : false,
'manager' => true
), false);
// ------------------------------------------------------------------
}
return array('success' => true, 'message' => $teams_guest_lists_reservations_id);
}
/*-------------------------------------------------------------------------
| Retrieval Methods (retrieve)
| ------------------------------------------------------------------------ */
/**
* Used for retrieving a single TGLA from a gearman worker for FB requests
*
* @param int (tv_id)
* @param int (tgla_id)
* @return object || false
*/
function retrieve_tgla($tv_id, $tgla_id){
$sql = "SELECT
tgla.id as tgla_id,
tgla.team_venue_id as tgla_team_venue_id,
tgla.day as tgla_day,
tgla.name as tgla_name,
tgla.create_time as tgla_create_time,
tgla.deactivated as tgla_deactivated,
tgla.deactivated_time as tgla_deactivated_time,
tgla.image as tgla_image,
tv.name as tv_name,
tv.id as tv_id,
tv.description as tv_description,
tv.street_address as tv_street_address,
c.name as c_name,
c.state as c_state,
c.url_identifier as c_url_identifier
FROM teams_guest_list_authorizations tgla
JOIN team_venues tv
ON tgla.team_venue_id = tv.id
JOIN cities c
ON tv.city_id = c.id
WHERE tgla.id = ?";
$query = $this->db->query($sql, array($tgla_id));
return $query->row();
}
/**
* Retrieve guest lists for a given team
*
* @param array (query options)
* @param array (result/query filter parameters)
* @return array
*/
function retrieve_team_guest_lists_authorizations($options = array(), $filters = array()){
/* --------- CONFIGURATION SETTINGS --------- *
* This method will require a lot of optional configuration settings. Passing in a configurable
* array of key/value pairs will work better than a method with 20 optional arguments.
*/
$default_options = array(
'cache' => false,
'cache_length' => 900, //15 minutes
'limit' => 1000
);
foreach($options as $key => $value){
//is this a recognized configuration setting?
if(!array_key_exists($key, $default_options))
die('model_team_guest_lists->retrieve_team_guest_lists: unknown configuration setting - ' . $key);
//overwrite default configuration value with new one specified in function call
$default_options[$key] = $value;
}
foreach($default_options as $key => $value){
//turn all default_config keys into local variables
${'config_' . $key} = $value;
}
/* --------- END CONFIGURATION SETTINGS --------- */
/* --------- FILTER SETTINGS --------- */
//FILTERS... remove results based on these paramters
$default_filters = array(
'fan_page_id' => false,
'team_venue_id' => false,
'weekday' => false,
'deactivated' => true //true means 'remove deactivated'
);
foreach($filters as $key => $value){
//is this a recognized configuration setting?
if(!array_key_exists($key, $default_filters))
die('model_team_guest_lists->retrieve_team_guest_lists_authorizations: unknown filter setting - ' . $key);
//overwrite default configuration value with new one specified in function call
$default_filters[$key] = $value;
}
foreach($default_filters as $key => $value){
//turn all default_config keys into local variables
${'filter_' . $key} = $value;
}
/* --------- END FILTER SETTINGS --------- */
$sql = "SELECT DISTINCT
tgla.id as tgla_id,
tgla.team_venue_id as tgla_team_venue_id,
tgla.day as tgla_day,
tgla.name as tgla_name,
tgla.image as tgla_image,
tgla.create_time as tgla_create_time,
tgla.deactivated as tgla_deactivated,
tgla.deactivated_time as tgla_deactivated_time,
tv.name as tv_name,
tv.id as tv_id,
tv.description as tv_description,
tv.street_address as tv_street_address,
tv.monday as tv_monday,
tv.tuesday as tv_tuesday,
tv.wednesday as tv_wednesday,
tv.thursday as tv_thursday,
tv.friday as tv_friday,
tv.saturday as tv_saturday,
tv.sunday as tv_sunday,
c.url_identifier as c_url_identifier
FROM teams_guest_list_authorizations tgla
JOIN team_venues tv
ON tgla.team_venue_id = tv.id
JOIN teams_venues_pairs tvp
ON tvp.team_venue_id = tv.id
JOIN teams t
ON tvp.team_fan_page_id = t.fan_page_id
JOIN cities c
ON tv.city_id = c.id
WHERE
tv.banned = 0
AND tvp.deleted = 0
AND t.completed_setup = 1
AND tgla.deactivated = 0 ";
if($filter_fan_page_id)
$sql .= "AND tgla.team_fan_page_id = $filter_fan_page_id AND tvp.team_fan_page_id = $filter_fan_page_id AND t.fan_page_id = $filter_fan_page_id ";
if($filter_team_venue_id)
$sql .= "AND tgla.team_venue_id = $filter_team_venue_id ";
if($filter_weekday)
$sql .= "AND tgla.day = '$filter_weekday' ";
// if($filter_deactivated)
// $sql .= "AND tgla.deactivated = 0 ";
$sql .= "GROUP BY tgla.id";
$query = $this->db->query($sql);
return $query->result();
}
/**
* Retrieve all guest lists at a venue
*
* @return array
*/
function retrieve_all_guest_lists($venue_id){
$sql = "SELECT DISTINCT
tgla.id as tgla_id,
tgla.team_venue_id as tgla_team_venue_id,
tgla.day as tgla_day,
tgla.event as tgla_event,
tgla.event_date as tgla_event_date,
tgla.event_override as tgla_event_override,
tgla.name as tgla_name,
tgla.create_time as tgla_create_time,
tgla.deactivated as tgla_deactivated,
tgla.deactivated_time as tgla_deactivated_time,
tgla.auto_approve as tgla_auto_approve,
tgla.description as tgla_description,
tgla.image as tgla_image,
tv.banned as tv_banned,
tv.city_id as tv_city_id,
tv.name as tv_name,
tv.image as tv_image,
tv.id as tv_id,
c.url_identifier as c_url_identifier
FROM teams_guest_list_authorizations tgla
JOIN team_venues tv
ON tgla.team_venue_id = tv.id
JOIN teams_venues_pairs tvp
ON tvp.team_venue_id = tv.id && tvp.team_fan_page_id = tgla.team_fan_page_id
/*
JOIN teams t
ON tv.team_fan_page_id = t.fan_page_id
*/
JOIN cities c
ON tv.city_id = c.id
WHERE tgla.deactivated = 0
AND tgla.team_venue_id = ?
AND tvp.deleted = 0";
$query = $this->db->query($sql, array($venue_id));
$result = $query->result();
return $result;
//NOTE: might be a need to attach this week's guest list reservations for friends lookup
}
/**
* Retrieves an individual guest list at a venue
*
* @return object || false
*/
function retrieve_individual_guest_list($venue_id, $guest_list_name){
//prep guest list name
$guest_list_name = str_replace('_', ' ', $guest_list_name);
$sql = "SELECT DISTINCT
tgla.id as tgla_id,
tgla.team_venue_id as tgla_team_venue_id,
tgla.team_fan_page_id as tgla_team_fan_page_id,
tgla.day as tgla_day,
tgla.event as tgla_event,
tgla.event_date as tgla_event_date,
tgla.event_override as tgla_event_override,
tgla.name as tgla_name,
tgla.create_time as tgla_create_time,
tgla.deactivated as tgla_deactivated,
tgla.deactivated_time as tgla_deactivated_time,
tgla.auto_approve as tgla_auto_approve,
tgla.description as tgla_description,
tgla.image as tgla_image,
tgla.min_age as tgla_min_age,
tgla.door_open as tgla_door_open,
tgla.door_close as tgla_door_close,
tgla.regular_cover as tgla_regular_cover,
tgla.gl_cover as tgla_gl_cover,
tgla.additional_info_1 as tgla_additional_info_1,
tgla.additional_info_2 as tgla_additional_info_2,
tgla.additional_info_3 as tgla_additional_info_3,
tv.name as tv_name,
tv.id as tv_id,
tv.image as tv_image,
tv.street_address as tv_street_address,
tv.city as tv_city,
tv.state as tv_state,
tv.zip as tv_zip,
tv.team_fan_page_id as tv_team_fan_page_id,
c.url_identifier as c_url_identifier
FROM teams_guest_list_authorizations tgla
JOIN team_venues tv
ON tgla.team_venue_id = tv.id
JOIN teams_venues_pairs tvp
ON tvp.team_venue_id = tv.id AND tvp.team_fan_page_id = tgla.team_fan_page_id
JOIN teams t
ON tvp.team_fan_page_id = t.fan_page_id
JOIN cities c
ON tv.city_id = c.id
WHERE tgla.deactivated = 0
AND tgla.team_venue_id = ?
AND tgla.name = ?
AND tvp.deleted = 0
AND t.completed_setup = 1
AND tv.banned = 0";
$query = $this->db->query($sql, array($venue_id, $guest_list_name));
$result = $query->row();
// Kint::dump($this->db->last_query());
if(!$result){
return $result;
}
//attach latest status
$this->db->select('
glas.id as glas_id,
glas.status as glas_status,
glas.create_time as glas_create_time,
glas.users_oauth_uid as glas_users_oauth_uid')
->from('guest_list_authorizations_statuses glas')
->where(array(
'glas.team_guest_list_authorizations_id' => $result->tgla_id
))
->order_by('glas_id', 'desc')
->limit(1, 0);
$query = $this->db->get();
$result->status = $query->row();
if($result->status)
$result->status->glas_human_date = date('l m/d/y h:i:s A', $result->status->glas_create_time);
Kint::dump($result);
return $result;
//NOTE: might be a need to attach this week's guest list reservations for friends lookup
}
/**
*
*/
function retrieve_individual_guest_list_for_plugin($tgla_id){
$sql = "SELECT
tgla.id as tgla_id,
tgla.team_venue_id as tgla_team_venue_id,
tgla.day as tgla_day,
tgla.name as tgla_name,
tgla.create_time as tgla_create_time,
tgla.deactivated as tgla_deactivated,
tgla.deactivated_time as tgla_deactivated_time,
tgla.auto_approve as tgla_auto_approve,
tgla.description as tgla_description,
tgla.image as tgla_image,
tgla.min_age as tgla_min_age,
tgla.door_open as tgla_door_open,
tgla.door_close as tgla_door_close,
tgla.regular_cover as tgla_regular_cover,
tgla.gl_cover as tgla_gl_cover,
tgla.additional_info_1 as tgla_additional_info_1,
tgla.additional_info_2 as tgla_additional_info_2,
tgla.additional_info_3 as tgla_additional_info_3,
tv.name as tv_name,
tv.id as tv_id,
tv.image as tv_image,
tv.street_address as tv_street_address,
tv.city as tv_city,
tv.state as tv_state,
tv.zip as tv_zip,
tv.team_fan_page_id as tv_team_fan_page_id,
c.url_identifier as c_url_identifier
FROM teams_guest_list_authorizations tgla
/*
JOIN team_venues tv
ON tgla.team_venue_id = tv.id
JOIN teams t
ON tv.team_fan_page_id = t.fan_page_id
*/
JOIN team_venues tv
ON tgla.team_venue_id = tv.id
JOIN teams_venues_pairs tvp
ON tvp.team_venue_id = tv.id AND tvp.team_fan_page_id = tgla.team_fan_page_id
JOIN teams t
ON tvp.team_fan_page_id = t.fan_page_id
JOIN cities c
ON tv.city_id = c.id
WHERE tgla.deactivated = 0
AND tgla.id = ?
AND t.completed_setup = 1
AND tv.banned = 0";
$query = $this->db->query($sql, array($tgla_id));
$result = $query->row();
if(!$result){
return $result;
}
//attach latest status
$this->db->select('
glas.id as glas_id,
glas.status as glas_status,
glas.create_time as glas_create_time,
glas.users_oauth_uid as glas_users_oauth_uid')
->from('guest_list_authorizations_statuses glas')
->where(array(
'glas.team_guest_list_authorizations_id' => $result->tgla_id
))
->order_by('glas_id', 'desc')
->limit(1, 0);
$query = $this->db->get();
$result->status = $query->row();
if($result->status)
$result->status->glas_human_date = date('l m/d/y h:i:s A', $result->status->glas_create_time);
return $result;
}
/*-------------------------------------------------------------------------
| Update Methods (update)
| ------------------------------------------------------------------------ */
function update_reservation_reassign($options){
//retrieve & simultaniously confirm this guest list matches this team
$sql = "SELECT
tglr.user_oauth_uid as tglr_user_oauth_uid,
tglr.approved as tglr_approved,
tglr.text_message as tglr_text_message,
tglr.share_facebook as tglr_share_facebook,
tgl.date as tgl_date,
tgla.name as tgla_name,
tgla.image as tgla_image,
tv.id as tv_id,
tv.name as tv_name,
tv.image as tv_image,
c.name as c_name,
c.url_identifier as c_url_identifier
FROM teams_guest_lists_reservations tglr
JOIN teams_guest_lists tgl
ON tglr.team_guest_list_id = tgl.id
JOIN teams_guest_list_authorizations tgla
ON tgl.team_guest_list_authorization_id = tgla.id
JOIN team_venues tv
ON tgla.team_venue_id = tv.id
JOIN cities c
ON tv.city_id = c.id
WHERE tglr.id = ? AND tgla.team_fan_page_id = ? ";
// if($team_fan_page_id)
// $sql .= "AND tgla.team_fan_page_id = $team_fan_page_id";
// AND tv.team_fan_page_id = $team_venue_id";
$query = $this->db->query($sql, array($options['tglr_id'], $options['team_fan_page_id']));
$result = $query->row();
if(!$result)
return false;
if($result->tglr_approved == 0)
return false; //this guest list reservation hasn't been approved
if($options['vlfit_id'] !== false){
//verify vlfit_id is for a venue that belongs to this team
$sql = "SELECT
*
FROM venues_layout_floors_items_tables vlfit
JOIN venues_layout_floors_items vlfi
ON vlfit.venues_layout_floors_items_id = vlfi.id
JOIN venues_layout_floors vlf
ON vlfi.venues_layout_floor_id = vlf.id
WHERE vlf.team_venue_id = ?
AND
vlfit.id = ?";
$query = $this->db->query($sql, array($result->tv_id, $options['vlfit_id']));
$result2_temp = $query->row();
if(!$result2_temp){
return false; //this vlfit_id doesn't belong to a venue that's part of this team
}
}
//update record, after we recieve original data (necessary for this to work...)
$this->db->where('id', $options['tglr_id']);
$this->db->update('teams_guest_lists_reservations', array('venues_layout_floors_items_table_id' => $options['vlfit_id']));
return true;
}
/**
* Update a user's guest list reservation request as either 'approved' or 'rejected'
*
* Also perform all related functions such as text-message notifications, emails, etc
*
* @param bool (approved or rejected)
* @param string (response message)
* @param int (team_fan_page_id)
* @param int (team_guest_list_reservation_id)
* @return bool
*/
function update_team_guest_list_reservation_reject_or_approve($approved,
$message,
$team_venue_id,
$team_guest_list_reservation_id,
$approve_override = false,
$table_request = false,
$vlfit_id = false,
$team_fan_page_id = false){
//retrieve & simultaniously confirm this guest list matches this team
$sql = "SELECT
tglr.user_oauth_uid as tglr_user_oauth_uid,
tglr.approved as tglr_approved,
tglr.text_message as tglr_text_message,
tglr.share_facebook as tglr_share_facebook,
tglr.table_request as tglr_table_request,
tglr.manual_add as tglr_manual_add,
tgl.date as tgl_date,
tgla.name as tgla_name,
tgla.image as tgla_image,
tgla.team_fan_page_id as tgla_team_fan_page_id,
tv.id as tv_id,
tv.name as tv_name,