Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Categories/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Phproberto\Joomla\Entity\Traits as EntityTraits;
use Phproberto\Joomla\Entity\Exception\SaveException;
use Phproberto\Joomla\Entity\Core\Traits as CoreTraits;
use Phproberto\Joomla\Entity\Core\Contracts\Assetable;
use Phproberto\Joomla\Entity\Core\Contracts\Publishable;
use Phproberto\Joomla\Entity\Users\Traits as UsersTraits;
use Phproberto\Joomla\Entity\Validation\Contracts\Validable;
Expand All @@ -32,13 +33,14 @@
*
* @since 1.0.0
*/
class Category extends ComponentEntity implements Publishable, Translatable, Validable
class Category extends ComponentEntity implements Publishable, Translatable, Validable, Assetable
{
use CoreTraits\HasAccess, CoreTraits\HasAncestors, CoreTraits\HasAsset, CoreTraits\HasAssociations, CoreTraits\HasChildren;
use CoreTraits\HasDescendants, CoreTraits\HasLevel, CoreTraits\HasMetadata, CoreTraits\HasParams, CoreTraits\HasParent;
use CoreTraits\HasState;
use HasTranslations, HasValidation;
use UsersTraits\HasAuthor, UsersTraits\HasEditor;
use CoreTraits\HasAsset;

/**
* Cached root instance.
Expand Down
6 changes: 4 additions & 2 deletions src/Content/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
use Phproberto\Joomla\Entity\Categories\Category as BaseCategory;
use Phproberto\Joomla\Entity\Content\Command\CreateUncategorisedCategory;
use Phproberto\Joomla\Entity\Core\Contracts\Assetable;
use Phproberto\Joomla\Entity\Core\Traits\HasAsset;

/**
* Content category entity.
*
* @since 1.0.0
*/
class Category extends BaseCategory implements Aclable
class Category extends BaseCategory implements Aclable, Assetable
{
use HasArticles, HasAcl, HasLink, HasTags;
use HasArticles, HasAcl, HasLink, HasTags, HasAsset;

/**
* Extension associated to this category.
Expand Down
49 changes: 49 additions & 0 deletions src/Core/Contracts/Assetable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Joomla! entity library.
*
* @copyright Copyright (C) 2017-2019 Roberto Segura López, Inc. All rights reserved.
* @license See COPYING.txt
*/

namespace Phproberto\Joomla\Entity\Core\Contracts;

defined('_JEXEC') || die;

/**
* Publishable entities requirements.
*
* @since 1.0.0
*/
interface Assetable
{
/**
* Get the alias for a specific DB column.
*
* @param string $column Name of the DB column. Example: created_by
*
* @return string
*/
public function columnAlias($column);

/**
* Get a property of this entity.
*
* @param string $property Name of the property to get
* @param mixed $default Value to use as default if property is not set or is null
*
* @return mixed
*/
public function get($property, $default = null);

/**
* Get the associated asset.
*
* @param boolean $reload Force asset reloading
*
* @return Asset
*/
public function asset($reload = false);

public function getContentExtension();
}
5 changes: 5 additions & 0 deletions src/Core/Traits/HasAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public function asset($reload = false)
return $this->asset;
}

public function getContentExtension()
{
return self::$extension;
}

/**
* Load the asset from the database.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Phproberto\Joomla\Entity\Helper\ArrayHelper;
use Phproberto\Joomla\Entity\Exception\SaveException;
use Phproberto\Joomla\Entity\Contracts\EntityInterface;
use Phproberto\Joomla\Entity\Core\Contracts\Assetable;
use Phproberto\Joomla\Entity\Core\Traits as CoreTraits;
use Phproberto\Joomla\Entity\Exception\DeleteException;
use Phproberto\Joomla\Entity\Exception\InvalidEntityData;
Expand Down Expand Up @@ -300,6 +301,12 @@ public static function delete($ids)

foreach ($ids as $id)
{
if ($entity instanceof Assetable) {
$table->extension = $entity->getContentExtension();
$pk = $entity->primaryKey();
$table->$pk = $id;
}

if (!$table->delete($id))
{
$entity->bind([$entity->primaryKey() => $id]);
Expand Down