Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2009, 12:20 AM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Is there a more efficient way to write this code?

I have a plugin I am using in two different locations, however it essentially does the exact same thing for each location with the exception that it pulls data from a different array to set the DM.

PHP Code:
global $sc_typeset;
if (
$sc_typeset == 'sc_typetask' OR $sc_typeset == 'sc_typeevent')
{
    if (
THIS_SCRIPT == 'newthread')
    {
        
$dataman->set('sc_typeset',         $post['sc_typeset']);
        
$dataman->setr('dateline_from',     $post['dateline_from']);
        
$dataman->setr('dateline_to',         $post['dateline_to']);
        
$dataman->setr('sc_description',    $post['sc_description']);
        
$dataman->setr('sc_location',        $post['sc_location']);
    }
    
    if (
THIS_SCRIPT == 'editpost')
    {
        
$dataman->set('sc_typeset',         $edit['sc_typeset']);
        
$dataman->setr('dateline_from',     $edit['dateline_from']);
        
$dataman->setr('dateline_to',         $edit['dateline_to']);
        
$dataman->setr('sc_description',    $edit['sc_description']);
        
$dataman->setr('sc_location',        $edit['sc_location']);
    }
    

As you can see, it's somewhat redundant. I want to include this same plugin code in both hook locations ('newpost_process' & 'editpost_update_process') and simply use a conditional to determine which array to pass to the DM. I was thinking on something like this:
PHP Code:
if (THIS_SCRIPT == 'newthread')
{
    
// use the $newpost array
}
else if (
THIS_SCRIPT == 'editpost')
{
    
// use the $edit array

So basically, what I am asking is if anyone can think of a shorter way to write this than I am currently using?

Thanks!
Reply With Quote
  #2  
Old 03-26-2009, 07:46 AM
AHealthForum AHealthForum is offline
 
Join Date: Mar 2009
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

THIS_SCRIPT == 'editpost' OR THIS_SCRIPT == 'newthread'

maybe?
Reply With Quote
  #3  
Old 03-26-2009, 10:37 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Put the code in a function and pass the array to be used as argument.
Reply With Quote
  #4  
Old 03-26-2009, 03:42 PM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

A function is another way of handling it, but actually the way I solved it was by simply using a new var like this:

PHP Code:
global $sc_typeset
if (
$sc_typeset == 'sc_typetask' OR $sc_typeset == 'sc_typeevent'

    if (
THIS_SCRIPT == 'newthread')
    {
        
$scdata $post;
    }
    else if (
THIS_SCRIPT == 'editpost')
    {
        
$scdata $edit;
    }
    
    
$dataman->set('sc_typeset',         $scdata['sc_typeset']);
    
$dataman->setr('dateline_from',     $scdata['dateline_from']);
    
$dataman->setr('dateline_to',         $scdata['dateline_to']);
    
$dataman->setr('sc_description',    $scdata['sc_description']);
    
$dataman->setr('sc_location',        $scdata['sc_location']);

It's silly now, as the solution was so simple i couldn't see it last night - just goes to show me that my brain doesn't really work all that well after 14+ hours of coding, lol.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:19 PM.


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.04618 seconds
  • Memory Usage 2,209KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete