first commit
This commit is contained in:
54
libraries/src/Tag/TagApiSerializerTrait.php
Normal file
54
libraries/src/Tag/TagApiSerializerTrait.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Joomla! Content Management System
|
||||
*
|
||||
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\CMS\Tag;
|
||||
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Serializer\JoomlaSerializer;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Tobscure\JsonApi\Collection;
|
||||
use Tobscure\JsonApi\Relationship;
|
||||
use Tobscure\JsonApi\Resource;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Trait for implementing tags in an API Serializer
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
trait TagApiSerializerTrait
|
||||
{
|
||||
/**
|
||||
* Build tags relationship
|
||||
*
|
||||
* @param \stdClass $model Item model
|
||||
*
|
||||
* @return Relationship
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function tags($model)
|
||||
{
|
||||
$resources = [];
|
||||
|
||||
$serializer = new JoomlaSerializer('tags');
|
||||
|
||||
foreach ($model->tags as $id => $tagName) {
|
||||
$resources[] = (new Resource($id, $serializer))
|
||||
->addLink('self', Route::link('site', Uri::root() . 'api/index.php/v1/tags/' . $id));
|
||||
}
|
||||
|
||||
$collection = new Collection($resources, $serializer);
|
||||
|
||||
return new Relationship($collection);
|
||||
}
|
||||
}
|
||||
35
libraries/src/Tag/TagServiceInterface.php
Normal file
35
libraries/src/Tag/TagServiceInterface.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Joomla! Content Management System
|
||||
*
|
||||
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\CMS\Tag;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Access to component specific tagging information.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
interface TagServiceInterface
|
||||
{
|
||||
/**
|
||||
* Adds Count Items for Tag Manager.
|
||||
*
|
||||
* @param \stdClass[] $items The content objects
|
||||
* @param string $extension The name of the active view.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function countTagItems(array $items, string $extension);
|
||||
}
|
||||
78
libraries/src/Tag/TagServiceTrait.php
Normal file
78
libraries/src/Tag/TagServiceTrait.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Joomla! Content Management System
|
||||
*
|
||||
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\CMS\Tag;
|
||||
|
||||
use Joomla\CMS\Helper\ContentHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Trait for component tags service.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
trait TagServiceTrait
|
||||
{
|
||||
/**
|
||||
* Adds Count Items for Tag Manager.
|
||||
*
|
||||
* @param \stdClass[] $items The content objects
|
||||
* @param string $extension The name of the active view.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function countTagItems(array $items, string $extension)
|
||||
{
|
||||
$parts = explode('.', $extension);
|
||||
$section = \count($parts) > 1 ? $parts[1] : null;
|
||||
|
||||
$config = (object) [
|
||||
'related_tbl' => $this->getTableNameForSection($section),
|
||||
'state_col' => $this->getStateColumnForSection($section),
|
||||
'group_col' => 'tag_id',
|
||||
'extension' => $extension,
|
||||
'relation_type' => 'tag_assigments',
|
||||
];
|
||||
|
||||
ContentHelper::countRelations($items, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the table for the count items functions for the given section.
|
||||
*
|
||||
* @param string $section The section
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function getTableNameForSection(string $section = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state column for the count items functions for the given section.
|
||||
*
|
||||
* @param string $section The section
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function getStateColumnForSection(string $section = null)
|
||||
{
|
||||
return 'state';
|
||||
}
|
||||
}
|
||||
66
libraries/src/Tag/TaggableTableInterface.php
Normal file
66
libraries/src/Tag/TaggableTableInterface.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Joomla! Content Management System
|
||||
*
|
||||
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\CMS\Tag;
|
||||
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use Joomla\CMS\Table\TableInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Interface for a taggable Table class
|
||||
*
|
||||
* @since 3.10.0
|
||||
*/
|
||||
interface TaggableTableInterface extends TableInterface
|
||||
{
|
||||
/**
|
||||
* Get the type alias for the tags mapping table
|
||||
*
|
||||
* The type alias generally is the internal component name with the
|
||||
* content type. Ex.: com_content.article
|
||||
*
|
||||
* @return string The alias as described above
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getTypeAlias();
|
||||
|
||||
/**
|
||||
* Get the tags helper
|
||||
*
|
||||
* @return ?TagsHelper The tags helper object
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getTagsHelper(): ?TagsHelper;
|
||||
|
||||
/**
|
||||
* Set the tags helper
|
||||
*
|
||||
* @param TagsHelper $tagsHelper The tags helper object
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function setTagsHelper(TagsHelper $tagsHelper): void;
|
||||
|
||||
/**
|
||||
* Clears a set tags helper
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function clearTagsHelper(): void;
|
||||
}
|
||||
72
libraries/src/Tag/TaggableTableTrait.php
Normal file
72
libraries/src/Tag/TaggableTableTrait.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Joomla! Content Management System
|
||||
*
|
||||
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\CMS\Tag;
|
||||
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Defines the trait for a Taggable Table Class.
|
||||
*
|
||||
* @since 3.10.0
|
||||
*/
|
||||
trait TaggableTableTrait
|
||||
{
|
||||
/**
|
||||
* The tags helper property
|
||||
*
|
||||
* @var TagsHelper
|
||||
* @since 4.0.0
|
||||
* @note The tags helper property is set to public for backwards compatibility for Joomla 4.0. It will be made a
|
||||
* protected property in Joomla 6.0
|
||||
*/
|
||||
public $tagsHelper;
|
||||
|
||||
/**
|
||||
* Get the tags helper
|
||||
*
|
||||
* @return TagsHelper The tags helper object
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getTagsHelper(): ?TagsHelper
|
||||
{
|
||||
return $this->tagsHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tags helper
|
||||
*
|
||||
* @param TagsHelper $tagsHelper The tags helper to be set
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function setTagsHelper(TagsHelper $tagsHelper): void
|
||||
{
|
||||
$this->tagsHelper = $tagsHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the tags helper
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function clearTagsHelper(): void
|
||||
{
|
||||
$this->tagsHelper = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user