Version 1.7.0 - Stable
How to install / upgrade
Download joomla-entity-v1.7.0.zip an install through Joomla! Extension Manager.
New Features
New fitler.active_language
filter for ArticleSearch
& CategorySearch
It allows to show content only from the active language.
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
use Phproberto\Joomla\Entity\Categories\Search\CategorySearch;
// Return only articles assigned to the active language
$articles = ArticleSearch::instance(['filter.active_language' => true])->search();
// Return only categories assigned to the active language
$categories = CategorySearch::instance(['filter.active_language' => true])->search();
New IsNullOrPositiveInteger
validation rule.
This rule will check if a value is null or a positive integer. Useful to test foreign keys values.
use Phproberto\Joomla\Entity\Validation\Rule\IsNullOrPositiveInteger;
$rule = new IsNullOrPositiveInteger;
// True
var_dump($rule->passes(1));
var_dump($rule->passes('1'));
var_dump($rule->passes(1.0));
var_dump($rule->passes(null));
// False
var_dump($rule->passes('test-string'));
var_dump($rule->passes(''));
var_dump($rule->passes(1.1));
New IsZeroOrPositiveInteger
validation rule.
This new rule will return true when a value is zero or a positive integer (1,2,3,etc.)
use Phproberto\Joomla\Entity\Validation\Rule\IsZeroOrPositiveInteger;
$rule = new IsZeroOrPositiveInteger;
// True
var_dump($rule->passes(1));
var_dump($rule->passes('1'));
var_dump($rule->passes(1.0));
var_dump($rule->passes(0));
// False
var_dump($rule->passes('test-string'));
var_dump($rule->passes(''));
var_dump($rule->passes(1.1));
New filter.not_author_id
filter for ArticleSearch
Allows to show articles created by a different user. This can be useful to show related articles or to show an user articles he/she may be interested in.
use Phproberto\Joomla\Entity\Users\User;
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
$user = User::active();
// If the active user is not a guest load articles not created by him/her
$articles = $user->isGuest() ? [] : ArticleSearch::instance(['filter.not_author_id' => $user->id()])->search();
New filter.not_language
filter for ArticleSearch
.
It allows to search articles with a language different than the specified.
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Search articles that are not written in english
$articles = ArticleSearch::instance(['filter.not_language' => 'en-GB'])->search();
New CategoryValidator
assigned to Category
entity.
It prevents categories from being saved without the minimum required or valid data. You can see all the assigned validation rules here
use Phproberto\Joomla\Entity\Categories\Category;
$category = new Category;
$category->bind(['title' => 'My category']);
try
{
$category->save();
}
catch (\Exception $e)
{
/**
* This will show something like:
*
* Validation failed trying to create `category`:
* `category` is not valid:
* * `extension` does not pass `Not empty extension` validation rule
*/
echo $e->getMessage();
}
// This will add the missing extension and allow to save without errors;
$category->assign('extension', 'com_content');
try
{
$category->save();
}
catch (\Exception $e)
{
// No exception should happen
}
New TagSearch
class.
Use this class to search for tags.
use Phproberto\Joomla\Entity\Tags\Search\TagSearch;
// Only return tags with specific view level
$tags = TagSearch::instance(['filter.access' => 1])->search();
// Only return tags available for the active language
$tags = TagSearch::instance(['filter.active_language' => true])->search();
// Only return tags available for the active user
$tags = TagSearch::instance(['filter.active_user_access' => true])->search();
// Only return tags with specified ancestor
$tags = TagSearch::instance(['filter.ancestor_id' => 12])->search();
// Only return tags assigned to a specified content_item. This is only useful combined with filter.content_type_alias because 2 different content types can have the same id.
$tags = TagSearch::instance(['filter.content_item_id' => 14])->search();
// Only return tags from the specifiec content type
$tags = TagSearch::instance(['filter.content_type_alias' => 'com_content.article'])->search();
// Only return tags that are ascendants of the specified tag
$tags = TagSearch::instance(['filter.descendant_id' => 14])->search();
// Only return tags with the specified id/ids
$tags = TagSearch::instance(['filter.id' => [12,14]])->search();
// Only return tags with the specified language/languages
$tags = TagSearch::instance(['filter.language' => ['en-GB','*']])->search();
// Only return tags with the specified level/levels
$tags = TagSearch::instance(['filter.level' => 2])->search();
// Only return tags with ids distinct to the specified
$tags = TagSearch::instance(['filter.not_id' => [1,2]])->search();
// Only return tags that are direct children of specfied tags
$tags = TagSearch::instance(['filter.parent_id' => 1])->search();
// Only return published tags
$tags = TagSearch::instance(['filter.published' => 1])->search();
// Only return unpublished tags
$tags = TagSearch::instance(['filter.published' => 0])->search();
// Only return tags with a title, alias or path containing specified string
$tags = TagSearch::instance(['filter.search' => 'cars'])->search();
New HasTags::searchTags()
method to easily search within an entity tags.
use Phproberto\Joomla\Entity\Content\Article;
$article = Article::find(1);
// You can pass filters to the search as if you were directly using an TagSearch instance
$tags = $article->searchTags(['filter.published' => 1, 'list.limit' => 5]);
foreach ($tags as $tag)
{
echo 'Article `' . $article->get('title') . '` has ' . $tag->get('title) . ' tag';
}
New Category::searchArticles()
method to easily search within an category articles.
use Phproberto\Joomla\Entity\Content\Category;
$category = Category::find(1);
// You can pass filters to the search as if you were directly using an ArticleSearch instance
$articles = $article->searchTags(['filter.active_language' => true, 'list.limit' => 5]);
foreach ($articles as $article)
{
echo 'Category `' . $category->get('title') . '` has ' . $article->get('title) . ' article';
}
New HasTags::removeAllTags()
method
This method can be used to remove all the tags assigned to an entity.
use Phproberto\Joomla\Entity\Content\Article;
// This will unassign all the article tags
Article::find(1)->removeAllTags();