Thread on usergroup promtion

KCGaming

Member
I have been trying to get a thread created when a usergroup promotion is done.

I have edited the cron in /library/XenForo/CronEntry/UserGroupPromotion.php

I read somewhere this worked but believe it might be for an earlier version off Xenforo

PHP:
<?php

/**
* Cron entry for executing user group promotions.
*/
class XenForo_CronEntry_UserGroupPromotion
{
    /**
    * Runs the cron-based check for new promotions that users should be awarded.
    */
    public static function runPromotions()
    {
        /* @var $promotionModel XenForo_Model_UserGroupPromotion */
        $promotionModel = XenForo_Model::create('XenForo_Model_UserGroupPromotion');
        $promotions = $promotionModel->getPromotions(array(
            'active' => 1
        ));
        if (!$promotions)
        {
            return;
        }
        /* @var $userModel XenForo_Model_User */
        $userModel = XenForo_Model::create('XenForo_Model_User');
        $users = $userModel->getUsers(array(
            'user_state' => 'valid',
            'is_banned' => 0,
            'last_activity' => array('>', XenForo_Application::$time - 2 * 3600)
        ), array(
            'join' => XenForo_Model_User::FETCH_USER_FULL
        ));
        $userPromotionStates = $promotionModel->getPromotionStatesByUserIds(array_keys($users));
        foreach ($users AS $userId => $user)
        {
            $promotionModel->updatePromotionsForUser(
                $user,
                isset($userPromotionStates[$userId]) ? $userPromotionStates[$userId] : array(),
                $promotions
            );
                        /**
                        Post a Thread addon
                        */
                            $forumId = "57";
                            $username = "Admin";
                            $userid = "1";
                            $subjet = $user['username']." Has been Promoted to ".$promotions['title'];
                                            $message = "Congradulations ".$user['username']." on your promtion to ".$promotions['title'].", your dedication to the clan is appreciated and you have earnt this promtion keep up the good work";
                            $writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
                            $writer->set('user_id', $userid);
                            $writer->set('username', $username);
                            $writer->set('title', $subjet);
                            $postWriter = $writer->getFirstMessageDw();
                            $postWriter->set('message', $message);
                            $writer->set('node_id', $forumId);
                                $writer->preSave();
                                $writer->save();
                                $thread = $writer->getMergedData();
        }
    }
}

Can someone please point me in the right direction for 1.2 Xenforo as this creates an error when run
"Undefined index: title"
 
I'm sure some one can point me to a file to browse where I might be able to see how this works or tell me of a nod to do this.

I run a gaming forum and really would like promotions of users posted as as thread to create content and encourgaing users to use the website, team speak and game servers
 
Hello KCGaming,
PHP:
$promotions = $promotionModel->getPromotions(array(
            'active' => 1
        ));
This will return array such as:
Code:
array(
    'promotion_id' => array(
        'informations'
    )
)
So if you get $promotions['title']
You can using this:
PHP:
foreach($promotions as $promotion)
{
    var_dump($promotion['title']);
}
 
Top Bottom