You are here

function nexcloud::get_itemperms in filedepot 7

Same name and namespace in other branches
  1. 6 nexcloud.class.php \nexcloud::get_itemperms()
4 calls to nexcloud::get_itemperms()
nexcloud::add_accessmetrics in ./nexcloud.class.php
nexcloud::remove_accessmetrics in ./nexcloud.class.php
nexcloud::update_accessmetrics in ./nexcloud.class.php
nexcloud::update_tags in ./nexcloud.class.php

File

./nexcloud.class.php, line 63
nexcloud.class.php Tag Cloud class for the filedepot module

Class

nexcloud
@file nexcloud.class.php Tag Cloud class for the filedepot module

Code

function get_itemperms($fid, $sitewide = FALSE) {
  global $user;
  $perms = array(
    'groups' => array(),
    'roles' => array(),
  );
  $cid = db_query("SELECT cid FROM {filedepot_files} WHERE fid=:fid", array(
    ':fid' => $fid,
  ))
    ->fetchField();
  if ($cid > 0) {
    if (module_exists('og') and module_exists('og_access')) {
      $groups = filedepot_og_get_user_groups();
      if (!empty($groups)) {
        $groupids = implode(',', array_values($groups));
        if (!empty($groupids) or $sitewide === TRUE) {
          $sql = "SELECT permid from {filedepot_access} WHERE catid=:cid AND permtype='group' AND view = 1 AND permid > 0 ";
          $sql .= "AND permid in ({$groupids}) ";
          $query = db_query($sql, array(
            ':cid' => $cid,
          ));
          if ($query) {
            while ($A = $query
              ->fetchAssoc()) {
              $perms['groups'][] = $A['permid'];
            }
          }
        }
      }
    }

    // Determine all the roles the active user has and test for view permission.
    $roleids = implode(',', array_keys($user->roles));
    if (!empty($roleids) or $sitewide === TRUE) {
      $sql = "SELECT permid from {filedepot_access} WHERE catid=:cid AND permtype='role' AND view = 1 AND permid > 0 ";
      if (!$sitewide) {
        $sql .= "AND permid in ({$roleids}) ";
      }
      $query = db_query($sql, array(
        ':cid' => $cid,
      ));
      if ($query) {
        while ($A = $query
          ->fetchAssoc()) {
          $perms['roles'][] = $A['permid'];
        }
      }
    }
  }
  return $perms;
}