protected function prepare_user_acceptances($userid) {
        global $USER;

        // Get all the policy version acceptances for this user.
        $lang = current_language();
        foreach ($this->policies as $policy) {
            // Get a link to display the full policy document.
            $policy->url = new moodle_url('/admin/tool/policy/view.php',
                array('policyid' => $policy->policyid, 'returnurl' => qualified_me()));
            $policyattributes = array('data-action' => 'view',
                                      'data-versionid' => $policy->id,
                                      'data-behalfid' => $this->behalfid);
            $policymodal = html_writer::link($policy->url, $policy->name, $policyattributes);

            // Check if this policy version has been agreed or not.
            if ($this->isexistinguser) {
                // Existing user.
                $versionagreed = false;
                $versiondeclined = false;
                $acceptances = api::get_user_acceptances($userid);
                $policy->versionacceptance = api::get_user_version_acceptance($userid, $policy->id, $acceptances);
                if (!empty($policy->versionacceptance)) {
                    // The policy version has ever been replied to before. Check if status = 1 to know if still is accepted.
                    if ($policy->versionacceptance->status) {
                        $versionagreed = true;
                    } else {
                        $versiondeclined = true;
                    }
                    if ($versionagreed) {
                        if ($policy->versionacceptance->lang != $lang) {
                            // Add a message because this version has been accepted in a different language than the current one.
                            $policy->versionlangsagreed = get_string('policyversionacceptedinotherlang', 'tool_policy');
                        }
                        $usermodified = $policy->versionacceptance->usermodified;
                        if ($usermodified && $usermodified != $userid && $USER->id == $userid) {
                            // Add a message because this version has been accepted on behalf of current user.
                            $policy->versionbehalfsagreed = get_string('policyversionacceptedinbehalf', 'tool_policy');
                        }
                    }
                }
            } else {
                // New user.
                $versionagreed = in_array($policy->id, $this->agreedocs);
                $versiondeclined = false;
            }
            $policy->versionagreed = $versionagreed;
            $policy->versiondeclined = $versiondeclined;
            $policy->policylink = html_writer::link($policy->url, $policy->name);
            $policy->policymodal = $policymodal;
        }
    }
protected function prepare_user_acceptances($userid) {
        global $USER;

        // Get all the policy version acceptances for this user.
        $lang = current_language();
        foreach ($this->policies as $policy) {
            // Get a link to display the full policy document.
            $policy->url = new moodle_url('/admin/tool/policy/view.php',
                array('policyid' => $policy->policyid, 'returnurl' => qualified_me()));
            $policyattributes = array('data-action' => 'view',
                                      'data-versionid' => $policy->id,
                                      'data-behalfid' => $this->behalfid);
            $policymodal = html_writer::link($policy->url, $policy->name, $policyattributes);

            // Check if this policy version has been agreed or not.
            if ($this->isexistinguser) {
                // Existing user.
                $versionagreed = false;
                $versiondeclined = false;
                $acceptances = api::get_user_acceptances($userid);
                $policy->versionacceptance = api::get_user_version_acceptance($userid, $policy->id, $acceptances);
                if (!empty($policy->versionacceptance)) {
                    // The policy version has ever been replied to before. Check if status = 1 to know if still is accepted.
                    if ($policy->versionacceptance->status) {
                        $versionagreed = true;
                    } else {
                        $versiondeclined = true;
                    }
                    if ($versionagreed) {
                        if ($policy->versionacceptance->lang != $lang) {
                            // Add a message because this version has been accepted in a different language than the current one.
                            $policy->versionlangsagreed = get_string('policyversionacceptedinotherlang', 'tool_policy');
                        }
                        $usermodified = $policy->versionacceptance->usermodified;
                        if ($usermodified && $usermodified != $userid && $USER->id == $userid) {
                            // Add a message because this version has been accepted on behalf of current user.
                            $policy->versionbehalfsagreed = get_string('policyversionacceptedinbehalf', 'tool_policy');
                        }
                    }
                }
            } else {
                // New user.
                $versionagreed = in_array($policy->id, $this->agreedocs);
                $versiondeclined = false;
            }
            $policy->versionagreed = $versionagreed;
            $policy->versiondeclined = $versiondeclined;
            $policy->policylink = html_writer::link($policy->url, $policy->name);
            $policy->policymodal = $policymodal;
        }
    }
protected function prepare_user_acceptances ( $ userid ) { global $ USER ; // Get all the policy version acceptances for this user. $ lang = current_language ( ) ; foreach ( $ this -> policies as $ policy ) { // Get a link to display the full policy document. $ policy -> url = new moodle_url ( '/admin/tool/policy/view.php' , array ( 'policyid' => $ policy -> policyid , 'returnurl' => qualified_me ( ) ) ) ; $ policyattributes = array ( 'data-action' => 'view' , 'data-versionid' => $ policy -> id , 'data-behalfid' => $ this -> behalfid ) ; $ policymodal = html_writer :: link ( $ policy -> url , $ policy -> name , $ policyattributes ) ; // Check if this policy version has been agreed or not. if ( $ this -> isexistinguser ) { // Existing user. $ versionagreed = false ; $ versiondeclined = false ; $ acceptances = api :: get_user_acceptances ( $ userid ) ; $ policy -> versionacceptance = api :: get_user_version_acceptance ( $ userid , $ policy -> id , $ acceptances ) ; if ( ! empty ( $ policy -> versionacceptance ) ) { // The policy version has ever been replied to before. Check if status = 1 to know if still is accepted. if ( $ policy -> versionacceptance -> status ) { $ versionagreed = true ; } else { $ versiondeclined = true ; } if ( $ versionagreed ) { if ( $ policy -> versionacceptance -> lang != $ lang ) { // Add a message because this version has been accepted in a different language than the current one. $ policy -> versionlangsagreed = get_string ( 'policyversionacceptedinotherlang' , 'tool_policy' ) ; } $ usermodified = $ policy -> versionacceptance -> usermodified ; if ( $ usermodified && $ usermodified != $ userid && $ USER -> id == $ userid ) { // Add a message because this version has been accepted on behalf of current user. $ policy -> versionbehalfsagreed = get_string ( 'policyversionacceptedinbehalf' , 'tool_policy' ) ; } } } } else { // New user. $ versionagreed = in_array ( $ policy -> id , $ this -> agreedocs ) ; $ versiondeclined = false ; } $ policy -> versionagreed = $ versionagreed ; $ policy -> versiondeclined = $ versiondeclined ; $ policy -> policylink = html_writer :: link ( $ policy -> url , $ policy -> name ) ; $ policy -> policymodal = $ policymodal ; } }
Prepare user acceptances.

@param int $userid
Prepare user acceptances .