Fork me on GitHub

Multiple tables and hooks?  Bottom

Go to page 1 - 2 [+1]:

  • In my module, I have three main tables: people, organizations, and projects. Right now, I've got it set up so that only the projects have hooks available. If I want to make them available for the people and organizations, how might I go about doing that? Is there anything special I need to do? Or is it even possible?
  • I'm not sure I quite understand - you call transform hooks, for example, on the content you are going to display, so what's stopping you calling it on different sets of content?

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • Not transform hooks, but ... um, like EZComments or pnUpper. I can have people upload files to projects, but if I want to let them make comments on a person or organization, or also upload files for those, how would I do that?
  • You'd probably have to have a seperate display page for each thing you wanted to call display hook on..

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • This might help you unless we have a more comprehensive documentation about hooks.

    Frank

    --
    "He is not dangerous, he just wants to play...."
  • Hello,
    you will have a problem if you only pass the people's, project's or organization's id to the display hook as objectid because of course people can have the same id as an organization for instance
    but you can use the same system as Pagesetter :
    Pagesetter use pid_tid as objectid where pid is the publication type's id and tid the document's id.
    you can use:
    objectd = 1_peopleid for people
    objectid = 2_projectid for projects
    objectid = 3_orgganizationid for organizations
    doing this will permit the hook module to distinguish among people, projects and organizations
    Of course this will not work with hook modules that expect objectid to be numeric (so far Mark West's ping and trackback modules are the only released hook modules that expect objectid to be numeric this is the reason why they don't work with Pagesetter I don't know why Mark put this limitation in these 2 modules ?)

    --
    Visit my live reef aquarium.

    My Amazon wish list.
  • Hrrrrmmmmm.... So I can call the hooks in the template and not worry about it in the APIs?

    The Example Module sends something to hooks when it adds, deletes, and (.760) modifies things. Do I need to worry about that for my module to display other hooked modules, or is that for other modules to hook into mine? (I think this is a different question than I originally asked.) I think know how I'm going to modify things, but I want to make sure I understand what I'm doing first. :)
  • You can use display and transform hooks in templates if you want, all others need to be called in the code.

    Using a create/delete/update in a template does not make sense if there has not been anything created/deleted/updated before.

    Frank

    --
    "He is not dangerous, he just wants to play...."
  • jediping,

    I know what you are talking about. I wanted to use EZComments and a few other hooks on different pages in some of my modules, but in the current incarnation of the hooks system, you cannot do this. It only saves the module name and the item id. I added a feature request for this type of improvement http://noc.postnuke.…group_id=5&atid=104. Right now if you want comments (for example) on different types of data in the same module, you'll need to implement your own solution.

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • It is possible to use a displayhook on different pages of the same module if you create unique ids. Pagesetter is doing this currently using its own function. In fact its unique ids are a combination of publication type and publication id: pid_tid. This works quite well.

    The hooks have to support this because doing it this way means that the hookobject is not longer an int but a string - some hooks will throw an error!

    Have a look at the Pagesetter code.

    --
    "He is not dangerous, he just wants to play...."
  • That's interesting. I never thought of doing that. I'll have to try and implement that.

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • It is of course possible to specify unique IDs for tables that are numeric, as a very simple example you can set it so that the unit digit of the ID identifies the table, e.g.
    1, 11, 21, 31, 41, ... 12541, ... etc. all from table 1
    2, 12, 22, 32, 42, .... 12652, ... etc. all from table 2

    This allows up to 9 tables (you can obviously have as many tables as you want by extending the digits).

    Or if you want to be a little more fancy just use modulus and div... (Mod by number of tables to get table ID and div to get ID)... that way it doesn't matter if hooks require numeric IDs.
  • is this still the case?


    i want to use EZComments for multiple items (different tables).


    i have Artists and Albums. i can users to comment on both.

    is the unique ids still the only solution?
  • It will always be the only solution, unless you have a better way for discerning different content? :)

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • Couldn't the hooks implementation pass an optional "type" parameter in the argument array? I'm running into this same issue. The implementation seems limited to me. The unique ID solution seems more of a hack to me than a real solution. It would require maintaining an extra ID for each object and removing the convenience of using the primary key of the table as your object ID for auto-incrementing tables.

    Maybe I'm wrong, but I just think the hook implementation could be a little more robust.

Go to page 1 - 2 [+1]:

This list is based on users active over the last 60 minutes.