@@ -64,10 +64,10 @@ static public function widget_instances_get($inst_ids = null, bool $deleted = fa
64
64
*
65
65
* @return array of objects containing total_num_pages and widget instances that are visible to the user.
66
66
*/
67
- static public function widget_paginate_instances_get ($ page_number = 0 )
67
+ static public function widget_paginate_user_instances_get ($ page_number = 0 )
68
68
{
69
69
if (\Service_User::verify_session () !== true ) return Msg::no_login ();
70
- $ data = Widget_Instance_Manager::get_paginated_for_user (\Model_User::find_current_id (), $ page_number );
70
+ $ data = Widget_Instance_Manager::get_paginated_instances_for_user (\Model_User::find_current_id (), $ page_number );
71
71
return $ data ;
72
72
}
73
73
@@ -218,7 +218,7 @@ static public function widget_instance_new($widget_id=null, $name=null, $qset=nu
218
218
* @param int $close_at
219
219
* @param int $attempts
220
220
* @param bool $guest_access
221
- * @param bool $is_student_made
221
+ * @param bool $is_student_made // NOT USED
222
222
*
223
223
* @return array An associative array with details about the save
224
224
*/
@@ -237,6 +237,10 @@ static public function widget_instance_update($inst_id=null, $name=null, $qset=n
237
237
// student made widgets are locked forever
238
238
if ($ inst ->is_student_made )
239
239
{
240
+ if ($ guest_access === false )
241
+ {
242
+ return new Msg ('Student-made widgets must stay in guest access mode. ' , 'Student Made ' , 'error ' , false );
243
+ }
240
244
$ attempts = -1 ;
241
245
$ guest_access = true ;
242
246
}
@@ -328,36 +332,42 @@ static public function widget_instance_update($inst_id=null, $name=null, $qset=n
328
332
}
329
333
if ($ guest_access !== null )
330
334
{
331
- if ($ inst ->guest_access != $ guest_access )
332
- {
333
- $ activity = new Session_Activity ([
334
- 'user_id ' => \Model_User::find_current_id (),
335
- 'type ' => Session_Activity::TYPE_EDIT_WIDGET_SETTINGS ,
336
- 'item_id ' => $ inst_id ,
337
- 'value_1 ' => 'Guest Access ' ,
338
- 'value_2 ' => $ guest_access
339
- ]);
340
- $ activity ->db_store ();
341
- }
342
- $ inst ->guest_access = $ guest_access ;
343
- // when disabling guest mode on a widget, make sure no students have access to that widget
344
- if ( ! $ guest_access )
335
+ // if the user is a student and they're not the owner, they can't do anything
336
+ // if the user is a student and they're the owner, they're allowed to set it to guest access
337
+ if (($ inst ->user_id == \Model_User::find_current_id () && $ guest_access ) || ! Perm_Manager::is_student (\Model_User::find_current_id ()))
345
338
{
346
- $ access = Perm_Manager::get_all_users_explicit_perms ($ inst_id , Perm::INSTANCE )['widget_user_perms ' ];
347
- foreach ($ access as $ user_id => $ user_perms )
339
+ if ($ inst ->guest_access != $ guest_access )
348
340
{
349
- if (Perm_Manager::is_student ($ user_id ))
341
+ $ activity = new Session_Activity ([
342
+ 'user_id ' => \Model_User::find_current_id (),
343
+ 'type ' => Session_Activity::TYPE_EDIT_WIDGET_SETTINGS ,
344
+ 'item_id ' => $ inst_id ,
345
+ 'value_1 ' => 'Guest Access ' ,
346
+ 'value_2 ' => $ guest_access
347
+ ]);
348
+ $ activity ->db_store ();
349
+ }
350
+ $ inst ->guest_access = $ guest_access ;
351
+ // when disabling guest mode on a widget, make sure no students have access to that widget
352
+ if ( ! $ guest_access )
353
+ {
354
+ $ access = Perm_Manager::get_all_users_explicit_perms ($ inst_id , Perm::INSTANCE )['widget_user_perms ' ];
355
+ foreach ($ access as $ user_id => $ user_perms )
350
356
{
351
- \Model_Notification::send_item_notification (\Model_user::find_current_id (), $ user_id , Perm::INSTANCE , $ inst_id , 'disabled ' , null );
352
- Perm_Manager::clear_user_object_perms ($ inst_id , Perm::INSTANCE , $ user_id );
357
+ if (Perm_Manager::is_student ($ user_id ) && $ user_id != $ inst ->user_id )
358
+ {
359
+ \Model_Notification::send_item_notification (\Model_user::find_current_id (), $ user_id , Perm::INSTANCE , $ inst_id , 'disabled ' , null );
360
+ Perm_Manager::clear_user_object_perms ($ inst_id , Perm::INSTANCE , $ user_id );
361
+ }
353
362
}
354
363
}
355
364
}
356
365
}
357
366
358
367
if ($ embedded_only !== null )
359
368
{
360
- if ($ inst ->embedded_only != $ embedded_only )
369
+ // if current user is student, they cannot change embedded_only
370
+ if ($ inst ->embedded_only != $ embedded_only && ! Perm_Manager::is_student (\Model_User::find_current_id ()))
361
371
{
362
372
$ activity = new Session_Activity ([
363
373
'user_id ' => \Model_User::find_current_id (),
@@ -367,8 +377,9 @@ static public function widget_instance_update($inst_id=null, $name=null, $qset=n
367
377
'value_2 ' => $ embedded_only
368
378
]);
369
379
$ activity ->db_store ();
380
+
381
+ $ inst ->embedded_only = $ embedded_only ;
370
382
}
371
- $ inst ->embedded_only = $ embedded_only ;
372
383
}
373
384
374
385
try
@@ -662,11 +673,12 @@ static public function guest_widget_instance_scores_get($inst_id, $play_id)
662
673
*/
663
674
static public function play_logs_get ($ inst_id , $ semester = 'all ' , $ year = 'all ' , $ page_number =1 )
664
675
{
665
- if ( ! Util_Validator::is_valid_hash ($ inst_id )) return Msg::invalid_input ($ inst_id );
676
+ if ( ! Util_Validator::is_valid_hash ($ inst_id )) return Msg::invalid_input ($ inst_id );
666
677
if (\Service_User::verify_session () !== true ) return Msg::no_login ();
667
678
if ( ! static ::has_perms_to_inst ($ inst_id , [Perm::VISIBLE , Perm::FULL ])) return Msg::no_perm ();
679
+ $ is_student = ! \Service_User::verify_session (['basic_author ' , 'super_user ' ]);
668
680
669
- $ data = Session_Play::get_by_inst_id_paginated ($ inst_id , $ semester , $ year , $ page_number );
681
+ $ data = Session_Play::get_by_inst_id_paginated ($ inst_id , $ semester , $ year , $ page_number, $ is_student );
670
682
return $ data ;
671
683
}
672
684
@@ -881,23 +893,39 @@ static public function semester_date_ranges_get()
881
893
return Utils::get_date_ranges ();
882
894
}
883
895
884
- static public function users_search ($ search )
896
+ /**
897
+ * Paginated search for users that match input
898
+ *
899
+ * @param string Search query
900
+ * @param string Page number
901
+ * @return array List of users
902
+ */
903
+ static public function users_search ($ input , $ page_number = 0 )
885
904
{
886
905
if (\Service_User::verify_session () !== true ) return Msg::no_login ();
887
906
888
- $ user_objects = \Model_User::find_by_name_search ($ search );
889
- $ user_arrays = [];
907
+ $ items_per_page = 50 ;
908
+ $ offset = $ items_per_page * $ page_number ;
909
+
910
+ // query DB for only a single page + 1 item
911
+ $ displayable_items = \Model_User::find_by_name_search ($ input , $ offset , $ items_per_page + 1 );
912
+
913
+ $ has_next_page = sizeof ($ displayable_items ) > $ items_per_page ? true : false ;
914
+
915
+ if ($ has_next_page ) array_pop ($ displayable_items );
890
916
891
- // scrub the user models with to_array
892
- if (count ($ user_objects ))
917
+ foreach ($ displayable_items as $ key => $ person )
893
918
{
894
- foreach ($ user_objects as $ key => $ person )
895
- {
896
- $ user_arrays [$ key ] = $ person ->to_array ();
897
- }
919
+ $ displayable_items [$ key ] = $ person ->to_array ();
898
920
}
899
921
900
- return $ user_arrays ;
922
+ $ data = [
923
+ 'pagination ' => $ displayable_items ,
924
+ ];
925
+
926
+ if ($ has_next_page ) $ data ['next_page ' ] = $ page_number + 1 ;
927
+
928
+ return $ data ;
901
929
}
902
930
/**
903
931
* Gets information about the current user
0 commit comments