original_string: protected static function set_acceptances_status($policyversionid, $userid = null, $note = null, $lang = null, $status = 1) {
          global $DB, $USER;
  
          // Validate arguments and capabilities.
          if (empty($policyversionid)) {
              return;
          } else if (!is_array($policyversionid)) {
              $policyversionid = [$policyversionid];
          }
          if (!$userid) {
              $userid = $USER->id;
          }
          self::can_accept_policies([$policyversionid], $userid, true);
  
          // Retrieve the list of policy versions that need agreement (do not update existing agreements).
          list($sql, $params) = $DB->get_in_or_equal($policyversionid, SQL_PARAMS_NAMED);
          $sql = "SELECT v.id AS versionid, a.*
                    FROM {tool_policy_versions} v
               LEFT JOIN {tool_policy_acceptances} a ON a.userid = :userid AND a.policyversionid = v.id
                   WHERE v.id $sql AND (a.id IS NULL OR a.status <> :status)";
  
          $needacceptance = $DB->get_records_sql($sql, $params + [
              'userid' => $userid,
              'status' => $status,
          ]);
  
          $realuser = manager::get_realuser();
          $updatedata = ['status' => $status, 'lang' => $lang ?: current_language(),
              'timemodified' => time(), 'usermodified' => $realuser->id, 'note' => $note];
          foreach ($needacceptance as $versionid => $currentacceptance) {
              unset($currentacceptance->versionid);
              if ($currentacceptance->id) {
                  $updatedata['id'] = $currentacceptance->id;
                  $DB->update_record('tool_policy_acceptances', $updatedata);
                  acceptance_updated::create_from_record((object)($updatedata + (array)$currentacceptance))->trigger();
              } else {
                  $updatedata['timecreated'] = $updatedata['timemodified'];
                  $updatedata['policyversionid'] = $versionid;
                  $updatedata['userid'] = $userid;
                  $updatedata['id'] = $DB->insert_record('tool_policy_acceptances', $updatedata);
                  acceptance_created::create_from_record((object)($updatedata + (array)$currentacceptance))->trigger();
              }
          }
  
          static::update_policyagreed($userid);
      }
code: protected static function set_acceptances_status($policyversionid, $userid = null, $note = null, $lang = null, $status = 1) {
          global $DB, $USER;
  
          // Validate arguments and capabilities.
          if (empty($policyversionid)) {
              return;
          } else if (!is_array($policyversionid)) {
              $policyversionid = [$policyversionid];
          }
          if (!$userid) {
              $userid = $USER->id;
          }
          self::can_accept_policies([$policyversionid], $userid, true);
  
          // Retrieve the list of policy versions that need agreement (do not update existing agreements).
          list($sql, $params) = $DB->get_in_or_equal($policyversionid, SQL_PARAMS_NAMED);
          $sql = "SELECT v.id AS versionid, a.*
                    FROM {tool_policy_versions} v
               LEFT JOIN {tool_policy_acceptances} a ON a.userid = :userid AND a.policyversionid = v.id
                   WHERE v.id $sql AND (a.id IS NULL OR a.status <> :status)";
  
          $needacceptance = $DB->get_records_sql($sql, $params + [
              'userid' => $userid,
              'status' => $status,
          ]);
  
          $realuser = manager::get_realuser();
          $updatedata = ['status' => $status, 'lang' => $lang ?: current_language(),
              'timemodified' => time(), 'usermodified' => $realuser->id, 'note' => $note];
          foreach ($needacceptance as $versionid => $currentacceptance) {
              unset($currentacceptance->versionid);
              if ($currentacceptance->id) {
                  $updatedata['id'] = $currentacceptance->id;
                  $DB->update_record('tool_policy_acceptances', $updatedata);
                  acceptance_updated::create_from_record((object)($updatedata + (array)$currentacceptance))->trigger();
              } else {
                  $updatedata['timecreated'] = $updatedata['timemodified'];
                  $updatedata['policyversionid'] = $versionid;
                  $updatedata['userid'] = $userid;
                  $updatedata['id'] = $DB->insert_record('tool_policy_acceptances', $updatedata);
                  acceptance_created::create_from_record((object)($updatedata + (array)$currentacceptance))->trigger();
              }
          }
  
          static::update_policyagreed($userid);
      }
code_tokens: protected static function set_acceptances_status ( $ policyversionid , $ userid = null , $ note = null , $ lang = null , $ status = 1 ) { global $ DB , $ USER ; // Validate arguments and capabilities. if ( empty ( $ policyversionid ) ) { return ; } else if ( ! is_array ( $ policyversionid ) ) { $ policyversionid = [ $ policyversionid ] ; } if ( ! $ userid ) { $ userid = $ USER -> id ; } self :: can_accept_policies ( [ $ policyversionid ] , $ userid , true ) ; // Retrieve the list of policy versions that need agreement (do not update existing agreements). list ( $ sql , $ params ) = $ DB -> get_in_or_equal ( $ policyversionid , SQL_PARAMS_NAMED ) ; $ sql = "SELECT v.id AS versionid, a.*
                    FROM {tool_policy_versions} v
               LEFT JOIN {tool_policy_acceptances} a ON a.userid = :userid AND a.policyversionid = v.id
                   WHERE v.id $sql AND (a.id IS NULL OR a.status <> :status)" ; $ needacceptance = $ DB -> get_records_sql ( $ sql , $ params + [ 'userid' => $ userid , 'status' => $ status , ] ) ; $ realuser = manager :: get_realuser ( ) ; $ updatedata = [ 'status' => $ status , 'lang' => $ lang ? : current_language ( ) , 'timemodified' => time ( ) , 'usermodified' => $ realuser -> id , 'note' => $ note ] ; foreach ( $ needacceptance as $ versionid => $ currentacceptance ) { unset ( $ currentacceptance -> versionid ) ; if ( $ currentacceptance -> id ) { $ updatedata [ 'id' ] = $ currentacceptance -> id ; $ DB -> update_record ( 'tool_policy_acceptances' , $ updatedata ) ; acceptance_updated :: create_from_record ( ( object ) ( $ updatedata + ( array ) $ currentacceptance ) ) -> trigger ( ) ; } else { $ updatedata [ 'timecreated' ] = $ updatedata [ 'timemodified' ] ; $ updatedata [ 'policyversionid' ] = $ versionid ; $ updatedata [ 'userid' ] = $ userid ; $ updatedata [ 'id' ] = $ DB -> insert_record ( 'tool_policy_acceptances' , $ updatedata ) ; acceptance_created :: create_from_record ( ( object ) ( $ updatedata + ( array ) $ currentacceptance ) ) -> trigger ( ) ; } } static :: update_policyagreed ( $ userid ) ; }
docstring: Mark the given policy versions as accepted or declined by the user.
  
  @param array|int $policyversionid Policy version id(s) to set acceptance status for.
  @param int|null $userid Id of the user accepting the policy version, defaults to the current one.
  @param string|null $note Note to be recorded.
  @param string|null $lang Language in which the policy was shown, defaults to the current one.
  @param int $status The acceptance status, defaults to 1 = accepted
docstring_tokens: Mark the given policy versions as accepted or declined by the user .