This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

codacopia
codacopia

I have created the following partial:

 <?php

/**
 * Returns true if member is throttled and cannot post
 * again. Maximum 3 posts every 15 minutes.
 * @return bool
 */
public static function checkThrottle($member)
{
    if (!$member) {
        return false;
    }

    $timeLimit = Carbon::now()->subMinutes(15);
    $count = static::make()
        ->where('start_member_id', $member->id)
        ->where('created_at', '>', $timeLimit)
        ->count()
    ;

    return $count > 5;
}

   ?>

My attempt here is to allow 6 posts every 15 minutes. Ultimately I am going to modify the function to allow unlimited posts from specific users… but I digress. I have included this functions.htm partial reference in my topics.htm file like this: {{ topic.subject }} {% component 'forumTopic' %} {% partial "forum/functions" %}

I have then tested the topic posting and it still limits at 3. Any suggestions on how I can make this modification? Thanks.

Last updated

codacopia
codacopia

I have taken it a step back to see if editing the component function tied to the topic post rather than the model function will do the trick. So, in the same partial location I added the following:

public function onCreate()
{
    try {
        if (!$user = Auth::getUser()) {
            throw new ApplicationException('You should be logged in.');
        }

        $member = $this->getMember();
        $channel = $this->getChannel();

        if ($channel->is_moderated && !$member->is_moderator) {
            throw new ApplicationException('You cannot create a topic in this channel.');
        }

        if (TopicModel::checkThrottle($member)) {
            throw new ApplicationException('This is a custom output message...');
        }

        if ($member->is_banned) {
            throw new ApplicationException('You cannot create new topics: Your account is banned.');
        }

        $topic = TopicModel::createInChannel($channel, $member, post());
        $topicUrl = $this->currentPageUrl([$this->paramName('slug') => $topic->slug]);

        Flash::success(post('flash', 'Topic created successfully!'));

        /*
         * Extensbility
         */
        Event::fire('rainlab.forum.topic.create', [$this, $topic, $topicUrl]);
        $this->fireEvent('topic.create', [$topic, $topicUrl]);

        /*
         * Redirect to the intended page after successful update
         */
        $redirectUrl = post('redirect', $topicUrl);

        return Redirect::to($redirectUrl);
    }
    catch (Exception $ex) {
        Flash::error($ex->getMessage());
    }
}

So here you can see This is a custom output message... rather than the given message. This also is not working... Any ideas?

Last updated

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.