You are here

function filedepot_updateFolderLastModified in filedepot 7

Same name and namespace in other branches
  1. 6 lib-common.php \filedepot_updateFolderLastModified()
3 calls to filedepot_updateFolderLastModified()
filedepot::approveFileSubmission in ./filedepot.class.php
filedepot_native_submit in ./filedepot.module
filedepot_newfile_submit in ./filedepot.module

File

./lib-common.php, line 183
lib-common.php Common library of functions for the applications

Code

function filedepot_updateFolderLastModified($id) {
  $last_modified_parentdate = 0;
  if (db_query("SELECT cid FROM {filedepot_categories} WHERE cid=:cid", array(
    ':cid' => $id,
  ))
    ->fetchField() > 0) {
    $q1 = db_query("SELECT cid FROM {filedepot_categories} WHERE pid=:cid ORDER BY folderorder ASC", array(
      ':cid' => $id,
    ));
    while ($A = $q1
      ->fetchAssoc()) {
      $last_modified_date = 0;
      $q2 = db_query_range("SELECT date FROM {filedepot_files} WHERE cid=:cid ORDER BY date DESC", 0, 1, array(
        ':cid' => $A['cid'],
      ));
      $B = $q2
        ->fetchAssoc();
      if ($B['date'] > $last_modified_date) {
        $last_modified_date = $B['date'];
      }
      if (db_query("SELECT pid FROM {filedepot_categories} WHERE cid=:cid", array(
        ':cid' => $A['cid'],
      ))
        ->fetchField() > 0) {
        $latestdate = filedepot_updateFolderLastModified($A['cid']);
        if ($latestdate > $last_modified_date) {
          $last_modified_date = $latestdate;
        }
      }
      db_query("UPDATE {filedepot_categories} SET last_modified_date=:time WHERE cid=:cid", array(
        ':time' => $last_modified_date,
        ':cid' => $A['cid'],
      ));
      if ($last_modified_date > $last_modified_parentdate) {
        $last_modified_parentdate = $last_modified_date;
      }
    }
    db_query("UPDATE {filedepot_categories} SET last_modified_date=:time WHERE cid=:cid", array(
      ':time' => $last_modified_parentdate,
      ':cid' => $id,
    ));
  }
  $q4 = db_query("SELECT date FROM {filedepot_files} WHERE cid=:cid ORDER BY date DESC", array(
    ':cid' => $id,
  ));
  $C = $q4
    ->fetchAssoc();
  if ($C['date'] > $last_modified_parentdate) {
    $last_modified_parentdate = $C['date'];
  }
  db_query("UPDATE {filedepot_categories} SET last_modified_date=:time WHERE cid=:cid", array(
    ':time' => $last_modified_parentdate,
    ':cid' => $id,
  ));
  return $last_modified_parentdate;
}