vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Create a New Thread as Poll (https://vborg.vbsupport.ru/showthread.php?t=247852)

Kozical 08-03-2010 02:51 AM

Create a New Thread as Poll
 
Hey, I have recently found code for creating a new post but I need to create a thread and hopefully without me having to personally write the sql inserts and queues to manually create a new thread that works as a poll.
I wanted to stop by here and ask the community if there was a way.

I am trying to make an application form to join my community and then once it is submitted have it automatically create a new poll thread that people will vote on. Rather than having to manually go in and create one every time someone applies..

Question again just for clarity:

I need the php code to create a new poll thread. Does anyone know where I can locate this?

Thanks!

Kozical 08-15-2010 10:26 PM

Well it seems noone cared to help or just didn't know how so I sought out the information I wanted and I will be nice and show you the class I wrote specifically for my forums. So you may want to modify it to suite your needs. However, I am trying to be nice by adding this here so please do not flame my coding style..

Code:


<?php
require_once('global.php');
require_once('includes/class_dm.php');
require_once('includes/class_dm_poll.php');
require_once('includes/class_dm_threadpost.php');
require_once('includes/functions_databuild.php');

define(FORUM_ID,                29); //-> Forum Id of poster's forum
define(USER_ID,                        1);  //-> User Id of poster

$instance = $vbulletin; //-> Fix for FATAL ERROR: Registry not found

class ThreadPoll
{
        var $threadId,
                $pollId,
                $forumId;
       
        function ThreadPoll()
        {
                $forumId = FORUM_ID;
        }
        function InitPoll($question)
        {
                global $instance;
                $poll =& datamanager_init('Poll', $instance, ERRTYPE_STANDARD);
               
                $poll->setr('question', $question);
                $poll->set_option("YES");
                $poll->set_option("NO");
                $poll->set_vote(0);
                $poll->pre_save();
                if (!empty($poll->errors))
                {
                        echo ($poll->errors);
                        exit;
                }
                $this->pollId = $poll->save();
                unset($poll);
        }
        function InitThread($title, $pagetext)
        {
                global $instance;
                $thread =& datamanager_init('Thread_FirstPost', $instance, ERRTYPE_ARRAY, 'threadpost');
                $forumInfo = fetch_foruminfo($forumId);
               
                $thread->set('forumid',                FORUM_ID);
                $thread->setr('title',                $title);
                $thread->setr('pagetext',        $pagetext);
                $thread->setr('pollid',                $this->pollId);
                $thread->set('userid',                USER_ID);
                $thread->set('open',                1);
                $thread->set('visible',                1);
                $thread->set('allowsmilie',        1);
               
                $thread->set_info('forum', $forumInfo);
                $thread->set_info('thread', array());
                $thread->pre_save();
               
                if (!empty($thread->errors))
                {
                        print_r($thread->errors);
                        exit;
                }
                $threadId = $thread->save();
                unset($thread);
        }       
        function BuildThread()
        {
                build_thread_counters($threadId);
                build_forum_counters(FORUM_ID);
        }
}

$obj = new ThreadPoll;

$obj->InitPoll("Poll Question");
$obj->InitThread("Title of the thread", "Text to be display in first post.. use \n for new line");
$obj->BuildThread();

?>


FortressGamers 03-09-2011 04:24 PM

I'm about to give this a go :)


All times are GMT. The time now is 07:46 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00944 seconds
  • Memory Usage 1,726KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete