@@ -109,8 +109,8 @@ class Rest extends WebService
109
109
public const GET_COURSES_FROM_EXTRA_FIELD = 'get_courses_from_extra_field ' ;
110
110
public const SAVE_COURSE = 'save_course ' ;
111
111
public const DELETE_COURSE = 'delete_course ' ;
112
-
113
112
public const GET_SESSION_FROM_EXTRA_FIELD = 'get_session_from_extra_field ' ;
113
+ public const GET_SESSION_INFO_FROM_EXTRA_FIELD = 'get_session_info_from_extra_field ' ;
114
114
public const SAVE_SESSION = 'save_session ' ;
115
115
public const CREATE_SESSION_FROM_MODEL = 'create_session_from_model ' ;
116
116
public const UPDATE_SESSION = 'update_session ' ;
@@ -2514,18 +2514,18 @@ public function subscribeUserToSessionFromUsername(int $sessionId, string $login
2514
2514
}
2515
2515
2516
2516
/**
2517
- * finds the session which has a specific value in a specific extra field.
2517
+ * Finds the session which has a specific value in a specific extra field and return its ID (only that)
2518
2518
*
2519
- * @param $fieldName
2520
- * @param $fieldValue
2519
+ * @param string $fieldName
2520
+ * @param string $fieldValue
2521
2521
*
2522
+ * @return int The matching session id, or an array with details about the session
2522
2523
* @throws Exception when no session matched or more than one session matched
2523
2524
*
2524
- * @return int, the matching session id
2525
2525
*/
2526
- public function getSessionFromExtraField ($ fieldName , $ fieldValue )
2526
+ public function getSessionFromExtraField (string $ fieldName , string $ fieldValue )
2527
2527
{
2528
- // find sessions that that have value in field
2528
+ // find sessions that have that value in the given field
2529
2529
$ valueModel = new ExtraFieldValue ('session ' );
2530
2530
$ sessionIdList = $ valueModel ->get_item_id_from_field_variable_and_field_value (
2531
2531
$ fieldName ,
@@ -2549,6 +2549,54 @@ public function getSessionFromExtraField($fieldName, $fieldValue)
2549
2549
return intval ($ sessionIdList [0 ]['item_id ' ]);
2550
2550
}
2551
2551
2552
+ /**
2553
+ * Finds the session which has a specific value in a specific extra field and return its details
2554
+ *
2555
+ * @param string $fieldName
2556
+ * @param string $fieldValue
2557
+ *
2558
+ * @return array The matching session id, or an array with details about the session
2559
+ * @throws Exception when no session matched or more than one session matched
2560
+ *
2561
+ */
2562
+ public function getSessionInfoFromExtraField (string $ fieldName , string $ fieldValue ): array
2563
+ {
2564
+ $ session = [];
2565
+ // find sessions that have that value in the given field
2566
+ $ valueModel = new ExtraFieldValue ('session ' );
2567
+ $ sessionIdList = $ valueModel ->get_item_id_from_field_variable_and_field_value (
2568
+ $ fieldName ,
2569
+ $ fieldValue ,
2570
+ false ,
2571
+ false ,
2572
+ true
2573
+ );
2574
+
2575
+ // throw if none found
2576
+ if (empty ($ sessionIdList )) {
2577
+ throw new Exception (get_lang ('NoSessionMatched ' ));
2578
+ }
2579
+
2580
+ // throw if more than one found
2581
+ if (count ($ sessionIdList ) > 1 ) {
2582
+ throw new Exception (get_lang ('MoreThanOneSessionMatched ' ));
2583
+ }
2584
+
2585
+ $ session = api_get_session_info ($ sessionIdList [0 ]['item_id ' ]);
2586
+ $ bundle = [
2587
+ 'id ' => $ session ['id ' ],
2588
+ 'name ' => $ session ['name ' ],
2589
+ 'access_start_date ' => $ session ['access_start_date ' ],
2590
+ 'access_end_date ' => $ session ['access_end_date ' ],
2591
+ ];
2592
+ $ extraFieldValues = new ExtraFieldValue ('session ' );
2593
+ $ extraFields = $ extraFieldValues ->getAllValuesByItem ($ session ['id ' ]);
2594
+ $ bundle ['extra_fields ' ] = $ extraFields ;
2595
+
2596
+ // return session details, including extra fields that have filter=1
2597
+ return $ bundle ;
2598
+ }
2599
+
2552
2600
/**
2553
2601
* Get a list of users subscribed to the given session.
2554
2602
*
0 commit comments