PDA

View Full Version : How to update thread field on new post


-=Sniper=-
29 Jun 2006, 15:37
I think this should help someone, I posted this as a question but now have it working.

First add the field foobar to the threads table (as an example). This is true/false based field, you will have to add your own checks, e.g who can update foobar etc

In the quick reply/new reply template/s add this HTML in the thread management area quick reply area

<label for="qr_foobar"><input type="checkbox" name="foobar" value="1" id="qr_foobar" accesskey="w" tabindex="4" />Please update my Foobar</label>

In threaddata_start

$this->validfields['foobar'] = array(TYPE_BOOL, REQ_NO);

In newpost_complete

$set_foobar_status = false;
if ($vbulletin->GPC['foobar'])
{
$set_foobar_status = true;
}
if ($set_foobar_status)
{
$thread =& datamanager_init('Thread', $vbulletin, ERRTYPE_SILENT, 'threadpost');
if ($type == 'thread')
{
$thread->set_existing($dataman->thread);
}
else
{
$thread->set_existing($threadinfo);
}

if ($set_foobar_status)
{
$thread->set('foobar', ($thread->fetch_field('foobar') == 1 ? 0 : 1));
}

$thread->save();
}

In newreply_post_start

$vbulletin->input->clean_array_gpc('p', array('foobar' => TYPE_BOOL));
$newpost['foobar'] =& $vbulletin->GPC['foobar'];

I hope this helps, the advanced coders please improve if needed :)

Paul M
29 Jun 2006, 18:49
Moved to Articles as a "how to".

Dean C
30 Jun 2006, 13:11
I'm pretty sure you don't have to instantiate a new instance of the Thread datamanager class.

-=Sniper=-
30 Jun 2006, 13:17
I based the code on how vb deals with openclose/sticky threads, when making a new post, so would be interested if we don't have to instantiate another instance of the thread manager class :)