XF 2.1 Criteria User posted x messages in y days.

Yodrak

in memoriam 1976 - 2020
Hello i have made an criteria addon, which checks if a user has posted x messages in y days.
This addon should be used for demote users, where are not active for a given time in the forum.
The promotion to the group "Leecher" works fine, but after the user does not longer met the criteria,
the demotion does not work.

This is my code what im using.

PHP:
<?php

namespace Yodrak\Criteria;

use Yodrak\Criteria\XF\Entity\User;

class Listener
{
    public static function criteriaUser($rule, array $data, User $user, &$returnValue)
{
        switch ($rule)
        {
            case 'ycr_criteria_x_messages_y_days':
                                $date = floor(time()) - ($data['days'] * 86400);
                                $userId = \XF::visitor()->user_id;
                                $messages = $user->getMessageCountSinceDate($date, $userId);
                                if ($messages <= ($data['messages'])) {
                                    $returnValue = true;
                                }
        }
    }
}


PHP:
<?php

namespace Yodrak\Criteria\XF\Entity;

use XF\Mvc\Entity\ArrayCollection;
use XF\Mvc\Entity\Structure;
use XF\Util\Arr;

class User extends XFCP_User {

        public function getMessageCountSinceDate($date, $userId)
        {
          $finder = \XF::finder('XF:Post');
          $messages = $finder
            ->where('user_id', '=', $userId)
            ->where('post_date', '>', $date)
            ->where('message_state', '=', 'visible')
            ->fetch();
        }
      }
 
Does it apply when you rebuild the promotions via the tools section?

Promotions are only actively applied when users are active on the forum. If a user doesn't visit, their promotions won't be recalculated.
 
Does it apply when you rebuild the promotions via the tools section?

Promotions are only actively applied when users are active on the forum. If a user doesn't visit, their promotions won't be recalculated.

I have Testusers where met the criteria and i login with the Testusers. After this i let run the cronjob and the Testusers get promoted. If i post something with the Testusers they should get demoted, but this don't happen.
 
Top Bottom