id());
$ResourceCount = $RFactory->getItemCount();
$Fields = $Schema->getFields(MetadataSchema::MDFTYPE_CONTROLLEDNAME);
$SearchButton = new HtmlButton("Search");
$SearchButton->setIcon("MagnifyingGlass.svg");
$SearchButton->setSize(HtmlButton::SIZE_SMALL);
$SearchButton->makeSubmitButton();
$ExportButton = new HtmlButton("Export Vocabulary");
$ExportButton->setIcon("FileExport.svg");
$ExportButton->setSize(HtmlButton::SIZE_SMALL);
# Compute the width of the submit buttons in characters based on
# the lengths of the field names plus "Search ".
$Width = 0;
foreach ($Fields as $Field) {
$Width = max($Width, strlen($Field->GetDisplayName()) + 10);
}
$FieldListTable = new HtmlTable();
$FieldListTable->setTableClass("table table-striped table-sm mv-content-optionlist");
foreach ($Fields as $Field) {
$CNFactory = new ControlledNameFactory($Field->Id());
$DisplayName = $Field->Name()
.(strlen($Field->Label()) ? ": (".$Field->Label().")" : "");
$UsageCount = $CNFactory->getUsageCount();
$UsagePercentage = ($ResourceCount > 0) ?
round((100 * $UsageCount) / $ResourceCount) : 0 ;
$SearchButton->setLabel("Search ".$Field->getDisplayName());
$ExportButton->setLink(
"index.php?P=DBExportField&Id=".$Field->id()
);
$FieldListTable->addRow([
$DisplayName,
"(" . number_format($Field->GetCountOfPossibleValues()) . " values)",
$SearchButton->getHtml() . " " . $ExportButton->getHtml(),
$Field->Description(),
"Assigned to " . number_format($UsageCount) . " resources\n"
. "(" . $UsagePercentage . "% coverage)"
]);
}
return $FieldListTable->getHtml();
}
/**
* Display a list of search results.
* @param array $SearchResults List of ControlledNames that matched the
* search string, where each element is an array suitable for
* DisplaySearchResult().
* @param int $Start Starting result.
* @param int $PerPage Number of results per page.
*/
function displaySearchResults($SearchResults, $Start, $PerPage): void
{
$Results = array_slice($SearchResults, $Start, $PerPage);
$Index = 0;
foreach ($Results as $Result) {
displaySearchResult($Result, $Index);
$Index++;
}
}
/**
* Display a single result from a search for ControlledNames.
* @param int $CNId ControlledNameId.
* @param int $Index Index to use for form field names.
*/
function displaySearchResult($CNId, $Index): void
{
$CN = new ControlledName($CNId);
$Field = MetadataField::getField($CN->fieldId());
$InUseCount = $CN->getAssociatedResourceCount();
$SearchParams = new SearchParameterSet();
$SearchParams->addParameter("=".$CN->name(), $Field);
$Link = "index.php?P=SearchResults&".$SearchParams->urlParameterString();
# display number of resources that use this controlled name
if ($InUseCount == 1) {
$InUseMessage = "(".$InUseCount." resource)";
} elseif ($InUseCount > 0) {
$InUseMessage = "(".$InUseCount." resources)";
} else {
$InUseMessage = "(Not Used)";
}
$VariantsButton = new HtmlButton("Variants");
$VariantsButton->addClass("D_Variants_Button");
$VariantsButton->hide();
$VariantsButton->setValue("Variants");
$VariantsButton->setOnclick("$('#D_Variants_" . $Index . "').toggle();");
// @codingStandardsIgnoreStart
?>
= $InUseMessage; ?>
0){ ?>
Remap to:
id(), "", "", FALSE, "D_Remap_".$Index); ?>
= $VariantsButton->getHtml(); ?>
usesQualifiers()) {
if ($Field->hasItemLevelQualifiers()) {
# first value is "--"
$Items = $Field->associatedQualifierList();
$Items["--"] = "--";
ksort($Items);
$OptList = new HtmlOptionList("F_QualifierName_".$Index, $Items, $CName->qualifierId());
$OptList->printIfEmpty(false);
$OptList->printHtml();
} elseif ($Field->defaultQualifier()) {
# if field has a default qualifier, but item level qualifiers are not allowed,
# display the default with no option to change, otherwise don't display anything
$Qualifier = new Qualifier($Field->defaultQualifier());
print $Qualifier->name();
}
}
}
/**
* Display pagination controls for ControlledName search.
* @param int $NumResults Number of results per page.
* @param MetadataField $Field Field searched.
* @param string $ControlledName Name searched for.
* @param int $StartRecord Numerical index of the first record on this
* page.
* @param int $PerPage Number of records per page.
*/
function displayPagination(
int $NumResults,
MetadataField $Field,
string $ControlledName,
int $StartRecord,
int $PerPage
): void {
if ($NumResults > $PerPage) { ?>
Id()] = $Schema->Name() . " Schema";
}
$OptList = new HtmlOptionList("SC", $Options, $SchemaInUse->id());
$OptList->submitOnChange(true);
$OptList->printHtml();
}
# ----- COMPLETE FUNCTIONS ---------------------------------------------------
# functions for when changes are submitted
/**
* Display list of modified controlled names.
* @param array $CNArray Array giving modified controlled names, keyed
* by ControlledName with Variants for values.
*/
function displayControlledNameList($CNArray): void
{
if (count($CNArray) > 0) {
foreach ($CNArray as $CNName => $CNVariant) {
print $CNName;
if (!empty($CNVariant)) {
print ", Variant ($CNVariant)";
}
print " ";
}
} else {
print "(none)";
}
}
/**
* Display list of modified resources.
* @param array $LinkArray Array of links to modified resources.
*/
function displayModifiedResourceList($LinkArray): void
{
if (count($LinkArray) > 0) {
foreach ($LinkArray as $LinkString) {
print $LinkString;
}
} else {
print "(none)";
}
}
# ----- SETUP ----------------------------------------------------------------
if (!isset($H_ControlledName)) {
throw new Exception("H_ControlledName not defined.");
}
if (!isset($H_DeletedCNames)) {
$H_DeletedCNames = null;
}
if (!isset($H_Field)) {
$H_Field = null;
}
if (!isset($H_MatchingControlledNames)) {
throw new Exception("H_MatchingControlledNames not defined.");
}
if (!isset($H_ModifiedCNames)) {
$H_ModifiedCNames = null;
}
if (!isset($H_ModifiedResources)) {
$H_ModifiedResources = null;
}
if (!isset($H_NumResults)) {
throw new Exception("H_NumResults not defined.");
}
if (!isset($H_RecordsPerPage)) {
throw new Exception("H_RecordsPerPage not defined.");
}
if (!isset($H_SavedChanges)) {
throw new Exception("H_SavedChanges not defined.");
}
if (!isset($H_Schema)) {
throw new Exception("H_Schema not defined.");
}
if (!isset($H_SearchEntered)) {
throw new Exception("H_SearchEntered not defined.");
}
if (!isset($H_StartRec)) {
throw new Exception("H_StartRec not defined.");
}
$SafeSchemaId = defaulthtmlentities($H_Schema->Id());
$SaveButton = new HtmlButton("Save Changes");
$SaveButton->setIcon("Disk.svg");
$SaveButton->setSize(HtmlButton::SIZE_SMALL);
$SaveButton->makeSubmitButton();
$CancelButton = new HtmlButton("Cancel");
$CancelButton->setIcon("Cross.svg");
$CancelButton->setSize(HtmlButton::SIZE_SMALL);
$CancelButton->addSemanticClass("btn-danger");
$CancelButton->makeSubmitButton();
// @codingStandardsIgnoreStart
# ----- DISPLAY --------------------------------------------------------------
?>
0) { ?>