Export all user preferences for the plugin.

@param   int $userid The userid of the user whose data is to be exported.
345428
public static function export_user_preferences(int $userid) {
        $preffilter = get_user_preferences(tool_helper::PREF_REQUEST_FILTERS, null, $userid);
        if ($preffilter !== null) {
            $filters = json_decode($preffilter);
            $descriptions = [];
            foreach ($filters as $filter) {
                list($category, $value) = explode(':', $filter);
                $option = new stdClass();
                switch($category) {
                    case tool_helper::FILTER_TYPE:
                        $option->category = get_string('requesttype', 'tool_dataprivacy');
                        $option->name = tool_helper::get_shortened_request_type_string($value);
                        break;
                    case tool_helper::FILTER_STATUS:
                        $option->category = get_string('requeststatus', 'tool_dataprivacy');
                        $option->name = tool_helper::get_request_status_string($value);
                        break;
                    case tool_helper::FILTER_CREATION:
                        $option->category = get_string('requestcreation', 'tool_dataprivacy');
                        $option->name = tool_helper::get_request_creation_method_string($value);
                        break;
                }
                $descriptions[] = get_string('filteroption', 'tool_dataprivacy', $option);
            }
            // Export the filter preference as comma-separated values and text descriptions.
            $values = implode(', ', $filters);
            $descriptionstext = implode(', ', $descriptions);
            writer::export_user_preference('tool_dataprivacy', tool_helper::PREF_REQUEST_FILTERS, $values, $descriptionstext);
        }

        $prefperpage = get_user_preferences(tool_helper::PREF_REQUEST_PERPAGE, null, $userid);
        if ($prefperpage !== null) {
            writer::export_user_preference('tool_dataprivacy', tool_helper::PREF_REQUEST_PERPAGE, $prefperpage,
                get_string('privacy:metadata:preference:tool_dataprivacy_request-perpage', 'tool_dataprivacy'));
        }
    }
1046456
public static function export_user_preferences(int $userid) {
        $lastpasswordupdatetime = get_user_preferences('auth_manual_passwordupdatetime', null, $userid);
        if ($lastpasswordupdatetime !== null) {
            $time = transform::datetime($lastpasswordupdatetime);
            writer::export_user_preference('auth_manual',
                'auth_manual_passwordupdatetime',
                $time,
                get_string('privacy:metadata:preference:passwordupdatetime', 'auth_manual')
            );
        }
    }
407845
public static function export_user_preferences(int $userid) {
        $preference = get_user_preferences('quiz_overview_slotmarks', null);
        if (null !== $preference) {
            if (empty($preference)) {
                $description = get_string('privacy:preference:slotmarks:no', 'quiz_overview');
            } else {
                $description = get_string('privacy:preference:slotmarks:yes', 'quiz_overview');
            }

            writer::export_user_preference(
                'quiz_overview',
                'slotmarks',
                transform::yesno($preference),
                $description
            );
        }
    }
321718
public function getRatingsByUserId($userId)
    {
        $queryBuilder = $this->queryBuilderFactory->create();
        $queryBuilder
            ->select('r.*')
            ->from('oxratings', 'r')
            ->where('r.oxuserid = :userId')
            ->orderBy('r.oxtimestamp', 'DESC')
            ->setParameter('userId', $userId);

        return $this->mapRatings($queryBuilder->execute()->fetchAll());
    }
1362078
public static function get_providers_preferences($providers, $userid) {
        $preferences = new \stdClass();

        // Get providers preferences.
        foreach ($providers as $provider) {
            foreach (array('loggedin', 'loggedoff') as $state) {
                $linepref = get_user_preferences('message_provider_' . $provider->component . '_' . $provider->name
                    . '_' . $state, '', $userid);
                if ($linepref == '') {
                    continue;
                }
                $lineprefarray = explode(',', $linepref);
                $preferences->{$provider->component.'_'.$provider->name.'_'.$state} = array();
                foreach ($lineprefarray as $pref) {
                    $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$pref] = 1;
                }
            }
        }

        return $preferences;
    }
626223
public function getUserOptions(string $id, string $userID): ?array
    {
        $data = Internal\Data::getValue('.temp/bearcms/userthemeoptions/' . md5($userID) . '/' . md5($id) . '.json');
        if ($data !== null) {
            $data = json_decode($data, true);
            if (isset($data['options'])) {
                return $data['options'];
            }
        }
        return null;
    }
183287
public static function export_user_preferences(int $userid) {
        $userhomepagepreference = get_user_preferences('user_home_page_preference', null, $userid);

        if (null !== $userhomepagepreference) {
            writer::export_user_preference(
                'core_my',
                'user_home_page_preference',
                $userhomepagepreference,
                get_string('privacy:metadata:core_my:preference:user_home_page_preference', 'core_my')
            );
        }
    }
501283
public static function convertUserIdToVisitorIdBin($userId)
    {
        require_once PIWIK_INCLUDE_PATH . '/libs/PiwikTracker/PiwikTracker.php';
        $userIdHashed = \PiwikTracker::getUserIdHashed($userId);

        return self::convertVisitorIdToBin($userIdHashed);
    }
413809
public static function get_user_message_preferences($userid = 0) {
        global $CFG, $PAGE;

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

        $user = self::validate_preferences_permissions($params['userid']);

        // Filter out enabled, available system_configured and user_configured processors only.
        $readyprocessors = array_filter(get_message_processors(), function($processor) {
            return $processor->enabled &&
                $processor->configured &&
                $processor->object->is_user_configured() &&
                // Filter out processors that don't have and message preferences to configure.
                $processor->object->has_message_preferences();
        });

        $providers = array_filter(message_get_providers_for_user($user->id), function($provider) {
            return $provider->component === 'moodle';
        });
        $preferences = \core_message\api::get_all_message_preferences($readyprocessors, $providers, $user);
        $notificationlistoutput = new \core_message\output\preferences\message_notification_list($readyprocessors,
            $providers, $preferences, $user);

        $renderer = $PAGE->get_renderer('core_message');

        $entertosend = get_user_preferences('message_entertosend', $CFG->messagingdefaultpressenter, $user);

        $result = array(
            'warnings' => array(),
            'preferences' => $notificationlistoutput->export_for_template($renderer),
            'blocknoncontacts' => \core_message\api::get_user_privacy_messaging_preference($user->id),
            'entertosend' => $entertosend
        );
        return $result;
    }
1301337
protected static function delete_data(int $userid) {
        global $DB;

        foreach (static::get_records($userid) as $record) {
            $DB->delete_records('message_airnotifier_devices', ['id' => $record->id]);
        }
    }
47695
public function delete($userId)
    {
        if (is_array($userId)) {
            return $this->batchDelete($userId);
        }

        return $this->httpGet('cgi-bin/user/delete', ['userid' => $userId]);
    }
1226836
public static function export_user_preferences(int $userid) {
        $preferences = get_user_preferences();
        foreach ($preferences as $name => $value) {
            $prefname = null;
            $prefdescription = null;
            $transformedvalue = null;
            switch ($name) {
                case 'grade_report_showcalculations':
                case 'grade_report_showeyecons':
                case 'grade_report_showaverages':
                case 'grade_report_showlocks':
                case 'grade_report_showuserimage':
                case 'grade_report_showactivityicons':
                case 'grade_report_showranges':
                case 'grade_report_showanalysisicon':
                case 'grade_report_shownumberofgrades':
                case 'grade_report_quickgrading':
                case 'grade_report_showonlyactiveenrol':
                case 'grade_report_showquickfeedback':
                case 'grade_report_enableajax':
                    $prefname = $name;
                    $transformedvalue = transform::yesno($value);
                    break;
                case 'grade_report_meanselection':
                    $prefname = $name;
                    switch ($value) {
                        case GRADE_REPORT_MEAN_ALL:
                            $transformedvalue = get_string('meanall', 'grades');
                            break;
                        case GRADE_REPORT_MEAN_GRADED:
                            $transformedvalue = get_string('meangraded', 'grades');
                            break;
                    }
                    break;
                case 'grade_report_rangesdecimalpoints':
                case 'grade_report_averagesdecimalpoints':
                case 'grade_report_studentsperpage':
                    $prefname = $name;
                    $transformedvalue = $value;
                    break;
                case 'grade_report_rangesdisplaytype':
                case 'grade_report_averagesdisplaytype':
                    $prefname = $name;
                    switch ($value) {
                        case GRADE_REPORT_PREFERENCE_INHERIT:
                            $transformedvalue = get_string('inherit', 'grades');
                            break;
                        case GRADE_DISPLAY_TYPE_REAL:
                            $transformedvalue = get_string('real', 'grades');
                            break;
                        case GRADE_DISPLAY_TYPE_PERCENTAGE:
                            $transformedvalue = get_string('percentage', 'grades');
                            break;
                        case GRADE_DISPLAY_TYPE_LETTER:
                            $transformedvalue = get_string('letter', 'grades');
                            break;
                    }
                    break;
                case 'grade_report_aggregationposition':
                    $prefname = $name;
                    switch ($value) {
                        case GRADE_REPORT_AGGREGATION_POSITION_FIRST:
                            $transformedvalue = get_string('positionfirst', 'grades');
                            break;
                        case GRADE_REPORT_AGGREGATION_POSITION_LAST:
                            $transformedvalue = get_string('positionlast', 'grades');
                            break;
                    }
                    break;
                default:
                    if (strpos($name, 'grade_report_grader_collapsed_categories') === 0) {
                        $prefname = 'grade_report_grader_collapsed_categories';
                        $courseid = substr($name, strlen('grade_report_grader_collapsed_categories'));
                        $transformedvalue = $value;
                        $course = get_course($courseid);
                        $prefdescription = get_string(
                            'privacy:request:preference:'.$prefname,
                            'gradereport_grader',
                            (object) [
                                'name' => $course->fullname,
                            ]
                        );
                    }
            }

            if ($prefname !== null) {
                if ($prefdescription == null) {
                    $prefdescription = get_string('privacy:metadata:preference:'.$prefname, 'gradereport_grader');
                }
                writer::export_user_preference(
                    'gradereport_grader',
                    $prefname,
                    $transformedvalue,
                    $prefdescription
                );
            }
        }
    }
325744
protected function fetchUserData($userId)
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->select(
                $this->connection->quoteIdentifier('usr.contentobject_id'),
                $this->connection->quoteIdentifier('usr.login'),
                $this->connection->quoteIdentifier('usr.email'),
                $this->connection->quoteIdentifier('usr.password_hash'),
                $this->connection->quoteIdentifier('usr.password_hash_type')
            )
            ->from($this->connection->quoteIdentifier(self::USER_TABLE), 'usr')
            ->where(
                $query->expr()->eq(
                    $this->connection->quoteIdentifier('usr.contentobject_id'),
                    ':userId'
                )
            )
            ->setParameter(':userId', $userId, PDO::PARAM_INT)
        ;

        $statement = $query->execute();

        $rows = $statement->fetchAll(PDO::FETCH_ASSOC);

        return isset($rows[0]) ? $this->convertColumnsToProperties($rows[0]) : [];
    }
948750
public function clearUserCachedPerms($userId)
    {
        $cache = $this->getCache();
        
        $ids = $cache->getIds();
        foreach ($ids as $id) {
            // get the item, see if it has the user ID
            if ($id == self::SOURCES_MAP || strpos($id, 'source_') !== false || strpos($id, self::ITEM_PREFIX) === false) {
                continue;
            }

            $userPerms = $cache->load($id);
            if (is_array($userPerms)) {
                $changed = false;
                foreach ($userPerms as $type => $grantedUserIds) {
                    $newIds = array();
                    foreach ($grantedUserIds as $grantedUserId => $grant) {
                        if ($userId != $grantedUserId) {
                            $newIds[$grantedUserId] = $grant;
                        }
                    }
                    if (count($newIds) != count($userPerms[$type])) {
                        $userPerms[$type] = $newIds;
                        $changed = true;
                    }
                }
                if ($changed) {
                    $cache->save($userPerms, $id);
                }
            }
        }
    }
1011648
public function userCopy($userId, $options=array()){

        $data = array();
        
        $data['user_id'] = $userId;

        $data = array_merge($data, $options);

        return $this->request($this->userCopyUrl, $data);
    }
216362
protected static function export_user_data_contact_requests(int $userid) {
        global $DB;

        $context = \context_user::instance($userid);

        if ($contactrequests = $DB->get_records_select('message_contact_requests', 'userid = ? OR requesteduserid = ?',
                [$userid, $userid], 'id ASC')) {
            $contactrequestsdata = [];
            foreach ($contactrequests as $contactrequest) {
                if ($userid == $contactrequest->requesteduserid) {
                    $maderequest = false;
                    $contactid = $contactrequest->userid;
                } else {
                    $maderequest = true;
                    $contactid = $contactrequest->requesteduserid;
                }

                $contactrequestsdata[] = (object) [
                    'contactrequest' => transform::user($contactid),
                    'maderequest' => transform::yesno($maderequest)
                ];
            }
            writer::with_context($context)->export_data([get_string('contactrequests', 'core_message')],
                (object) $contactrequestsdata);
        }
    }
445468
protected static function export_user_data_in_module_contexts($userid, array $contexts) {
        global $DB;

        $contexts = array_filter($contexts, function($context) {
            return $context->contextlevel == CONTEXT_MODULE;
        });
        if (empty($contexts)) {
            return;
        }

        $path = [get_string('competencies', 'core_competency')];
        $cmids = array_map(function($context) {
            return $context->instanceid;
        }, $contexts);

        // Fetch all the modules with associations we created or modified.
        $compfields = competency::get_sql_fields('c', 'c_');
        $cmcfields = course_module_competency::get_sql_fields('cmc', 'cmc_');
        $ctxfields = context_helper::get_preload_record_columns_sql('ctx');
        list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED);
        $sql = "
            SELECT $compfields, $cmcfields, $ctxfields
              FROM {" . course_module_competency::TABLE . "} cmc
              JOIN {" . competency::TABLE . "} c
                ON c.id = cmc.competencyid
              JOIN {" . competency_framework::TABLE . "} f
                ON f.id = c.competencyframeworkid
              JOIN {context} ctx
                ON ctx.id = f.contextid
             WHERE cmc.usermodified = :userid
               AND cmc.cmid $insql
          ORDER BY cmc.cmid";
        $params = array_merge($inparams, ['userid' => $userid]);

        // Export the data.
        $recordset = $DB->get_recordset_sql($sql, $params);
        static::recordset_loop_and_export($recordset, 'cmc_cmid', [], function($carry, $record) {
            context_helper::preload_from_record($record);
            $competency = new competency(null, competency::extract_record($record, 'c_'));
            $cmc = new course_module_competency(null, course_module_competency::extract_record($record, 'cmc_'));
            $carry[] = array_merge(static::transform_competency_brief($competency), [
                'timecreated' => transform::datetime($cmc->get('timecreated')),
                'timemodified' => transform::datetime($cmc->get('timemodified')),
                'created_or_modified_by_you' => transform::yesno(true)
            ]);
            return $carry;

        }, function($cmid, $data) use ($path) {
            $context = context_module::instance($cmid);
            writer::with_context($context)->export_data($path, (object) ['associations' => $data]);
        });
    }