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 06-21-2006, 01:55 PM
Guest190829
Guest
 
Posts: n/a
Default Custom Datamanagers

Anyone have experience with creating their own Datamanagers for large-scale projects?
Reply With Quote
  #2  
Old 06-21-2006, 02:15 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I wrote one once and decided not to use it. It wasn't difficult.
Reply With Quote
  #3  
Old 06-21-2006, 02:30 PM
tgreer tgreer is offline
 
Join Date: Oct 2005
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What would the pros and cons, advantages and disadvantages be?
Reply With Quote
  #4  
Old 06-21-2006, 02:37 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I liked that it gave me the option to let others hook into the mod I was writing and to use external scripts to work with it. It gave it a simple interface for other devs. It also provided good data verification mechanisms to validate incoming info.

But, I didn't like the extra overhead and went with a more simplistic approach for my own use when I decided that I did not want to release such a large modification.
Reply With Quote
  #5  
Old 06-21-2006, 02:39 PM
Alan @ CIT Alan @ CIT is offline
 
Join Date: Nov 2004
Location: South UK
Posts: 625
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Creating custom datamangers is fairly easy once you've done one

To start with, create your new PHP file to hold your DM code and save it as
includes/class_dm_example.php

Now, the first thing we need to do is check that the vB_Datamanger class exists - without that, we can't do much of anything.

At the top of your new PHP file, put:

PHP Code:
if (!class_exists('vB_DataManager'))
{
exit;

This will end the script if the vB_Datamanger class doesn't exist.

Now we need to extend the vB_DataManager class to make our own Datamanager.

On the next line down in your PHP file, put:

PHP Code:
class vB_DataManager_Example extends vB_DataManager

This tells PHP that we want to create a Class called "vB_DataManager_Example", and that we want to base it on the vB_DataManager class. This means that our new DM class will inherit all of the vB_DataManagers variables and methods (functions) so we don't have to make our own save() method for example

Now we need to give our new Datamanager some fields to update. For example, the User DM would have fields such as "userid", "username", "email", etc. These fields will usually be the same as the columns in your database table.

These fields all go in an array called $validfields. The $validfields array is in the following format:

PHP Code:
'fieldname' => array(typerequired?, verify data?, function name to verify data
The verificatoin options (the last 2) are optional.

With that in mind, lets start adding to our own $validfields array. Our example datamanager will have 4 fields:

'exampleid' - this is an auto increment field from the database which is incremented automaticly.
'userid' - a vBulletin user id
'username' - a vBulletin username
'exampletext' - some random text

First things first, lets create our $validfields array variable.

PHP Code:
var $validfields = array( 
Now we can add our first field:

PHP Code:
'exampleid' => array(TYPE_UINTREQ_INCRVF_METHOD'verify_nonzero'), 
Lets go through this line bit by bit.

First we have the field name - in this case 'exampleid'.
Next we have the type - in this case we're saying it will be an Unsigned Int (ie, a number). A list of valid types can be found at the bottom of this post.
Next we specify that it is required, and that it is an auto-increment value with REQ_INCR. Valid options for this field can be found at the bottom of this post.
Next we tell it that we want to verify the data, with VF_METHOD
And finally, we give it the name of a function to verifiy the data with. In this case, we are using the verify_nonzero() function which is a standard function in the vB_DataManager class.

Now we can add our other 3 fields to the $validfields array:

PHP Code:
'userid' => array(TYPE_UINTREQ_YESVF_METHOD'verify_nonzero'),
'username' => array(TYPE_STRREQ_YESVF_METHOD),
'exampletext' => array(TYPE_STRREQ_NO)
); 
This has added a further 3 fields to the $validfields, and closed the $validfields array

Now, the next step is to tell vBulletin what table to save our data in. Your table should match the $validfields array in terms of layout and column names.

In this case, we'll use a table called "example":

PHP Code:
var $table 'example'
Now we have to give vBulletin a temporary array that it uses to store the data we give it when it's saving to out database table that we specified above. It doesn't really matter what this is called, but for convention, try to stick with the name of your DM class

PHP Code:
var $example = array(); 
The final step in our very basic Datamanager is to create our Class Initator method. This is a function that is run automaticly when our Example Datamanager is created using datamanager_init().

PHP Code:
 function vB_DataManager_Example(&$registry$errtype ERRTYPE_STANDARD)
{
parent::vB_DataManager($registry$errtype);

The name of this functoin should be exactly the same as your class name. So in this case, we've called it "vB_DataManager_Example".

You don't need to worry about the rest of the code, and if you understand OOP, you'll know what it means

Now, all we've got left to do is add our closing bracket for our class, and we're done:

PHP Code:

You can now create your new Datamanager as you would any standard Datamanager by using the datamanager_init() function

That's the gist of it anyway, take a look at some of the existing Datamanagers for more advanced options such as Bitfields, custom verify methods, etc.

Valid field types:
  • TYPE_NOCLEAN - Any value - it won't be checked/cleaned
  • TYPE_INT - An signed integer
  • TYPE_UINT - An un-signed integer
  • TYPE_NUM - A number
  • TYPE_UNUM - An un-signed number
  • TYPE_UNIXTIME - A unix timestamp (time()
  • TYPE_STR - A string
  • TYPE_NOTRIM - A string that won't have trim() run on it
  • TYPE_NOHTML - A string that will have the HTML made-safe
  • TYPE_FILE - A file upload (ie, $_FILES)
  • TYPE_BOOL - A bool (true or false)
You can also pass Arrays of these items. For example to pass an array of INT's, use TYPE_ARRAY_INT. To pass an array of Strings, use TYPE_ARRAY_STR

Valid Requirement Options:

(The following is taken directly from vBulletin's DataManager documentation)

Quote:
REQ_YES - the field is required

REQ_NO - the field is not required

REQ_AUTO - the field can be automatically generated. The does not have any effect on code execution at this time. This is appropriate for things like post times that can be reasonably guessed before inserting the new data. (You will still need to write code to generate the appropriate value!)

REQ_INCR - this field is an AUTO_INCREMENT field in the database, and thus will be automatically generated upon insertion.
Hopefully all that ^^^ makes some sort of sense, and good luck making your new DataManager Danny

(class_dm_example.php attached)

Thanks,
Alan.
Attached Files
File Type: php class_dm_example.php (678 Bytes, 28 views)
Reply With Quote
  #6  
Old 06-21-2006, 08:32 PM
-=Sniper=- -=Sniper=- is offline
 
Join Date: May 2002
Posts: 605
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

wow, thanks Alan
Reply With Quote
  #7  
Old 06-21-2006, 08:49 PM
tgreer tgreer is offline
 
Join Date: Oct 2005
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Alan, would you be willing to make this an article? I've been exploring DataManagers on my own, so was pleased to see a public discussion on it here, and your excellent post did shed some light. Thanks.
Reply With Quote
  #8  
Old 06-21-2006, 08:50 PM
Alan @ CIT Alan @ CIT is offline
 
Join Date: Nov 2004
Location: South UK
Posts: 625
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'll try and clean it up a bit and post it as an Article. Not sure when though

Thanks,
Alan.
Reply With Quote
  #9  
Old 06-21-2006, 08:55 PM
Guest190829
Guest
 
Posts: n/a
Default

This is excellant Alan - Great job!
Reply With Quote
  #10  
Old 08-10-2007, 05:20 PM
kjhkjh's Avatar
kjhkjh kjhkjh is offline
 
Join Date: Jul 2005
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can this help me?? Or anyone here?

I have added forums to the table 'forum'
I have updated the parent ID's, descriptions etc of each of the forums that I've added.
I believe I now have to updates the datastore which is basically a series of records in an serialized form that has information about the forums and its permissions. (this was the advice vb.com gave but I can find no documentation about how to do this - especially how to do it safely)

They also said it would be in your best interested to look at http://member.vbulletin.com/api. In particular the Datamanager class for Forums. but the link isn't working for me.

Any help here is much appreciated - I'm trying to save myself over 100 hours of adding and updating forums - please help
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 11:31 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05677 seconds
  • Memory Usage 2,304KB
  • Queries Executed 14 (?)
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
  • (10)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (8)postbit_onlinestatus
  • (10)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
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_imicons
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete