vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Can someone break down this code for me please? (https://vborg.vbsupport.ru/showthread.php?t=99370)

fly 10-26-2005 03:08 PM

Can someone break down this code for me please?
 
I know what it's supposed to do, and I know the outcome, but I'm having trouble determining what all the values are and why.

PHP Code:

$this->set('open'"IF(votenum >= 5 AND votetotal/votenum <= 2, 0, IF(votenum >= 5 AND votetotal/votenum >= 3 AND open=0, 1, open))"false); 

This little plugin was written for me by Kirby/Andreas, but I'm sure he's pretty busy right now. So if any of you have a minute...

Why the double quotes? What are the zeros for? What does the false at the end mean?

Thanks for the help.

Wired1 10-26-2005 03:42 PM

Here's a basic pseudocode breakdown:

$this->set('open', "BINARY SWITCH_1", false);

BINARY_SWITCH_1 = IF(votenum >= 5 AND votetotal/votenum <= 2, 0, BINARY_SWITCH_2)

BINARY_SWITCH_2 = IF(votenum >= 5 AND votetotal/votenum >= 3 AND open=0, 1, open)

The first part of the switches seems to relate to a voting schema.

For #2, if there's more than 5 votes with an average vote that is equal to or greater than 3, AND open = 0, then that part is true. Dunno what the 1, open means.

For # 1, there's more than 5 votes with an average vote that is equal to or less than 2, then that part is true. Dunno what the rest means.

Is that the whole plugin? Which plugin hook does it use?

Paul M 10-26-2005 04:03 PM

Why not just ask Andreas ?

fly 10-26-2005 04:16 PM

Quote:

Originally Posted by Paul M
Why not just ask Andreas ?

I could, but I bothered him enough to get this plugin written. Thought maybe someone else could help me out, as I'd like to add more to it but am failing to understand it.

btw, this is a 'thread rating moderation hack' It allows the users to vote crappy threads closed and good threads open...

Wired1 10-26-2005 06:49 PM

Makes more sense now, but I dunno why the if statement has 3 parts, unless it's another way to do a x ? y : z

Alan @ CIT 10-26-2005 07:59 PM

The IF() in the original code is an SQL if(), not a PHP if().

The format for SQL if() can be found here: http://dev.mysql.com/doc/refman/5.0/...functions.html

What the first IF() statement is saying is:

Code:

if 'votenum' is greater than or equal to '5' and 'votetotal' divded by 'votenum' is less than or equal to '2', then return '0'
The second one is saying:

Code:

if 'votenum' is greater than or equal to 5 and 'votetotal' devided by 'votenum' is greater than or equal to '3', then return '1', otherwise return 'open' (which in this case is 0)
As for the double quotes, they are there because the Jelsoft code standards say that all SQL should be enclosed in double quotes.

The 'false' at the end of the set() method indicates that the data being passed (in this case the SQL statement) doesn't need to be cleaned by vBulletin (characters converted, etc)

Look up the set() method in class_dm.php for more info on it's arguments.

fly 10-27-2005 11:11 AM

One more question. How do I determine what $this refers to? I'm guessing it just refers to the active table (maybe?), but how do I know what that is?

Thanks for all the help guys.

Alan @ CIT 10-27-2005 12:16 PM

The plugin that you posted is run within a PHP class. $this, refers to that class.

For more info on Object Orientated PHP, take a look at http://www.spoono.com/php/tutorials/tutorial.php?id=27 or http://www.php.net/manual/en/language.oop.php

fly 10-27-2005 03:46 PM

Quote:

Originally Posted by Alan @ CIT
The plugin that you posted is run within a PHP class. $this, refers to that class.

For more info on Object Orientated PHP, take a look at http://www.spoono.com/php/tutorials/tutorial.php?id=27 or http://www.php.net/manual/en/language.oop.php

Very helpful. Thank you.

How would I wrap that SQL IF statement inside a PHP contitional?

PHP Code:

if ("IF(votenum >= 5 AND votetotal/votenum <= 2")
{
stuff


I doubt that is correct, but it's my only guess...

edit: What about this?
PHP Code:

if ("IF(votenum >= 5 AND votetotal/votenum <= 2, 1, 0)" == '1'



All times are GMT. The time now is 04:42 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.01150 seconds
  • Memory Usage 1,737KB
  • 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
  • (2)bbcode_code_printable
  • (3)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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