query(GetClassificationDBQuery( /** @phpstan-ignore function.notFound */ $ParentId, $StartingLetter, $EndingLetter )); # retrieve count of entries to be displayed $RecordCount = $ClassDB->numRowsSelected(); # for each entry $ClassCount = 0; $Entry = ""; while ($Class = $ClassDB->fetchRow()) { $ClassId = $Class["ClassificationId"]; # if filter function defined if (function_exists("FilterClassificationBrowseList")) { # call filter function to find out if okay to display entry $DoNotDisplay = FilterClassificationBrowseList($ClassId); # assume okay to display entry } else { $DoNotDisplay = false; } # if okay to display entry if ($DoNotDisplay == false) { # if entries per column limit reached $ClassCount++; if (($ClassCount > intval($RecordCount / $NumberOfColumns)) && ($ClassCount > $MinEntriesPerColumn)) { # move to next column $Entries[] = $Entry; $Entry = ""; $ClassCount = 0; } # construct link address $LinkUrl = sprintf("index.php?P=BrowseResources&ID=%d", $Class["ClassificationId"]); if ($EditingEnabled) { $LinkUrl .= "&Editing=1"; } # construct link address for editing $EditLinkUrl = $EditingEnabled ? sprintf( "index.php?P=EditClassification&ClassificationId=%d", $Class["ClassificationId"] ) : null; # get the correct count for the context $Count = (int)$EditingEnabled ? $Class["FullResourceCount"] : $Class["ResourceCount"]; # add this entry $Entry .= "". $Class["SegmentName"] . ""; $Entry .= " (" . number_format($Count) . ")"; if ($EditLinkUrl !== null) { $EditButton = new HtmlButton("Edit"); $EditButton->setIcon("Pencil.svg"); $EditButton->setSize(HtmlButton::SIZE_SMALL); $EditButton->setLink($EditLinkUrl); $Entry .= $EditButton->getHtml(); } $Entry .= "
"; } } $Entries[] = $Entry; return $Entries; } /** * Retrieve string link to view classifications in alphabetical order, * based on $ParentId if isset * @param int $ParentId The ID of the parent classification. * @param bool $EditingEnabled If user is in editing mode. * @return string Link string. */ function getAlphabeticClassificationLinks(int $ParentId, bool $EditingEnabled): string { # if classification ID passed in if ($ParentId > 0) { # retrieve link string for classification $Class = new Classification($ParentId); $LinkString = $Class->linkString(); # if link string has not yet been set if ($LinkString == "") { # create and save new link string $LinkString = BuildClassificationLinkString( /** @phpstan-ignore function.notFound */ $ParentId ); $Class->linkString($LinkString); } } else { $LinkString = BuildClassificationLinkString(0); /** @phpstan-ignore function.notFound */ global $StartingLetter; global $EndingLetter; if (preg_match( "%StartingLetter=([0-9A-Za-z\"]+)\&EndingLetter=([0-9A-Za-z\"]+)%", $LinkString, $Matches ) && !strlen($StartingLetter ?? "") && !strlen($EndingLetter ?? "")) { # extract and save new default to ?? ""p-level begin and end letters $StartingLetter = $Matches[1]; $EndingLetter = $Matches[2]; } } if (!is_string($LinkString)) { throw new Exception("Value returned by BuildClassificationLinkString() was not a string."); } # if link string is placeholder if ($LinkString == "X") { # clear link string $LinkString = ""; } else { # if link string is not empty if ($LinkString != "") { # insert target browse page name into link string $LinkString = preg_replace( "/BROWSEPAGE/", "index.php?P=BrowseResources", $LinkString ); # insert editing flag value into link string $LinkString = preg_replace( "/EDITFLAG/", ($EditingEnabled ? "1" : "0"), $LinkString ); if ($LinkString === null) { throw new Exception("preg_replace() failed"); } } } # return link string to caller return $LinkString; } /** * Starting with the parent id, step upwards through parents, generating a * string containing a series of tree (classification) nodes, each formatted * with a link. * @param int $ParentId The ID of the parent classification * @param string $LinkStyle Any classes to add to the returned link * @param bool $EditingEnabled If user is in editing mode. * @return string $RootClassString The formatted link to the root classification */ function getRootClassificationHTML(int $ParentId, string $LinkStyle, bool $EditingEnabled): string { # start with empty string $RootClassString = ""; # if top of classification tree specified if ($ParentId > 0) { # do while classification segments left to add do { # if not first segment in string if ($RootClassString != "") { # add segment separator to string $RootClassString = " -- ".$RootClassString; } # get current segment name $Class = new Classification($ParentId); # add current segment to string $RootClassString = "" .$Class->segmentName()."" .$RootClassString; # move to next segment $ParentId = $Class->parentId(); } while ($ParentId > 0); } # return root classification HTML string to caller return $RootClassString; } /** * Highlight the current browsing letter. * @param string $AlphabeticClassificationString The original string to display letter * classifications. * @return string The highlighted string */ function HighlightCurrentBrowsingLetter(string $AlphabeticClassificationString): string { # determine current browsing StartingLetter and EndingLetter if (isset($_GET["StartingLetter"])) { $StartingLetter = substr($_GET["StartingLetter"], 0, 2); } else { $StartingLetter = null; } if (isset($_GET["EndingLetter"])) { $EndingLetter = substr($_GET["EndingLetter"], 0, 2); } else { $EndingLetter = null; } if ($StartingLetter == null || $EndingLetter == null) { return $AlphabeticClassificationString; } $StartingLetter = preg_quote($StartingLetter, "/"); $EndingLetter = preg_quote($EndingLetter, "/"); $HighlightString = "" . $StartingLetter . "-" . $EndingLetter . ""; $MatchingString = "/" . $StartingLetter . "-" . $EndingLetter . "/"; # match and replace current browsing classification with the highlighted one $Result = preg_replace($MatchingString, $HighlightString, $AlphabeticClassificationString); return $Result; } # ----- SETUP ---------------------------------------------------------------- global $ParentId; if (!isset($H_BrowseLinks)) { throw new Exception("H_BrowseLinks not defined."); } if (!isset($H_ClassificationCount)) { throw new Exception("H_ClassificationCount not defined."); } if (!isset($H_EditingEnabled)) { throw new Exception("H_EditingEnabled not defined."); } if (!isset($H_MaxResourcesPerPage)) { throw new Exception("H_MaxResourcesPerPage not defined."); } if (!isset($H_NumberOfColumns)) { throw new Exception("H_NumberOfColumns not defined."); } if (!isset($H_ResourceCount)) { throw new Exception("H_ResourceCount not defined."); } if (!isset($H_StartingResourceIndex)) { throw new Exception("H_StartingResourceIndex not defined."); } $IntConfig = InterfaceConfiguration::getInstance(); $Header = $H_EditingEnabled ? "Add/Edit Classifications" : $IntConfig->getString("BrowsingPageTitle"); $Schema = new MetadataSchema(); $HasClassifications = ($H_ClassificationCount > 0); $HasResources = ($H_ResourceCount > 0); if ($HasClassifications) { $HeaderHTML = ""; $BrowsingFieldId = GetBrowsingFieldId(); /** @phpstan-ignore function.notFound */ if ($H_EditingEnabled) { $FieldNames = $Schema->getFieldNames(MetadataSchema::MDFTYPE_TREE); $OptList = new HtmlOptionList("F_BrowsingFieldId", $FieldNames, $BrowsingFieldId); $OptList->submitOnChange(true); $OptList->printIfEmpty(false); $HeaderHTML .= $OptList->getHtml(); $HeaderHTML .= " Classifications"; } else { $Field = MetadataField::getField($BrowsingFieldId); $TreeName = $Field->getDisplayName(); $HeaderHTML .= $TreeName; if ((strpos($TreeName, "Classification") === false) && (strpos($TreeName, "classification") === false)) { $HeaderHTML .= " Classifications"; } } $HeaderHTML .= ""; $ClassificationsTable = new HtmlTable(); $ClassificationsTable->setTableClass("table mv-table mv-table-fullsize mv-content-browsetable"); $ClassificationsTable->addHeaderRow([$HeaderHTML]); $ClassificationsTable->addRow(getClassificationListArray( $H_NumberOfColumns, $H_EditingEnabled, $ParentId )); } if ($HasResources) { $PreviousResourcesAvailable = $H_StartingResourceIndex > 0; $NextResourcesAvailable = ($H_StartingResourceIndex + $H_MaxResourcesPerPage) < $H_ResourceCount; $NumberOfNextResources = min( $H_MaxResourcesPerPage, ($H_ResourceCount - ($H_StartingResourceIndex + $H_MaxResourcesPerPage)) ); $BasePaginationLink = "index.php?P=BrowseResources&ID=" . $ParentId . ($H_EditingEnabled ? "&Editing=1" : "") . "&StartingResourceIndex=" ; $FooterCell = ""; if ($PreviousResourcesAvailable) { $PreviousButton = new HtmlButton("← Previous"); $PreviousButton->setTitle("Previous " . $H_MaxResourcesPerPage . " resources"); $PreviousButton->setLink($BasePaginationLink . ($H_StartingResourceIndex - $H_MaxResourcesPerPage)); $FooterCell = "" . $PreviousButton->getHtml() . ""; } if ($NextResourcesAvailable) { $NextButton = new HtmlButton("Next →"); $NextButton->setTitle("Next " . $NumberOfNextResources . " resources"); $NextButton->setLink($BasePaginationLink . ($H_StartingResourceIndex + $H_MaxResourcesPerPage)); $FooterCell .= "" . $NextButton->getHtml() . ""; } $ResourcesTable = new HtmlTable(); $ResourcesTable->setTableClass( "mv-table mv-table-fullsize mv-table-pagination mv-content-browsetable" ); $ResourcesTable->addHeaderRow(["

## Resources

"]); $ResourcesTable->addRow([getResourceListHtml()]); // @phpstan-ignore function.notFound $ResourcesTable->addFooterRow([$FooterCell]); } # ----- DISPLAY -------------------------------------------------------------- ?>

#

( ) ( )

Add Classification Here

(browse hierarchy to add or edit classifications at other levels)

There are currently no classifications to browse by in this field.

getHtml(); } ?>

getHtml(); ?>

$Link) { ?>
- Browse by

hasPriv(PRIV_RESOURCEADMIN, PRIV_COLLECTIONADMIN)) { ?>

NOTE: Only publicly visible records are shown in Browse Resources.