First of all, I'm quite new to creating my own modules and plugins (and very much in learning stages!) and I find the help here excellent and very inspirational - thank you.
I'm trying to create a plugin that displays a notification when a new article has been created in a chosen category. Eventually, the plugin will link to a module which will display a link to the newly created article.
I'm doing this in stages and so far, so good. However, onContentAfterSave returns all new articles from the chosen category, but I just want to display one, the newest.
Here's what I have so far:
public function onContentAfterSave ($context, $article, $isNew)
{
}
public function onContentPrepare($context, &$article, &$params)
{
$category = $article->catid;
$article_title = $article->title;
$newarticlenotificationcategory = $this->params->get('newarticlenotificationcategory');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "
SELECT *
FROM #__content
WHERE (title LIKE '$article_title')
ORDER BY id DESC
LIMIT 1
;";
$db->setQuery($query);
$results = $db->loadObjectList();
if ($category == $newarticlenotificationcategory)
{
echo '<h3 style="color:white;background:red">There is a new article called - ' . $article_title . ' - ID - ' . $results->id . ' - in category - ' . $category . ' .</h3>';
}
}
Also, what do I have access to from $article and $isNew please?
Many thanks.
EDIT:
Thank you all for your answers and comments, it is appreciated. Based on everything I'm going to take the advice and scrap what I have and re-think my approach to this entirely. Once I have a working example of what I'm attempting to do I'll post an update here. Again, thanks everyone.