original_string: public function share_file($fileid, $businesscheck = true) {
          // Sharing the file, this requires a PUT request with data within it. We cannot use
          // the standard PUT request 'CURLOPT_PUT' because it expects a file.
          $data = array('shared_link' => array('access' => 'open', 'permissions' =>
              array('can_download' => true, 'can_preview' => true)));
          $options = array(
              'CURLOPT_CUSTOMREQUEST' => 'PUT',
              'CURLOPT_POSTFIELDS' => json_encode($data)
          );
          $this->reset_state();
          $result = $this->request($this->make_url("/files/$fileid"), $options);
          $result = json_decode($result);
  
          if ($businesscheck) {
              // Checks that the user has the right to share the file. If not, throw an exception.
              $this->reset_state();
              $this->head($result->shared_link->download_url);
              $info = $this->get_info();
              if ($info['http_code'] == 403) {
                  throw new moodle_exception('No permission to share the file');
              }
          }
  
          return $result->shared_link;
      }
code: public function share_file($fileid, $businesscheck = true) {
          // Sharing the file, this requires a PUT request with data within it. We cannot use
          // the standard PUT request 'CURLOPT_PUT' because it expects a file.
          $data = array('shared_link' => array('access' => 'open', 'permissions' =>
              array('can_download' => true, 'can_preview' => true)));
          $options = array(
              'CURLOPT_CUSTOMREQUEST' => 'PUT',
              'CURLOPT_POSTFIELDS' => json_encode($data)
          );
          $this->reset_state();
          $result = $this->request($this->make_url("/files/$fileid"), $options);
          $result = json_decode($result);
  
          if ($businesscheck) {
              // Checks that the user has the right to share the file. If not, throw an exception.
              $this->reset_state();
              $this->head($result->shared_link->download_url);
              $info = $this->get_info();
              if ($info['http_code'] == 403) {
                  throw new moodle_exception('No permission to share the file');
              }
          }
  
          return $result->shared_link;
      }
code_tokens: public function share_file ( $ fileid , $ businesscheck = true ) { // Sharing the file, this requires a PUT request with data within it. We cannot use // the standard PUT request 'CURLOPT_PUT' because it expects a file. $ data = array ( 'shared_link' => array ( 'access' => 'open' , 'permissions' => array ( 'can_download' => true , 'can_preview' => true ) ) ) ; $ options = array ( 'CURLOPT_CUSTOMREQUEST' => 'PUT' , 'CURLOPT_POSTFIELDS' => json_encode ( $ data ) ) ; $ this -> reset_state ( ) ; $ result = $ this -> request ( $ this -> make_url ( "/files/$fileid" ) , $ options ) ; $ result = json_decode ( $ result ) ; if ( $ businesscheck ) { // Checks that the user has the right to share the file. If not, throw an exception. $ this -> reset_state ( ) ; $ this -> head ( $ result -> shared_link -> download_url ) ; $ info = $ this -> get_info ( ) ; if ( $ info [ 'http_code' ] == 403 ) { throw new moodle_exception ( 'No permission to share the file' ) ; } } return $ result -> shared_link ; }
docstring: Share a file and return the link to it.
  
  @param string $fileid The file ID.
  @param bool $businesscheck Whether or not to check if the user can share files, has a business account.
  @return object
docstring_tokens: Share a file and return the link to it .