Is there anyway to remove the following prefix option when starting a new thread in a Q & A forum?
I guess, I'm wondering if there is some form of identifier I can test against to hide this option when a forum is detected that is running the solved feature.
I found this:
But am currently unsure how it is evaluated when the
newthread template is evaluated.
The following code block shows the section in the section I am referring to:
Code:
<vb:if condition="$prefix_options">
<label for="prefixfield" class="full">{vb:rawphrase prefix}:</label>
<select name="prefixid" id="prefixfield" class="full" tabindex="1">
<option value="">{vb:rawphrase no_prefix_meta}</option>
{vb:raw prefix_options}
</select>
<p class="description"></p>
</vb:if>
I'll keep digging and if I find a solution, I'll post it, else if someone else knows, please let me know.
Cheers
M
update
I have had some success with this:
Starting @ line 45 in the newthread template, find the code noted above and replace with the one below:
Code:
<!-- Start hiding the prefix option if Q & A thread -->
<vb:if condition="$forumid == 16">
<!-- Do Not show prefix options-->
<vb:else />
<!-- Start Prefix Options Display -->
<vb:if condition="$prefix_options">
<label for="prefixfield" class="full">{vb:rawphrase prefix}:</label>
<select name="prefixid" id="prefixfield" class="full" tabindex="1">
<option value="">{vb:rawphrase no_prefix_meta}</option>
{vb:raw prefix_options}
</select>
<p class="description"></p>
</vb:if>
<!-- End Prefix Options Display -->
</vb:if>
<!-- End hiding the prefix option if Q & A thread -->
you will note in the following line:
Code:
<vb:if condition="$forumid == 16">
You will need to change the number 16 for whatever your Q & A forumid is.
To find this out, you can execute the following SQL against your DB:
Code:
select * from forumprefixset;
This will provide you a list of all forums where you have selected them as Q & A type forums as shown below:
(I'm using mysql workbench in this example)
Hope this helps someone.
Next I'll see if I can get an array of forums based on the table
forumprefixset
SQL will be something like:
Code:
SELECT forumid from forumprefixset WHERE prefixsetid = 'solvedthread';
Once I can get this into an array and register that array as a variable vBulletin can accept, perhaps I can test against that array in the template and not have to manually code the forum ids in. This would mean a one time change in the newthread template and any forum could have this feature.
Any help with this would be really awesome as I am really unfamiliar with the vBulletin codebase and have just started looking into it.
I'll report back as I make progress.
Cheers
M
Update
Can select from an array now
Code:
<!-- Start hiding the prefix option if Q & A thread -->
<vb:if condition="in_array($forumid, array(16))">
Update
So I got this working,
I created a new plugin by using the
Add New Plugin in the Products & Plugins section as shown below.
The only reason I went down this route is to avoid changing any of the original plugins code. So I hope this method for extending the plugin is OK.
Then I added the following PHP code:
Code:
$result = $vbulletin->db->query_read("SELECT * FROM " . TABLE_PREFIX . "forumprefixset WHERE prefixsetid = 'solvedthread'");
$returnSolvedForumIDS = array();
while ($output = $vbulletin->db->fetch_array($result))
{
$returnSolvedForumIDS[] = $output['forumid'];
}
if(is_array($returnSolvedForumIDS)){
vB_Template::preRegister('newthread', array('returnSolvedForumIDS' => $returnSolvedForumIDS));
}
Finally in the
newthread template, as noted in the above template edits, the following change was made:
Find:
Code:
<vb:if condition="$prefix_options">
<label for="prefixfield" class="full">{vb:rawphrase prefix}:</label>
<select name="prefixid" id="prefixfield" class="full" tabindex="1">
<option value="">{vb:rawphrase no_prefix_meta}</option>
{vb:raw prefix_options}
</select>
<p class="description"></p>
</vb:if>
Replace with:
Code:
<!-- Start hiding the prefix option if Q & A thread -->
<vb:if condition="in_array($forumid, $returnSolvedForumIDS)">
<!-- Do Not show prefix options-->
<vb:else />
<!-- Start Prefix Options Display -->
<vb:if condition="$prefix_options">
<label for="prefixfield" class="full">{vb:rawphrase prefix}:</label>
<select name="prefixid" id="prefixfield" class="full" tabindex="1">
<option value="">{vb:rawphrase no_prefix_meta}</option>
{vb:raw prefix_options}
</select>
<p class="description"></p>
</vb:if>
<!-- End Prefix Options Display -->
</vb:if>
<!-- End hiding the prefix option if Q & A thread -->
The core bit of information I was missing, was the method used to return variables from PHP in a way that they can be used in conditional statements in vBulletin templates. This eluded me for a while but was the key to making the changes I required work. See below for the exact code I used to register the PHP variable for use in the template system:
Code:
vB_Template::preRegister('newthread', array('returnSolvedForumIDS' => $returnSolvedForumIDS));
As soon as this variable was registered, everything fell into place.
You could easily modify the original Plugins PHP code to return this information. It is probably the best way forward too, as the method outlined in this post does add an additional query, which is not really required, as the same query exists in the original plugin. As stated previously, I did this to:
- Separate the test/modification code from the actual plugin code
- Avoid changin the plugin code as I am not 100% sure if this is an OK thing to do?
- Teach myself and provide an example to others how to accomplish such modifications to the original plugin without changing any of the core plugin code.
I hope this helps someone else understand how this system works. I'll continue to extend this plugin via the separate plugin code.
Unless anyone has an issue with it, I'll keep posting updates on my progress.
Hope you have found this useful.
Cheers
M