public static function get_user_devices($appid, $userid = 0) {
        global $USER;

        $params = self::validate_parameters(
            self::get_user_devices_parameters(),
            array(
                'appid' => $appid,
                'userid' => $userid,
            )
        );

        $context = context_system::instance();
        self::validate_context($context);

        if (empty($params['userid'])) {
            $user = $USER;
        } else {
            $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
            core_user::require_active_user($user);
            // Allow only admins to retrieve other users devices.
            if ($user->id != $USER->id) {
                require_capability('moodle/site:config', $context);
            }
        }

        $warnings = array();
        $devices = array();
        // Check if mobile notifications are enabled.
        if (!self::is_system_configured()) {
            $warnings[] = array(
                'item' => 'user',
                'itemid' => $user->id,
                'warningcode' => 'systemnotconfigured',
                'message' => 'Mobile notifications are not configured'
            );
        } else {
            // We catch exceptions here because get_user_devices may try to connect to Airnotifier.
            try {
                $manager = new message_airnotifier_manager();
                $devices = $manager->get_user_devices($appid, $user->id);
            } catch (Exception $e) {
                $warnings[] = array(
                    'item' => 'user',
                    'itemid' => $user->id,
                    'warningcode' => 'errorgettingdevices',
                    'message' => $e->getMessage()
                );
            }
        }

        return array(
            'devices' => $devices,
            'warnings' => $warnings
        );
    }
public static function get_user_devices($appid, $userid = 0) {
        global $USER;

        $params = self::validate_parameters(
            self::get_user_devices_parameters(),
            array(
                'appid' => $appid,
                'userid' => $userid,
            )
        );

        $context = context_system::instance();
        self::validate_context($context);

        if (empty($params['userid'])) {
            $user = $USER;
        } else {
            $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
            core_user::require_active_user($user);
            // Allow only admins to retrieve other users devices.
            if ($user->id != $USER->id) {
                require_capability('moodle/site:config', $context);
            }
        }

        $warnings = array();
        $devices = array();
        // Check if mobile notifications are enabled.
        if (!self::is_system_configured()) {
            $warnings[] = array(
                'item' => 'user',
                'itemid' => $user->id,
                'warningcode' => 'systemnotconfigured',
                'message' => 'Mobile notifications are not configured'
            );
        } else {
            // We catch exceptions here because get_user_devices may try to connect to Airnotifier.
            try {
                $manager = new message_airnotifier_manager();
                $devices = $manager->get_user_devices($appid, $user->id);
            } catch (Exception $e) {
                $warnings[] = array(
                    'item' => 'user',
                    'itemid' => $user->id,
                    'warningcode' => 'errorgettingdevices',
                    'message' => $e->getMessage()
                );
            }
        }

        return array(
            'devices' => $devices,
            'warnings' => $warnings
        );
    }
public static function get_user_devices ( $ appid , $ userid = 0 ) { global $ USER ; $ params = self :: validate_parameters ( self :: get_user_devices_parameters ( ) , array ( 'appid' => $ appid , 'userid' => $ userid , ) ) ; $ context = context_system :: instance ( ) ; self :: validate_context ( $ context ) ; if ( empty ( $ params [ 'userid' ] ) ) { $ user = $ USER ; } else { $ user = core_user :: get_user ( $ params [ 'userid' ] , '*' , MUST_EXIST ) ; core_user :: require_active_user ( $ user ) ; // Allow only admins to retrieve other users devices. if ( $ user -> id != $ USER -> id ) { require_capability ( 'moodle/site:config' , $ context ) ; } } $ warnings = array ( ) ; $ devices = array ( ) ; // Check if mobile notifications are enabled. if ( ! self :: is_system_configured ( ) ) { $ warnings [ ] = array ( 'item' => 'user' , 'itemid' => $ user -> id , 'warningcode' => 'systemnotconfigured' , 'message' => 'Mobile notifications are not configured' ) ; } else { // We catch exceptions here because get_user_devices may try to connect to Airnotifier. try { $ manager = new message_airnotifier_manager ( ) ; $ devices = $ manager -> get_user_devices ( $ appid , $ user -> id ) ; } catch ( Exception $ e ) { $ warnings [ ] = array ( 'item' => 'user' , 'itemid' => $ user -> id , 'warningcode' => 'errorgettingdevices' , 'message' => $ e -> getMessage ( ) ) ; } } return array ( 'devices' => $ devices , 'warnings' => $ warnings ) ; }
Return the list of mobile devices that are registered in Moodle for the given user.

@param  string  $appid  app unique id (usually a reversed domain)
@param  integer $userid the user id, 0 for current user
@return array warnings and devices
@throws moodle_exception
@since Moodle 3.2
Return the list of mobile devices that are registered in Moodle for the given user .