Portal Administration Guide : Customize Xinet Portal : Code Example: Filtering what users see based on metadata value

Code Example: Filtering what users see based on metadata value
Note: This example may help you understand more about customizing Xinet Portal using PHP. However, if you’re actually interested in filtering metadata, use the alternative example, Code Example: Filtering what users see using Search Engine stored procedures
Goal: Create a boolean metadata field for each group name, and show only files and directories that have the group metadata field checked on (for the logged-in user’s group).
Customization method: Create boolean fields, then edit the file:
Site_Directory/templates/local.inc.php.
For use with: Exhibit-style sites.
Directions:
1.
2.
3.
4.
5.
To allow your Xinet Portal site to filter the files and directories, edit the local.inc.php file, as follows. However, please note that this example doesn’t take into account the case where someone doesn’t have a group. In that case, he or she will see no files.
/* This will work for Exhibit based sites, running Portal 4 */
/* or later, only. */
if (isset ($files_info)) {
 
/* Create temporary $files_info, $keywords_info, and */
/* $nav_info tables. */
$temp_files_info = $files_info;
if (isset ($keywords_info)) {
$temp_keywords_info = $keywords_info;
}
if (isset ($nav_info)) {
$temp_nav_info = $nav_info;
}
/* Erase the contents of the existing tables; */
/* They will be rebuilt later */
$files_info = array();
$keywords_info = array();
$file_info = array();
$keyword_info = array();
$dir_info = array();
$dirkywd_info = array();
$nav_info = array();
 
/* Define the appropriate keyword, based on group name. */
/* First translate the group name into uppercase */
$upgroupname = strtoupper ( $tmpl->
SERVERINFO[$tmpl->user_wnhost]['PRIMARYGROUP'] );
/* Translate any non-alphanumeric characters into */ 
/* underscores. */
$portalgroup = preg_replace ( '/\W/', '_', $upgroupname );
 
/* This is the term that will supply the value of the */ 
/* keyword associated with the group name. (The keyword */ 
/* name will automatically be translated by WebNative */ 
/* Portal into all uppercase letters with underscores */ 
/* instead of non-alpha-numeric characters.) */
$kw_term = $portalgroup . "_VALUE";
 
/* Cycle through the temporary $nav_info array. */
if (isset($temp_nav_info)) {
foreach ($temp_nav_info as $key => $value) {
 
/* If the metadata value for the group name is set, */ 
/* add the file to the nav_info array. */
/* NOTE: the below will show all directories */
/* for navigation */
/* and will only filter files. */
/* If you to filter directories as well, replace */
/* 'FILE_ISADIR' */
/* with 'ISVENTUREVOLUME'. */
if ($value['FILE_ISADIR'] || $value[$kw_term]) {
$nav_info[] = $value;
}
}
}
 
/* Cycle through the temporary $files_info table. */
foreach ( $temp_files_info as $key => $value ) {
 
/* If the metadata value for the group name is set, */ 
/* add the file to the files_info array, and its keywords */ 
/* to the keywords info array */
if ($value[$kw_term]) {
$files_info [] = $value;
if (isset ( $temp_keywords_info [$key] )) {
$keywords_info [] = $temp_keywords_info [$key];
}
 
/* If item is a directory, do the same for the */
/* $dir_info */
if ($value ['ISADIR'] == true) {
$dir_info [] = $value;
if (isset ( $temp_keywords_info [$key] )) {
$dirkywd_info [] = $temp_keywords_info [$key];
}
} else {
/* add files back into the $file_info array as well. */
$file_info [] = $value;
if (isset ( $temp_keywords_info [$key] )) {
$keyword_info [] = $temp_keywords_info [$key];
}
}
}
}
}