You are here

function webform_protected_downloads_node_get_private_files in Webform Protected Downloads 7

Retrieve private files for the given node

Parameters

object $node:

Return value

array

1 call to webform_protected_downloads_node_get_private_files()
webform_protected_downloads_node_load in ./webform_protected_downloads.module
Implementation of hook_node_load().

File

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

Code

function webform_protected_downloads_node_get_private_files($node) {
  $private_file_fields = webform_protected_downloads_node_get_private_file_fields($node);
  if (!count($private_file_fields)) {
    return array();
  }

  /*
  When trying to retrieve attached private fields, we need to pay attention
  to language handling, possibilities:
   1. Node has no language (locale disabled) and file has no language either
   2. Node has a language but file has no language
   3. Node has a language and file has a language
  For now all attached files are treated the same.
  See http://drupal.org/node/1239916 for examples of arising problems.
  */
  $private_files = array();
  foreach ($private_file_fields as $field) {

    // check if the node has acceptable file fields
    if (!is_array($node->{$field}) || !count($node->{$field})) {
      continue;
    }

    // iterate over possible fields, in the node object they are organised by a
    // language code, so in the first iteration we go into the langcode
    foreach ($node->{$field} as $langcode => $files) {

      // now iterate over the specific files
      foreach ($files as $key => $file) {
        $file = (object) $file;
        $file->field = $field;
        $file->nid = $node->nid;
        $file->weight = $key;
        $file->protected = webform_protected_downloads_file_is_protected($node->nid, $file->fid);
        $private_files[$file->fid] = $file;
      }
    }
  }
  return $private_files;
}