@@ -109,8 +109,8 @@ class Rest extends WebService
109109 public const GET_COURSES_FROM_EXTRA_FIELD = 'get_courses_from_extra_field ' ;
110110 public const SAVE_COURSE = 'save_course ' ;
111111 public const DELETE_COURSE = 'delete_course ' ;
112-
113112 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 ' ;
114114 public const SAVE_SESSION = 'save_session ' ;
115115 public const CREATE_SESSION_FROM_MODEL = 'create_session_from_model ' ;
116116 public const UPDATE_SESSION = 'update_session ' ;
@@ -2514,18 +2514,18 @@ public function subscribeUserToSessionFromUsername(int $sessionId, string $login
25142514 }
25152515
25162516 /**
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)
25182518 *
2519- * @param $fieldName
2520- * @param $fieldValue
2519+ * @param string $fieldName
2520+ * @param string $fieldValue
25212521 *
2522+ * @return int The matching session id, or an array with details about the session
25222523 * @throws Exception when no session matched or more than one session matched
25232524 *
2524- * @return int, the matching session id
25252525 */
2526- public function getSessionFromExtraField ($ fieldName , $ fieldValue )
2526+ public function getSessionFromExtraField (string $ fieldName , string $ fieldValue )
25272527 {
2528- // find sessions that that have value in field
2528+ // find sessions that have that value in the given field
25292529 $ valueModel = new ExtraFieldValue ('session ' );
25302530 $ sessionIdList = $ valueModel ->get_item_id_from_field_variable_and_field_value (
25312531 $ fieldName ,
@@ -2549,6 +2549,54 @@ public function getSessionFromExtraField($fieldName, $fieldValue)
25492549 return intval ($ sessionIdList [0 ]['item_id ' ]);
25502550 }
25512551
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+
25522600 /**
25532601 * Get a list of users subscribed to the given session.
25542602 *
0 commit comments