Skip to content

Commit

Permalink
add sub props into usage: according to change reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Nov 8, 2023
1 parent fc7f013 commit e145e92
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
4 changes: 2 additions & 2 deletions classes/Event/class.xoctEventRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ public function getDownloadLinkHTML(
)->withLabel($display_name);
$html = $this->renderer->renderAsync($dropdown);
} else {
$usage_type = $download_publication_usage->is_sub ? 'sub' : 'org';
$usage_type = $download_publication_usage->isSub() ? 'sub' : 'org';
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'usage_type', $usage_type);
$usage_id = $usage_type === 'sub' ? $download_publication_usage->sub_id :
$usage_id = $usage_type === 'sub' ? $download_publication_usage->getSubId() :
$download_publication_usage->getUsageId();
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'usage_id', $usage_id);
$link = $this->ctrl->getLinkTargetByClass(xoctEventGUI::class, xoctEventGUI::CMD_DOWNLOAD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public function convertSingleSubToUsage($sub_id): ?PublicationUsage
$usage->setIgnoreObjectSettings($sub->ignoreObjectSettings());
$usage->setExternalDownloadSource($sub->isExternalDownloadSource());
// Add extra tracking information.
$usage->is_sub = true;
$usage->sub_id = $sub->getId();
$usage->setAsSub(true);
$usage->setSubId($sub->getId());
return $usage;
}
return null;
Expand Down
44 changes: 44 additions & 0 deletions src/Model/Publication/Config/PublicationUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ public function getConnectorContainerName()
*/
protected $ext_dl_source = false;

/**
* An indicator flag to determine if the usage is a sub-usage or not.
* @var bool
*/
protected $is_sub = false;

/**
* A variable that works as an id holder, for when the usage is a sub-usage.
* @var int
*/
protected $sub_id = 0;

public function getUsageId(): string
{
return $this->usage_id ?? '';
Expand Down Expand Up @@ -424,4 +436,36 @@ public function setExternalDownloadSource(bool $ext_dl_source)
{
$this->ext_dl_source = $ext_dl_source;
}

/**
* @return bool
*/
public function isSub(): bool
{
return (bool) $this->is_sub;
}

/**
* @param bool $is_sub
*/
public function setAsSub(bool $is_sub)
{
$this->is_sub = $is_sub;
}

/**
* @return int
*/
public function getSubId(): int
{
return (int) $this->sub_id;
}

/**
* @param int $sub_id
*/
public function setSubId(int $sub_id): void
{
$this->sub_id = $sub_id;
}
}
12 changes: 8 additions & 4 deletions src/Model/Publication/PublicationSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ public function getDownloadPublications(): array
$usage_type = $pub->usage_type;
$usage_filtered = array_filter($download_usages, function ($usage) use ($usage_id, $usage_type) {
if ($usage_type == 'sub') {
return property_exists($usage, 'is_sub') && $usage->is_sub == true && $usage->sub_id == $usage_id;
return $usage->isSub() && $usage->getSubId() == $usage_id;
} else {
return !property_exists($usage, 'is_sub') && $usage->getUsageId() == $usage_id;
return !$usage->isSub() && $usage->getUsageId() == $usage_id;
}
});
if (!empty($usage_filtered)) {
Expand Down Expand Up @@ -479,8 +479,12 @@ public function getPublicationMetadataForUsage($publication_usage): array
if (!$publication_usage instanceof PublicationUsage) {
return [];
}
$usage_type = property_exists($publication_usage, 'is_sub') ? PublicationUsage::USAGE_TYPE_SUB : PublicationUsage::USAGE_TYPE_ORG;
$usage_id = property_exists($publication_usage, 'sub_id') ? $publication_usage->sub_id : $publication_usage->getUsageId();
$usage_type = PublicationUsage::USAGE_TYPE_ORG;
$usage_id = $publication_usage->getUsageId();
if ($publication_usage->isSub()) {
$usage_type = PublicationUsage::USAGE_TYPE_SUB;
$usage_id = $publication_usage->getSubId();
}
/**
* @var $publication_usage PublicationUsage
* @var $attachment Attachment
Expand Down

0 comments on commit e145e92

Please sign in to comment.