You are here

function webform_protected_downloads_file_set_protected in Webform Protected Downloads 7

Same name and namespace in other branches
  1. 6 webform_protected_downloads.module \webform_protected_downloads_file_set_protected()

Set the protected status for the given node / file combination

Parameters

int $nid:

int $fid:

boolean $protected:

Return value

void

2 calls to webform_protected_downloads_file_set_protected()
webform_protected_downloads_configuration_form_submit in ./webform_protected_downloads.form.inc
Implementation of hook_submit().
webform_protected_downloads_node_insert in ./webform_protected_downloads.module
Implementation of hook_insert().

File

./webform_protected_downloads.module, line 619
This file contains hook declarations and functions for the Webform Protected Downloads module.

Code

function webform_protected_downloads_file_set_protected($nid, $fid, $protected) {
  if (webform_protected_downloads_file_is_protected($nid, $fid) && !$protected) {
    db_delete('wpd_protected_files')
      ->condition('nid', $nid)
      ->condition('fid', $fid)
      ->execute();
  }
  elseif (!webform_protected_downloads_file_is_protected($nid, $fid) && $protected) {
    $record = array(
      'nid' => $nid,
      'fid' => $fid,
      'created' => time(),
    );
    drupal_write_record('wpd_protected_files', $record);
  }
}