The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Creating Custom Datamanagers
Note: Originally posted here: https://vborg.vbsupport.ru/showthrea...43#post1013143 ------------------------------------------------- Creating Custom Datamanagers This article will show you the basics of creating your own fully working Datamanager. 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:
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:
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:
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:
PHP Code:
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:
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:
PHP Code:
PHP Code:
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:
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:
Valid Requirement Options: (The following is taken directly from vBulletin's DataManager documentation) Quote:
Good luck using your new found knowledge of the vBulletin Input Cleaner class, and remember: If you get stuck, just ask! Knowledge sharing is what vBulletin.org is all about! (Note: If you want to reproduce this article anywhere, I have no objections, but I do request that you give me credit for writing it, and a PM letting me know would be appreciated ) |
#22
|
||||
|
||||
bump
|
#23
|
|||
|
|||
You are correct, as they are both referencing the same db object. I do not know vBulletin is not consistent in your particular example.
If you were to choose one, I would go with $this->registry->db As there must always be a valid registry object in the registry. |
#24
|
||||
|
||||
thanks for clarifying Danny
|
#25
|
|||
|
|||
Great article, will come in useful in the future I'm sure! Bookmarked.
|
#26
|
||||
|
||||
Can this help me?? Or anyone here?
I'm in the process of trying to add many forums without the ACP, here's where I'm up to: 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 to look at http://members.vbulletin.com/api. In particular the Datamanager class for Forums but it's difficult to know where to start. Any help here is much appreciated - I'm trying to save myself over 100 hours of adding and updating forums - please help |
#27
|
||||
|
||||
are you trying to create forum swith a datamanager? One doesn't exist ( i dont think) so you'll have to create the DM.
|
#28
|
||||
|
||||
thx for your reply.
I have no idea how to create them or what they are! But I was tld they could help me duplicate forums or just help me make the process of adding almost 2000 forums easier. Aparently they are the missing loop to make the forums that I added into the mysql table 'forum' appear by serializing the forums data and adding them to the datastore - I'm just repeating this from earlier advice but still no good because I have no idea.... Really wanted it to work out and had offered throughout the forum to pay someone to help, but no takers! So I've started adding the forums through the ACP... Just looks like its about 100 hours work (85%+ of the forums are redirects to an active forum) but this whole thing is still taking too much time. I'm about 20 hours into it... If someone comes up with a solution then I am open eared and open walleted |
#29
|
|||
|
|||
Any chance someone could give an example of this and cleansing using TYPE_ARRAY_INT or TYPE_ARRAY_STR?
I can get it to work normally but I'm having some trouble with the arrays. Thanks! |
#30
|
|||
|
|||
Figured it out
PHP Code:
|
#31
|
||||
|
||||
Hey, thanks, this was a real help. ^_^
One thing I'd like to ask, by trial and error I found out that I was (stupidly) forgetting to include includes/class_dm.php on my page. Now, I've got a page, g13.php, and two files I include, includes/class_dm_g13.php and includes/functions_g13.php. Should I include the includes/class_dm.php in my includes/class_dm_g13.php page, or just the main g13.php page? I'm currently doing the latter, but it would work jsut fine doing the former, right? |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|