1

I´m a bit puzzled where to start.

This should happen:

  1. admins should be able to edit a Usergroup and define the amount of articles members of this group can create.
  2. Before a group member creates/saves a new article in fronted, the amount of articles created by this user is compared to the max allowed articles of it´s group membership. Pseudo Code:

    if ($articlesCreatedByUser < $allowedArticlesByGroup){
      $article->save();
    } else {
      die('you reached the article limit');
    

As I´m just starting with Joomla development here my questions.

  • with Joomla3 it´s easy to create integer extra fields for Users, is this possible with Usergroups as well? If not what would be needed to extend the Usergroup backend form?
  • what´s the easiest way to limit the article creation form as explained above. I´m unsure if I should dive into plugin creation (and hook into beforesave) or to extend com_content and it´s model save method?

Thanks!

Toni

enter image description here

1 Answer 1

1

I would suggest developing a content plugin along with template override to do this task. The below example limits max 5 articles per day per user.

public function onContentBeforeSave($context, $article, $isNew)
{
    if ( $context != 'com_content.form' || !$isNew) 
    {
        return true;
    }

    $user = JFactory::getUser();
    $db = JFactory::getDbo();

    $query = $db->getQuery(true)
        ->select('count(*)')
        ->from('#__content')
        ->where('created_by = '.$user->id.' and created > CURDATE()');
    $db->setQuery($query);
    $articlesCreatedByUser = (int)$db->loadResult();

    // get the allowed articles somehow..
    $allowedArticlesByGroup = 5;

    // check the allowed articles.
    if ($articlesCreatedByUser >= $allowedArticlesByGroup)
    {
        $article->setError('Maximum of '.$allowedArticlesByGroup.' articles are allowed per day.');
        return false;
    }

    return true;
}

The plugin will prevent users from creating new articles beyond the allowed limit. Now to prevent users from accessing the create article page itself, override the form layout and add above logic.

2
  • Thanks Nagarjun! This is a great. Do you have a recommondation how to add an extra field to the Admin User Group form as well? (As written I would need to check if the user reached the allowed group limit and like to set the group limit in joomla backend for each group)
    – Anatol
    Jan 26, 2018 at 14:38
  • Found it, it should be possible to extend user groups with another plugin.
    – Anatol
    Jan 27, 2018 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.