Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
#16 Extend extension frontend data
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderpotjer committed Jul 18, 2020
1 parent 87c2042 commit b4fd2d9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
73 changes: 73 additions & 0 deletions public_html/components/com_jed/models/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public function getItem($pk = null)
$extension->body = str_replace($extension->intro, '', $extension->body);
}

// Extend extension data
$extension->extensionTypes = $this->getExtensionTypes($extension->id);
$extension->relatedCategories = $this->getRelatedCategories($extension->id);
$extension->phpVersion = $this->getVersions($extension->id, 'php');
$extension->joomlaVersion = $this->getVersions($extension->id, 'joomla');

return $extension;
}

Expand All @@ -127,4 +133,71 @@ protected function populateState(): void

parent::populateState();
}

/**
* Get the used extension types.
*
* @param int $extensionId The extension ID to get the types for
*
* @return array List of used extension types.
*
* @since 4.0.0
*/
public function getExtensionTypes(int $extensionId): array
{
// Get the related categories
$db = $this->getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('type'))
->from($db->quoteName('#__jed_extensions_types'))
->where($db->quoteName('extension_id') . ' = ' . $extensionId);
$db->setQuery($query);

return $db->loadColumn();
}

/**
* Get the related categories.
*
* @param int $extensionId The extension ID to get the categories for
*
* @return array List of related categories.
*
* @since 4.0.0
*/
public function getRelatedCategories(int $extensionId): array
{
$db = $this->getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('category_id'))
->from($db->quoteName('#__jed_extensions_categories'))
->where($db->quoteName('extension_id') . ' = ' . $extensionId);
$db->setQuery($query);

return $db->loadColumn();
}

/**
* Get the supported PHP versions.
*
* @param int $extensionId The extension ID to get the PHP versions for
* @param string $type The type of version to get
*
* @return array List of supported PHP versions.
*
* @since 4.0.0
*/
public function getVersions(int $extensionId, string $type): array
{
// Get the related categories
$db = $this->getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('version'))
->from($db->quoteName('#__jed_extensions_' . $type . '_versions'))
->where($db->quoteName('extension_id') . ' = ' . $extensionId);
$db->setQuery($query);

return $db->loadColumn();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<div class="jed-grid__item">
<p class="extension-tags font-size-s">
<span aria-hidden="true" class="icon-tag"></span>
<a href="#">Main category</a>,
<a href="#"><?php echo $this->item->category; ?></a>,
<a href="#">Sub category</a>,
<a href="#">Sub category</a>,
<a href="#">Sub category</a>,
Expand Down Expand Up @@ -121,7 +121,7 @@
</div>
<div>
<dt>Includes</dt>
<dd>Plugin, Module, Component</dd>
<dd><?php echo implode(', ', array_map('ucfirst', $this->item->extensionTypes)); ?></dd>
</div>
<div>
<dt>Compatibility</dt>
Expand Down

0 comments on commit b4fd2d9

Please sign in to comment.