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.
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();
}
}