private function nexcloud::add_accessmetrics in filedepot 6
Same name and namespace in other branches
- 7 nexcloud.class.php \nexcloud::add_accessmetrics()
1 call to nexcloud::add_accessmetrics()
File
- ./
nexcloud.class.php, line 132 - nexcloud.class.php Tag Cloud class for the fildepot module
Class
- nexcloud
- @file nexcloud.class.php Tag Cloud class for the fildepot module
Code
private function add_accessmetrics($itemid, $tagids) {
// Test that a valid array of tag id's is passed in
if (is_array($tagids) and count($tagids) > 0) {
// Test that a valid item record exist
if (db_result(db_query("SELECT count(itemid) FROM {nextag_items} WHERE type='%s' AND itemid=%d", $this->_type, $itemid)) > 0) {
// Get item permissions to determine what rights to use for tag metrics record
$perms = $this
->get_itemperms($itemid, true);
// Add any new tags
foreach ($tagids as $id) {
if (!empty($id)) {
// For each role or group with view access to this item - create or update the access metric record count.
$haveGroupsToUpdate = count($perms['groups']) > 0;
$haveRolesToUpdate = count($perms['roles']) > 0;
if ($haveGroupsToUpdate or $haveRolesToUpdate) {
db_query("UPDATE {nextag_words} SET metric=metric+1 WHERE id=%d", $id);
// use an array to handle the logic of whether to process groups, roles, or both
// use the key to track the field to update and the value to track the values
$permAccessMetric = array();
if ($haveGroupsToUpdate) {
$permAccessMetric['groupid'] = $perms['groups'];
}
if ($haveRolesToUpdate) {
$permAccessMetric['roleid'] = $perms['roles'];
}
foreach ($permAccessMetric as $permKey => $permValue) {
foreach ($permValue as $permid) {
if ($permid > 0) {
$sql = "SELECT count(tagid) FROM {nextag_metrics} WHERE tagid = %d AND type = '%s' AND " . $permKey . " = %d";
if (db_result(db_query($sql, $id, $this->_type, $permid)) > 0) {
$sql = "UPDATE {nextag_metrics} SET metric=metric+1, last_updated=%d " . "WHERE tagid=%d AND type='%s' AND " . $permKey . "=%d";
db_query($sql, time(), $id, $this->_type, $permid);
}
else {
$sql = "INSERT INTO {nextag_metrics} (tagid,type," . $permKey . ",metric,last_updated) " . "VALUES (%d,'%s',%d,%d,%d)";
db_query($sql, $id, $this->_type, $permid, 1, time());
}
}
}
}
}
}
}
}
}
}