Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Delegate request: access to rowset

edited April 2008 in Vanilla 1.0 Help
An extension I am working on needs additional information about the user in the comments page. I have attached to the CommentBuilder_PreSelect to add these columns to the query, but there doesn't appear to be any way to get to that information once its been retrieved from the database.

I will be playing with modifying /themes/comments.php to add a DelegateParameters['Row'] = $Row, but what I figured would be most useful would be to have a delegate return the result set just after it returns from the database.

Would it be possible to add a delegate to \library\Framework\Framework.Class.MySQL.php on line 86 right before GetRow returns $DataSet?

I figure the SenderObject and SenderMethod can be checked by the extension that attaches to this to make sure the query executed is the one the extension wants to capture.

Comments

  • MarkMark Vanilla Staff
    I realized a while ago that you can dynamically add properties to objects in PHP - at least in the version I was testing with. If anyone knows otherwise with different versions, please share.

    Anyway, my idea was to add delegates to the GetPropertiesFromDataSet methods on the comments and discussion objects. Then you could attach to the comment object's GetPropertiesFromDataSet method and make up your new property like..

    $DataSet = &$Comment->DelegateParameters['DataSet']; $Comment->MyNewProperty = ForceString($DataSet['MyNewColumnName'], '');

    Know what I mean? Then you can access your property down in the theme somewhere. It could be neato.
  • Interesting... then I just access the property just like Comment Protection does?

    Where can I learn more about this?
  • edited April 2008
    I would like to play with something like Mark says in the comment above, however, didn't find the delegate in Comment::GetPropertiesFromDataset(). should the new property be added beforehand in the database (as a new column, attached to the main table, e.g. comment table)? does this work? there's another, better, way of doing this? thanks PS: sorry for rescuing such an ooold thread :P
  • I asked this about my 'buy a drink' extension, wound up adding the column to the SQL query with one delegate and since Vanilla already read the row and moved on, I had to back up the dataset one record and re-read it again.

    Both records were from existing database values so I didn't have to add an additional column, but you can see examples of how to do that in some of Jazzman's extensions.

    I wouldn't really consider my method better then what I originally wanted since it seems kind of dispersed, but it works.

    You still also have the option of using the ObjectFactory to completely replace the comment class with another one that does what you want. My Forced Category extension does this.
  • edited April 2008
    wouldn't it be better to delegate the row from the database as a parameter (DelegateParameters['Row'] = $Row) ? so if we can add columns to the database and retrieve it by the SQL query (adding a select through delegation), i find it reasonable to be able to fetch these fields in the same way, saving another query to the DB. EDIT: I also thought about extending the Comment class and use it with the ObjectFactory, but involves more work for a thing that can be done by just adding a line of code. Thanks for the response, anyway!
  • miquel[W]ouldn't it be better to delegate the row from the database as a parameter (DelegateParameters['Row'] = $Row) ?
    I agree. The Discussion class offers the dataset as a delegate parameter, I find it weird and potentially frustrating that the Comment class doesn't. (I think every class ought to do that in their "GetPropertiesFromDataset"-type functions.)
  • I've seen in the SVN that the Dataset can be delegated, can i get the file, how? (i have no experience with svns... :( ) thanks
  • edited April 2008
    It's possible to save the file as a regular PHP right from your browser window and use it that way--but tiring if you wanted to check out all the changes. For that try Tortoise SVN, then right-click in the folder you want to export to, and select 'SVN Checkout'. It will ask for the URL you want to check out, enter http://lussumo.com/svn/vanilla/trunk/src/ Once Vanilla is checked out, go into the created library folder and check out the framework and people folders into that (delete them if they are already there--probably old stuff). http://lussumo.com/svn/framework/trunk/ http://lussumo.com/svn/people/trunk/ And then you should be all set!
  • can I replace the files in the svn directly for my old ones?
  • That should work fine. I'd make a backup first, just to be safe.
This discussion has been closed.